From c9a1bd86b58ce4a41bfc0eeb527cac9d30802353 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 30 Jul 2023 16:15:21 -0400 Subject: [PATCH] Refactor some Screens to be classes Not really much point in keeping these as singletons. Hopefully allows for these to be GC-ed after closing them. --- .../settings/screen/SettingsAdvancedScreen.kt | 2 +- .../screen/debug/BackupSchemaScreen.kt | 6 ++++-- .../settings/screen/debug/DebugInfoScreen.kt | 21 ++++++++++++------- .../settings/screen/debug/WorkerInfoScreen.kt | 6 ++++-- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index 70374e908..cd600969c 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -114,7 +114,7 @@ object SettingsAdvancedScreen : SearchableSettings { ), Preference.PreferenceItem.TextPreference( title = stringResource(R.string.pref_debug_info), - onClick = { navigator.push(DebugInfoScreen) }, + onClick = { navigator.push(DebugInfoScreen()) }, ), ), ) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/BackupSchemaScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/BackupSchemaScreen.kt index 61dd1543c..bc8905050 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/BackupSchemaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/BackupSchemaScreen.kt @@ -28,9 +28,11 @@ import eu.kanade.tachiyomi.util.system.copyToClipboard import kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator import tachiyomi.presentation.core.components.material.Scaffold -object BackupSchemaScreen : Screen() { +class BackupSchemaScreen : Screen() { - const val title = "Backup file schema" + companion object { + const val title = "Backup file schema" + } @Composable override fun Content() { diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/DebugInfoScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/DebugInfoScreen.kt index 8f656aa95..37fa0189d 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/DebugInfoScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/DebugInfoScreen.kt @@ -18,7 +18,8 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.DeviceUtil import kotlinx.coroutines.guava.await -object DebugInfoScreen : Screen() { +class DebugInfoScreen : Screen() { + @Composable override fun Content() { val navigator = LocalNavigator.currentOrThrow @@ -29,11 +30,11 @@ object DebugInfoScreen : Screen() { listOf( Preference.PreferenceItem.TextPreference( title = WorkerInfoScreen.title, - onClick = { navigator.push(WorkerInfoScreen) }, + onClick = { navigator.push(WorkerInfoScreen()) }, ), Preference.PreferenceItem.TextPreference( title = BackupSchemaScreen.title, - onClick = { navigator.push(BackupSchemaScreen) }, + onClick = { navigator.push(BackupSchemaScreen()) }, ), getAppInfoGroup(), getDeviceInfoGroup(), @@ -67,11 +68,15 @@ object DebugInfoScreen : Screen() { @Composable @ReadOnlyComposable private fun getWebViewVersion(): String { - val webView = WebView.getCurrentWebViewPackage() ?: return "how did you get here?" - val pm = LocalContext.current.packageManager - val label = webView.applicationInfo.loadLabel(pm) - val version = webView.versionName - return "$label $version" + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val webView = WebView.getCurrentWebViewPackage() ?: return "how did you get here?" + val pm = LocalContext.current.packageManager + val label = webView.applicationInfo.loadLabel(pm) + val version = webView.versionName + return "$label $version" + } else { + return "Unknown" + } } @Composable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt index 12393080d..ff318a9b4 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt @@ -43,9 +43,11 @@ import kotlinx.coroutines.flow.stateIn import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.util.plus -object WorkerInfoScreen : Screen() { +class WorkerInfoScreen : Screen() { - const val title = "Worker info" + companion object { + const val title = "Worker info" + } @Composable override fun Content() {