Skip to content

Commit 60fcd27

Browse files
manager: Refactor the click logic of ModuleItem (#2105)
Drop `com.google.accompanist` that we needn't it Remove unused metadata, abi Optimize app icon (No visual changes) Update Gradle to 8.10.2 Enable per app language support Optimize `SwitchItem` https://github.com/user-attachments/assets/777729e6-5108-4060-91a7-28b5b9d98441 Refactor the click logic of `ModuleItem` https://github.com/user-attachments/assets/e61da54a-6c1c-45d7-bf27-52b452134b7e Use compose's Text in AboutCard to support dynamicColor ![Screenshot_20241001-094116](https://github.com/user-attachments/assets/9882a4c1-719d-4622-a316-063cf349a753) Add scroll behavior for TopAppBar ![Screenshot_20241001-133657.png](https://github.com/user-attachments/assets/1a884648-bc91-4f8a-9940-f2a5f0b8f6da) ![Screenshot_20241001-133645.png](https://github.com/user-attachments/assets/cd4712d3-a2c7-47f1-bba4-4312b779f6b1) Fix padding for BottomNavigationBar
1 parent 7be82d2 commit 60fcd27

24 files changed

+363
-179
lines changed

manager/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
*.iml
22
.gradle
3-
local.properties
43
.idea
4+
.kotlin
55
.DS_Store
66
build
77
captures
88
.cxx
9+
local.properties
910
key.jks

manager/app/build.gradle.kts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
@file:Suppress("UnstableApiUsage")
2+
13
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
4+
import com.android.build.gradle.tasks.PackageAndroidArtifact
25

36
plugins {
47
alias(libs.plugins.agp.app)
@@ -46,7 +49,13 @@ android {
4649
useLegacyPackaging = true
4750
}
4851
resources {
49-
excludes += "/META-INF/{AL2.0,LGPL2.1}"
52+
// https://stackoverflow.com/a/58956288
53+
// It will break Layout Inspector, but it's unused for release build.
54+
excludes += "META-INF/*.version"
55+
// https://github.com/Kotlin/kotlinx.coroutines?tab=readme-ov-file#avoiding-including-the-debug-infrastructure-in-the-resulting-apk
56+
excludes += "DebugProbesKt.bin"
57+
// https://issueantenna.com/repo/kotlin/kotlinx.coroutines/issues/3158
58+
excludes += "kotlin-tooling-metadata.json"
5059
}
5160
}
5261

@@ -67,6 +76,20 @@ android {
6776
}
6877
}
6978
}
79+
80+
// https://stackoverflow.com/a/77745844
81+
tasks.withType<PackageAndroidArtifact> {
82+
doFirst { appMetadata.asFile.orNull?.writeText("") }
83+
}
84+
85+
dependenciesInfo {
86+
includeInApk = false
87+
includeInBundle = false
88+
}
89+
90+
androidResources {
91+
generateLocaleConfig = true
92+
}
7093
}
7194

