sms-translate/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Collections.kt
Paul Akhamiogu 9656207135 Import SMS
2021-09-12 18:44:52 +01:00

32 lines
1 KiB
Kotlin

package com.simplemobiletools.smsmessenger.extensions
import android.content.ContentValues
inline fun <T> List<T>.indexOfFirstOrNull(predicate: (T) -> Boolean): Int? {
var index = 0
for (item in this) {
if (predicate(item))
return index
index++
}
return null
}
fun Map<String, Any>.toContentValues(): ContentValues {
val contentValues = ContentValues()
for (item in entries) {
when (val value = item.value) {
is String -> contentValues.put(item.key, value)
is Byte -> contentValues.put(item.key, value)
is Short -> contentValues.put(item.key, value)
is Int -> contentValues.put(item.key, value)
is Long -> contentValues.put(item.key, value)
is Float -> contentValues.put(item.key, value)
is Double -> contentValues.put(item.key, value)
is Boolean -> contentValues.put(item.key, value)
is ByteArray -> contentValues.put(item.key, value)
}
}
return contentValues
}