manager: refine about dialog

This commit is contained in:
tiann
2023-04-20 15:20:10 +08:00
parent 2f6df20085
commit 3b9cab3432
6 changed files with 117 additions and 28 deletions

View File

@@ -88,6 +88,8 @@ dependencies {
implementation("com.github.alorma:compose-settings-ui-m3:0.22.0")
implementation("com.github.ireward:compose-html:1.0.2")
ksp("io.github.raamcosta.compose-destinations:ksp:$composeDestinationsVersion")
testImplementation("junit:junit:4.13.2")

View File

@@ -0,0 +1,107 @@
package me.weishu.kernelsu.ui.component
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.core.content.res.ResourcesCompat
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.ireward.htmlcompose.HtmlText
import me.weishu.kernelsu.BuildConfig
import me.weishu.kernelsu.R
@Preview
@Composable
fun AboutCard() {
ElevatedCard(
modifier = Modifier
.fillMaxWidth(),
shape = RoundedCornerShape(8.dp),
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(24.dp)
) {
AboutCardContent()
}
}
}
@Composable
fun AboutDialog(showAboutDialog: MutableState<Boolean>) {
if (showAboutDialog.value) {
Dialog(onDismissRequest = { showAboutDialog.value = false }) {
AboutCard()
}
}
}
@Composable
private fun AboutCardContent() {
Column(
modifier = Modifier
.fillMaxWidth()
) {
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyMedium) {
val drawable = ResourcesCompat.getDrawable(
LocalContext.current.resources,
R.mipmap.ic_launcher,
LocalContext.current.theme
)
Row {
Image(
painter = rememberDrawablePainter(drawable),
contentDescription = "icon",
modifier = Modifier.size(40.dp)
)
Spacer(modifier = Modifier.width(12.dp))
Column {
Text(
stringResource(id = R.string.app_name),
style = MaterialTheme.typography.titleSmall,
fontSize = 18.sp
)
Text(
BuildConfig.VERSION_NAME,
style = MaterialTheme.typography.bodySmall,
fontSize = 14.sp
)
Spacer(modifier = Modifier.height(8.dp))
val uriHandler = LocalUriHandler.current
HtmlText(
text = stringResource(
id = R.string.about_source_code,
"<b><a href=\"https://github.com/tiann/KernelSU\">GitHub</a></b>",
"<b><a href=\"https://t.me/KernelSU\">Telegram</a></b>"
),
linkClicked = {
uriHandler.openUri(it)
},
style = MaterialTheme.typography.bodyMedium,
fontSize = 16.sp,
)
}
}
}
}
}

View File

@@ -62,7 +62,7 @@ fun HomeScreen(navigator: DestinationsNavigator) {
StatusCard(kernelVersion, ksuVersion)
InfoCard()
DonateCard()
AboutCard()
LearnMoreCard()
Spacer(Modifier)
}
}
@@ -205,7 +205,7 @@ private fun StatusCard(kernelVersion: KernelVersion, ksuVersion: Int?) {
}
@Composable
fun AboutCard() {
fun LearnMoreCard() {
val uriHandler = LocalUriHandler.current
ElevatedCard {

View File

@@ -14,7 +14,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
@@ -27,8 +26,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.weishu.kernelsu.BuildConfig
import me.weishu.kernelsu.R
import me.weishu.kernelsu.ui.component.SimpleDialog
import me.weishu.kernelsu.ui.util.LinkifyText
import me.weishu.kernelsu.ui.component.AboutDialog
import me.weishu.kernelsu.ui.util.LocalDialogHost
import me.weishu.kernelsu.ui.util.getBugreportFile
@@ -49,9 +47,8 @@ fun SettingScreen(navigator: DestinationsNavigator) {
}
) { paddingValues ->
SimpleDialog {
SupportCard()
}
val showAboutDialog = remember { mutableStateOf(false) }
AboutDialog(showAboutDialog)
var showLoadingDialog by remember { mutableStateOf(false) }
LoadingDialog(showLoadingDialog)
@@ -98,15 +95,12 @@ fun SettingScreen(navigator: DestinationsNavigator) {
)
val about = stringResource(id = R.string.about)
val ok = stringResource(id = android.R.string.ok)
SettingsMenuLink(
title = {
Text(about)
},
onClick = {
scope.launch {
dialogHost.showDialog(about, content = "unused", confirm = ok)
}
showAboutDialog.value = true
}
)
}
@@ -145,20 +139,4 @@ fun LoadingDialog(showLoadingDialog: Boolean) {
CircularProgressIndicator()
}
}
}
@Preview
@Composable
private fun SupportCard() {
Column(
modifier = Modifier
.fillMaxWidth()
) {
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyMedium) {
LinkifyText("Author: weishu")
LinkifyText("Github: https://github.com/tiann/KernelSU")
LinkifyText("Telegram: https://t.me/KernelSU")
LinkifyText("QQ: https://pd.qq.com/s/8lipl1brp")
}
}
}

View File

@@ -59,4 +59,5 @@
<string name="home_click_to_learn_kernelsu">了解如何安装 KernelSU 以及如何开发模块</string>
<string name="home_support_title">支持开发</string>
<string name="home_support_content">KernelSU 将保持免费和开源,向开发者捐赠以表示支持。</string>
<string name="about_source_code"><![CDATA[在 %1$s 查看源码<br/>加入我们的 %2$s 频道<br/>加入我们的 <b><a href="https://pd.qq.com/s/8lipl1brp">QQ 频道</a></b>]]></string>
</resources>

View File

@@ -63,4 +63,5 @@
<string name="home_click_to_learn_kernelsu">Learn how to install KernelSU and use modules</string>
<string name="home_support_title">Support Us</string>
<string name="home_support_content">KernelSU is, and always will be, free, and open source. You can however show us that you care by making a donation.</string>
<string name="about_source_code"><![CDATA[View source code at %1$s<br/>Join our %2$s channel]]></string>
</resources>