From 4bcd6238293e0583cdcc082711128358c5ae2069 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 14 Apr 2023 22:12:28 -0400 Subject: [PATCH] Move worker info screen into debug info menu No need to translate anything for debug info. Dunno what else will end up in that menu in the future. --- .../settings/screen/SettingsAdvancedScreen.kt | 12 ++++---- .../settings/screen/debug/DebugInfoScreen.kt | 29 +++++++++++++++++++ .../screen/{ => debug}/WorkerInfoScreen.kt | 28 +++++------------- i18n/src/main/res/values/strings.xml | 2 +- .../presentation/core/screens/EmptyScreen.kt | 7 ++--- 5 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/DebugInfoScreen.kt rename app/src/main/java/eu/kanade/presentation/more/settings/screen/{ => debug}/WorkerInfoScreen.kt (82%) 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 8a334a0364..f067af9a88 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 @@ -26,6 +26,7 @@ import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.domain.base.BasePreferences import eu.kanade.presentation.more.settings.Preference +import eu.kanade.presentation.more.settings.screen.debug.DebugInfoScreen import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.ChapterCache @@ -75,6 +76,8 @@ object SettingsAdvancedScreen : SearchableSettings { override fun getPreferences(): List { val scope = rememberCoroutineScope() val context = LocalContext.current + val navigator = LocalNavigator.currentOrThrow + val basePreferences = remember { Injekt.get() } val networkPreferences = remember { Injekt.get() } @@ -103,6 +106,10 @@ object SettingsAdvancedScreen : SearchableSettings { true }, ), + Preference.PreferenceItem.TextPreference( + title = stringResource(R.string.pref_debug_info), + onClick = { navigator.push(DebugInfoScreen) }, + ), getBackgroundActivityGroup(), getDataGroup(), getNetworkGroup(networkPreferences = networkPreferences), @@ -115,7 +122,6 @@ object SettingsAdvancedScreen : SearchableSettings { private fun getBackgroundActivityGroup(): Preference.PreferenceGroup { val context = LocalContext.current val uriHandler = LocalUriHandler.current - val navigator = LocalNavigator.currentOrThrow return Preference.PreferenceGroup( title = stringResource(R.string.label_background_activity), @@ -147,10 +153,6 @@ object SettingsAdvancedScreen : SearchableSettings { subtitle = stringResource(R.string.about_dont_kill_my_app), onClick = { uriHandler.openUri("https://dontkillmyapp.com/") }, ), - Preference.PreferenceItem.TextPreference( - title = stringResource(R.string.pref_worker_info), - onClick = { navigator.push(WorkerInfoScreen) }, - ), ), ) } 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 new file mode 100644 index 0000000000..0cd65d96f3 --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/DebugInfoScreen.kt @@ -0,0 +1,29 @@ +package eu.kanade.presentation.more.settings.screen.debug + +import androidx.annotation.StringRes +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import cafe.adriel.voyager.navigator.LocalNavigator +import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.presentation.more.settings.Preference +import eu.kanade.presentation.more.settings.screen.SearchableSettings +import eu.kanade.tachiyomi.R + +object DebugInfoScreen : SearchableSettings { + @ReadOnlyComposable + @Composable + @StringRes + override fun getTitleRes() = R.string.pref_debug_info + + @Composable + override fun getPreferences(): List { + val navigator = LocalNavigator.currentOrThrow + + return listOf( + Preference.PreferenceItem.TextPreference( + title = WorkerInfoScreen.title, + onClick = { navigator.push(WorkerInfoScreen) }, + ), + ) + } +} diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/WorkerInfoScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt similarity index 82% rename from app/src/main/java/eu/kanade/presentation/more/settings/screen/WorkerInfoScreen.kt rename to app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt index b37eed762a..8f533fa01d 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/WorkerInfoScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt @@ -1,4 +1,4 @@ -package eu.kanade.presentation.more.settings.screen +package eu.kanade.presentation.more.settings.screen.debug import android.content.Context import androidx.compose.foundation.horizontalScroll @@ -11,22 +11,16 @@ import androidx.compose.material.icons.filled.ContentCopy import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.SnackbarHost -import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp +import androidx.compose.ui.util.fastForEach import androidx.lifecycle.asFlow import androidx.work.WorkInfo import androidx.work.WorkQuery @@ -36,47 +30,42 @@ import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.presentation.util.Screen import eu.kanade.presentation.util.ioCoroutineScope -import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.workManager import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn -import kotlinx.coroutines.launch import tachiyomi.presentation.core.components.LazyColumn import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.util.plus object WorkerInfoScreen : Screen() { + const val title = "Worker info" + @Composable override fun Content() { val context = LocalContext.current val navigator = LocalNavigator.currentOrThrow - val clipboardManager = LocalClipboardManager.current val screenModel = rememberScreenModel { Model(context) } val enqueued by screenModel.enqueued.collectAsState() val finished by screenModel.finished.collectAsState() val running by screenModel.running.collectAsState() - val snackbarHostState = remember { SnackbarHostState() } - val scope = rememberCoroutineScope() - Scaffold( topBar = { TopAppBar( - title = { Text(text = stringResource(R.string.pref_worker_info)) }, + title = { Text(text = title) }, navigationIcon = { IconButton(onClick = navigator::pop) { Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null) } }, actions = { - val copiedString = stringResource(R.string.copied_to_clipboard_plain) IconButton( onClick = { - clipboardManager.setText(AnnotatedString(enqueued + finished + running)) - scope.launch { snackbarHostState.showSnackbar(copiedString) } + context.copyToClipboard(title, enqueued + finished + running) }, ) { Icon(imageVector = Icons.Default.ContentCopy, contentDescription = null) @@ -85,7 +74,6 @@ object WorkerInfoScreen : Screen() { scrollBehavior = it, ) }, - snackbarHost = { SnackbarHost(hostState = snackbarHostState) }, ) { contentPadding -> LazyColumn( contentPadding = contentPadding + PaddingValues(horizontal = 16.dp), @@ -146,7 +134,7 @@ object WorkerInfoScreen : Screen() { if (list.isEmpty()) { appendLine("-") } else { - list.forEach { workInfo -> + list.fastForEach { workInfo -> appendLine("Id: ${workInfo.id}") appendLine("Tags:") workInfo.tags.forEach { diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index fc60be1566..85f34d7948 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -540,7 +540,7 @@ Tablet UI Verbose logging Print verbose logs to system log (reduces app performance) - Worker info + Debug info Website diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/screens/EmptyScreen.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/screens/EmptyScreen.kt index 1ecd802f92..6327632399 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/screens/EmptyScreen.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/screens/EmptyScreen.kt @@ -23,6 +23,7 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import androidx.compose.ui.util.fastForEach import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.util.secondaryItemAlpha import kotlin.random.Random @@ -79,12 +80,10 @@ fun EmptyScreen( if (!actions.isNullOrEmpty()) { Row( modifier = Modifier - .padding( - top = 24.dp, - ), + .padding(top = 24.dp), horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small), ) { - actions.forEach { + actions.fastForEach { ActionButton( modifier = Modifier.weight(1f), title = stringResource(it.stringResId),