From 26a42ba9c01c670f60bedfca41bd72c99aa2a278 Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 11 Oct 2022 22:40:02 -0400 Subject: [PATCH] Upgrade to Kotlin 1.7.20 Also run formatter and address some deprecation warnings. --- .../tachiyomi/data/coil/MangaCoverFetcher.kt | 2 +- .../data/download/model/DownloadQueue.kt | 3 --- .../tachiyomi/util/system/ContextExtensions.kt | 8 +++++++- .../core/preference/AndroidPreference.kt | 17 +++++++---------- .../core/preference/AndroidPreferenceStore.kt | 12 ++++++------ .../tachiyomi/core/preference/Preference.kt | 1 - .../core/preference/PreferenceStore.kt | 9 ++++----- .../provider/AndroidBackupFolderProvider.kt | 3 +-- .../provider/AndroidDownloadFolderProvider.kt | 5 ++--- .../tachiyomi/core/provider/FolderProvider.kt | 2 -- .../core/security/SecurityPreferences.kt | 2 +- .../tachiyomi/network/JavaScriptEngine.kt | 2 +- .../kanade/tachiyomi/network/NetworkHelper.kt | 1 - .../tachiyomi/network/NetworkPreferences.kt | 3 +-- .../tachiyomi/network/OkHttpExtensions.kt | 2 ++ .../tachiyomi/util/lang/RxCoroutineBridge.kt | 2 ++ gradle/compose.versions.toml | 2 +- gradle/kotlinx.versions.toml | 2 +- gradle/libs.versions.toml | 2 +- .../macrobenchmark/BaselineProfileGenerator.kt | 2 +- .../macrobenchmark/StartupBenchmark.kt | 4 ++-- .../tachiyomi/source/model/UpdateStrategy.kt | 2 +- 22 files changed, 42 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt b/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt index 21895c7d2..d7973936b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt @@ -232,7 +232,7 @@ class MangaCoverFetcher( val editor = diskCacheLazy.value.edit(diskCacheKey) ?: return null try { diskCacheLazy.value.fileSystem.write(editor.data) { - response.body!!.source().readAll(this) + response.body.source().readAll(this) } return editor.commitAndGet() } catch (e: Exception) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt index 137e7dfd0..96ce16153 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt @@ -74,14 +74,12 @@ class DownloadQueue( private fun getActiveDownloads(): Observable = Observable.from(this).filter { download -> download.status == Download.State.DOWNLOADING } - @Deprecated("Use getStatusAsFlow instead") private fun getStatusObservable(): Observable = statusSubject .startWith(getActiveDownloads()) .onBackpressureBuffer() fun getStatusAsFlow(): Flow = getStatusObservable().asFlow() - @Deprecated("Use getUpdatedAsFlow instead") private fun getUpdatedObservable(): Observable> = updatedRelay.onBackpressureBuffer() .startWith(Unit) .map { this } @@ -94,7 +92,6 @@ class DownloadQueue( } } - @Deprecated("Use getProgressAsFlow instead") private fun getProgressObservable(): Observable { return statusSubject.onBackpressureBuffer() .startWith(getActiveDownloads()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index a055212d3..401e5e1ad 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -243,7 +243,13 @@ fun Context.openInBrowser(uri: Uri, forceDefaultBrowser: Boolean = false) { fun Context.defaultBrowserPackageName(): String? { val browserIntent = Intent(Intent.ACTION_VIEW, "http://".toUri()) - return packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY) + val resolveInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + packageManager.resolveActivity(browserIntent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong())) + } else { + @Suppress("DEPRECATION") + packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY) + } + return resolveInfo ?.activityInfo?.packageName ?.takeUnless { it in DeviceUtil.invalidDefaultBrowsers } } diff --git a/core/src/main/java/eu/kanade/tachiyomi/core/preference/AndroidPreference.kt b/core/src/main/java/eu/kanade/tachiyomi/core/preference/AndroidPreference.kt index 4c2e6c0f5..05d63ee18 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/core/preference/AndroidPreference.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/core/preference/AndroidPreference.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.core.preference import android.content.SharedPreferences import android.content.SharedPreferences.Editor import androidx.core.content.edit -import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted @@ -11,7 +10,6 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn @@ -68,7 +66,7 @@ sealed class AndroidPreference( preferences: SharedPreferences, keyFlow: Flow, key: String, - defaultValue: String + defaultValue: String, ) : AndroidPreference(preferences, keyFlow, key, defaultValue) { override fun read(preferences: SharedPreferences, key: String, defaultValue: String): String { return preferences.getString(key, defaultValue) ?: defaultValue @@ -83,7 +81,7 @@ sealed class AndroidPreference( preferences: SharedPreferences, keyFlow: Flow, key: String, - defaultValue: Long + defaultValue: Long, ) : AndroidPreference(preferences, keyFlow, key, defaultValue) { override fun read(preferences: SharedPreferences, key: String, defaultValue: Long): Long { return preferences.getLong(key, defaultValue) @@ -98,7 +96,7 @@ sealed class AndroidPreference( preferences: SharedPreferences, keyFlow: Flow, key: String, - defaultValue: Int + defaultValue: Int, ) : AndroidPreference(preferences, keyFlow, key, defaultValue) { override fun read(preferences: SharedPreferences, key: String, defaultValue: Int): Int { return preferences.getInt(key, defaultValue) @@ -113,7 +111,7 @@ sealed class AndroidPreference( preferences: SharedPreferences, keyFlow: Flow, key: String, - defaultValue: Float + defaultValue: Float, ) : AndroidPreference(preferences, keyFlow, key, defaultValue) { override fun read(preferences: SharedPreferences, key: String, defaultValue: Float): Float { return preferences.getFloat(key, defaultValue) @@ -128,7 +126,7 @@ sealed class AndroidPreference( preferences: SharedPreferences, keyFlow: Flow, key: String, - defaultValue: Boolean + defaultValue: Boolean, ) : AndroidPreference(preferences, keyFlow, key, defaultValue) { override fun read(preferences: SharedPreferences, key: String, defaultValue: Boolean): Boolean { return preferences.getBoolean(key, defaultValue) @@ -143,7 +141,7 @@ sealed class AndroidPreference( preferences: SharedPreferences, keyFlow: Flow, key: String, - defaultValue: Set + defaultValue: Set, ) : AndroidPreference>(preferences, keyFlow, key, defaultValue) { override fun read(preferences: SharedPreferences, key: String, defaultValue: Set): Set { return preferences.getStringSet(key, defaultValue) ?: defaultValue @@ -160,7 +158,7 @@ sealed class AndroidPreference( key: String, defaultValue: T, val serializer: (T) -> String, - val deserializer: (String) -> T + val deserializer: (String) -> T, ) : AndroidPreference(preferences, keyFlow, key, defaultValue) { override fun read(preferences: SharedPreferences, key: String, defaultValue: T): T { return try { @@ -174,5 +172,4 @@ sealed class AndroidPreference( putString(key, serializer(value)) } } - } diff --git a/core/src/main/java/eu/kanade/tachiyomi/core/preference/AndroidPreferenceStore.kt b/core/src/main/java/eu/kanade/tachiyomi/core/preference/AndroidPreferenceStore.kt index 49fa9d714..f028148d2 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/core/preference/AndroidPreferenceStore.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/core/preference/AndroidPreferenceStore.kt @@ -14,7 +14,7 @@ import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.callbackFlow class AndroidPreferenceStore( - context: Context + context: Context, ) : PreferenceStore { private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) @@ -26,15 +26,15 @@ class AndroidPreferenceStore( } override fun getLong(key: String, defaultValue: Long): Preference { - return LongPrimitive(sharedPreferences, keyFlow,key, defaultValue) + return LongPrimitive(sharedPreferences, keyFlow, key, defaultValue) } override fun getInt(key: String, defaultValue: Int): Preference { - return IntPrimitive(sharedPreferences, keyFlow,key, defaultValue) + return IntPrimitive(sharedPreferences, keyFlow, key, defaultValue) } override fun getFloat(key: String, defaultValue: Float): Preference { - return FloatPrimitive(sharedPreferences, keyFlow,key, defaultValue) + return FloatPrimitive(sharedPreferences, keyFlow, key, defaultValue) } override fun getBoolean(key: String, defaultValue: Boolean): Preference { @@ -57,9 +57,9 @@ class AndroidPreferenceStore( key = key, defaultValue = defaultValue, serializer = serializer, - deserializer = deserializer + deserializer = deserializer, ) -} + } } private val SharedPreferences.keyFlow diff --git a/core/src/main/java/eu/kanade/tachiyomi/core/preference/Preference.kt b/core/src/main/java/eu/kanade/tachiyomi/core/preference/Preference.kt index a88bbc51a..dc898f4d8 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/core/preference/Preference.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/core/preference/Preference.kt @@ -21,7 +21,6 @@ interface Preference { fun changes(): Flow fun stateIn(scope: CoroutineScope): StateFlow - } inline fun Preference.getAndSet(crossinline block: (T) -> R) = set(block(get())) diff --git a/core/src/main/java/eu/kanade/tachiyomi/core/preference/PreferenceStore.kt b/core/src/main/java/eu/kanade/tachiyomi/core/preference/PreferenceStore.kt index 374368c7d..c4a1abe83 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/core/preference/PreferenceStore.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/core/preference/PreferenceStore.kt @@ -18,15 +18,14 @@ interface PreferenceStore { key: String, defaultValue: T, serializer: (T) -> String, - deserializer: (String) -> T + deserializer: (String) -> T, ): Preference - } inline fun > PreferenceStore.getEnum( key: String, - defaultValue: T -) : Preference { + defaultValue: T, +): Preference { return getObject( key = key, defaultValue = defaultValue, @@ -37,6 +36,6 @@ inline fun > PreferenceStore.getEnum( } catch (e: IllegalArgumentException) { defaultValue } - } + }, ) } diff --git a/core/src/main/java/eu/kanade/tachiyomi/core/provider/AndroidBackupFolderProvider.kt b/core/src/main/java/eu/kanade/tachiyomi/core/provider/AndroidBackupFolderProvider.kt index 193cfa2fb..d9d0a0201 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/core/provider/AndroidBackupFolderProvider.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/core/provider/AndroidBackupFolderProvider.kt @@ -7,7 +7,7 @@ import eu.kanade.tachiyomi.core.R import java.io.File class AndroidBackupFolderProvider( - private val context: Context + private val context: Context, ) : FolderProvider { override fun directory(): File { @@ -21,5 +21,4 @@ class AndroidBackupFolderProvider( override fun path(): String { return directory().toUri().toString() } - } diff --git a/core/src/main/java/eu/kanade/tachiyomi/core/provider/AndroidDownloadFolderProvider.kt b/core/src/main/java/eu/kanade/tachiyomi/core/provider/AndroidDownloadFolderProvider.kt index f9a5f035f..267ddc7ee 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/core/provider/AndroidDownloadFolderProvider.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/core/provider/AndroidDownloadFolderProvider.kt @@ -7,13 +7,13 @@ import eu.kanade.tachiyomi.core.R import java.io.File class AndroidDownloadFolderProvider( - val context: Context + val context: Context, ) : FolderProvider { override fun directory(): File { return File( Environment.getExternalStorageDirectory().absolutePath + File.separator + - context.getString(R.string.app_name), + context.getString(R.string.app_name), "downloads", ) } @@ -21,5 +21,4 @@ class AndroidDownloadFolderProvider( override fun path(): String { return directory().toUri().toString() } - } diff --git a/core/src/main/java/eu/kanade/tachiyomi/core/provider/FolderProvider.kt b/core/src/main/java/eu/kanade/tachiyomi/core/provider/FolderProvider.kt index 1f3fc30a8..167e04e6b 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/core/provider/FolderProvider.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/core/provider/FolderProvider.kt @@ -7,6 +7,4 @@ interface FolderProvider { fun directory(): File fun path(): String - } - diff --git a/core/src/main/java/eu/kanade/tachiyomi/core/security/SecurityPreferences.kt b/core/src/main/java/eu/kanade/tachiyomi/core/security/SecurityPreferences.kt index 27263e312..effe1e411 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/core/security/SecurityPreferences.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/core/security/SecurityPreferences.kt @@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.core.preference.getEnum class SecurityPreferences( - private val preferenceStore: PreferenceStore + private val preferenceStore: PreferenceStore, ) { fun useAuthenticator() = preferenceStore.getBoolean("use_biometric_lock", false) diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/JavaScriptEngine.kt b/core/src/main/java/eu/kanade/tachiyomi/network/JavaScriptEngine.kt index a1efdba05..e3e3577cc 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/JavaScriptEngine.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/JavaScriptEngine.kt @@ -17,7 +17,7 @@ class JavaScriptEngine(context: Context) { * @param script JavaScript to execute. * @return Result of JavaScript code as a primitive type. */ - @Suppress("UNUSED") + @Suppress("UNUSED", "UNCHECKED_CAST") suspend fun evaluate(script: String): T = withIOContext { QuickJs.create().use { it.evaluate(script) as T diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt b/core/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt index 3c69671cc..c11d4bd1b 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.network import android.content.Context -import androidx.preference.PreferenceManager import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor import eu.kanade.tachiyomi.network.interceptor.Http103Interceptor import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/NetworkPreferences.kt b/core/src/main/java/eu/kanade/tachiyomi/network/NetworkPreferences.kt index be136fb15..6e9d145f6 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/NetworkPreferences.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/NetworkPreferences.kt @@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.core.preference.PreferenceStore class NetworkPreferences( private val preferenceStore: PreferenceStore, - private val verboseLogging: Boolean = false + private val verboseLogging: Boolean = false, ) { fun verboseLogging(): Preference { @@ -19,5 +19,4 @@ class NetworkPreferences( fun defaultUserAgent(): Preference { return preferenceStore.getString("default_user_agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0") } - } diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt b/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt index fd68e81fe..34b95adeb 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.network +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json @@ -59,6 +60,7 @@ fun Call.asObservable(): Observable { } // Based on https://github.com/gildor/kotlin-coroutines-okhttp +@OptIn(ExperimentalCoroutinesApi::class) suspend fun Call.await(): Response { return suspendCancellableCoroutine { continuation -> enqueue( diff --git a/core/src/main/java/eu/kanade/tachiyomi/util/lang/RxCoroutineBridge.kt b/core/src/main/java/eu/kanade/tachiyomi/util/lang/RxCoroutineBridge.kt index 73dc7c89b..0a80e8485 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/util/lang/RxCoroutineBridge.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/util/lang/RxCoroutineBridge.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.CancellableContinuation import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.launch @@ -63,6 +64,7 @@ private suspend fun Observable.awaitOne(): T = suspendCancellableCoroutin internal fun CancellableContinuation.unsubscribeOnCancellation(sub: Subscription) = invokeOnCancellation { sub.unsubscribe() } +@OptIn(ExperimentalCoroutinesApi::class) fun runAsObservable( backpressureMode: Emitter.BackpressureMode = Emitter.BackpressureMode.NONE, block: suspend () -> T, diff --git a/gradle/compose.versions.toml b/gradle/compose.versions.toml index 79d2f7fb4..caea579e9 100644 --- a/gradle/compose.versions.toml +++ b/gradle/compose.versions.toml @@ -1,5 +1,5 @@ [versions] -compiler = "1.3.1" +compiler = "1.3.2" compose = "1.2.1" accompanist = "0.25.1" material3 = "1.0.0-rc01" diff --git a/gradle/kotlinx.versions.toml b/gradle/kotlinx.versions.toml index 3949618e5..b573d3fc0 100644 --- a/gradle/kotlinx.versions.toml +++ b/gradle/kotlinx.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlin_version = "1.7.10" +kotlin_version = "1.7.20" coroutines_version = "1.6.4" serialization_version = "1.4.0" xml_serialization_version = "0.84.3" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 12f9cc3ca..a133aaa0f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ coil_version = "2.2.2" conductor_version = "3.1.7" flowbinding_version = "1.2.0" shizuku_version = "12.2.0" -sqldelight = "1.5.3" +sqldelight = "1.5.4" leakcanary = "2.9.1" [libraries] diff --git a/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/BaselineProfileGenerator.kt b/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/BaselineProfileGenerator.kt index 9cf728beb..565e9410c 100644 --- a/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/BaselineProfileGenerator.kt +++ b/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/BaselineProfileGenerator.kt @@ -19,6 +19,6 @@ class BaselineProfileGenerator { // TODO: Navigate to browse-extensions screen when storage permission // in sources screen moved. Possibly open manga details screen too? - } + }, ) } diff --git a/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/StartupBenchmark.kt b/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/StartupBenchmark.kt index ba3585fac..cd1002770 100644 --- a/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/StartupBenchmark.kt +++ b/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/StartupBenchmark.kt @@ -60,7 +60,7 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) { @Test fun startupBaselineProfileDisabled() = startup( - CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Disable, warmupIterations = 1) + CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Disable, warmupIterations = 1), ) @Test @@ -77,7 +77,7 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) { startupMode = startupMode, setupBlock = { pressHome() - } + }, ) { startActivityAndWait() } diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt b/source-api/src/main/java/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt index 95392e361..91b5f5e29 100644 --- a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt +++ b/source-api/src/main/java/eu/kanade/tachiyomi/source/model/UpdateStrategy.kt @@ -18,5 +18,5 @@ enum class UpdateStrategy { * during library updates. Useful for cases where the series is previously * known to be finished and have only a single chapter, for example. */ - ONLY_FETCH_ONCE + ONLY_FETCH_ONCE, }