Compare commits

..

13 Commits

6 changed files with 87 additions and 16 deletions

View File

@@ -1,5 +1,29 @@
# Changelog # Changelog
## 0.5.22
* `Versions`
* `Kotlin`: `1.5.21` -> `1.5.30`
* `Klock`: `2.3.2` -> `2.3.4`
* `AppCompat`: `1.3.0` -> `1.3.1`
* `Ktor`: `1.6.2` -> `1.6.3`
## 0.5.21
* `Versions`
* `Klock`: `2.3.1` -> `2.3.2`
* `Serialization`
* `Typed Serializer`:
* `TypedSerializer` Descriptor serial name has been fixed
## 0.5.20
* `Repos`:
* `Common`
* `Android`:
* `*OrNull` analogs of `Cursor.get*(String)` extensions have been added
* Extensions `Cursor.getFloat` and `Cursor.getFloatOrNull` have been added
## 0.5.19 ## 0.5.19
* `LanguageCode`: * `LanguageCode`:

View File

@@ -12,9 +12,7 @@ package dev.inmo.micro_utils.common
AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.FUNCTION, AnnotationTarget.FUNCTION,
AnnotationTarget.TYPE, AnnotationTarget.TYPEALIAS
AnnotationTarget.TYPEALIAS,
AnnotationTarget.TYPE_PARAMETER
) )
annotation class PreviewFeature(val message: String = "It is possible, that behaviour of this thing will be changed or removed in future releases") annotation class PreviewFeature(val message: String = "It is possible, that behaviour of this thing will be changed or removed in future releases")
@@ -30,8 +28,6 @@ annotation class PreviewFeature(val message: String = "It is possible, that beha
AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.FUNCTION, AnnotationTarget.FUNCTION,
AnnotationTarget.TYPE, AnnotationTarget.TYPEALIAS
AnnotationTarget.TYPEALIAS,
AnnotationTarget.TYPE_PARAMETER
) )
annotation class Warning(val message: String) annotation class Warning(val message: String)

View File

