Update dependencies and refine code style

This commit is contained in:
Mygod
2019-09-19 10:35:51 +08:00
parent 5e2aeef1d2
commit 650b06beae
16 changed files with 105 additions and 42 deletions

View File

@@ -3,7 +3,6 @@ package be.mygod.vpnhotspot.net.wifi
import android.net.wifi.WifiConfiguration
import android.net.wifi.WifiManager
import be.mygod.vpnhotspot.App.Companion.app
import java.lang.IllegalArgumentException
object WifiApManager {
private val getWifiApConfiguration by lazy { WifiManager::class.java.getDeclaredMethod("getWifiApConfiguration") }
@@ -13,8 +12,8 @@ object WifiApManager {
var configuration: WifiConfiguration
get() = getWifiApConfiguration.invoke(app.wifi) as? WifiConfiguration ?: WifiConfiguration()
set(value) {
if (setWifiApConfiguration.invoke(app.wifi, value) as? Boolean != true) {
throw IllegalArgumentException("setWifiApConfiguration failed")
require(setWifiApConfiguration.invoke(app.wifi, value) as? Boolean == true) {
"setWifiApConfiguration failed"
}
}

View File

@@ -7,7 +7,6 @@ import android.net.wifi.p2p.WifiP2pManager
import be.mygod.vpnhotspot.DebugHelper
import com.android.dx.stock.ProxyBuilder
import timber.log.Timber
import java.lang.IllegalArgumentException
import java.lang.reflect.Proxy
object WifiP2pManagerHelper {
@@ -30,7 +29,7 @@ object WifiP2pManagerHelper {
listener: WifiP2pManager.ActionListener) {
try {
setWifiP2pChannels.invoke(this, c, lc, oc, listener)
} catch (e: NoSuchMethodException) {
} catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_setWifiP2pChannels")
listener.onFailure(UNSUPPORTED)
}
@@ -46,7 +45,7 @@ object WifiP2pManagerHelper {
try {
WifiP2pManager::class.java.getDeclaredMethod("startWps",
WifiP2pManager.Channel::class.java, WpsInfo::class.java, WifiP2pManager.ActionListener::class.java)
} catch (e: NoSuchMethodException) {
} catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_startWps")
null
}
@@ -69,7 +68,7 @@ object WifiP2pManagerHelper {
listener: WifiP2pManager.ActionListener) {
try {
deletePersistentGroup.invoke(this, c, netId, listener)
} catch (e: NoSuchMethodException) {
} catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_deletePersistentGroup")
listener.onFailure(UNSUPPORTED)
}

View File

@@ -7,7 +7,6 @@ import be.mygod.vpnhotspot.DebugHelper
import be.mygod.vpnhotspot.RepeaterService
import be.mygod.vpnhotspot.util.RootSession
import java.io.File
import java.lang.IllegalStateException
/**
* This parser is based on:

View File

@@ -1,5 +1,6 @@
package be.mygod.vpnhotspot.net.wifi.configuration
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.ClipData
import android.content.DialogInterface
@@ -90,6 +91,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
override fun AlertDialog.Builder.prepare(listener: DialogInterface.OnClickListener) {
val activity = requireActivity()
@SuppressLint("InflateParams")
dialogView = activity.layoutInflater.inflate(R.layout.dialog_wifi_ap, null)
setView(dialogView)
if (!arg.readOnly) setPositiveButton(R.string.wifi_save, listener)
@@ -103,8 +105,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
}
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) =
throw IllegalStateException("Must select something")
override fun onNothingSelected(parent: AdapterView<*>?) = error("Must select something")
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
dialogView.password_wrapper.isGone = position == WifiConfiguration.KeyMgmt.NONE
}