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
try {
diskCacheLazy.value.fileSystem.write(editor.data) {
response.body!!.source().readAll(this)
response.body.source().readAll(this)
}
return editor.commitAndGet()
} catch (e: Exception) {

View file

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

View file

@ -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 }
}

View file

@ -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<T>(
preferences: SharedPreferences,
keyFlow: Flow<String?>,
key: String,
defaultValue: String
defaultValue: String,
) : AndroidPreference<String>(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<T>(
preferences: SharedPreferences,
keyFlow: Flow<String?>,
key: String,
defaultValue: Long
defaultValue: Long,
) : AndroidPreference<Long>(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<T>(
preferences: SharedPreferences,
keyFlow: Flow<String?>,
key: String,
defaultValue: Int
defaultValue: Int,
) : AndroidPreference<Int>(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<T>(
preferences: SharedPreferences,
keyFlow: Flow<String?>,
key: String,
defaultValue: Float
defaultValue: Float,
) : AndroidPreference<Float>(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<T>(
preferences: SharedPreferences,
keyFlow: Flow<String?>,
key: String,
defaultValue: Boolean
defaultValue: Boolean,
) : AndroidPreference<Boolean>(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<T>(
preferences: SharedPreferences,
keyFlow: Flow<String?>,
key: String,
defaultValue: Set<String>
defaultValue: Set<String>,
) : AndroidPreference<Set<String>>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: Set<String>): Set<String> {
return preferences.getStringSet(key, defaultValue) ?: defaultValue
@ -160,7 +158,7 @@ sealed class AndroidPreference<T>(
key: String,
defaultValue: T,
val serializer: (T) -> String,
val deserializer: (String) -> T
val deserializer: (String) -> T,
) : AndroidPreference<T>(preferences, keyFlow, key, defaultValue) {
override fun read(preferences: SharedPreferences, key: String, defaultValue: T): T {
return try {
@ -174,5 +172,4 @@ sealed class AndroidPreference<T>(
putString(key, serializer(value))
}
}
}

View file

@ -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<Long> {
return LongPrimitive(sharedPreferences, keyFlow,key, defaultValue)
return LongPrimitive(sharedPreferences, keyFlow, key, defaultValue)
}
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> {
return FloatPrimitive(sharedPreferences, keyFlow,key, defaultValue)
return FloatPrimitive(sharedPreferences, keyFlow, key, defaultValue)
}
override fun getBoolean(key: String, defaultValue: Boolean): Preference<Boolean> {
@ -57,9 +57,9 @@ class AndroidPreferenceStore(
key = key,
defaultValue = defaultValue,
serializer = serializer,
deserializer = deserializer
deserializer = deserializer,
)
}
}
}
private val SharedPreferences.keyFlow

View file

@ -21,7 +21,6 @@ interface Preference<T> {
fun changes(): Flow<T>
fun stateIn(scope: CoroutineScope): StateFlow<T>
}
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,
defaultValue: T,
serializer: (T) -> String,
deserializer: (String) -> T
deserializer: (String) -> T,
): Preference<T>
}
inline fun <reified T : Enum<T>> PreferenceStore.getEnum(
key: String,
defaultValue: T
) : Preference<T> {
defaultValue: T,
): Preference<T> {
return getObject(
key = key,
defaultValue = defaultValue,
@ -37,6 +36,6 @@ inline fun <reified T : Enum<T>> PreferenceStore.getEnum(
} catch (e: IllegalArgumentException) {
defaultValue
}
}
},
)
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

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

View file

@ -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)

View file

@ -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 <T> evaluate(script: String): T = withIOContext {
QuickJs.create().use {
it.evaluate(script) as T

View file

@ -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

View file

@ -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<Boolean> {
@ -19,5 +19,4 @@ class NetworkPreferences(
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")
}
}

View file

@ -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<Response> {
}
// Based on https://github.com/gildor/kotlin-coroutines-okhttp
@OptIn(ExperimentalCoroutinesApi::class)
suspend fun Call.await(): Response {
return suspendCancellableCoroutine { continuation ->
enqueue(

View file

@ -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 <T> Observable<T>.awaitOne(): T = suspendCancellableCoroutin
internal fun <T> CancellableContinuation<T>.unsubscribeOnCancellation(sub: Subscription) =
invokeOnCancellation { sub.unsubscribe() }
@OptIn(ExperimentalCoroutinesApi::class)
fun <T> runAsObservable(
backpressureMode: Emitter.BackpressureMode = Emitter.BackpressureMode.NONE,
block: suspend () -> T,

View file

@ -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"

View file

@ -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"

View file

@ -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]

View file

@ -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?
}
},
)
}

View file

@ -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()
}

View file

@ -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,
}