@@ -11,7 +11,7 @@ class DiffUtilsTests {
val withIndex = oldList.withIndex() val withIndex = oldList.withIndex()
for (count in 1 .. (floor(oldList.size.toFloat() / 2).toInt())) { for (count in 1 .. (floor(oldList.size.toFloat() / 2).toInt())) {
for ((i, v) in withIndex) { for ((i, _) in withIndex) {
if (i + count > oldList.lastIndex) { if (i + count > oldList.lastIndex) {
continue continue
} }

View File

@@ -7,14 +7,14 @@ android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
org.gradle.jvmargs=-Xmx2g org.gradle.jvmargs=-Xmx2g
kotlin_version=1.5.21 kotlin_version=1.5.30
kotlin_coroutines_version=1.5.1 kotlin_coroutines_version=1.5.1
kotlin_serialisation_core_version=1.2.2 kotlin_serialisation_core_version=1.2.2
kotlin_exposed_version=0.33.1 kotlin_exposed_version=0.33.1
ktor_version=1.6.2 ktor_version=1.6.3
klockVersion=2.3.1 klockVersion=2.3.4
github_release_plugin_version=2.2.12 github_release_plugin_version=2.2.12
@@ -24,12 +24,12 @@ uuidVersion=0.3.0
core_ktx_version=1.6.0 core_ktx_version=1.6.0
androidx_recycler_version=1.2.1 androidx_recycler_version=1.2.1
appcompat_version=1.3.0 appcompat_version=1.3.1
android_minSdkVersion=19 android_minSdkVersion=19
android_compileSdkVersion=30 android_compileSdkVersion=30
android_buildToolsVersion=30.0.3 android_buildToolsVersion=30.0.3
dexcount_version=2.1.0-RC01 dexcount_version=3.0.0
junit_version=4.12 junit_version=4.12
test_ext_junit_version=1.1.2 test_ext_junit_version=1.1.2
espresso_core=3.3.0 espresso_core=3.3.0
@@ -45,5 +45,5 @@ dokka_version=1.5.0
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.5.19 version=0.5.22
android_code_version=60 android_code_version=63

View File

@@ -2,6 +2,8 @@ package dev.inmo.micro_utils.repos
import android.database.Cursor import android.database.Cursor
import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteDatabase
import androidx.core.database.*
import dev.inmo.micro_utils.repos.getLongOrNull
fun createTableQuery( fun createTableQuery(
tableName: String, tableName: String,
@@ -32,6 +34,11 @@ fun SQLiteDatabase.createTable(
fun Cursor.getString(columnName: String): String = getString( fun Cursor.getString(columnName: String): String = getString(
getColumnIndexOrThrow(columnName) getColumnIndexOrThrow(columnName)
) )
fun Cursor.getStringOrNull(columnName: String): String? {
return getStringOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/** /**
* @throws IllegalArgumentException * @throws IllegalArgumentException
@@ -39,6 +46,11 @@ fun Cursor.getString(columnName: String): String = getString(
fun Cursor.getShort(columnName: String): Short = getShort( fun Cursor.getShort(columnName: String): Short = getShort(
getColumnIndexOrThrow(columnName) getColumnIndexOrThrow(columnName)
) )
fun Cursor.getShortOrNull(columnName: String): Short? {
return getShortOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/** /**
* @throws IllegalArgumentException * @throws IllegalArgumentException
@@ -46,6 +58,11 @@ fun Cursor.getShort(columnName: String): Short = getShort(
fun Cursor.getLong(columnName: String): Long = getLong( fun Cursor.getLong(columnName: String): Long = getLong(
getColumnIndexOrThrow(columnName) getColumnIndexOrThrow(columnName)
) )
fun Cursor.getLongOrNull(columnName: String): Long? {
return getLongOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/** /**
* @throws IllegalArgumentException * @throws IllegalArgumentException
@@ -53,6 +70,23 @@ fun Cursor.getLong(columnName: String): Long = getLong(
fun Cursor.getInt(columnName: String): Int = getInt( fun Cursor.getInt(columnName: String): Int = getInt(
getColumnIndexOrThrow(columnName) getColumnIndexOrThrow(columnName)
) )
fun Cursor.getIntOrNull(columnName: String): Int? {
return getIntOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/**
* @throws IllegalArgumentException
*/
fun Cursor.getFloat(columnName: String): Float = getFloat(
getColumnIndexOrThrow(columnName)
)
fun Cursor.getFloatOrNull(columnName: String): Float? {
return getFloatOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/** /**
* @throws IllegalArgumentException * @throws IllegalArgumentException
@@ -60,6 +94,11 @@ fun Cursor.getInt(columnName: String): Int = getInt(
fun Cursor.getDouble(columnName: String): Double = getDouble( fun Cursor.getDouble(columnName: String): Double = getDouble(
getColumnIndexOrThrow(columnName) getColumnIndexOrThrow(columnName)
) )
fun Cursor.getDoubleOrNull(columnName: String): Double? {
return getDoubleOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
fun SQLiteDatabase.select( fun SQLiteDatabase.select(
table: String, table: String,

View File

@@ -8,11 +8,23 @@ import kotlin.reflect.KClass
open class TypedSerializer<T : Any>( open class TypedSerializer<T : Any>(
kClass: KClass<T>, kClass: KClass<T>,
presetSerializers: Map<String, KSerializer<out T>> = emptyMap() presetSerializers: Map<String, KSerializer<out T>> = emptyMap(),
) : KSerializer<T> { ) : KSerializer<T> {
protected val serializers = presetSerializers.toMutableMap() protected val serializers = presetSerializers.toMutableMap()
@InternalSerializationApi @InternalSerializationApi
open override val descriptor: SerialDescriptor = buildSerialDescriptor( override val descriptor: SerialDescriptor = buildSerialDescriptor(
"TypedSerializer",
SerialKind.CONTEXTUAL
) {
element("type", String.serializer().descriptor)
element("value", ContextualSerializer(kClass).descriptor)
}
@InternalSerializationApi
@Deprecated(
"This descriptor was deprecated due to incorrect serial name. You may use it in case something require it, " +
"but it is strongly recommended to migrate onto new descriptor"
)
protected val oldDescriptor: SerialDescriptor = buildSerialDescriptor(
"TextSourceSerializer", "TextSourceSerializer",
SerialKind.CONTEXTUAL SerialKind.CONTEXTUAL
) { ) {