7295
dependencies {
@@ -87,10 +110,6 @@ dependencies {
87110
implementation(libs.androidx.lifecycle.runtime.ktx)
88111
implementation(libs.androidx.lifecycle.viewmodel.compose)
89112

90-
implementation(libs.com.google.accompanist.drawablepainter)
91-
implementation(libs.com.google.accompanist.navigation.animation)
92-
implementation(libs.com.google.accompanist.webview)
93-
94113
implementation(libs.compose.destinations.core)
95114
ksp(libs.compose.destinations.ksp)
96115

manager/app/proguard-rules.pro

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
-dontwarn org.bouncycastle.jsse.BCSSLParameters
2-
-dontwarn org.bouncycastle.jsse.BCSSLSocket
3-
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
4-
-dontwarn org.conscrypt.Conscrypt$Version
5-
-dontwarn org.conscrypt.Conscrypt
6-
-dontwarn org.conscrypt.ConscryptHostnameVerifier
7-
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
8-
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
9-
-dontwarn org.openjsse.net.ssl.OpenJSSE

manager/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
android:fullBackupContent="@xml/backup_rules"
1313
android:icon="@mipmap/ic_launcher"
1414
android:label="@string/app_name"
15-
android:supportsRtl="true"
1615
android:networkSecurityConfig="@xml/network_security_config"
16+
android:supportsRtl="true"
1717
android:theme="@style/Theme.KernelSU"
1818
tools:targetApi="34">
1919
<activity
@@ -24,13 +24,10 @@
2424
<action android:name="android.intent.action.MAIN" />
2525
<category android:name="android.intent.category.LAUNCHER" />
2626
</intent-filter>
27-
28-
<meta-data
29-
android:name="android.app.lib_name"
30-
android:value="" />
3127
</activity>
3228

33-
<activity android:name=".ui.webui.WebUIActivity"
29+
<activity
30+
android:name=".ui.webui.WebUIActivity"
3431
android:autoRemoveFromRecents="true"
3532
android:documentLaunchMode="intoExisting"
3633
android:exported="false"

manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import androidx.activity.compose.setContent
77
import androidx.activity.enableEdgeToEdge
88
import androidx.compose.foundation.layout.WindowInsets
99
import androidx.compose.foundation.layout.WindowInsetsSides
10+
import androidx.compose.foundation.layout.displayCutout
1011
import androidx.compose.foundation.layout.only
1112
import androidx.compose.foundation.layout.padding
12-
import androidx.compose.foundation.layout.safeDrawing
13+
import androidx.compose.foundation.layout.systemBars
14+
import androidx.compose.foundation.layout.union
1315
import androidx.compose.material3.Icon
1416
import androidx.compose.material3.NavigationBar
1517
import androidx.compose.material3.NavigationBarItem
@@ -80,7 +82,9 @@ private fun BottomBar(navController: NavHostController) {
8082
val fullFeatured = isManager && !Natives.requireNewKernel() && rootAvailable()
8183
NavigationBar(
8284
tonalElevation = 8.dp,
83-
windowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom + WindowInsetsSides.Horizontal)
85+
windowInsets = WindowInsets.systemBars.union(WindowInsets.displayCutout).only(
86+
WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
87+
)
8488
) {
8589
BottomBarDestination.entries.forEach { destination ->
8690
if (!fullFeatured && destination.rootRequired) return@forEach
Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package me.weishu.kernelsu.ui.component
22

3-
import android.text.method.LinkMovementMethod
4-
import android.widget.TextView
53
import androidx.compose.foundation.Image
64
import androidx.compose.foundation.layout.Column
75
import androidx.compose.foundation.layout.Row
@@ -11,34 +9,37 @@ import androidx.compose.foundation.layout.height
119
import androidx.compose.foundation.layout.padding
1210
import androidx.compose.foundation.layout.size
1311
import androidx.compose.foundation.layout.width
12+
import androidx.compose.foundation.shape.CircleShape
1413
import androidx.compose.foundation.shape.RoundedCornerShape
1514
import androidx.compose.material3.ElevatedCard
16-
import androidx.compose.material3.LocalContentColor
1715
import androidx.compose.material3.MaterialTheme
16+
import androidx.compose.material3.Surface
1817
import androidx.compose.material3.Text
1918
import androidx.compose.runtime.Composable
2019
import androidx.compose.ui.Modifier
21-
import androidx.compose.ui.graphics.toArgb
22-
import androidx.compose.ui.platform.LocalContext
20+
import androidx.compose.ui.draw.scale
21+
import androidx.compose.ui.res.colorResource
22+
import androidx.compose.ui.res.painterResource
2323
import androidx.compose.ui.res.stringResource
24+
import androidx.compose.ui.text.AnnotatedString
25+
import androidx.compose.ui.text.SpanStyle
26+
import androidx.compose.ui.text.TextLinkStyles
27+
import androidx.compose.ui.text.TextStyle
28+
import androidx.compose.ui.text.fromHtml
29+
import androidx.compose.ui.text.style.TextDecoration
2430
import androidx.compose.ui.tooling.preview.Preview
2531
import androidx.compose.ui.unit.dp
2632
import androidx.compose.ui.unit.sp
27-
import androidx.compose.ui.viewinterop.AndroidView
2833
import androidx.compose.ui.window.Dialog
29-
import androidx.core.content.res.ResourcesCompat
30-
import androidx.core.text.HtmlCompat
31-
import com.google.accompanist.drawablepainter.rememberDrawablePainter
3234
import me.weishu.kernelsu.BuildConfig
3335
import me.weishu.kernelsu.R
3436

3537
@Preview
3638
@Composable
3739
fun AboutCard() {
3840
ElevatedCard(
39-
modifier = Modifier
40-
.fillMaxWidth(),
41-
shape = RoundedCornerShape(8.dp),
41+
modifier = Modifier.fillMaxWidth(),
42+
shape = RoundedCornerShape(8.dp)
4243
) {
4344
Row(
4445
modifier = Modifier
@@ -52,29 +53,30 @@ fun AboutCard() {
5253

5354
@Composable
5455
fun AboutDialog(dismiss: () -> Unit) {
55-
Dialog(onDismissRequest = { dismiss() }) {
56+
Dialog(
57+
onDismissRequest = { dismiss() }
58+
) {
5659
AboutCard()
5760
}
5861
}
5962

6063
@Composable
6164
private fun AboutCardContent() {
6265
Column(
63-
modifier = Modifier
64-
.fillMaxWidth()
66+
modifier = Modifier.fillMaxWidth()
6567
) {
66-
val drawable = ResourcesCompat.getDrawable(
67-
LocalContext.current.resources,
68-
R.mipmap.ic_launcher,
69-
LocalContext.current.theme
70-
)
71-
7268
Row {
73-
Image(
74-
painter = rememberDrawablePainter(drawable),
75-
contentDescription = "icon",
76-
modifier = Modifier.size(40.dp)
77-
)
69+
Surface(
70+
modifier = Modifier.size(40.dp),
71+
color = colorResource(id = R.color.ic_launcher_background),
72+
shape = CircleShape
73+
) {
74+
Image(
75+
painter = painterResource(id = R.drawable.ic_launcher_foreground),
76+
contentDescription = "icon",
77+
modifier = Modifier.scale(1.4f)
78+
)
79+
}
7880

7981
Spacer(modifier = Modifier.width(12.dp))
8082

@@ -93,31 +95,31 @@ private fun AboutCardContent() {
9395

9496
Spacer(modifier = Modifier.height(8.dp))
9597

96-
HtmlText(
97-
html = stringResource(
98+
val annotatedString = AnnotatedString.Companion.fromHtml(
99+
htmlString = stringResource(
98100
id = R.string.about_source_code,
99101
"<b><a href=\"https://github.com/tiann/KernelSU\">GitHub</a></b>",
100102
"<b><a href=\"https://t.me/KernelSU\">Telegram</a></b>"
103+
),
104+
linkStyles = TextLinkStyles(
105+
style = SpanStyle(
106+
color = MaterialTheme.colorScheme.primary,
107+
textDecoration = TextDecoration.Underline
108+
),
109+
pressedStyle = SpanStyle(
110+
color = MaterialTheme.colorScheme.primary,
111+
background = MaterialTheme.colorScheme.secondaryContainer,
112+
textDecoration = TextDecoration.Underline
113+
)
114+
)
115+
)
116+
Text(
117+
text = annotatedString,
118+
style = TextStyle(
119+
fontSize = 14.sp
101120
)
102121
)
103122
}
104123
}
105124
}
106-
}
107-
108-
@Composable
109-
fun HtmlText(html: String, modifier: Modifier = Modifier) {
110-
val contentColor = LocalContentColor.current
111-
AndroidView(
112-
modifier = modifier,
113-
factory = { context ->
114-
TextView(context).also {
115-
it.movementMethod = LinkMovementMethod.getInstance()
116-
}
117-
},
118-
update = {
119-
it.text = HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_COMPACT)
120-
it.setTextColor(contentColor.toArgb())
121-
}
122-
)
123125
}

manager/app/src/main/java/me/weishu/kernelsu/ui/component/SearchBar.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.material3.IconButton
2323
import androidx.compose.material3.OutlinedTextField
2424
import androidx.compose.material3.Text
2525
import androidx.compose.material3.TopAppBar
26+
import androidx.compose.material3.TopAppBarScrollBehavior
2627
import androidx.compose.runtime.Composable
2728
import androidx.compose.runtime.DisposableEffect
2829
import androidx.compose.runtime.LaunchedEffect
@@ -52,6 +53,7 @@ fun SearchAppBar(
5253
onBackClick: (() -> Unit)? = null,
5354
onConfirm: (() -> Unit)? = null,
5455
dropdownContent: @Composable (() -> Unit)? = null,
56+
scrollBehavior: TopAppBarScrollBehavior? = null
5557
) {
5658
val keyboardController = LocalSoftwareKeyboardController.current
5759
val focusRequester = remember { FocusRequester() }
@@ -137,10 +139,12 @@ fun SearchAppBar(
137139
}
138140

139141
},
140-
windowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal)
142+
windowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
143+
scrollBehavior = scrollBehavior
141144
)
142145
}
143146

147+
@OptIn(ExperimentalMaterial3Api::class)
144148
@Preview
145149
@Composable
146150
private fun SearchAppBarPreview() {

manager/app/src/main/java/me/weishu/kernelsu/ui/component/SettingsItem.kt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package me.weishu.kernelsu.ui.component
22

3-
import androidx.compose.foundation.clickable
3+
import androidx.compose.foundation.LocalIndication
4+
import androidx.compose.foundation.interaction.MutableInteractionSource
5+
import androidx.compose.foundation.selection.toggleable
46
import androidx.compose.material3.Icon
57
import androidx.compose.material3.ListItem
68
import androidx.compose.material3.RadioButton
79
import androidx.compose.material3.Switch
810
import androidx.compose.material3.Text
911
import androidx.compose.runtime.Composable
12+
import androidx.compose.runtime.remember
1013
import androidx.compose.ui.Modifier
1114
import androidx.compose.ui.graphics.vector.ImageVector
15+
import androidx.compose.ui.semantics.Role
1216

1317
@Composable
1418
fun SwitchItem(
@@ -19,18 +23,31 @@ fun SwitchItem(
1923
enabled: Boolean = true,
2024
onCheckedChange: (Boolean) -> Unit
2125
) {
26+
val interactionSource = remember { MutableInteractionSource() }
27+
2228
ListItem(
23-
modifier = Modifier.clickable {
24-
onCheckedChange.invoke(!checked)
25-
},
29+
modifier = Modifier
30+
.toggleable(
31+
value = checked,
32+
interactionSource = interactionSource,
33+
role = Role.Switch,
34+
enabled = enabled,
35+
indication = LocalIndication.current,
36+
onValueChange = onCheckedChange
37+
),
2638
headlineContent = {
2739
Text(title)
2840
},
2941
leadingContent = icon?.let {
3042
{ Icon(icon, title) }
3143
},
3244
trailingContent = {
33-
Switch(checked = checked, enabled = enabled, onCheckedChange = onCheckedChange)
45+
Switch(
46+
checked = checked,
47+
enabled = enabled,
48+
onCheckedChange = onCheckedChange,
49+
interactionSource = interactionSource
50+
)
3451
},
3552
supportingContent = {
3653
if (summary != null) {
@@ -52,6 +69,6 @@ fun RadioItem(
5269
},
5370
leadingContent = {
5471
RadioButton(selected = selected, onClick = onClick)
55-
},
72+
}
5673
)
5774
}

0 commit comments

Comments
 (0)