Skip to content

Commit

Permalink
feat: add patch bundle info screen (ReVanced#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyffhabwe authored Jul 23, 2023
1 parent 1331479 commit 21d99a1
Show file tree
Hide file tree
Showing 19 changed files with 892 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import java.io.File
@Stable
class RemoteSource(name: String, id: Int, directory: File) : Source(name, id, directory) {
private val api: ManagerAPI = get()

suspend fun downloadLatest() = withContext(Dispatchers.IO) {
api.downloadBundle(patchesJar, integrations).also { (patchesVer, integrationsVer) ->
saveVersion(patchesVer, integrationsVer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ fun AppTopBar(
containerColor = containerColor
)
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package app.revanced.manager.ui.component

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp

@Composable
fun NotificationCard(
color: Color,
icon: ImageVector,
text: String,
content: @Composable () -> Unit
) {
Card(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(28.dp))
.background(color)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(
16.dp,
Alignment.Start
)
) {
Icon(
imageVector = icon,
contentDescription = null,
)
Text(
modifier = Modifier.width(220.dp),
text = text,
style = MaterialTheme.typography.bodyMedium
)
content()
}
}
}
96 changes: 96 additions & 0 deletions app/src/main/java/app/revanced/manager/ui/component/SourceItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package app.revanced.manager.ui.component


import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.revanced.manager.R
import app.revanced.manager.domain.sources.RemoteSource
import app.revanced.manager.domain.sources.Source
import app.revanced.manager.ui.component.bundle.BundleInformationDialog
import app.revanced.manager.ui.viewmodel.SourcesViewModel
import app.revanced.manager.util.uiSafe
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@Composable
fun SourceItem(
source: Source, onDelete: () -> Unit,
coroutineScope: CoroutineScope,
) {
var viewBundleDialogPage by rememberSaveable { mutableStateOf(false) }

val bundle by source.bundle.collectAsStateWithLifecycle()
val patchCount = bundle.patches.size
val padding = PaddingValues(16.dp, 0.dp)

val androidContext = LocalContext.current

if (viewBundleDialogPage) {
BundleInformationDialog(
onDismissRequest = { viewBundleDialogPage = false },
onDeleteRequest = {
viewBundleDialogPage = false
onDelete()
},
source = source,
patchCount = patchCount,
onRefreshButton = {
coroutineScope.launch {
uiSafe(
androidContext,
R.string.source_download_fail,
SourcesViewModel.failLogMsg
) {
if (source is RemoteSource) source.update()
}
}
},
)
}

Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.height(64.dp)
.fillMaxWidth()
.clickable {
viewBundleDialogPage = true
}
) {
Text(
text = source.name,
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(padding)
)

Spacer(
modifier = Modifier.weight(1f)
)

Text(
text = pluralStringResource(R.plurals.patches_count, patchCount, patchCount),
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(padding)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package app.revanced.manager.ui.component.bundle

import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowRight
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.revanced.manager.R

@Composable
fun BundleInfoContent(
switchChecked: Boolean,
onCheckedChange: (Boolean) -> Unit,
patchInfoText: String,
patchCount: Int,
onArrowClick: () -> Unit,
isLocal: Boolean,
tonalButtonOnClick: () -> Unit = {},
tonalButtonContent: @Composable RowScope.() -> Unit,
) {
if(!isLocal) {
BundleInfoListItem(
headlineText = stringResource(R.string.automatically_update),
supportingText = stringResource(R.string.automatically_update_description),
trailingContent = {
Switch(
checked = switchChecked,
onCheckedChange = onCheckedChange
)
}
)
}

BundleInfoListItem(
headlineText = stringResource(R.string.bundle_type),
supportingText = stringResource(R.string.bundle_type_description)
) {
FilledTonalButton(
onClick = tonalButtonOnClick,
content = tonalButtonContent,
)
}

Text(
text = stringResource(R.string.information),
modifier = Modifier.padding(
horizontal = 16.dp,
vertical = 12.dp
),
style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.colorScheme.primary,
)

BundleInfoListItem(
headlineText = stringResource(R.string.patches),
supportingText = patchInfoText,
trailingContent = {
if (patchCount > 0) {
IconButton(onClick = onArrowClick) {
Icon(
Icons.Outlined.ArrowRight,
stringResource(R.string.patches)
)
}
}
}
)

BundleInfoListItem(
headlineText = stringResource(R.string.patches_version),
supportingText = "1.0.0",
)

BundleInfoListItem(
headlineText = stringResource(R.string.integrations_version),
supportingText = "1.0.0",
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package app.revanced.manager.ui.component.bundle

import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable

@Composable
fun BundleInfoListItem(
headlineText: String,
supportingText: String = "",
trailingContent: @Composable (() -> Unit)? = null,
) {
ListItem(
headlineContent = {
Text(
text = headlineText,
style = MaterialTheme.typography.titleLarge
)
},
supportingContent = {
Text(
text = supportingText,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.outline
)
},
trailingContent = trailingContent,
)
}
Loading

0 comments on commit 21d99a1

Please sign in to comment.