Skip to content

Commit 55524f7

Browse files
brossshoSumAtrIX
authored andcommitted
feat: Improve bundle info screen design (#2548)
1 parent cd2dbcc commit 55524f7

File tree

7 files changed

+93
-52
lines changed

7 files changed

+93
-52
lines changed

app/src/main/java/app/revanced/manager/domain/bundles/LocalPatchBundle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LocalPatchBundle(name: String, id: Int, directory: File) :
1515
}
1616

1717
reload()?.also {
18-
saveVersionHash(it.readManifestAttribute("Version"))
18+
saveVersionHash(it.patchBundleManifestAttributes?.version)
1919
}
2020
}
2121
}

app/src/main/java/app/revanced/manager/domain/bundles/PatchBundleSource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sealed class PatchBundleSource(initialName: String, val uid: Int, directory: Fil
3838

3939
suspend fun getName() = nameFlow.first()
4040

41-
val versionFlow = state.map { it.patchBundleOrNull()?.readManifestAttribute("Version") }
41+
val versionFlow = state.map { it.patchBundleOrNull()?.patchBundleManifestAttributes?.version }
4242
val patchCountFlow = state.map { it.patchBundleOrNull()?.patches?.size ?: 0 }
4343

4444
/**
@@ -74,7 +74,7 @@ sealed class PatchBundleSource(initialName: String, val uid: Int, directory: Fil
7474
val bundle = newState.patchBundleOrNull()
7575
// Try to read the name from the patch bundle manifest if the bundle does not have a name.
7676
if (bundle != null && _nameFlow.value.isEmpty()) {
77-
bundle.readManifestAttribute("Name")?.let { setName(it) }
77+
bundle.patchBundleManifestAttributes?.name?.let { setName(it) }
7878
}
7979

8080
return bundle

app/src/main/java/app/revanced/manager/patcher/patch/PatchBundle.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import java.io.File
88
import java.io.IOException
99
import java.util.jar.JarFile
1010

11+
class PatchBundleManifestAttributes(
12+
val name: String?,
13+
val version: String?,
14+
val description: String?,
15+
val source: String?,
16+
val author: String?,
17+
val contact: String?,
18+
val website: String?,
19+
val license: String?
20+
)
21+
1122
class PatchBundle(val patchesJar: File) {
1223
private val loader = object : Iterable<Patch<*>> {
1324
private fun load(): Iterable<Patch<*>> {
@@ -36,7 +47,20 @@ class PatchBundle(val patchesJar: File) {
3647
null
3748
}
3849

39-
fun readManifestAttribute(name: String) = manifest?.mainAttributes?.getValue(name)
50+
val patchBundleManifestAttributes = if(manifest != null)
51+
PatchBundleManifestAttributes(
52+
name = readManifestAttribute("name"),
53+
version = readManifestAttribute("version"),
54+
description = readManifestAttribute("description"),
55+
source = readManifestAttribute("source"),
56+
author = readManifestAttribute("author"),
57+
contact = readManifestAttribute("contact"),
58+
website = readManifestAttribute("website"),
59+
license = readManifestAttribute("license")
60+
) else
61+
null
62+
63+
private fun readManifestAttribute(name: String) = manifest?.mainAttributes?.getValue(name)?.takeIf { it.isNotBlank() } // If empty, set it to null instead.
4064

4165
/**
4266
* Load all patches compatible with the specified package.
@@ -53,4 +77,4 @@ class PatchBundle(val patchesJar: File) {
5377

5478
true
5579
}
56-
}
80+
}

app/src/main/java/app/revanced/manager/ui/component/bundle/BaseBundleDialog.kt

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@ package app.revanced.manager.ui.component.bundle
22

33
import android.webkit.URLUtil
44
import androidx.compose.foundation.clickable
5-
import androidx.compose.foundation.layout.*
5+
import androidx.compose.foundation.layout.Arrangement
6+
import androidx.compose.foundation.layout.Column
7+
import androidx.compose.foundation.layout.ColumnScope
8+
import androidx.compose.foundation.layout.Row
9+
import androidx.compose.foundation.layout.fillMaxWidth
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.foundation.layout.size
612
import androidx.compose.material.icons.Icons
713
import androidx.compose.material.icons.automirrored.outlined.ArrowRight
8-
import androidx.compose.material.icons.outlined.Extension
9-
import androidx.compose.material.icons.outlined.Inventory2
14+
import androidx.compose.material.icons.automirrored.outlined.Send
15+
import androidx.compose.material.icons.outlined.Commit
16+
import androidx.compose.material.icons.outlined.Description
17+
import androidx.compose.material.icons.outlined.Gavel
18+
import androidx.compose.material.icons.outlined.Language
19+
import androidx.compose.material.icons.outlined.Person
1020
import androidx.compose.material.icons.outlined.Sell
11-
import androidx.compose.material3.*
21+
import androidx.compose.material3.HorizontalDivider
22+
import androidx.compose.material3.Icon
23+
import androidx.compose.material3.MaterialTheme
24+
import androidx.compose.material3.Text
1225
import androidx.compose.runtime.Composable
1326
import androidx.compose.runtime.getValue
1427
import androidx.compose.runtime.mutableStateOf
@@ -17,10 +30,11 @@ import androidx.compose.runtime.setValue
1730
import androidx.compose.ui.Alignment
1831
import androidx.compose.ui.Modifier
1932
import androidx.compose.ui.graphics.vector.ImageVector
33+
import androidx.compose.ui.platform.LocalUriHandler
2034
import androidx.compose.ui.res.stringResource
21-
import androidx.compose.ui.text.font.FontWeight
2235
import androidx.compose.ui.unit.dp
2336
import app.revanced.manager.R
37+
import app.revanced.manager.patcher.patch.PatchBundleManifestAttributes
2438
import app.revanced.manager.ui.component.ColumnWithScrollbar
2539
import app.revanced.manager.ui.component.TextInputDialog
2640
import app.revanced.manager.ui.component.haptics.HapticSwitch
@@ -29,12 +43,12 @@ import app.revanced.manager.ui.component.haptics.HapticSwitch
2943
fun BaseBundleDialog(
3044
modifier: Modifier = Modifier,
3145
isDefault: Boolean,
32-
name: String?,
3346
remoteUrl: String?,
3447
onRemoteUrlChange: ((String) -> Unit)? = null,
3548
patchCount: Int,
3649
version: String?,
3750
autoUpdate: Boolean,
51+
bundleManifestAttributes: PatchBundleManifestAttributes?,
3852
onAutoUpdateChange: (Boolean) -> Unit,
3953
onPatchesClick: () -> Unit,
4054
extraFields: @Composable ColumnScope.() -> Unit = {}
@@ -48,35 +62,26 @@ fun BaseBundleDialog(
4862
modifier = Modifier.padding(16.dp),
4963
verticalArrangement = Arrangement.spacedBy(4.dp)
5064
) {
51-
Row(
52-
modifier = Modifier.fillMaxWidth(),
53-
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.Start),
54-
verticalAlignment = Alignment.CenterVertically
55-
) {
56-
Icon(
57-
imageVector = Icons.Outlined.Inventory2,
58-
contentDescription = null,
59-
tint = MaterialTheme.colorScheme.primary,
60-
modifier = Modifier.size(32.dp)
61-
)
62-
name?.let {
63-
Text(
64-
text = it,
65-
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight(800)),
66-
color = MaterialTheme.colorScheme.primary,
67-
)
68-
}
65+
version?.let {
66+
Tag(Icons.Outlined.Sell, it)
6967
}
70-
Row(
71-
horizontalArrangement = Arrangement.spacedBy(16.dp),
72-
modifier = Modifier
73-
.fillMaxWidth()
74-
.padding(start = 2.dp)
75-
) {
76-
version?.let {
77-
Tag(Icons.Outlined.Sell, it)
78-
}
79-
Tag(Icons.Outlined.Extension, patchCount.toString())
68+
bundleManifestAttributes?.description?.let {
69+
Tag(Icons.Outlined.Description, it)
70+
}
71+
bundleManifestAttributes?.source?.let {
72+
Tag(Icons.Outlined.Commit, it)
73+
}
74+
bundleManifestAttributes?.author?.let {
75+
Tag(Icons.Outlined.Person, it)
76+
}
77+
bundleManifestAttributes?.contact?.let {
78+
Tag(Icons.AutoMirrored.Outlined.Send, it)
79+
}
80+
bundleManifestAttributes?.website?.let {
81+
Tag(Icons.Outlined.Language, it, isUrl = true)
82+
}
83+
bundleManifestAttributes?.license?.let {
84+
Tag(Icons.Outlined.Gavel, it)
8085
}
8186
}
8287

@@ -138,8 +143,8 @@ fun BaseBundleDialog(
138143

139144
val patchesClickable = patchCount > 0
140145
BundleListItem(
141-
headlineText = stringResource(R.string.patches),
142-
supportingText = stringResource(R.string.bundle_view_patches),
146+
headlineText = stringResource(R.string.bundle_view_patches),
147+
supportingText = stringResource(R.string.bundle_view_all_patches, patchCount),
143148
modifier = Modifier.clickable(
144149
enabled = patchesClickable,
145150
onClick = onPatchesClick
@@ -160,22 +165,34 @@ fun BaseBundleDialog(
160165
@Composable
161166
private fun Tag(
162167
icon: ImageVector,
163-
text: String
168+
text: String,
169+
isUrl: Boolean = false
164170
) {
171+
val uriHandler = LocalUriHandler.current
172+
165173
Row(
166174
horizontalArrangement = Arrangement.spacedBy(6.dp),
167-
verticalAlignment = Alignment.CenterVertically
175+
verticalAlignment = Alignment.CenterVertically,
176+
modifier = if (isUrl) {
177+
Modifier
178+
.clickable {
179+
try {
180+
uriHandler.openUri(text)
181+
} catch (_: Exception) {}
182+
}
183+
}
184+
else
185+
Modifier,
168186
) {
169187
Icon(
170188
imageVector = icon,
171189
contentDescription = null,
172-
modifier = Modifier.size(16.dp),
173-
tint = MaterialTheme.colorScheme.outline,
190+
modifier = Modifier.size(16.dp)
174191
)
175192
Text(
176193
text,
177194
style = MaterialTheme.typography.bodyMedium,
178-
color = MaterialTheme.colorScheme.outline,
195+
color = if(isUrl) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.outline,
179196
)
180197
}
181198
}

app/src/main/java/app/revanced/manager/ui/component/bundle/BundleInformationDialog.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ fun BundleInformationDialog(
4444
}.collectAsStateWithLifecycle(null)
4545
val patchCount by bundle.patchCountFlow.collectAsStateWithLifecycle(0)
4646
val version by bundle.versionFlow.collectAsStateWithLifecycle(null)
47+
val bundleManifestAttributes = state.patchBundleOrNull()?.patchBundleManifestAttributes
4748

4849
if (viewCurrentBundlePatches) {
4950
BundlePatchesDialog(
5051
onDismissRequest = {
5152
viewCurrentBundlePatches = false
5253
},
53-
bundle = bundle,
54+
bundle = bundle
5455
)
5556
}
5657

@@ -62,7 +63,7 @@ fun BundleInformationDialog(
6263
Scaffold(
6364
topBar = {
6465
BundleTopBar(
65-
title = stringResource(R.string.patch_bundle_field),
66+
title = bundleName,
6667
onBackClick = onDismissRequest,
6768
backIcon = {
6869
Icon(
@@ -94,11 +95,11 @@ fun BundleInformationDialog(
9495
BaseBundleDialog(
9596
modifier = Modifier.padding(paddingValues),
9697
isDefault = bundle.isDefault,
97-
name = bundleName,
9898
remoteUrl = bundle.asRemoteOrNull?.endpoint,
9999
patchCount = patchCount,
100100
version = version,
101101
autoUpdate = props?.autoUpdate == true,
102+
bundleManifestAttributes = bundleManifestAttributes,
102103
onAutoUpdateChange = {
103104
composableScope.launch {
104105
bundle.asRemoteOrNull?.setAutoUpdate(it)

app/src/main/java/app/revanced/manager/ui/model/BundleInfo.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ data class BundleInfo(
2323
yieldAll(universal)
2424
}
2525

26-
val patchCount get() = compatible.size + incompatible.size + universal.size
27-
2826
fun patchSequence(allowIncompatible: Boolean) = if (allowIncompatible) {
2927
all
3028
} else {
@@ -79,7 +77,7 @@ data class BundleInfo(
7977
targetList.add(it)
8078
}
8179

82-
BundleInfo(source.getName(), bundle.readManifestAttribute("Version"), source.uid, compatible, incompatible, universal)
80+
BundleInfo(source.getName(), bundle.patchBundleManifestAttributes?.version, source.uid, compatible, incompatible, universal)
8381
}
8482
}
8583

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@
354354
<string name="bundle_auto_update">Auto update</string>
355355
<string name="bundle_auto_update_description">Automatically update this bundle when ReVanced starts</string>
356356
<string name="bundle_view_patches">View patches</string>
357+
<string name="bundle_view_all_patches">View all %d patches</string>
357358
<string name="bundle_view_patches_any_version">Any version</string>
358359
<string name="bundle_view_patches_any_package">Any package</string>
359360
<string name="bundle_delete_single_dialog_title">Delete bundle</string>

0 commit comments

Comments
 (0)