mirror of
				https://github.com/InsanusMokrassar/MicroUtils.git
				synced 2025-10-31 04:05:32 +00:00 
			
		
		
		
	Compare commits
	
		
			29 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c9bbfa3820 | |||
| eed7cfdc42 | |||
| bd9b0d16ab | |||
| ea6c33b497 | |||
| dc80ade2fb | |||
| f6a06ee8ea | |||
| 2644f27975 | |||
| 3dc68a7b8b | |||
| 97fc1d6239 | |||
| 662f4d22a3 | |||
| b70aa12be9 | |||
| 71f12f5f19 | |||
| e10504eeeb | |||
| 2dea9f3bc0 | |||
| 35c9dda5bc | |||
| e831f3949a | |||
| b0b39cc693 | |||
| fc03be3f73 | |||
| b61f6b81f1 | |||
| f5bc1c1fce | |||
| a729f9568c | |||
| 5749e00377 | |||
| ef73c24a0c | |||
| 94717ee351 | |||
| 9a18ded65b | |||
| b23220f491 | |||
| 6e6bb03246 | |||
| 1ae6bae3b8 | |||
| 57b7797ea4 | 
							
								
								
									
										39
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -1,5 +1,44 @@ | |||||||
| # Changelog | # Changelog | ||||||
|  |  | ||||||
|  | ## 0.5.24 | ||||||
|  |  | ||||||
|  | * `Versions`: | ||||||
|  |     * `Coroutines`: `1.5.1` -> `1.5.2` | ||||||
|  |     * `Klock`: `2.3.4` -> `2.4.1` | ||||||
|  | * `Coroutines`: | ||||||
|  |     * New function `CoroutineScope` with safely exceptions handler as second parameter | ||||||
|  |  | ||||||
|  | ## 0.5.23 | ||||||
|  |  | ||||||
|  | * `Versions`: | ||||||
|  |     * `Exposed`: `0.33.1` -> `0.34.1` | ||||||
|  | * `Common`: | ||||||
|  |     * New extensions `Iterable#joinTo` and `Array#joinTo` | ||||||
|  |  | ||||||
|  | ## 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`: | ||||||
|   | |||||||
| @@ -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) | ||||||
|   | |||||||
| @@ -0,0 +1,59 @@ | |||||||
|  | package dev.inmo.micro_utils.common | ||||||
|  |  | ||||||
|  | inline fun <I, R> Iterable<I>.joinTo( | ||||||
|  |     crossinline separatorFun: (I) -> R?, | ||||||
|  |     prefix: R? = null, | ||||||
|  |     postfix: R? = null, | ||||||
|  |     crossinline transform: (I) -> R? | ||||||
|  | ): List<R> { | ||||||
|  |     val result = mutableListOf<R>() | ||||||
|  |     val iterator = iterator() | ||||||
|  |  | ||||||
|  |     prefix ?.let(result::add) | ||||||
|  |  | ||||||
|  |     while (iterator.hasNext()) { | ||||||
|  |         val element = iterator.next() | ||||||
|  |         result.add(transform(element) ?: continue) | ||||||
|  |  | ||||||
|  |         if (iterator.hasNext()) { | ||||||
|  |             result.add(separatorFun(element) ?: continue) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     postfix ?.let(result::add) | ||||||
|  |  | ||||||
|  |     return result | ||||||
|  | } | ||||||
|  |  | ||||||
|  | inline fun <I, R> Iterable<I>.joinTo( | ||||||
|  |     separator: R? = null, | ||||||
|  |     prefix: R? = null, | ||||||
|  |     postfix: R? = null, | ||||||
|  |     crossinline transform: (I) -> R? | ||||||
|  | ): List<R> = joinTo({ separator }, prefix, postfix, transform) | ||||||
|  |  | ||||||
|  | inline fun <I> Iterable<I>.joinTo( | ||||||
|  |     crossinline separatorFun: (I) -> I?, | ||||||
|  |     prefix: I? = null, | ||||||
|  |     postfix: I? = null | ||||||
|  | ): List<I> = joinTo<I, I>(separatorFun, prefix, postfix) { it } | ||||||
|  |  | ||||||
|  | inline fun <I> Iterable<I>.joinTo( | ||||||
|  |     separator: I? = null, | ||||||
|  |     prefix: I? = null, | ||||||
|  |     postfix: I? = null | ||||||
|  | ): List<I> = joinTo<I>({ separator }, prefix, postfix) | ||||||
|  |  | ||||||
|  | inline fun <I, reified R> Array<I>.joinTo( | ||||||
|  |     crossinline separatorFun: (I) -> R?, | ||||||
|  |     prefix: R? = null, | ||||||
|  |     postfix: R? = null, | ||||||
|  |     crossinline transform: (I) -> R? | ||||||
|  | ): Array<R> = asIterable().joinTo(separatorFun, prefix, postfix, transform).toTypedArray() | ||||||
|  |  | ||||||
|  | inline fun <I, reified R> Array<I>.joinTo( | ||||||
|  |     separator: R? = null, | ||||||
|  |     prefix: R? = null, | ||||||
|  |     postfix: R? = null, | ||||||
|  |     crossinline transform: (I) -> R? | ||||||
|  | ): Array<R> = asIterable().joinTo(separator, prefix, postfix, transform).toTypedArray() | ||||||
| @@ -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 | ||||||
|                 } |                 } | ||||||
|   | |||||||
| @@ -147,3 +147,10 @@ suspend inline fun <T> runCatchingSafelyWithoutExceptions( | |||||||
| ): Result<T?> = runCatching { | ): Result<T?> = runCatching { | ||||||
|     safelyWithoutExceptions(onException, block) |     safelyWithoutExceptions(onException, block) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | inline fun CoroutineScope( | ||||||
|  |     context: CoroutineContext, | ||||||
|  |     noinline defaultExceptionsHandler: ExceptionHandler<Unit> | ||||||
|  | ) = CoroutineScope( | ||||||
|  |     context + ContextSafelyExceptionHandler(defaultExceptionsHandler) | ||||||
|  | ) | ||||||
|   | |||||||
| @@ -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.2 | ||||||
| kotlin_serialisation_core_version=1.2.2 | kotlin_serialisation_core_version=1.2.2 | ||||||
| kotlin_exposed_version=0.33.1 | kotlin_exposed_version=0.34.1 | ||||||
|  |  | ||||||
| ktor_version=1.6.2 | ktor_version=1.6.3 | ||||||
|  |  | ||||||
| klockVersion=2.3.1 | klockVersion=2.4.1 | ||||||
|  |  | ||||||
| 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.24 | ||||||
| android_code_version=60 | android_code_version=65 | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							| @@ -1,5 +1,5 @@ | |||||||
| distributionBase=GRADLE_USER_HOME | distributionBase=GRADLE_USER_HOME | ||||||
| distributionPath=wrapper/dists | distributionPath=wrapper/dists | ||||||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||||||
| zipStoreBase=GRADLE_USER_HOME | zipStoreBase=GRADLE_USER_HOME | ||||||
| zipStorePath=wrapper/dists | zipStorePath=wrapper/dists | ||||||
|   | |||||||
| @@ -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, | ||||||
|   | |||||||
| @@ -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 | ||||||
|     ) { |     ) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user