fix: always use default patch selection if customization is disabled

This commit is contained in:
Ax333l 2024-07-20 16:17:41 +02:00
parent de6fddf405
commit 2eca45d397
No known key found for this signature in database
GPG key ID: D2B4D85271127D23

View file

@ -1,6 +1,5 @@
package app.revanced.manager.ui.viewmodel package app.revanced.manager.ui.viewmodel
import android.app.Application
import android.content.pm.PackageInfo import android.content.pm.PackageInfo
import android.os.Parcelable import android.os.Parcelable
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
@ -38,7 +37,6 @@ class SelectedAppInfoViewModel(input: Params) : ViewModel(), KoinComponent {
private val optionsRepository: PatchOptionsRepository = get() private val optionsRepository: PatchOptionsRepository = get()
private val pm: PM = get() private val pm: PM = get()
private val savedStateHandle: SavedStateHandle = get() private val savedStateHandle: SavedStateHandle = get()
private val app: Application = get()
val prefs: PreferencesManager = get() val prefs: PreferencesManager = get()
private val persistConfiguration = input.patches == null private val persistConfiguration = input.patches == null
@ -82,20 +80,17 @@ class SelectedAppInfoViewModel(input: Params) : ViewModel(), KoinComponent {
private set private set
private var selectionState by savedStateHandle.saveable { private var selectionState by savedStateHandle.saveable {
if (input.patches != null) { if (input.patches != null)
return@saveable mutableStateOf(SelectionState.Customized(input.patches)) return@saveable mutableStateOf(SelectionState.Customized(input.patches))
}
val selection: MutableState<SelectionState> = mutableStateOf(SelectionState.Default) val selection: MutableState<SelectionState> = mutableStateOf(SelectionState.Default)
// Get previous selection (if present). // Try to get the previous selection if customization is enabled.
viewModelScope.launch { viewModelScope.launch {
if (!prefs.disableSelectionWarning.get()) return@launch
val previous = selectionRepository.getSelection(selectedApp.packageName) val previous = selectionRepository.getSelection(selectedApp.packageName)
if (previous.values.sumOf { it.size } == 0) return@launch
if (previous.values.sumOf { it.size } == 0) {
return@launch
}
selection.value = SelectionState.Customized(previous) selection.value = SelectionState.Customized(previous)
} }