mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-05-20 21:47:06 +02:00
fix: hide patch button (#1284)
This commit is contained in:
parent
212e55ffd8
commit
5aefb3bc59
@ -44,6 +44,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
@ -56,6 +57,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
import app.revanced.manager.R
|
import app.revanced.manager.R
|
||||||
import app.revanced.manager.domain.manager.PreferencesManager
|
import app.revanced.manager.domain.manager.PreferencesManager
|
||||||
import app.revanced.manager.patcher.patch.PatchInfo
|
import app.revanced.manager.patcher.patch.PatchInfo
|
||||||
@ -91,7 +93,10 @@ fun PatchesSelectorScreen(
|
|||||||
mutableStateOf(null)
|
mutableStateOf(null)
|
||||||
}
|
}
|
||||||
var showBottomSheet by rememberSaveable { mutableStateOf(false) }
|
var showBottomSheet by rememberSaveable { mutableStateOf(false) }
|
||||||
|
var showPatchButton by remember { mutableStateOf(true) }
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
showPatchButton = vm.isSelectionNotEmpty()
|
||||||
|
}
|
||||||
if (showBottomSheet) {
|
if (showBottomSheet) {
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = {
|
onDismissRequest = {
|
||||||
@ -222,10 +227,17 @@ fun PatchesSelectorScreen(
|
|||||||
if (vm.selectionWarningEnabled) {
|
if (vm.selectionWarningEnabled) {
|
||||||
vm.pendingSelectionAction = {
|
vm.pendingSelectionAction = {
|
||||||
vm.togglePatch(uid, patch)
|
vm.togglePatch(uid, patch)
|
||||||
|
vm.viewModelScope.launch {
|
||||||
|
showPatchButton = vm.isSelectionNotEmpty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vm.togglePatch(uid, patch)
|
vm.togglePatch(uid, patch)
|
||||||
|
vm.viewModelScope.launch {
|
||||||
|
showPatchButton = vm.isSelectionNotEmpty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
supported = supported
|
supported = supported
|
||||||
)
|
)
|
||||||
@ -296,6 +308,7 @@ fun PatchesSelectorScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
AppTopBar(
|
AppTopBar(
|
||||||
@ -319,18 +332,22 @@ fun PatchesSelectorScreen(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
ExtendedFloatingActionButton(
|
if(showPatchButton) {
|
||||||
text = { Text(stringResource(R.string.patch)) },
|
ExtendedFloatingActionButton(
|
||||||
icon = { Icon(Icons.Default.Build, null) },
|
text = {
|
||||||
onClick = {
|
Text(stringResource(R.string.patch))
|
||||||
// TODO: only allow this if all required options have been set.
|
},
|
||||||
composableScope.launch {
|
icon = { Icon(Icons.Default.Build, null) },
|
||||||
val selection = vm.getSelection()
|
onClick = {
|
||||||
vm.saveSelection(selection).join()
|
// TODO: only allow this if all required options have been set.
|
||||||
onPatchClick(selection, vm.getOptions())
|
composableScope.launch {
|
||||||
|
val selection = vm.getSelection()
|
||||||
|
vm.saveSelection(selection).join()
|
||||||
|
onPatchClick(selection, vm.getOptions())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
Column(
|
Column(
|
||||||
|
@ -175,6 +175,20 @@ class PatchesSelectorViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun patchesAvailable(bundle: BundleInfo): List<PatchInfo> {
|
||||||
|
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) =
|
private fun getOrCreateSelection(bundle: Int) =
|
||||||
explicitPatchesSelection.getOrPut(bundle, ::mutableStateMapOf)
|
explicitPatchesSelection.getOrPut(bundle, ::mutableStateMapOf)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user