I currently have the following code
fun main() {
// Build.Fingerprint sample strings
val debug_fingerprint: String? = "Company/device/device:11/3526.4353/0064504902000:userdebug/com-d,dev-keys"
val dev_fingerprint: String? = "Company/device/device:11/526.4353/0064504902000:user/com-d,dev-keys"
val user_fingerprint: String? = "Company/device/device:11/526.4353/0064504902000:user/com-p,release-keys"
//Testing
val osVarient: String = user_fingerprint?.let {
when {
check(listOf("userdebug", "dev-keys"), it) -> "Userdebug"
check(listOf("user", "dev-keys"), it) -> "Userdevsigned"
check(listOf("user", "release-keys"), it) -> "User"
else -> "Unknown variant"
}
} ?: run {
"Unknown variant null"
}
print(osVarient)
}
fun check(args: List<String>,fingerprint: String): Boolean {
for(arg in args) {
if(!fingerprint.contains(arg)){
return false
}
}
return true
}
The above code works but I'm wondering if there is more elegant way of writing the code.
Are there any alternatives in Kotlin to compare multiple substrings to a string?