Skip to content

Commit

Permalink
refactor: fix terminology and wording related to patches (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
Axelen123 authored Jan 18, 2024
1 parent 36c8f59 commit c0f3d02
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 106 deletions.
10 changes: 5 additions & 5 deletions app/src/main/java/app/revanced/manager/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ class MainActivity : ComponentActivity() {
)

is Destination.InstalledApplicationInfo -> InstalledAppInfoScreen(
onPatchClick = { packageName, patchesSelection ->
onPatchClick = { packageName, patchSelection ->
navController.navigate(
Destination.VersionSelector(
packageName,
patchesSelection
patchSelection
)
)
},
Expand Down Expand Up @@ -142,14 +142,14 @@ class MainActivity : ComponentActivity() {
navController.navigate(
Destination.SelectedApplicationInfo(
selectedApp,
destination.patchesSelection,
destination.patchSelection,
)
)
},
viewModel = getComposeViewModel {
parametersOf(
destination.packageName,
destination.patchesSelection
destination.patchSelection
)
}
)
Expand All @@ -167,7 +167,7 @@ class MainActivity : ComponentActivity() {
parametersOf(
SelectedAppInfoViewModel.Params(
destination.selectedApp,
destination.patchesSelection
destination.patchSelection
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import app.revanced.manager.data.room.AppDatabase
import app.revanced.manager.data.room.apps.installed.AppliedPatch
import app.revanced.manager.data.room.apps.installed.InstallType
import app.revanced.manager.data.room.apps.installed.InstalledApp
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.PatchSelection
import kotlinx.coroutines.flow.distinctUntilChanged

class InstalledAppRepository(
Expand All @@ -16,15 +16,15 @@ class InstalledAppRepository(

suspend fun get(packageName: String) = dao.get(packageName)

suspend fun getAppliedPatches(packageName: String): PatchesSelection =
suspend fun getAppliedPatches(packageName: String): PatchSelection =
dao.getPatchesSelection(packageName).mapValues { (_, patches) -> patches.toSet() }

suspend fun addOrUpdate(
currentPackageName: String,
originalPackageName: String,
version: String,
installType: InstallType,
patchesSelection: PatchesSelection
patchSelection: PatchSelection
) {
dao.upsertApp(
InstalledApp(
Expand All @@ -33,7 +33,7 @@ class InstalledAppRepository(
version = version,
installType = installType
),
patchesSelection.flatMap { (uid, patches) ->
patchSelection.flatMap { (uid, patches) ->
patches.map { patch ->
AppliedPatch(
packageName = currentPackageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import app.revanced.manager.ui.model.SelectedApp
import app.revanced.manager.ui.model.State
import app.revanced.manager.util.Options
import app.revanced.manager.util.PM
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.PatchSelection
import app.revanced.manager.util.tag
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
Expand All @@ -59,7 +59,7 @@ class PatcherWorker(
data class Args(
val input: SelectedApp,
val output: String,
val selectedPatches: PatchesSelection,
val selectedPatches: PatchSelection,
val options: Options,
val logger: ManagerLogger,
val downloadProgress: MutableStateFlow<Pair<Float, Float>?>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun BundleItem(
supportingContent = {
state.patchBundleOrNull()?.patches?.size?.let { patchCount ->
Text(
text = pluralStringResource(R.plurals.patches_count, patchCount, patchCount),
text = pluralStringResource(R.plurals.patch_count, patchCount, patchCount),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Parcelable
import app.revanced.manager.data.room.apps.installed.InstalledApp
import app.revanced.manager.ui.model.SelectedApp
import app.revanced.manager.util.Options
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.PatchSelection
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue

Expand All @@ -23,12 +23,12 @@ sealed interface Destination : Parcelable {
data class Settings(val startDestination: SettingsDestination = SettingsDestination.Settings) : Destination

@Parcelize
data class VersionSelector(val packageName: String, val patchesSelection: PatchesSelection? = null) : Destination
data class VersionSelector(val packageName: String, val patchSelection: PatchSelection? = null) : Destination

@Parcelize
data class SelectedApplicationInfo(val selectedApp: SelectedApp, val patchesSelection: PatchesSelection? = null) : Destination
data class SelectedApplicationInfo(val selectedApp: SelectedApp, val patchSelection: PatchSelection? = null) : Destination

@Parcelize
data class Patcher(val selectedApp: SelectedApp, val selectedPatches: PatchesSelection, val options: @RawValue Options) : Destination
data class Patcher(val selectedApp: SelectedApp, val selectedPatches: PatchSelection, val options: @RawValue Options) : Destination

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.revanced.manager.ui.destination
import android.os.Parcelable
import app.revanced.manager.ui.model.SelectedApp
import app.revanced.manager.util.Options
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.PatchSelection
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue

Expand All @@ -12,7 +12,7 @@ sealed interface SelectedAppInfoDestination : Parcelable {
data object Main : SelectedAppInfoDestination

@Parcelize
data class PatchesSelector(val app: SelectedApp, val currentSelection: PatchesSelection?, val options: @RawValue Options) : SelectedAppInfoDestination
data class PatchesSelector(val app: SelectedApp, val currentSelection: PatchSelection?, val options: @RawValue Options) : SelectedAppInfoDestination

@Parcelize
data object VersionSelector: SelectedAppInfoDestination
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/app/revanced/manager/ui/model/BundleInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.revanced.manager.ui.model

import app.revanced.manager.domain.repository.PatchBundleRepository
import app.revanced.manager.patcher.patch.PatchInfo
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.PatchSelection
import app.revanced.manager.util.flatMapLatestAndCombine
import kotlinx.coroutines.flow.map

Expand Down Expand Up @@ -34,7 +34,7 @@ data class BundleInfo(
}

companion object Extensions {
inline fun Iterable<BundleInfo>.toPatchSelection(allowUnsupported: Boolean, condition: (Int, PatchInfo) -> Boolean): PatchesSelection = this.associate { bundle ->
inline fun Iterable<BundleInfo>.toPatchSelection(allowUnsupported: Boolean, condition: (Int, PatchInfo) -> Boolean): PatchSelection = this.associate { bundle ->
val patches =
bundle.patchSequence(allowUnsupported)
.mapNotNullTo(mutableSetOf()) { patch ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fun AppSelectorScreen(
{
Text(
pluralStringResource(
R.plurals.patches_count,
R.plurals.patch_count,
it,
it
)
Expand Down Expand Up @@ -199,7 +199,7 @@ fun AppSelectorScreen(
{
Text(
pluralStringResource(
R.plurals.patches_count,
R.plurals.patch_count,
it,
it
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -40,15 +41,18 @@ import app.revanced.manager.ui.component.ColumnWithScrollbar
import app.revanced.manager.ui.component.SegmentedButton
import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.viewmodel.InstalledAppInfoViewModel
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.PatchSelection
import app.revanced.manager.util.toast

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun InstalledAppInfoScreen(
onPatchClick: (packageName: String, patchesSelection: PatchesSelection) -> Unit,
onPatchClick: (packageName: String, patchSelection: PatchSelection) -> Unit,
onBackClick: () -> Unit,
viewModel: InstalledAppInfoViewModel
) {
val context = LocalContext.current

SideEffect {
viewModel.onBackClick = onBackClick
}
Expand Down Expand Up @@ -142,12 +146,12 @@ fun InstalledAppInfoScreen(
modifier = Modifier.padding(vertical = 16.dp)
) {
SettingsListItem(
modifier = Modifier.clickable { },
modifier = Modifier.clickable { context.toast("Not implemented yet!") },
headlineContent = stringResource(R.string.applied_patches),
supportingContent =
(viewModel.appliedPatches?.values?.sumOf { it.size } ?: 0).let {
pluralStringResource(
id = R.plurals.applied_patches,
id = R.plurals.patch_count,
it,
it
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW_UNIVERSAL
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW_UNSUPPORTED
import app.revanced.manager.util.Options
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.PatchSelection
import kotlinx.coroutines.launch
import org.koin.compose.rememberKoinInject

@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun PatchesSelectorScreen(
onSave: (PatchesSelection?, Options) -> Unit,
onSave: (PatchSelection?, Options) -> Unit,
onBackClick: () -> Unit,
vm: PatchesSelectorViewModel
) {
Expand Down Expand Up @@ -105,13 +105,13 @@ fun PatchesSelectorScreen(
modifier = Modifier.padding(horizontal = 24.dp)
) {
Text(
text = stringResource(R.string.patches_selector_sheet_filter_title),
text = stringResource(R.string.patch_selector_sheet_filter_title),
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(bottom = 16.dp)
)

Text(
text = stringResource(R.string.patches_selector_sheet_filter_compat_title),
text = stringResource(R.string.patch_selector_sheet_filter_compat_title),
style = MaterialTheme.typography.titleMedium
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import app.revanced.manager.ui.model.SelectedApp
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel
import app.revanced.manager.ui.viewmodel.SelectedAppInfoViewModel
import app.revanced.manager.util.Options
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.PatchSelection
import app.revanced.manager.util.toast
import dev.olshevski.navigation.reimagined.AnimatedNavHost
import dev.olshevski.navigation.reimagined.NavBackHandler
Expand All @@ -44,7 +44,7 @@ import org.koin.core.parameter.parametersOf

@Composable
fun SelectedAppInfoScreen(
onPatchClick: (SelectedApp, PatchesSelection, Options) -> Unit,
onPatchClick: (SelectedApp, PatchSelection, Options) -> Unit,
onBackClick: () -> Unit,
vm: SelectedAppInfoViewModel
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fun SelectedAppItem(
else -> null
},
trailingContent = patchCount?.let { {
Text(pluralStringResource(R.plurals.patches_count, it, it))
Text(pluralStringResource(R.plurals.patch_count, it, it))
} },
modifier = Modifier
.clickable(enabled = !alreadyPatched && enabled, onClick = onClick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ fun ImportExportSettingsScreen(
description = R.string.regenerate_keystore_description
)

GroupHeader(stringResource(R.string.patches_selection))
GroupHeader(stringResource(R.string.patches))
GroupItem(
onClick = vm::importSelection,
headline = R.string.restore_patches_selection,
description = R.string.restore_patches_selection_description
headline = R.string.import_patch_selection,
description = R.string.import_patch_selection_description
)
GroupItem(
onClick = vm::exportSelection,
headline = R.string.backup_patches_selection,
description = R.string.backup_patches_selection_description
headline = R.string.export_patch_selection,
description = R.string.export_patch_selection_description
)
// TODO: allow resetting selection for specific bundle or package name.
GroupItem(
onClick = vm::resetSelection,
headline = R.string.clear_patches_selection,
description = R.string.clear_patches_selection_description
headline = R.string.reset_patch_selection,
description = R.string.reset_patch_selection_description
)

var showPackageSelector by rememberSaveable {
Expand All @@ -158,7 +158,7 @@ fun ImportExportSettingsScreen(

if (showPackageSelector)
PackageSelector(packages = packagesWithOptions) { selected ->
selected?.let(vm::clearOptionsForPackage)
selected?.let(vm::resetOptionsForPackage)

showPackageSelector = false
}
Expand All @@ -170,24 +170,23 @@ fun ImportExportSettingsScreen(
showBundleSelector = false
}

GroupHeader(stringResource(R.string.patch_options))
// TODO: patch options import/export.
GroupItem(
onClick = vm::resetOptions,
headline = R.string.patch_options_reset_all,
description = R.string.patch_options_reset_all_description,
)
GroupItem(
onClick = { showPackageSelector = true },
headline = R.string.patch_options_clear_package,
description = R.string.patch_options_clear_package_description
headline = R.string.patch_options_reset_package,
description = R.string.patch_options_reset_package_description
)
if (patchBundles.size > 1)
GroupItem(
onClick = { showBundleSelector = true },
headline = R.string.patch_options_clear_bundle,
description = R.string.patch_options_clear_bundle_description,
headline = R.string.patch_options_reset_bundle,
description = R.string.patch_options_reset_bundle_description,
)
GroupItem(
onClick = vm::resetOptions,
headline = R.string.patch_options_clear_all,
description = R.string.patch_options_clear_all_description,
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ImportExportViewModel(

val packagesWithOptions = optionsRepository.getPackagesWithSavedOptions()

fun clearOptionsForPackage(packageName: String) = viewModelScope.launch {
fun resetOptionsForPackage(packageName: String) = viewModelScope.launch {
optionsRepository.clearOptionsForPackage(packageName)
}

Expand Down Expand Up @@ -163,8 +163,8 @@ class ImportExportViewModel(
override val activityArg = JSON_MIMETYPE
override suspend fun execute(bundleUid: Int, location: Uri) = uiSafe(
app,
R.string.restore_patches_selection_fail,
"Failed to restore patches selection"
R.string.import_patch_selection_fail,
"Failed to restore patch selection"
) {
val selection = withContext(Dispatchers.IO) {
contentResolver.openInputStream(location)!!.use {
Expand All @@ -181,8 +181,8 @@ class ImportExportViewModel(
override val activityArg = "selection.json"
override suspend fun execute(bundleUid: Int, location: Uri) = uiSafe(
app,
R.string.backup_patches_selection_fail,
"Failed to backup patches selection"
R.string.export_patch_selection_fail,
"Failed to backup patch selection"
) {
val selection = selectionRepository.export(bundleUid)

Expand Down
Loading

0 comments on commit c0f3d02

Please sign in to comment.