From 6559e51ec2bf60609f69619829dd07b6e3d770c9 Mon Sep 17 00:00:00 2001 From: DatLag Date: Sun, 26 May 2024 19:33:07 +0200 Subject: [PATCH] update to K2 --- build.gradle.kts | 8 +- composeApp/build.gradle.kts | 7 +- gradle/libs.versions.toml | 20 +- .../dev/datlag/aniflow/model/CatchResult.kt | 180 ------------------ .../datlag/aniflow/nekos/NekosRepository.kt | 6 +- .../datlag/aniflow/trace/TraceRepository.kt | 6 +- 6 files changed, 24 insertions(+), 203 deletions(-) delete mode 100644 model/src/commonMain/kotlin/dev/datlag/aniflow/model/CatchResult.kt diff --git a/build.gradle.kts b/build.gradle.kts index 1348bda..c55668e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,14 +12,14 @@ plugins { alias(libs.plugins.android.library) apply false alias(libs.plugins.cocoapods) apply false alias(libs.plugins.compose) apply false - // alias(libs.plugins.compose.compiler) apply false + alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.crashlytics) apply false alias(libs.plugins.konfig) apply false alias(libs.plugins.multiplatform) apply false alias(libs.plugins.moko.resources) apply false alias(libs.plugins.sekret) apply false alias(libs.plugins.serialization) apply false - alias(libs.plugins.complete.kotlin) // Disable for K2 or bump version + // alias(libs.plugins.complete.kotlin) // Disable for K2 or bump version alias(libs.plugins.versions) } @@ -55,10 +55,6 @@ allprojects { tasks.withType().configureEach { compilerOptions { jvmTarget.set(JvmTarget.fromTarget(CompileOptions.jvmTargetString)) - freeCompilerArgs.addAll( - "-P", - "plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true" - ) } } plugins.withType { diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 8f4999f..075e20e 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -10,7 +10,7 @@ plugins { alias(libs.plugins.multiplatform) alias(libs.plugins.android.application) alias(libs.plugins.compose) - // alias(libs.plugins.compose.compiler) + alias(libs.plugins.compose.compiler) alias(libs.plugins.konfig) alias(libs.plugins.moko.resources) alias(libs.plugins.sekret) @@ -54,6 +54,11 @@ sekret { } } +composeCompiler { + enableStrongSkippingMode.set(true) + enableNonSkippingGroupOptimization.set(true) +} + kotlin { androidTarget() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c61e71a..3334f7b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,16 +13,16 @@ coil = "3.0.0-alpha06" compose = "1.6.10" complete-kotlin = "1.1.0" coroutines = "1.8.1" -crashlytics-plugin = "2.9.9" +crashlytics-plugin = "3.0.1" datastore = "1.1.1" datetime = "0.6.0-RC.2" decompose = "3.0.0" desugar = "2.0.4" -firebase = "1.11.1" -firebase-android = "20.4.3" -firebase-android-analytics = "21.6.2" -firebase-android-auth = "22.3.1" -firebase-android-crashlytics = "18.6.4" +firebase = "1.12.0" +firebase-android = "21.0.0" +firebase-android-analytics = "22.0.0" +firebase-android-auth = "23.0.0" +firebase-android-crashlytics = "19.0.0" flowredux = "1.2.1" google-identity = "1.1.0" haze = "0.7.1" @@ -35,15 +35,15 @@ kmpalette = "3.1.0" kodein = "7.22.0" kolor = "1.6.0" konfig = "0.15.1" -kotlin = "1.9.23" # K2 requires GitLive Firebase bump -ksp = "1.9.23-1.0.20" +kotlin = "2.0.0" # K2 requires GitLive Firebase bump +ksp = "2.0.0-1.0.21" ktor = "2.3.11" -ktorfit = "1.13.0" +ktorfit = "1.14.0" markdown-renderer = "0.16.0" moko-resources = "0.24.0-beta-4" multidex = "2.0.1" napier = "2.7.1" -sekret = "2.0.0-alpha-04" +sekret = "2.0.0-alpha-05" serialization = "1.6.3" splashscreen = "1.0.1" tooling = "1.4.0" diff --git a/model/src/commonMain/kotlin/dev/datlag/aniflow/model/CatchResult.kt b/model/src/commonMain/kotlin/dev/datlag/aniflow/model/CatchResult.kt deleted file mode 100644 index 685eaab..0000000 --- a/model/src/commonMain/kotlin/dev/datlag/aniflow/model/CatchResult.kt +++ /dev/null @@ -1,180 +0,0 @@ -package dev.datlag.aniflow.model - -import dev.datlag.aniflow.model.CatchResult.Companion.result -import dev.datlag.aniflow.model.CatchResult.Success -import dev.datlag.tooling.async.suspendCatching -import kotlinx.coroutines.* -import kotlin.time.Duration -import kotlin.time.Duration.Companion.milliseconds -import kotlin.time.Duration.Companion.seconds - -sealed interface CatchResult { - - val isSuccess: Boolean - get() = this is Success - - val isError: Boolean - get() = this is Error - - fun onSuccess(callback: (T & Any) -> Unit) = apply { - if (this is Success) { - callback(this.data) - } - } - - fun asSuccess(onError: (Throwable?) -> T & Any): T & Any { - return if (this is Success) { - this.data - } else { - onError((this as? Error)?.throwable) - } - } - - fun asNullableSuccess(onError: (Throwable?) -> T? = { null }): T? { - return if (this is Success) { - this.data - } else { - onError((this as? Error)?.throwable) - } - } - - fun asSuccessOrThrow(): T & Any { - return if (this is Success) { - this.data - } else { - throw (this as Error).throwable ?: IllegalStateException() - } - } - - fun validate(predicate: (CatchResult) -> Boolean): CatchResult { - return if (predicate(this)) { - this - } else { - Error(null) - } - } - - fun validateSuccess(predicate: (T & Any) -> Boolean): CatchResult { - return when (this) { - is Success -> { - if (predicate(this.data)) { - this - } else { - Error(null) - } - } - else -> this - } - } - - suspend fun mapSuccess(block: suspend (T & Any) -> M?): CatchResult { - return when (this) { - is Success -> { - block(this.data)?.let(::Success) ?: Error(null) - } - is Error -> { - Error(this.throwable) - } - } - } - - data class Success( - val data: T & Any - ) : CatchResult - - data class Error(val throwable: Throwable?) : CatchResult - - companion object { - suspend fun result(block: suspend CoroutineScope.() -> T): CatchResult = coroutineScope { - val result = suspendCatching(block = block) - return@coroutineScope if (result.isFailure) { - Error(result.exceptionOrNull()) - } else { - result.getOrNull()?.let(::Success) ?: Error(result.exceptionOrNull()) - } - } - - suspend fun repeat( - times: Int, - delayDuration: Duration = 0.seconds, - timeoutDuration: Duration = 0.seconds, - block: suspend CoroutineScope.() -> T - ): CatchResult = coroutineScope { - var result = if (timeoutDuration > 0.seconds) { - timeout(timeoutDuration, block) - } else { - result(block) - } - var request = 1 - - while (result.isError && request < times) { - delay(delayDuration) - result = if (timeoutDuration > 0.seconds) { - timeout(timeoutDuration, block) - } else { - result(block) - } - request++ - } - return@coroutineScope result - } - - suspend fun timeout( - time: Duration, - block: suspend CoroutineScope.() -> T - ): CatchResult = coroutineScope { - val result = suspendCatching( - catchTimeout = true - ) { - withTimeout(time) { - block() - } - } - - return@coroutineScope if (result.isFailure) { - Error(result.exceptionOrNull()) - } else { - result.getOrNull()?.let(::Success) ?: Error(result.exceptionOrNull()) - } - } - - suspend fun timeout( - timeMillis: Long, - block: suspend CoroutineScope.() -> T - ): CatchResult { - return timeout(timeMillis.milliseconds, block) - } - } -} - -suspend inline fun CatchResult.resultOnError(noinline block: CoroutineScope.() -> T): CatchResult { - return when (this) { - is CatchResult.Error -> result(block) - else -> this - } -} - -inline fun CatchResult<*>.mapError(block: (Throwable?) -> M?): CatchResult { - return when (this) { - is CatchResult.Error -> { - block(this.throwable)?.let(::Success) ?: CatchResult.Error(null) - } - is Success -> { - (this.data as? M)?.let(::Success) ?: block(null)?.let(::Success) ?: CatchResult.Error(null) - } - } -} - -inline fun CatchResult.asError(onSuccess: () -> Throwable? = { null }): Throwable? { - return if (this is CatchResult.Error) { - this.throwable - } else { - onSuccess() - } -} - -inline fun CatchResult.onError(callback: (Throwable?) -> Unit) = apply { - if (this is CatchResult.Error) { - callback(this.throwable) - } -} \ No newline at end of file diff --git a/nekos/src/commonMain/kotlin/dev/datlag/aniflow/nekos/NekosRepository.kt b/nekos/src/commonMain/kotlin/dev/datlag/aniflow/nekos/NekosRepository.kt index 49b8baa..548111d 100644 --- a/nekos/src/commonMain/kotlin/dev/datlag/aniflow/nekos/NekosRepository.kt +++ b/nekos/src/commonMain/kotlin/dev/datlag/aniflow/nekos/NekosRepository.kt @@ -1,8 +1,8 @@ package dev.datlag.aniflow.nekos -import dev.datlag.aniflow.model.CatchResult import dev.datlag.aniflow.nekos.model.ImagesResponse import dev.datlag.aniflow.nekos.model.Rating +import dev.datlag.tooling.async.suspendCatching import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.* @@ -17,13 +17,13 @@ class NekosRepository( @OptIn(ExperimentalCoroutinesApi::class) private val result = rating.mapLatest { - CatchResult.repeat(2) { + suspendCatching { nekos.images( rating = it.query ) } }.mapLatest { - State.fromResponse(it.asNullableSuccess()) + State.fromResponse(it.getOrNull()) } val response = combine(nsfw.distinctUntilChanged(), result, rating) { n, q, r -> if (n) { diff --git a/trace/src/commonMain/kotlin/dev/datlag/aniflow/trace/TraceRepository.kt b/trace/src/commonMain/kotlin/dev/datlag/aniflow/trace/TraceRepository.kt index 16c187c..356070e 100644 --- a/trace/src/commonMain/kotlin/dev/datlag/aniflow/trace/TraceRepository.kt +++ b/trace/src/commonMain/kotlin/dev/datlag/aniflow/trace/TraceRepository.kt @@ -1,7 +1,7 @@ package dev.datlag.aniflow.trace -import dev.datlag.aniflow.model.CatchResult import dev.datlag.aniflow.trace.model.SearchResponse +import dev.datlag.tooling.async.suspendCatching import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.* import kotlinx.serialization.Serializable @@ -22,9 +22,9 @@ class TraceRepository( } else { emit( State.fromResponse( - response = CatchResult.repeat(2) { + response = suspendCatching { trace.search(t1) - }.asNullableSuccess(), + }.getOrNull(), nsfw = t2 ) )