Compare commits

...

2 Commits

Author SHA1 Message Date
Tyff e353c01258 Made PR comment changes 2023-09-03 03:53:17 +12:00
Tyff a70167bed4 Deleted BundlesScreen.kt to make PR work
- should b more readable or something
2023-09-03 03:28:14 +12:00
7 changed files with 76 additions and 173 deletions

View File

@ -12,7 +12,6 @@ val viewModelModule = module {
viewModelOf(::AdvancedSettingsViewModel)
viewModelOf(::AppSelectorViewModel)
viewModelOf(::VersionSelectorViewModel)
viewModelOf(::BundlesViewModel)
viewModelOf(::InstallerViewModel)
viewModelOf(::UpdateProgressViewModel)
viewModelOf(::ManagerUpdateChangelogViewModel)

View File

@ -36,11 +36,10 @@ fun BundleItem(
bundle: PatchBundleSource,
onDelete: () -> Unit,
onUpdate: () -> Unit,
sourcesSelectable: Boolean,
editSelectedList: () -> Unit,
checkBoxTicked: Boolean,
onCheckBoxTicked: () -> Unit,
reAssignCheckBoxTicked: (Boolean) -> Unit,
selectable: Boolean,
onSelect: () -> Unit,
isBundleSelected: Boolean,
toggleSelection: (Boolean) -> Unit,
) {
var viewBundleDialogPage by rememberSaveable { mutableStateOf(false) }
val state by bundle.state.collectAsStateWithLifecycle()
@ -69,19 +68,13 @@ fun BundleItem(
onClick = {
viewBundleDialogPage = true
},
onLongClick = {
onCheckBoxTicked()
editSelectedList()
},
onLongClick = onSelect,
),
leadingContent = {
if(sourcesSelectable) {
if(selectable) {
Checkbox(
checked = checkBoxTicked,
onCheckedChange = {
reAssignCheckBoxTicked(it)
editSelectedList()
}
checked = isBundleSelected,
onCheckedChange = toggleSelection,
)
}
},

View File

@ -1,80 +0,0 @@
package app.revanced.manager.ui.screen
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
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.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.revanced.manager.domain.bundles.PatchBundleSource
import app.revanced.manager.domain.bundles.PatchBundleSource.Companion.isDefault
import app.revanced.manager.ui.component.bundle.BundleItem
import app.revanced.manager.ui.viewmodel.BundlesViewModel
import org.koin.androidx.compose.getViewModel
@Composable
fun BundlesScreen(
vm: BundlesViewModel = getViewModel(),
sourcesSelectable: Boolean,
editSelectedList: (PatchBundleSource) -> Unit,
deleteSelectedSources: Boolean,
onDeleteSelectedSources: () -> Unit,
refreshSelectedSources: Boolean,
onRefreshSelectedSources: () -> Unit,
clearAllCheckBoxes: Boolean,
onClearAllCheckBoxes: () -> Unit,
selectedSources: SnapshotStateList<PatchBundleSource>,
) {
val sources by vm.sources.collectAsStateWithLifecycle(initialValue = emptyList())
if (deleteSelectedSources) {
selectedSources.forEach {
if(!it.isDefault) {
vm.delete(it)
}
}
onDeleteSelectedSources()
}
if(refreshSelectedSources) {
selectedSources.forEach {
it.reload()
}
onRefreshSelectedSources()
}
Column(
modifier = Modifier
.fillMaxSize(),
) {
sources.forEach {
var checkBoxTicked by rememberSaveable { mutableStateOf(false) }
if(clearAllCheckBoxes) {
checkBoxTicked = false
onClearAllCheckBoxes()
}
BundleItem(
bundle = it,
onDelete = {
vm.delete(it)
},
onUpdate = {
vm.update(it)
},
sourcesSelectable = sourcesSelectable,
editSelectedList = {
editSelectedList(it)
},
checkBoxTicked = checkBoxTicked,
onCheckBoxTicked = { checkBoxTicked = true },
reAssignCheckBoxTicked = { newCheckBoxValue -> checkBoxTicked = newCheckBoxValue }
)
}
}
}

View File

@ -28,7 +28,6 @@ import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
@ -41,8 +40,9 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.revanced.manager.R
import app.revanced.manager.domain.bundles.PatchBundleSource
import app.revanced.manager.domain.bundles.PatchBundleSource.Companion.isDefault
import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.bundle.BundleItem
import app.revanced.manager.ui.component.bundle.BundleTopBar
import app.revanced.manager.ui.component.bundle.ImportBundleDialog
import app.revanced.manager.ui.viewmodel.DashboardViewModel
@ -67,12 +67,7 @@ fun DashboardScreen(
) {
var showImportBundleDialog by rememberSaveable { mutableStateOf(false) }
val selectedSources = remember { mutableStateListOf<PatchBundleSource>() }
val sourcesSelectable by remember { derivedStateOf { selectedSources.size > 0 } }
var deleteSelectedSources by remember { mutableStateOf(false) }
var refreshSelectedSources by remember { mutableStateOf(false) }
var clearAllCheckBoxes by remember { mutableStateOf(false) }
val bundlesSelectable by remember { derivedStateOf { vm.selectedSources.size > 0 } }
val pages: Array<DashboardPage> = DashboardPage.values()
val availablePatches by vm.availablePatches.collectAsStateWithLifecycle(0)
val androidContext = LocalContext.current
@ -100,12 +95,11 @@ fun DashboardScreen(
Scaffold(
topBar = {
if (sourcesSelectable) {
if (bundlesSelectable) {
BundleTopBar(
title = stringResource(R.string.patches_selected, selectedSources.size),
title = stringResource(R.string.bundles_selected, vm.selectedSources.size),
onBackClick = {
clearAllCheckBoxes = true
selectedSources.clear()
vm.selectedSources.clear()
},
onBackIcon = {
Icon(
@ -114,16 +108,18 @@ fun DashboardScreen(
)
},
actions = {
IconButton(onClick = { deleteSelectedSources = true }) {
IconButton(onClick = {
vm.selectedSources.forEach { if(!it.isDefault) vm.delete(it) }
vm.selectedSources.clear()
}) {
Icon(
Icons.Outlined.DeleteOutline,
stringResource(R.string.delete)
)
}
IconButton(onClick = {
refreshSelectedSources = true
clearAllCheckBoxes = true
selectedSources.clear()
vm.selectedSources.forEach { vm.update(it) }
vm.selectedSources.clear()
}) {
Icon(
Icons.Outlined.Refresh,
@ -203,31 +199,39 @@ fun DashboardScreen(
}
DashboardPage.BUNDLES -> {
BundlesScreen(
sourcesSelectable = sourcesSelectable,
editSelectedList = {
if (selectedSources.contains(it)) {
selectedSources.remove(it)
} else {
selectedSources.add(it)
}
},
deleteSelectedSources = deleteSelectedSources,
onDeleteSelectedSources = {
deleteSelectedSources = false
selectedSources.clear()
},
refreshSelectedSources = refreshSelectedSources,
onRefreshSelectedSources = {
refreshSelectedSources = false
selectedSources.clear()
},
selectedSources = selectedSources,
clearAllCheckBoxes = clearAllCheckBoxes,
onClearAllCheckBoxes = {
clearAllCheckBoxes = false
val sources by vm.sources.collectAsStateWithLifecycle(initialValue = emptyList())
Column(
modifier = Modifier
.fillMaxSize(),
) {
sources.forEach {
BundleItem(
bundle = it,
onDelete = {
vm.delete(it)
},
onUpdate = {
vm.update(it)
},
selectable = bundlesSelectable,
onSelect = {
vm.selectedSources.add(it)
},
isBundleSelected = vm.selectedSources.contains(it),
toggleSelection = { bundleIsNotSelected ->
if(bundleIsNotSelected) {
vm.selectedSources.add(it)
}
else {
vm.selectedSources.remove(it)
}
}
)
}
)
}
}
}
}

View File

@ -1,33 +0,0 @@
package app.revanced.manager.ui.viewmodel
import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.revanced.manager.R
import app.revanced.manager.domain.bundles.PatchBundleSource
import app.revanced.manager.domain.bundles.RemotePatchBundle
import app.revanced.manager.domain.repository.PatchBundleRepository
import app.revanced.manager.util.uiSafe
import kotlinx.coroutines.launch
class BundlesViewModel(
private val app: Application,
private val patchBundleRepository: PatchBundleRepository
) : ViewModel() {
val sources = patchBundleRepository.sources
fun delete(bundle: PatchBundleSource) =
viewModelScope.launch { patchBundleRepository.remove(bundle) }
fun update(bundle: PatchBundleSource) = viewModelScope.launch {
if (bundle !is RemotePatchBundle) return@launch
uiSafe(
app,
R.string.source_download_fail,
RemotePatchBundle.updateFailMsg
) {
bundle.update()
}
}
}

View File

@ -3,21 +3,26 @@ package app.revanced.manager.ui.viewmodel
import android.app.Application
import android.content.ContentResolver
import android.net.Uri
import androidx.compose.runtime.mutableStateListOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.revanced.manager.R
import app.revanced.manager.domain.bundles.PatchBundleSource
import app.revanced.manager.domain.bundles.RemotePatchBundle
import app.revanced.manager.domain.repository.PatchBundleRepository
import io.ktor.http.Url
import app.revanced.manager.util.uiSafe
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
class DashboardViewModel(
app: Application,
private val app: Application,
private val patchBundleRepository: PatchBundleRepository
) : ViewModel() {
val availablePatches =
patchBundleRepository.bundles.map { it.values.sumOf { bundle -> bundle.patches.size } }
private val contentResolver: ContentResolver = app.contentResolver
val sources = patchBundleRepository.sources
val selectedSources = mutableStateListOf<PatchBundleSource>()
fun createLocalSource(name: String, patchBundle: Uri, integrations: Uri?) =
viewModelScope.launch {
contentResolver.openInputStream(patchBundle)!!.use { patchesStream ->
@ -32,4 +37,19 @@ class DashboardViewModel(
fun createRemoteSource(name: String, apiUrl: String, autoUpdate: Boolean) =
viewModelScope.launch { patchBundleRepository.createRemote(name, apiUrl, autoUpdate) }
fun delete(bundle: PatchBundleSource) =
viewModelScope.launch { patchBundleRepository.remove(bundle) }
fun update(bundle: PatchBundleSource) = viewModelScope.launch {
if (bundle !is RemotePatchBundle) return@launch
uiSafe(
app,
R.string.source_download_fail,
RemotePatchBundle.updateFailMsg
) {
bundle.update()
}
}
}

View File

@ -133,7 +133,7 @@
<string name="no_patches">No patches available to view</string>
<string name="patches_available">%d Patches available, tap to view</string>
<string name="tap_on_patches">Tap on the patches to get more information about them</string>
<string name="patches_selected">%s selected</string>
<string name="bundles_selected">%s selected</string>
<string name="unsupported_app">Unsupported app</string>
<string name="unsupported_patches">Unsupported patches</string>
<string name="universal_patches">Universal patches</string>