Fix lint and incorrect lifecycle owner

This commit is contained in:
Mygod
2020-06-11 03:51:12 +08:00
parent b9994bda9e
commit b20e3ab4a7
11 changed files with 34 additions and 23 deletions

View File

@@ -31,14 +31,14 @@ class EBegFragment : AppCompatDialogFragment() {
}.setListener(this).build().also { it.startConnection(this) }
}
override fun onBillingSetupFinished(billingResult: BillingResult?) {
if (billingResult?.responseCode == BillingClient.BillingResponseCode.OK) {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
billingClient.queryPurchases(BillingClient.SkuType.INAPP).apply {
if (responseCode == BillingClient.BillingResponseCode.OK) {
onPurchasesUpdated(this.billingResult, purchasesList)
}
}
} else Timber.e("onBillingSetupFinished: ${billingResult?.responseCode}")
} else Timber.e("onBillingSetupFinished: ${billingResult.responseCode}")
}
override fun onBillingServiceDisconnected() {
@@ -46,11 +46,11 @@ class EBegFragment : AppCompatDialogFragment() {
billingClient.startConnection(this)
}
override fun onPurchasesUpdated(billingResult: BillingResult?, purchases: MutableList<Purchase>?) {
if (billingResult?.responseCode == BillingClient.BillingResponseCode.OK && purchases != null) {
override fun onPurchasesUpdated(billingResult: BillingResult, purchases: MutableList<Purchase>?) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && purchases != null) {
// directly consume in-app purchase, so that people can donate multiple times
purchases.filter { it.purchaseState == Purchase.PurchaseState.PURCHASED }.map(this::consumePurchase)
} else Timber.e("onPurchasesUpdated: ${billingResult?.responseCode}")
} else Timber.e("onPurchasesUpdated: ${billingResult.responseCode}")
}
private fun consumePurchase(purchase: Purchase) = GlobalScope.launch(Dispatchers.Main.immediate) {

View File

@@ -241,6 +241,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
if (!safeMode && key == KEY_OPERATING_CHANNEL) setOperatingChannel()
}
@SuppressLint("NewApi") // networkId is available since Android 4.2
private fun onPersistentGroupsChanged() {
val channel = channel ?: return
val device = binder.thisDevice ?: return

View File

@@ -109,10 +109,11 @@ class ClientsFragment : Fragment() {
"${Formatter.formatFileSize(app, send)}/s\t\t${Formatter.formatFileSize(app, receive)}/s"
}
private inner class ClientViewHolder(val binding: ListitemClientBinding) : RecyclerView.ViewHolder(binding.root),
View.OnClickListener, PopupMenu.OnMenuItemClickListener {
private inner class ClientViewHolder(parent: ViewGroup, val binding: ListitemClientBinding =
ListitemClientBinding.inflate(LayoutInflater.from(parent.context), parent, false)) :
RecyclerView.ViewHolder(binding.root), View.OnClickListener, PopupMenu.OnMenuItemClickListener {
init {
binding.lifecycleOwner = binding.root.findViewTreeLifecycleOwner()
binding.lifecycleOwner = parent.findViewTreeLifecycleOwner()!!
binding.root.setOnClickListener(this)
binding.description.movementMethod = LinkMovementMethod.getInstance()
}
@@ -178,9 +179,7 @@ class ClientsFragment : Fragment() {
binding.swipeRefresher.isRefreshing = false
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
ClientViewHolder(ListitemClientBinding.inflate(LayoutInflater.from(parent.context), parent, false))
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ClientViewHolder(parent)
override fun onBindViewHolder(holder: ClientViewHolder, position: Int) {
val client = getItem(position)
holder.binding.client = client

View File

@@ -59,8 +59,8 @@ enum class TetherType(@DrawableRes val icon: Int) {
}
@RequiresApi(30)
override fun onTetherableInterfaceRegexpsChanged() {
Timber.i("onTetherableInterfaceRegexpsChanged")
override fun onTetherableInterfaceRegexpsChanged(args: Array<out Any?>?) {
Timber.i("onTetherableInterfaceRegexpsChanged: ${args?.contentToString()}")
TetheringManager.unregisterTetheringEventCallback(this)
requiresUpdate = true
listener()

View File

@@ -333,7 +333,7 @@ object TetheringManager {
* *@param reg The new regular expressions.
* @hide
*/
fun onTetherableInterfaceRegexpsChanged() {}
fun onTetherableInterfaceRegexpsChanged(args: Array<out Any?>?) {}
/**
* Called when there was a change in the list of tetherable interfaces. Tetherable
@@ -437,7 +437,7 @@ object TetheringManager {
callback?.onUpstreamChanged(args!![0] as Network?)
}
"onTetherableInterfaceRegexpsChanged" -> {
if (regexpsSent) callback?.onTetherableInterfaceRegexpsChanged()
if (regexpsSent) callback?.onTetherableInterfaceRegexpsChanged(args)
regexpsSent = true
}
"onTetherableInterfacesChanged" -> {

View File

@@ -1,5 +1,6 @@
package be.mygod.vpnhotspot.net.wifi
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.net.MacAddress
import android.net.wifi.SoftApConfiguration
@@ -237,6 +238,7 @@ data class SoftApConfigurationCompat(
* https://android.googlesource.com/platform/packages/apps/Settings/+/android-5.0.0_r1/src/com/android/settings/wifi/WifiApDialog.java#88
* https://android.googlesource.com/platform/packages/apps/Settings/+/b1af85d/src/com/android/settings/wifi/tether/WifiTetherSettings.java#162
*/
@SuppressLint("NewApi") // https://android.googlesource.com/platform/frameworks/base/+/android-5.0.0_r1/wifi/java/android/net/wifi/WifiConfiguration.java#1385
@Deprecated("Class deprecated in framework")
@Suppress("DEPRECATION")
fun toWifiConfiguration(): android.net.wifi.WifiConfiguration {

View File

@@ -127,7 +127,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dip"
style="@style/wifi_item_label"
android:text="Hidden network"/>
android:text="@string/wifi_hidden_network"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@@ -2,11 +2,15 @@
<!--
Values copied from:
* https://android.googlesource.com/platform/packages/apps/Settings/+/7686ef8/res/xml/tether_prefs.xml
* https://android.googlesource.com/platform/packages/apps/Settings/+/5697a7e/res/values/strings.xml
* https://android.googlesource.com/platform/packages/apps/Settings/+/37c9c5b/res/values/strings.xml
* @string/usb_tethering_button_text
* @string/wifi_hotspot_checkbox_text
* @string/bluetooth_tether_checkbox_text
* @string/ethernet_tether_checkbox_text
* @string/wifi_ap_choose_auto
* @string/wifi_ap_choose_2G
* @string/wifi_ap_choose_5G
* @string/wifi_hidden_network
-->
<resources>
<string name="app_name">VPN Hotspot</string>
@@ -163,6 +167,7 @@
<string name="wifi_ap_choose_2G">2.4 GHz Band</string>
<string name="wifi_ap_choose_5G">5.0 GHz Band</string>
<string name="wifi_ap_choose_6G">6.0 GHz Band</string>
<string name="wifi_hidden_network">Hidden network</string>
<string name="wifi_save">Save</string>
<!-- Based on: https://github.com/PrivacyApps/donations/blob/747d36a18433c7e9329691054122a8ad337a62d2/Donations/src/main/res/values/donations__strings.xml -->