mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2026-01-15 08:12:33 +01:00
Add about libraries to show used libraries
This commit is contained in:
@@ -7,6 +7,7 @@ plugins {
|
||||
id("org.jetbrains.compose")
|
||||
id("com.google.devtools.ksp")
|
||||
id("org.jmailen.kotlinter")
|
||||
id("com.mikepenz.aboutlibraries.plugin")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -15,6 +15,7 @@ plugins {
|
||||
alias(libs.plugins.buildkonfig) apply false
|
||||
alias(libs.plugins.moko.gradle) apply false
|
||||
alias(libs.plugins.kotlinter) apply false
|
||||
alias(libs.plugins.aboutLibraries) apply false
|
||||
alias(libs.plugins.versions)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ plugins {
|
||||
id("com.google.devtools.ksp")
|
||||
id("com.github.gmazzo.buildconfig")
|
||||
id("org.jmailen.kotlinter")
|
||||
id("com.mikepenz.aboutlibraries.plugin")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -51,6 +51,7 @@ multiplatformSettings = "0.8.1"
|
||||
kroki = "1.22"
|
||||
desugarJdkLibs = "1.1.5"
|
||||
klock = "2.6.3"
|
||||
aboutLibraries = "10.0.1"
|
||||
|
||||
# Localization
|
||||
locale = "0.11.0"
|
||||
@@ -139,6 +140,8 @@ multiplatformSettings-coroutines = { module = "com.russhwolf:multiplatform-setti
|
||||
krokiCoroutines = { module = "io.github.kerubistan.kroki:kroki-coroutines", version.ref = "kroki" }
|
||||
desugarJdkLibs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugarJdkLibs" }
|
||||
klock = { module = "com.soywiz.korlibs.klock:klock", version.ref = "klock" }
|
||||
aboutLibraries-core = { module = "com.mikepenz:aboutlibraries-core", version.ref = "aboutLibraries" }
|
||||
aboutLibraries-ui = { module = "com.mikepenz:aboutlibraries-compose", version.ref = "aboutLibraries" }
|
||||
|
||||
# Localization
|
||||
moko-core = { module = "dev.icerock.moko:resources", version.ref = "moko" }
|
||||
@@ -174,4 +177,7 @@ buildkonfig = { id = "com.codingfeline.buildkonfig", version.ref = "buildkonfig"
|
||||
kotlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinter"}
|
||||
|
||||
# Version updates
|
||||
versions = { id = "com.github.ben-manes.versions", version.ref = "versions"}
|
||||
versions = { id = "com.github.ben-manes.versions", version.ref = "versions"}
|
||||
|
||||
# Utility
|
||||
aboutLibraries = { id = "com.mikepenz.aboutlibraries.plugin", version.ref = "aboutLibraries"}
|
||||
File diff suppressed because one or more lines are too long
@@ -122,6 +122,7 @@
|
||||
<string name="github">Github</string>
|
||||
<string name="discord">Discord</string>
|
||||
<string name="reddit">Reddit</string>
|
||||
<string name="open_source_licenses">Open source licenses</string>
|
||||
|
||||
|
||||
<!-- Settings-->
|
||||
|
||||
@@ -52,6 +52,8 @@ kotlin {
|
||||
api(libs.krokiCoroutines)
|
||||
api(libs.locale)
|
||||
api(libs.klock)
|
||||
api(libs.aboutLibraries.core)
|
||||
api(libs.aboutLibraries.ui)
|
||||
api(projects.core)
|
||||
api(projects.i18n)
|
||||
api(projects.data)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.ui.main.about.licenses.components
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import ca.gosyer.jui.core.lang.withIOContext
|
||||
import com.mikepenz.aboutlibraries.Libs
|
||||
import com.mikepenz.aboutlibraries.entity.Library
|
||||
import com.mikepenz.aboutlibraries.ui.compose.Libraries
|
||||
import com.mikepenz.aboutlibraries.ui.compose.LibraryColors
|
||||
import com.mikepenz.aboutlibraries.util.withContext
|
||||
|
||||
@Composable
|
||||
actual fun getLicenses(): Libs? {
|
||||
val context = LocalContext.current
|
||||
val libs by produceState<Libs?>(
|
||||
null,
|
||||
context
|
||||
) {
|
||||
withIOContext {
|
||||
value = Libs.Builder().withContext(context).build()
|
||||
}
|
||||
}
|
||||
return libs
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun InternalAboutLibraries(
|
||||
libraries: List<Library>,
|
||||
modifier: Modifier,
|
||||
contentPadding: PaddingValues,
|
||||
showAuthor: Boolean,
|
||||
showVersion: Boolean,
|
||||
showLicenseBadges: Boolean,
|
||||
colors: LibraryColors,
|
||||
itemContentPadding: PaddingValues,
|
||||
onLibraryClick: ((Library) -> Unit)?,
|
||||
) {
|
||||
Libraries(
|
||||
libraries = libraries,
|
||||
modifier = modifier,
|
||||
contentPadding = contentPadding,
|
||||
showAuthor = showAuthor,
|
||||
showVersion = showVersion,
|
||||
showLicenseBadges = showLicenseBadges,
|
||||
colors = colors,
|
||||
itemContentPadding = itemContentPadding,
|
||||
onLibraryClick = onLibraryClick
|
||||
)
|
||||
}
|
||||
@@ -11,10 +11,13 @@ import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import ca.gosyer.jui.ui.main.about.components.AboutContent
|
||||
import ca.gosyer.jui.ui.main.about.licenses.LicensesScreen
|
||||
import ca.gosyer.jui.uicore.vm.viewModel
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.core.screen.ScreenKey
|
||||
import cafe.adriel.voyager.core.screen.uniqueScreenKey
|
||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class AboutScreen : Screen {
|
||||
@@ -25,6 +28,7 @@ class AboutScreen : Screen {
|
||||
override fun Content() {
|
||||
val vm = viewModel<AboutViewModel>()
|
||||
val uriHandler = LocalUriHandler.current
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
LaunchedEffect(vm) {
|
||||
launch {
|
||||
vm.updates.collect {
|
||||
@@ -35,7 +39,10 @@ class AboutScreen : Screen {
|
||||
AboutContent(
|
||||
about = vm.about.collectAsState().value,
|
||||
formattedBuildTime = vm.formattedBuildTime.collectAsState().value,
|
||||
checkForUpdates = vm::checkForUpdates
|
||||
checkForUpdates = vm::checkForUpdates,
|
||||
openSourceLicenses = {
|
||||
navigator push LicensesScreen()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ import dev.icerock.moko.resources.StringResource
|
||||
fun AboutContent(
|
||||
about: About?,
|
||||
formattedBuildTime: String,
|
||||
checkForUpdates: () -> Unit
|
||||
checkForUpdates: () -> Unit,
|
||||
openSourceLicenses: () -> Unit
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -77,6 +78,9 @@ fun AboutContent(
|
||||
item {
|
||||
HelpTranslate()
|
||||
}
|
||||
item {
|
||||
OpenSourceLicenses(openSourceLicenses)
|
||||
}
|
||||
item {
|
||||
LinkDisplay()
|
||||
}
|
||||
@@ -162,6 +166,14 @@ private fun HelpTranslate() {
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun OpenSourceLicenses(openSourceLicenses: () -> Unit) {
|
||||
PreferenceRow(
|
||||
title = stringResource(MR.strings.open_source_licenses),
|
||||
onClick = openSourceLicenses
|
||||
)
|
||||
}
|
||||
|
||||
sealed class LinkIcon {
|
||||
data class Resource(val res: ImageResource) : LinkIcon()
|
||||
data class Icon(val icon: ImageVector) : LinkIcon()
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.ui.main.about.licenses
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import ca.gosyer.jui.ui.main.about.licenses.components.LicensesContent
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.core.screen.ScreenKey
|
||||
import cafe.adriel.voyager.core.screen.uniqueScreenKey
|
||||
|
||||
class LicensesScreen : Screen {
|
||||
|
||||
override val key: ScreenKey = uniqueScreenKey
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
LicensesContent()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.ui.main.about.licenses.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import ca.gosyer.jui.i18n.MR
|
||||
import ca.gosyer.jui.ui.base.navigation.Toolbar
|
||||
import ca.gosyer.jui.uicore.components.LoadingScreen
|
||||
import ca.gosyer.jui.uicore.resources.stringResource
|
||||
import com.mikepenz.aboutlibraries.Libs
|
||||
import com.mikepenz.aboutlibraries.entity.Library
|
||||
import com.mikepenz.aboutlibraries.ui.compose.LibraryColors
|
||||
import com.mikepenz.aboutlibraries.ui.compose.LibraryDefaults
|
||||
|
||||
@Composable
|
||||
expect fun getLicenses(): Libs?
|
||||
|
||||
@Composable
|
||||
internal expect fun InternalAboutLibraries(
|
||||
libraries: List<Library>,
|
||||
modifier: Modifier = Modifier,
|
||||
contentPadding: PaddingValues,
|
||||
showAuthor: Boolean,
|
||||
showVersion: Boolean,
|
||||
showLicenseBadges: Boolean,
|
||||
colors: LibraryColors,
|
||||
itemContentPadding: PaddingValues,
|
||||
onLibraryClick: ((Library) -> Unit)?,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun AboutLibraries(
|
||||
libraries: List<Library>,
|
||||
modifier: Modifier = Modifier,
|
||||
contentPadding: PaddingValues = PaddingValues(0.dp),
|
||||
showAuthor: Boolean = true,
|
||||
showVersion: Boolean = true,
|
||||
showLicenseBadges: Boolean = true,
|
||||
colors: LibraryColors = LibraryDefaults.libraryColors(),
|
||||
itemContentPadding: PaddingValues = LibraryDefaults.ContentPadding,
|
||||
onLibraryClick: ((Library) -> Unit)? = null,
|
||||
) {
|
||||
InternalAboutLibraries(
|
||||
libraries = libraries,
|
||||
modifier = modifier,
|
||||
contentPadding = contentPadding,
|
||||
showAuthor = showAuthor,
|
||||
showVersion = showVersion,
|
||||
showLicenseBadges = showLicenseBadges,
|
||||
colors = colors,
|
||||
itemContentPadding = itemContentPadding,
|
||||
onLibraryClick = onLibraryClick
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: 2022-04-02 Add scrollbar
|
||||
@Composable
|
||||
fun LicensesContent() {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
Toolbar(stringResource(MR.strings.open_source_licenses))
|
||||
}
|
||||
) {
|
||||
Box(Modifier.fillMaxSize().padding(it)) {
|
||||
val libs = getLicenses()
|
||||
if (libs != null) {
|
||||
AboutLibraries(
|
||||
libraries = libs.libraries
|
||||
)
|
||||
} else {
|
||||
LoadingScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.ui.main.about.licenses.components
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.ui.Modifier
|
||||
import ca.gosyer.jui.core.lang.withIOContext
|
||||
import ca.gosyer.jui.i18n.MR
|
||||
import com.mikepenz.aboutlibraries.Libs
|
||||
import com.mikepenz.aboutlibraries.entity.Library
|
||||
import com.mikepenz.aboutlibraries.ui.compose.Libraries
|
||||
import com.mikepenz.aboutlibraries.ui.compose.LibraryColors
|
||||
|
||||
@Composable
|
||||
actual fun getLicenses(): Libs? {
|
||||
val libs by produceState<Libs?>(
|
||||
null
|
||||
) {
|
||||
withIOContext {
|
||||
val json = MR.files.aboutlibraries.readText()
|
||||
value = Libs.Builder().withJson(json).build()
|
||||
}
|
||||
}
|
||||
return libs
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun InternalAboutLibraries(
|
||||
libraries: List<Library>,
|
||||
modifier: Modifier,
|
||||
contentPadding: PaddingValues,
|
||||
showAuthor: Boolean,
|
||||
showVersion: Boolean,
|
||||
showLicenseBadges: Boolean,
|
||||
colors: LibraryColors,
|
||||
itemContentPadding: PaddingValues,
|
||||
onLibraryClick: ((Library) -> Unit)?,
|
||||
) {
|
||||
Libraries(
|
||||
libraries = libraries,
|
||||
modifier = modifier,
|
||||
contentPadding = contentPadding,
|
||||
showAuthor = showAuthor,
|
||||
showVersion = showVersion,
|
||||
showLicenseBadges = showLicenseBadges,
|
||||
colors = colors,
|
||||
itemContentPadding = itemContentPadding,
|
||||
onLibraryClick = onLibraryClick
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user