Upgrade to Kotlin 1.7.20

Also run formatter and address some deprecation warnings.
This commit is contained in:
arkon 2022-10-11 22:40:02 -04:00
parent b1e104319f
commit 26a42ba9c0
22 changed files with 42 additions and 46 deletions

View File

@ -232,7 +232,7 @@ class MangaCoverFetcher(
val editor = diskCacheLazy.value.edit(diskCacheKey) ?: return null val editor = diskCacheLazy.value.edit(diskCacheKey) ?: return null
try { try {
diskCacheLazy.value.fileSystem.write(editor.data) { diskCacheLazy.value.fileSystem.write(editor.data) {
response.body!!.source().readAll(this) response.body.source().readAll(this)
} }
return editor.commitAndGet() return editor.commitAndGet()
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -74,14 +74,12 @@ class DownloadQueue(
private fun getActiveDownloads(): Observable<Download> = private fun getActiveDownloads(): Observable<Download> =
Observable.from(this).filter { download -> download.status == Download.State.DOWNLOADING } Observable.from(this).filter { download -> download.status == Download.State.DOWNLOADING }
@Deprecated("Use getStatusAsFlow instead")
private fun getStatusObservable(): Observable<Download> = statusSubject private fun getStatusObservable(): Observable<Download> = statusSubject
.startWith(getActiveDownloads()) .startWith(getActiveDownloads())
.onBackpressureBuffer() .onBackpressureBuffer()
fun getStatusAsFlow(): Flow<Download> = getStatusObservable().asFlow() fun getStatusAsFlow(): Flow<Download> = getStatusObservable().asFlow()
@Deprecated("Use getUpdatedAsFlow instead")
private fun getUpdatedObservable(): Observable<List<Download>> = updatedRelay.onBackpressureBuffer() private fun getUpdatedObservable(): Observable<List<Download>> = updatedRelay.onBackpressureBuffer()
.startWith(Unit) .startWith(Unit)
.map { this } .map { this }
@ -94,7 +92,6 @@ class DownloadQueue(
} }
} }
@Deprecated("Use getProgressAsFlow instead")
private fun getProgressObservable(): Observable<Download> { private fun getProgressObservable(): Observable<Download> {
return statusSubject.onBackpressureBuffer() return statusSubject.onBackpressureBuffer()
.startWith(getActiveDownloads()) .startWith(getActiveDownloads())

View File

@ -243,7 +243,13 @@ fun Context.openInBrowser(uri: Uri, forceDefaultBrowser: Boolean = false) {
fun Context.defaultBrowserPackageName(): String? { fun Context.defaultBrowserPackageName(): String? {
val browserIntent = Intent(Intent.ACTION_VIEW, "http://".toUri()) 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 ?.activityInfo?.packageName
?.takeUnless { it in DeviceUtil.invalidDefaultBrowsers } ?.takeUnless { it in DeviceUtil.invalidDefaultBrowsers }
} }

View File

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.core.preference
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.SharedPreferences.Editor import android.content.SharedPreferences.Editor
import androidx.core.content.edit import androidx.core.content.edit
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
@ -11,7 +10,6 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
@ -68,7 +66,7 @@ sealed class AndroidPreference<T>(
preferences: SharedPreferences, preferences: SharedPreferences,
keyFlow: Flow<String?>, keyFlow: Flow<String?>,
key: String, key: String,
defaultValue: String defaultValue: String,
) : AndroidPreference<String>(preferences, keyFlow, key, defaultValue) { ) : AndroidPreference<String>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: String): String { override fun read(preferences: SharedPreferences, key: String, defaultValue: String): String {
return preferences.getString(key, defaultValue) ?: defaultValue return preferences.getString(key, defaultValue) ?: defaultValue
@ -83,7 +81,7 @@ sealed class AndroidPreference<T>(
preferences: SharedPreferences, preferences: SharedPreferences,
keyFlow: Flow<String?>, keyFlow: Flow<String?>,
key: String, key: String,
defaultValue: Long defaultValue: Long,
) : AndroidPreference<Long>(preferences, keyFlow, key, defaultValue) { ) : AndroidPreference<Long>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: Long): Long { override fun read(preferences: SharedPreferences, key: String, defaultValue: Long): Long {
return preferences.getLong(key, defaultValue) return preferences.getLong(key, defaultValue)
@ -98,7 +96,7 @@ sealed class AndroidPreference<T>(
preferences: SharedPreferences, preferences: SharedPreferences,
keyFlow: Flow<String?>, keyFlow: Flow<String?>,
key: String, key: String,
defaultValue: Int defaultValue: Int,
) : AndroidPreference<Int>(preferences, keyFlow, key, defaultValue) { ) : AndroidPreference<Int>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: Int): Int { override fun read(preferences: SharedPreferences, key: String, defaultValue: Int): Int {
return preferences.getInt(key, defaultValue) return preferences.getInt(key, defaultValue)
@ -113,7 +111,7 @@ sealed class AndroidPreference<T>(
preferences: SharedPreferences, preferences: SharedPreferences,
keyFlow: Flow<String?>, keyFlow: Flow<String?>,
key: String, key: String,
defaultValue: Float defaultValue: Float,
) : AndroidPreference<Float>(preferences, keyFlow, key, defaultValue) { ) : AndroidPreference<Float>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: Float): Float { override fun read(preferences: SharedPreferences, key: String, defaultValue: Float): Float {
return preferences.getFloat(key, defaultValue) return preferences.getFloat(key, defaultValue)
@ -128,7 +126,7 @@ sealed class AndroidPreference<T>(
preferences: SharedPreferences, preferences: SharedPreferences,
keyFlow: Flow<String?>, keyFlow: Flow<String?>,
key: String, key: String,
defaultValue: Boolean defaultValue: Boolean,
) : AndroidPreference<Boolean>(preferences, keyFlow, key, defaultValue) { ) : AndroidPreference<Boolean>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: Boolean): Boolean { override fun read(preferences: SharedPreferences, key: String, defaultValue: Boolean): Boolean {
return preferences.getBoolean(key, defaultValue) return preferences.getBoolean(key, defaultValue)
@ -143,7 +141,7 @@ sealed class AndroidPreference<T>(
preferences: SharedPreferences, preferences: SharedPreferences,
keyFlow: Flow<String?>, keyFlow: Flow<String?>,
key: String, key: String,
defaultValue: Set<String> defaultValue: Set<String>,
) : AndroidPreference<Set<String>>(preferences, keyFlow, key, defaultValue) { ) : AndroidPreference<Set<String>>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: Set<String>): Set<String> { override fun read(preferences: SharedPreferences, key: String, defaultValue: Set<String>): Set<String> {
return preferences.getStringSet(key, defaultValue) ?: defaultValue return preferences.getStringSet(key, defaultValue) ?: defaultValue
@ -160,7 +158,7 @@ sealed class AndroidPreference<T>(
key: String, key: String,
defaultValue: T, defaultValue: T,
val serializer: (T) -> String, val serializer: (T) -> String,
val deserializer: (String) -> T val deserializer: (String) -> T,
) : AndroidPreference<T>(preferences, keyFlow, key, defaultValue) { ) : AndroidPreference<T>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: T): T { override fun read(preferences: SharedPreferences, key: String, defaultValue: T): T {
return try { return try {
@ -174,5 +172,4 @@ sealed class AndroidPreference<T>(
putString(key, serializer(value)) putString(key, serializer(value))
} }
} }
} }

View File

@ -14,7 +14,7 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.callbackFlow
class AndroidPreferenceStore( class AndroidPreferenceStore(
context: Context context: Context,
) : PreferenceStore { ) : PreferenceStore {
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
@ -26,15 +26,15 @@ class AndroidPreferenceStore(
} }
override fun getLong(key: String, defaultValue: Long): Preference<Long> { override fun getLong(key: String, defaultValue: Long): Preference<Long> {
return LongPrimitive(sharedPreferences, keyFlow,key, defaultValue) return LongPrimitive(sharedPreferences, keyFlow, key, defaultValue)
} }
override fun getInt(key: String, defaultValue: Int): Preference<Int> { override fun getInt(key: String, defaultValue: Int): Preference<Int> {
return IntPrimitive(sharedPreferences, keyFlow,key, defaultValue) return IntPrimitive(sharedPreferences, keyFlow, key, defaultValue)
} }
override fun getFloat(key: String, defaultValue: Float): Preference<Float> { override fun getFloat(key: String, defaultValue: Float): Preference<Float> {
return FloatPrimitive(sharedPreferences, keyFlow,key, defaultValue) return FloatPrimitive(sharedPreferences, keyFlow, key, defaultValue)
} }
override fun getBoolean(key: String, defaultValue: Boolean): Preference<Boolean> { override fun getBoolean(key: String, defaultValue: Boolean): Preference<Boolean> {
@ -57,9 +57,9 @@ class AndroidPreferenceStore(
key = key, key = key,
defaultValue = defaultValue, defaultValue = defaultValue,
serializer = serializer, serializer = serializer,
deserializer = deserializer deserializer = deserializer,
) )
} }
} }
private val SharedPreferences.keyFlow private val SharedPreferences.keyFlow

View File

@ -21,7 +21,6 @@ interface Preference<T> {
fun changes(): Flow<T> fun changes(): Flow<T>
fun stateIn(scope: CoroutineScope): StateFlow<T> fun stateIn(scope: CoroutineScope): StateFlow<T>
} }
inline fun <reified T, R : T> Preference<T>.getAndSet(crossinline block: (T) -> R) = set(block(get())) inline fun <reified T, R : T> Preference<T>.getAndSet(crossinline block: (T) -> R) = set(block(get()))

View File

@ -18,15 +18,14 @@ interface PreferenceStore {
key: String, key: String,
defaultValue: T, defaultValue: T,
serializer: (T) -> String, serializer: (T) -> String,
deserializer: (String) -> T deserializer: (String) -> T,
): Preference<T> ): Preference<T>
} }
inline fun <reified T : Enum<T>> PreferenceStore.getEnum( inline fun <reified T : Enum<T>> PreferenceStore.getEnum(
key: String, key: String,
defaultValue: T defaultValue: T,
) : Preference<T> { ): Preference<T> {
return getObject( return getObject(
key = key, key = key,
defaultValue = defaultValue, defaultValue = defaultValue,
@ -37,6 +36,6 @@ inline fun <reified T : Enum<T>> PreferenceStore.getEnum(
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
defaultValue defaultValue
} }
} },
) )
} }

