From 6ed27488462822d3141545dbbad7163e5d2597fa Mon Sep 17 00:00:00 2001 From: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Date: Mon, 26 Jun 2023 23:28:14 -0300 Subject: [PATCH] Show open source library license in a custom screen (#9645) Show open source library license in a custom screen. --- .../more/settings/screen/AboutScreen.kt | 2 +- .../screen/OpenSourceLibraryLicenseScreen.kt | 94 +++++++++++++++++++ ...sScreen.kt => OpenSourceLicensesScreen.kt} | 11 ++- 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/eu/kanade/presentation/more/settings/screen/OpenSourceLibraryLicenseScreen.kt rename app/src/main/java/eu/kanade/presentation/more/settings/screen/{LicensesScreen.kt => OpenSourceLicensesScreen.kt} (76%) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt index 5c0b83d9b..dd447d9f9 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt @@ -129,7 +129,7 @@ object AboutScreen : Screen() { item { TextPreferenceWidget( title = stringResource(R.string.licenses), - onPreferenceClick = { navigator.push(LicensesScreen()) }, + onPreferenceClick = { navigator.push(OpenSourceLicensesScreen()) }, ) } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/OpenSourceLibraryLicenseScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/OpenSourceLibraryLicenseScreen.kt new file mode 100644 index 000000000..2a35fb017 --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/OpenSourceLibraryLicenseScreen.kt @@ -0,0 +1,94 @@ +package eu.kanade.presentation.more.settings.screen + +import androidx.compose.foundation.layout.Column +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.Public +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.ui.Modifier +import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.viewinterop.AndroidView +import androidx.core.text.HtmlCompat +import cafe.adriel.voyager.navigator.LocalNavigator +import cafe.adriel.voyager.navigator.currentOrThrow +import com.google.android.material.textview.MaterialTextView +import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.AppBarActions +import eu.kanade.presentation.util.Screen +import eu.kanade.tachiyomi.R +import tachiyomi.presentation.core.components.material.Scaffold + +class OpenSourceLibraryLicenseScreen( + private val name: String, + private val website: String?, + private val license: String, +) : Screen() { + + @Composable + override fun Content() { + val navigator = LocalNavigator.currentOrThrow + val uriHandler = LocalUriHandler.current + + Scaffold( + topBar = { + TopAppBar( + title = { + Text( + text = name, + maxLines = 1, + ) + }, + navigationIcon = { + IconButton(onClick = navigator::pop) { + Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null) + } + }, + actions = { + if (!website.isNullOrEmpty()) { + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.website), + icon = Icons.Default.Public, + onClick = { uriHandler.openUri(website) }, + ), + ), + ) + } + }, + scrollBehavior = it, + ) + }, + ) { contentPadding -> + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .padding(contentPadding) + .padding(16.dp), + ) { + HtmlLicenseText(html = license) + } + } + } + + @Composable + private fun HtmlLicenseText(html: String) { + AndroidView( + factory = { + MaterialTextView(it) + }, + update = { + it.text = HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_COMPACT) + }, + ) + } +} diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/LicensesScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/OpenSourceLicensesScreen.kt similarity index 76% rename from app/src/main/java/eu/kanade/presentation/more/settings/screen/LicensesScreen.kt rename to app/src/main/java/eu/kanade/presentation/more/settings/screen/OpenSourceLicensesScreen.kt index f6fb430fe..6ca9b5831 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/LicensesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/OpenSourceLicensesScreen.kt @@ -9,12 +9,13 @@ import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow import com.mikepenz.aboutlibraries.ui.compose.LibrariesContainer import com.mikepenz.aboutlibraries.ui.compose.LibraryDefaults +import com.mikepenz.aboutlibraries.ui.compose.util.htmlReadyLicenseContent import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.R import tachiyomi.presentation.core.components.material.Scaffold -class LicensesScreen : Screen() { +class OpenSourceLicensesScreen : Screen() { @Composable override fun Content() { @@ -38,6 +39,14 @@ class LicensesScreen : Screen() { badgeBackgroundColor = MaterialTheme.colorScheme.primary, badgeContentColor = MaterialTheme.colorScheme.onPrimary, ), + onLibraryClick = { + val libraryLicenseScreen = OpenSourceLibraryLicenseScreen( + name = it.name, + website = it.website, + license = it.licenses.firstOrNull()?.htmlReadyLicenseContent.orEmpty(), + ) + navigator.push(libraryLicenseScreen) + }, ) } }