Skip to content

Commit 3730616

Browse files
committed
Show rule info dialog
1 parent ca740c9 commit 3730616

File tree

3 files changed

+167
-14
lines changed

3 files changed

+167
-14
lines changed

android/modules/module_component_manager/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ dependencies {
7575
implementation(libs.glide.landscapist)
7676
implementation(libs.glide)
7777
kapt(libs.glide.compiler)
78+
implementation(libs.gson)
7879
}

android/modules/module_component_manager/src/main/java/github/tornaco/thanos/module/component/manager/redesign/ComponentsActivity.kt

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ import github.tornaco.android.thanos.module.compose.common.widget.ThanoxSmallApp
7878
import github.tornaco.android.thanos.module.compose.common.widget.rememberConfirmDialogState
7979
import github.tornaco.android.thanos.module.compose.common.widget.rememberDropdownSelectorState
8080
import github.tornaco.android.thanos.module.compose.common.widget.rememberSearchBarState
81-
import github.tornaco.android.thanos.util.BrowserUtils
81+
import github.tornaco.android.thanos.res.R
8282
import github.tornaco.android.thanos.util.ToastUtils
83+
import github.tornaco.thanos.module.component.manager.ComponentRule
8384
import github.tornaco.thanos.module.component.manager.model.ComponentModel
8485
import kotlinx.coroutines.flow.distinctUntilChanged
8586