View File

@ -7,7 +7,7 @@ import eu.kanade.tachiyomi.core.R
import java.io.File import java.io.File
class AndroidBackupFolderProvider( class AndroidBackupFolderProvider(
private val context: Context private val context: Context,
) : FolderProvider { ) : FolderProvider {
override fun directory(): File { override fun directory(): File {
@ -21,5 +21,4 @@ class AndroidBackupFolderProvider(
override fun path(): String { override fun path(): String {
return directory().toUri().toString() return directory().toUri().toString()
} }
} }

View File

@ -7,7 +7,7 @@ import eu.kanade.tachiyomi.core.R
import java.io.File import java.io.File
class AndroidDownloadFolderProvider( class AndroidDownloadFolderProvider(
val context: Context val context: Context,
) : FolderProvider { ) : FolderProvider {
override fun directory(): File { override fun directory(): File {
@ -21,5 +21,4 @@ class AndroidDownloadFolderProvider(
override fun path(): String { override fun path(): String {
return directory().toUri().toString() return directory().toUri().toString()
} }
} }

View File

@ -7,6 +7,4 @@ interface FolderProvider {
fun directory(): File fun directory(): File
fun path(): String fun path(): String
} }

View File

@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.core.preference.PreferenceStore
import eu.kanade.tachiyomi.core.preference.getEnum import eu.kanade.tachiyomi.core.preference.getEnum
class SecurityPreferences( class SecurityPreferences(
private val preferenceStore: PreferenceStore private val preferenceStore: PreferenceStore,
) { ) {
fun useAuthenticator() = preferenceStore.getBoolean("use_biometric_lock", false) fun useAuthenticator() = preferenceStore.getBoolean("use_biometric_lock", false)

View File

@ -17,7 +17,7 @@ class JavaScriptEngine(context: Context) {
* @param script JavaScript to execute. * @param script JavaScript to execute.
* @return Result of JavaScript code as a primitive type. * @return Result of JavaScript code as a primitive type.
*/ */
@Suppress("UNUSED") @Suppress("UNUSED", "UNCHECKED_CAST")
suspend fun <T> evaluate(script: String): T = withIOContext { suspend fun <T> evaluate(script: String): T = withIOContext {
QuickJs.create().use { QuickJs.create().use {
it.evaluate(script) as T it.evaluate(script) as T

View File

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.network package eu.kanade.tachiyomi.network
import android.content.Context import android.content.Context
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor
import eu.kanade.tachiyomi.network.interceptor.Http103Interceptor import eu.kanade.tachiyomi.network.interceptor.Http103Interceptor
import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor

View File

@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.core.preference.PreferenceStore
class NetworkPreferences( class NetworkPreferences(
private val preferenceStore: PreferenceStore, private val preferenceStore: PreferenceStore,
private val verboseLogging: Boolean = false private val verboseLogging: Boolean = false,
) { ) {
fun verboseLogging(): Preference<Boolean> { fun verboseLogging(): Preference<Boolean> {
@ -19,5 +19,4 @@ class NetworkPreferences(
fun defaultUserAgent(): Preference<String> { fun defaultUserAgent(): Preference<String> {
return preferenceStore.getString("default_user_agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0") return preferenceStore.getString("default_user_agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0")
} }
} }

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.network package eu.kanade.tachiyomi.network
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
@ -59,6 +60,7 @@ fun Call.asObservable(): Observable<Response> {
} }
// Based on https://github.com/gildor/kotlin-coroutines-okhttp // Based on https://github.com/gildor/kotlin-coroutines-okhttp
@OptIn(ExperimentalCoroutinesApi::class)
suspend fun Call.await(): Response { suspend fun Call.await(): Response {
return suspendCancellableCoroutine { continuation -> return suspendCancellableCoroutine { continuation ->
enqueue( enqueue(

View File

@ -4,6 +4,7 @@ import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -63,6 +64,7 @@ private suspend fun <T> Observable<T>.awaitOne(): T = suspendCancellableCoroutin
internal fun <T> CancellableContinuation<T>.unsubscribeOnCancellation(sub: Subscription) = internal fun <T> CancellableContinuation<T>.unsubscribeOnCancellation(sub: Subscription) =
invokeOnCancellation { sub.unsubscribe() } invokeOnCancellation { sub.unsubscribe() }
@OptIn(ExperimentalCoroutinesApi::class)
fun <T> runAsObservable( fun <T> runAsObservable(
backpressureMode: Emitter.BackpressureMode = Emitter.BackpressureMode.NONE, backpressureMode: Emitter.BackpressureMode = Emitter.BackpressureMode.NONE,
block: suspend () -> T, block: suspend () -> T,

View File

@ -1,5 +1,5 @@
[versions] [versions]
compiler = "1.3.1" compiler = "1.3.2"
compose = "1.2.1" compose = "1.2.1"
accompanist = "0.25.1" accompanist = "0.25.1"
material3 = "1.0.0-rc01" material3 = "1.0.0-rc01"

View File

@ -1,5 +1,5 @@
[versions] [versions]
kotlin_version = "1.7.10" kotlin_version = "1.7.20"
coroutines_version = "1.6.4" coroutines_version = "1.6.4"
serialization_version = "1.4.0" serialization_version = "1.4.0"
xml_serialization_version = "0.84.3" xml_serialization_version = "0.84.3"

View File

@ -6,7 +6,7 @@ coil_version = "2.2.2"
conductor_version = "3.1.7" conductor_version = "3.1.7"
flowbinding_version = "1.2.0" flowbinding_version = "1.2.0"
shizuku_version = "12.2.0" shizuku_version = "12.2.0"
sqldelight = "1.5.3" sqldelight = "1.5.4"
leakcanary = "2.9.1" leakcanary = "2.9.1"
[libraries] [libraries]

View File

@ -19,6 +19,6 @@ class BaselineProfileGenerator {
// TODO: Navigate to browse-extensions screen when storage permission // TODO: Navigate to browse-extensions screen when storage permission
// in sources screen moved. Possibly open manga details screen too? // in sources screen moved. Possibly open manga details screen too?
} },
) )
} }

View File

@ -60,7 +60,7 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
@Test @Test
fun startupBaselineProfileDisabled() = startup( fun startupBaselineProfileDisabled() = startup(
CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Disable, warmupIterations = 1) CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Disable, warmupIterations = 1),
) )
@Test @Test
@ -77,7 +77,7 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
startupMode = startupMode, startupMode = startupMode,
setupBlock = { setupBlock = {
pressHome() pressHome()
} },
) { ) {
startActivityAndWait() startActivityAndWait()
} }

View File

@ -18,5 +18,5 @@ enum class UpdateStrategy {
* during library updates. Useful for cases where the series is previously * during library updates. Useful for cases where the series is previously
* known to be finished and have only a single chapter, for example. * known to be finished and have only a single chapter, for example.
*/ */
ONLY_FETCH_ONCE ONLY_FETCH_ONCE,
} }