Fix resources possibly defined under a different package name

This commit is contained in:
Mygod
2021-04-16 14:40:32 -04:00
parent 56155df3b8
commit 446ab8e624
3 changed files with 26 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package be.mygod.vpnhotspot.util
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.*
import android.content.res.Resources
import android.net.InetAddresses
import android.net.LinkProperties
import android.net.RouteInfo
@@ -134,6 +135,11 @@ var MenuItem.isNotGone: Boolean
isEnabled = value
}
fun Resources.findIdentifier(name: String, defType: String, defPackage: String, alternativePackage: String? = null) =
getIdentifier(name, defType, defPackage).let {
if (alternativePackage != null && it == 0) getIdentifier(name, defType, alternativePackage) else it
}
@get:RequiresApi(26)
private val newLookup by lazy @TargetApi(26) {
MethodHandles.Lookup::class.java.getDeclaredConstructor(Class::class.java, Int::class.java).apply {