From 6e19bdf4cbf38b10c4c6af628bcc1342693c4614 Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Thu, 21 Sep 2023 08:51:58 -0700 Subject: [PATCH 1/7] fix: hide patch button --- .../ui/screen/PatchesSelectorScreen.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt index 722e65e1b6..e8b257c1f2 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt @@ -101,16 +101,17 @@ fun PatchesSelectorScreen( ) }, floatingActionButton = { - ExtendedFloatingActionButton( - text = { Text(stringResource(R.string.patch)) }, - icon = { Icon(Icons.Default.Build, null) }, - onClick = { - composableScope.launch { - // TODO: only allow this if all required options have been set. - onPatchClick(vm.getAndSaveSelection(), vm.getOptions()) + if (!vm.isSelectionEmpty()) { + ExtendedFloatingActionButton( + text = { Text(stringResource(R.string.patch)) }, + icon = { Icon(Icons.Default.Build, null) }, + onClick = { + composableScope.launch { + onPatchClick(vm.getAndSaveSelection(), vm.getOptions()) + } } - } - ) + ) + } } ) { paddingValues -> Column( From d71d01697969c3f460924c6aa3cac676e85e43bd Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Thu, 21 Sep 2023 09:01:53 -0700 Subject: [PATCH 2/7] Update PatchesSelectorViewModel.kt --- .../revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt index b5c6b67065..761eb5115d 100644 --- a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt +++ b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt @@ -123,6 +123,7 @@ class PatchesSelectorViewModel( if (patches.contains(name)) patches.remove(name) else patches.add(name) } + fun isSelectionEmpty() = selectedPatches.values.all { it.isEmpty() } suspend fun getAndSaveSelection(): PatchesSelection = selectedPatches.also { withContext(Dispatchers.Default) { From 51707745664cc81d6a37a07215215fcc9c0d71e4 Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Thu, 21 Sep 2023 12:21:47 -0700 Subject: [PATCH 3/7] keep comment --- .../java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt index e8b257c1f2..12f083156f 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt @@ -107,6 +107,7 @@ fun PatchesSelectorScreen( icon = { Icon(Icons.Default.Build, null) }, onClick = { composableScope.launch { + // TODO: only allow this if all required options have been set. onPatchClick(vm.getAndSaveSelection(), vm.getOptions()) } } From eda3ceb3e6a5790dadb8b1f0b3447d0584c8bb40 Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Thu, 21 Sep 2023 12:26:30 -0700 Subject: [PATCH 4/7] add extra line --- .../revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt index 761eb5115d..4ccb11eb2c 100644 --- a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt +++ b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt @@ -124,6 +124,7 @@ class PatchesSelectorViewModel( } fun isSelectionEmpty() = selectedPatches.values.all { it.isEmpty() } + suspend fun getAndSaveSelection(): PatchesSelection = selectedPatches.also { withContext(Dispatchers.Default) { From f7d44e1a1b5a1bd69172fa9b6dc6f281a1b063f8 Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Sat, 14 Oct 2023 13:32:54 -0700 Subject: [PATCH 5/7] Toggle visibility --- .../ui/screen/PatchesSelectorScreen.kt | 34 ++++++++++++++----- .../ui/viewmodel/PatchesSelectorViewModel.kt | 16 +++++++-- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt index 1165e4abf5..3f2c615e55 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt @@ -1,5 +1,6 @@ package app.revanced.manager.ui.screen +import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -44,6 +45,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue @@ -56,6 +58,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.lifecycle.viewModelScope import app.revanced.manager.R import app.revanced.manager.domain.manager.PreferencesManager import app.revanced.manager.patcher.patch.PatchInfo @@ -85,6 +88,7 @@ fun PatchesSelectorScreen( mutableStateOf(null) } var showBottomSheet by rememberSaveable { mutableStateOf(false) } + var showPatchButton by remember { mutableStateOf(true) } val bundles by vm.bundlesFlow.collectAsStateWithLifecycle(initialValue = emptyList()) @@ -218,10 +222,17 @@ fun PatchesSelectorScreen( if (vm.selectionWarningEnabled) { vm.pendingSelectionAction = { vm.togglePatch(uid, patch) + vm.viewModelScope.launch { + showPatchButton = vm.isSelectionNotEmpty() + } } } else { vm.togglePatch(uid, patch) + vm.viewModelScope.launch { + showPatchButton = vm.isSelectionNotEmpty() + } } + }, supported = supported ) @@ -292,6 +303,7 @@ fun PatchesSelectorScreen( } } + Scaffold( topBar = { AppTopBar( @@ -315,15 +327,19 @@ fun PatchesSelectorScreen( ) }, floatingActionButton = { - ExtendedFloatingActionButton( - text = { Text(stringResource(R.string.patch)) }, - icon = { Icon(Icons.Default.Build, null) }, - onClick = { - // TODO: only allow this if all required options have been set. - composableScope.launch { - val selection = vm.getSelection() - vm.saveSelection(selection).join() - onPatchClick(selection, vm.getOptions()) + AnimatedVisibility(visible = showPatchButton) { + ExtendedFloatingActionButton( + text = { + Text(stringResource(R.string.patch)) + }, + icon = { Icon(Icons.Default.Build, null) }, + onClick = { + // TODO: only allow this if all required options have been set. + composableScope.launch { + val selection = vm.getSelection() + vm.saveSelection(selection).join() + onPatchClick(selection, vm.getOptions()) + } } ) } diff --git a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt index 3547e6f711..8e4f7246c1 100644 --- a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt +++ b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt @@ -167,8 +167,6 @@ class PatchesSelectorViewModel( } } - fun isSelectionEmpty() = selectedPatches.values.all { it.isEmpty() } - fun switchBaseSelectionMode() = viewModelScope.launch { baseSelectionMode = if (baseSelectionMode == BaseSelectionMode.DEFAULT) { BaseSelectionMode.PREVIOUS @@ -177,6 +175,20 @@ class PatchesSelectorViewModel( } } + private suspend fun patchesAvailable(bundle: BundleInfo): List { + val patches = (bundle.supported + bundle.universal).toMutableList() + val removeUnsupported = !allowExperimental.get() + if (!removeUnsupported) patches += bundle.unsupported + return patches + } + + suspend fun isSelectionNotEmpty() = + bundlesFlow.first().any { bundle -> + patchesAvailable(bundle).any { patch -> + isSelected(bundle.uid, patch) + } + } + private fun getOrCreateSelection(bundle: Int) = explicitPatchesSelection.getOrPut(bundle, ::mutableStateMapOf) From ce1b79c00a5e0aed2c5527838d3841ef3c639095 Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Sat, 14 Oct 2023 13:36:13 -0700 Subject: [PATCH 6/7] Hide patch button --- .../app/revanced/manager/ui/screen/PatchesSelectorScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt index 3f2c615e55..02ebca7316 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt @@ -327,7 +327,7 @@ fun PatchesSelectorScreen( ) }, floatingActionButton = { - AnimatedVisibility(visible = showPatchButton) { + if (showPatchButton) { ExtendedFloatingActionButton( text = { Text(stringResource(R.string.patch)) From 5b33d25d8d59ea02ede6110f6f888bdcc59dfff6 Mon Sep 17 00:00:00 2001 From: Benjamin Halko Date: Sat, 14 Oct 2023 14:01:11 -0700 Subject: [PATCH 7/7] Set showPatchButton correctly --- .../revanced/manager/ui/screen/PatchesSelectorScreen.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt index 02ebca7316..1bba71c978 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt @@ -1,6 +1,5 @@ package app.revanced.manager.ui.screen -import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -88,9 +87,13 @@ fun PatchesSelectorScreen( mutableStateOf(null) } var showBottomSheet by rememberSaveable { mutableStateOf(false) } - var showPatchButton by remember { mutableStateOf(true) } val bundles by vm.bundlesFlow.collectAsStateWithLifecycle(initialValue = emptyList()) + var showPatchButton by remember { mutableStateOf(true) } + + LaunchedEffect(Unit) { + showPatchButton = vm.isSelectionNotEmpty() + } if (showBottomSheet) { ModalBottomSheet( @@ -327,7 +330,7 @@ fun PatchesSelectorScreen( ) }, floatingActionButton = { - if (showPatchButton) { + if(showPatchButton) { ExtendedFloatingActionButton( text = { Text(stringResource(R.string.patch))