mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-25 12:30:41 +02:00
Don't use reflection for handling backup options as boolean array
Wasn't working correctly in release build, _probably_ because of R8 despite kotlin-reflect shipping with Proguard rules and us already keeping all Tachiyomi classes.
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
package tachiyomi.core.util.lang
|
||||
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.full.declaredMemberProperties
|
||||
import kotlin.reflect.full.primaryConstructor
|
||||
|
||||
fun <T : Any> T.asBooleanArray(): BooleanArray {
|
||||
val constructorParams = this::class.primaryConstructor!!.parameters.map { it.name }
|
||||
val properties = this::class.declaredMemberProperties
|
||||
.filterIsInstance<KProperty1<T, Boolean>>()
|
||||
return constructorParams
|
||||
.map { param -> properties.find { it.name == param }!!.get(this) }
|
||||
.toBooleanArray()
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> BooleanArray.asDataClass(): T {
|
||||
val properties = T::class.declaredMemberProperties.filterIsInstance<KProperty1<T, Boolean>>()
|
||||
require(properties.size == this.size) { "Boolean array size does not match data class property count" }
|
||||
return T::class.primaryConstructor!!.call(*this.toTypedArray())
|
||||
}
|
||||
|
||||
fun <T : Any> T.anyEnabled(): Boolean {
|
||||
return this::class.declaredMemberProperties
|
||||
.filterIsInstance<KProperty1<T, Boolean>>()
|
||||
.any { it.get(this) }
|
||||
}
|
||||
Reference in New Issue
Block a user