@@ -563,6 +564,15 @@ class ComponentsActivity : ComposeThemeActivity() {
563564
isGroupSelected: Boolean,
564565
updateGroupSelection: (ComponentGroup, Boolean) -> Unit
565566
) {
567+
var ruleInfoDialogState by remember { mutableStateOf(false) }
568+
if (ruleInfoDialogState) {
569+
BasicAlertDialog(onDismissRequest = { ruleInfoDialogState = false }) {
570+
RuleInfoDialog(rule = group.rule) {
571+
ruleInfoDialogState = false
572+
}
573+
}
574+
}
575+
566576
Row(
567577
modifier = Modifier
568578
.fillMaxWidth()
@@ -583,25 +593,15 @@ class ComponentsActivity : ComposeThemeActivity() {
583593
Modifier.weight(1f, fill = false),
584594
verticalAlignment = Alignment.CenterVertically,
585595
) {
586-
Icon(
587-
painter = painterResource(group.rule.iconRes.takeIf { it > 0 }
588-
?: github.tornaco.android.thanos.res.R.drawable.ic_logo_android_line),
589-
contentDescription = null,
590-
tint = if (group.rule.isSimpleColorIcon) {
591-
MaterialTheme.colorScheme.primary
592-
} else {
593-
Color.Unspecified
594-
}
595-
)
596+
RuleIcon(group.rule)
596597
SmallSpacer()
597598
Text(
598599
text = "${group.rule.label} (${group.components.size})",
599600
style = MaterialTheme.typography.titleSmall
600601
)
601602
group.rule.descriptionUrl?.let {
602-
val context = LocalContext.current
603603
IconButton(onClick = {
604-
BrowserUtils.launch(context, it)
604+
ruleInfoDialogState = true
605605
}) {
606606
Icon(
607607
imageVector = Icons.Outlined.Info,
@@ -625,6 +625,21 @@ class ComponentsActivity : ComposeThemeActivity() {
625625
}
626626
}
627627

628+
@Composable
629+
fun RuleIcon(rule: ComponentRule) {
630+
Icon(
631+
painter = painterResource(rule.iconRes.takeIf { it > 0 }
632+
?: R.drawable.ic_logo_android_line),
633+
contentDescription = null,
634+
tint = if (rule.isSimpleColorIcon) {
635+
MaterialTheme.colorScheme.primary
636+
} else {
637+
Color.Unspecified
638+
}
639+
)
640+
}
641+
628642
internal enum class ComponentItemAction {
629643
Copy, AddToSmartStandByKeepRules, AddToAppLockAllowList
630-
}
644+
}
645+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
@file:OptIn(ExperimentalLayoutApi::class)
2+
3+
package github.tornaco.thanos.module.component.manager.redesign;
4+
5+
import androidx.compose.animation.AnimatedContent
6+
import androidx.compose.foundation.layout.Arrangement
7+
import androidx.compose.foundation.layout.Column
8+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
9+
import androidx.compose.foundation.layout.FlowRow
10+
import androidx.compose.foundation.layout.Row
11+
import androidx.compose.foundation.layout.fillMaxWidth
12+
import androidx.compose.foundation.layout.heightIn
13+
import androidx.compose.foundation.layout.padding
14+
import androidx.compose.foundation.layout.size
15+
import androidx.compose.foundation.layout.wrapContentHeight
16+
import androidx.compose.foundation.layout.wrapContentWidth
17+
import androidx.compose.material3.AlertDialogDefaults
18+
import androidx.compose.material3.Badge
19+
import androidx.compose.material3.CircularProgressIndicator
20+
import androidx.compose.material3.Icon
21+
import androidx.compose.material3.MaterialTheme
22+
import androidx.compose.material3.Surface
23+
import androidx.compose.material3.Text
24+
import androidx.compose.runtime.Composable
25+
import androidx.compose.runtime.LaunchedEffect
26+
import androidx.compose.runtime.getValue
27+
import androidx.compose.runtime.mutableStateOf
28+
import androidx.compose.runtime.remember
29+
import androidx.compose.runtime.setValue
30+
import androidx.compose.ui.Alignment
31+
import androidx.compose.ui.Modifier
32+
import androidx.compose.ui.res.painterResource
33+
import androidx.compose.ui.text.font.FontWeight
34+
import androidx.compose.ui.unit.dp
35+
import github.tornaco.android.thanos.core.annotation.DoNotStrip
36+
import github.tornaco.android.thanos.core.util.GsonUtils
37+
import github.tornaco.android.thanos.module.compose.common.widget.LargeSpacer
38+
import github.tornaco.android.thanos.module.compose.common.widget.SmallSpacer
39+
import github.tornaco.android.thanos.module.compose.common.widget.StandardSpacer
40+
import github.tornaco.thanos.module.component.manager.ComponentRule
41+
import kotlinx.coroutines.Dispatchers
42+
import kotlinx.coroutines.withContext
43+
import java.net.URL
44+
45+
@Composable
46+
internal fun RuleInfoDialog(rule: ComponentRule, dismiss: () -> Unit) {
47+
Surface(
48+
modifier = Modifier
49+
.wrapContentWidth()
50+
.wrapContentHeight(),
51+
shape = MaterialTheme.shapes.large,
52+
tonalElevation = AlertDialogDefaults.TonalElevation
53+
) {
54+
var description by remember { mutableStateOf<RuleDescription?>(null) }
55+
LaunchedEffect(rule) {
56+
withContext(Dispatchers.IO) {
57+
kotlin.runCatching {
58+
val json =
59+
URL(rule.descriptionUrl.orEmpty()).readText(charset = Charsets.UTF_8)
60+
val model = GsonUtils.GSON.fromJson(json, RuleDescription::class.java)
61+
description = model
62+
}.onFailure {
63+
description = RuleDescription(
64+
description = "${it.message}",
65+
label = "ERROR"
66+
)
67+
}
68+
}
69+
}
70+
Column(
71+
Modifier
72+
.fillMaxWidth()
73+
.heightIn(min = 200.dp)
74+
.padding(16.dp)
75+
.padding(vertical = 20.dp),
76+
horizontalAlignment = Alignment.CenterHorizontally,
77+
verticalArrangement = Arrangement.Center
78+
) {
79+
Row(verticalAlignment = Alignment.CenterVertically) {
80+
Text(
81+
rule.label,
82+
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.W500)
83+
)
84+
SmallSpacer()
85+
RuleIcon(rule)
86+
}
87+
LargeSpacer()
88+
AnimatedContent(description) { rd ->
89+
if (rd == null) {
90+
CircularProgressIndicator()
91+
} else {
92+
Column {
93+
Text("Team: ${rd.team.orEmpty()}")
94+
StandardSpacer()
95+
FlowRow {
96+
rd.contributors?.forEach {
97+
Badge(containerColor = MaterialTheme.colorScheme.primaryContainer) {
98+
Icon(
99+
painter = painterResource(github.tornaco.android.thanos.icon.remix.R.drawable.ic_remix_user_line),
100+
contentDescription = "Filter",
101+
modifier = Modifier.size(9.dp)
102+
)
103+
SmallSpacer()
104+
Text(it)
105+
}
106+
SmallSpacer()
107+
}
108+
}
109+
StandardSpacer()
110+
Text(
111+
rd.description.orEmpty(),
112+
style = MaterialTheme.typography.bodySmall
113+
)
114+
}
115+
}
116+
}
117+
}
118+
}
119+
}
120+
121+
// {
122+
// "label": "Jetpack Camera",
123+
// "team": "Google",
124+
// "iconUrl": "",
125+
// "contributors": ["Absinthe"],
126+
// "description": "CameraX 是 Jetpack 的新增库。利用该库,可以更轻松地向应用添加相机功能。该库提供了很多兼容性修复程序和解决方法,有助于在众多设备上打造一致的开发者体验。",
127+
// "relativeUrl": "https://developer.android.com/jetpack/androidx/releases/camera"
128+
//}
129+
@DoNotStrip
130+
data class RuleDescription(
131+
val label: String? = null,
132+
val team: String? = null,
133+
val iconUrl: String? = null,
134+
val contributors: List<String>? = null,
135+
val description: String? = null,
136+
val relativeUrl: String? = null
137+
)

0 commit comments

Comments
 (0)