From bac42edabba421d80dd650c5e1781b64c262ed0e Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 27 May 2023 18:53:11 -0400 Subject: [PATCH] Add debug screen to copy backup file schema Closes #8544 --- .../screen/debug/BackupSchemaScreen.kt | 78 +++++++++++++++++++ .../settings/screen/debug/DebugInfoScreen.kt | 4 + 2 files changed, 82 insertions(+) create mode 100644 app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/BackupSchemaScreen.kt 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 new file mode 100644 index 0000000000..61dd1543c7 --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/BackupSchemaScreen.kt @@ -0,0 +1,78 @@ +package eu.kanade.presentation.more.settings.screen.debug + +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material.icons.filled.ContentCopy +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.unit.dp +import cafe.adriel.voyager.navigator.LocalNavigator +import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.AppBarActions +import eu.kanade.presentation.util.Screen +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.backup.models.Backup +import eu.kanade.tachiyomi.util.system.copyToClipboard +import kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator +import tachiyomi.presentation.core.components.material.Scaffold + +object BackupSchemaScreen : Screen() { + + const val title = "Backup file schema" + + @Composable + override fun Content() { + val context = LocalContext.current + val navigator = LocalNavigator.currentOrThrow + + val schema = remember { ProtoBufSchemaGenerator.generateSchemaText(Backup.serializer().descriptor) } + + Scaffold( + topBar = { + TopAppBar( + title = { Text(text = title) }, + navigationIcon = { + IconButton(onClick = navigator::pop) { + Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null) + } + }, + actions = { + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.action_copy_to_clipboard), + icon = Icons.Default.ContentCopy, + onClick = { + context.copyToClipboard(title, schema) + }, + ), + ), + ) + }, + scrollBehavior = it, + ) + }, + ) { contentPadding -> + Text( + text = schema, + modifier = Modifier + .verticalScroll(rememberScrollState()) + .padding(contentPadding) + .padding(16.dp), + fontFamily = FontFamily.Monospace, + ) + } + } +} 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 e45a1c777e..4588c5fe23 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 @@ -31,6 +31,10 @@ object DebugInfoScreen : Screen() { title = WorkerInfoScreen.title, onClick = { navigator.push(WorkerInfoScreen) }, ), + Preference.PreferenceItem.TextPreference( + title = BackupSchemaScreen.title, + onClick = { navigator.push(BackupSchemaScreen) }, + ), getAppInfoGroup(), getDeviceInfoGroup(), )