Use invoke operators

This commit is contained in:
Mygod
2020-05-30 21:01:22 -04:00
parent 6e5714913c
commit 9e820e888f
5 changed files with 24 additions and 25 deletions

View File

@@ -10,17 +10,15 @@ object WifiApManager {
WifiManager::class.java.getDeclaredMethod("setWifiApConfiguration", WifiConfiguration::class.java)
}
var configuration: WifiConfiguration
get() = getWifiApConfiguration.invoke(app.wifi) as? WifiConfiguration ?: WifiConfiguration()
set(value) {
require(setWifiApConfiguration.invoke(app.wifi, value) as? Boolean == true) {
"setWifiApConfiguration failed"
}
get() = getWifiApConfiguration(app.wifi) as? WifiConfiguration ?: WifiConfiguration()
set(value) = require(setWifiApConfiguration(app.wifi, value) as? Boolean == true) {
"setWifiApConfiguration failed"
}
private val cancelLocalOnlyHotspotRequest by lazy {
WifiManager::class.java.getDeclaredMethod("cancelLocalOnlyHotspotRequest")
}
fun cancelLocalOnlyHotspotRequest() = cancelLocalOnlyHotspotRequest.invoke(app.wifi)
fun cancelLocalOnlyHotspotRequest() = cancelLocalOnlyHotspotRequest(app.wifi)
private val setWifiApEnabled by lazy {
WifiManager::class.java.getDeclaredMethod("setWifiApEnabled",
@@ -37,7 +35,7 @@ object WifiApManager {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
private fun WifiManager.setWifiApEnabled(wifiConfig: WifiConfiguration?, enabled: Boolean) =
setWifiApEnabled.invoke(this, wifiConfig, enabled) as Boolean
setWifiApEnabled(this, wifiConfig, enabled) as Boolean
/**
* Although the functionalities were removed in API 26, it is already not functioning correctly on API 25.

View File

@@ -28,7 +28,7 @@ object WifiP2pManagerHelper {
fun WifiP2pManager.setWifiP2pChannels(c: WifiP2pManager.Channel, lc: Int, oc: Int,
listener: WifiP2pManager.ActionListener) {
try {
setWifiP2pChannels.invoke(this, c, lc, oc, listener)
setWifiP2pChannels(this, c, lc, oc, listener)
} catch (_: NoSuchMethodException) {
app.logEvent("NoSuchMethod_setWifiP2pChannels")
listener.onFailure(UNSUPPORTED)
@@ -51,7 +51,7 @@ object WifiP2pManagerHelper {
}
}
fun WifiP2pManager.startWps(c: WifiP2pManager.Channel, wps: WpsInfo, listener: WifiP2pManager.ActionListener) {
startWps!!.invoke(this, c, wps, listener)
startWps!!(this, c, wps, listener)
}
/**
@@ -66,7 +66,7 @@ object WifiP2pManagerHelper {
fun WifiP2pManager.deletePersistentGroup(c: WifiP2pManager.Channel, netId: Int,
listener: WifiP2pManager.ActionListener) {
try {
deletePersistentGroup.invoke(this, c, netId, listener)
deletePersistentGroup(this, c, netId, listener)
} catch (_: NoSuchMethodException) {
app.logEvent("NoSuchMethod_deletePersistentGroup")
listener.onFailure(UNSUPPORTED)
@@ -96,11 +96,11 @@ object WifiP2pManagerHelper {
override fun invoke(proxy: Any, method: Method, args: Array<out Any?>?): Any? = when (method.name) {
"onPersistentGroupInfoAvailable" -> {
if (args?.size != 1) Timber.w(IllegalArgumentException("Unexpected args: $args"))
@Suppress("UNCHECKED_CAST") listener(getGroupList.invoke(args!![0]) as Collection<WifiP2pGroup>)
@Suppress("UNCHECKED_CAST") listener(getGroupList(args!![0]) as Collection<WifiP2pGroup>)
}
else -> callSuper(interfacePersistentGroupInfoListener, proxy, method, args)
}
})
requestPersistentGroupInfo.invoke(this, c, proxy)
requestPersistentGroupInfo(this, c, proxy)
}
}