mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2026-01-11 13:46:17 +00:00
Implement basic source selector UI
This commit is contained in:
@@ -243,12 +243,13 @@ private fun ReVancedManager() {
|
||||
)
|
||||
)
|
||||
},
|
||||
onSourceClick = { packageName, version ->
|
||||
onSourceClick = { packageName, version, selectedSource ->
|
||||
navController.navigateComplex(
|
||||
SelectedAppInfo.SourceSelector,
|
||||
SelectedAppInfo.SourceSelector.ViewModelParams(
|
||||
packageName,
|
||||
version,
|
||||
selectedSource,
|
||||
)
|
||||
)
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ package app.revanced.manager.ui.model.navigation
|
||||
|
||||
import android.os.Parcelable
|
||||
import app.revanced.manager.ui.model.SelectedApp
|
||||
import app.revanced.manager.ui.model.SelectedSource
|
||||
import app.revanced.manager.ui.model.SelectedVersion
|
||||
import app.revanced.manager.util.Options
|
||||
import app.revanced.manager.util.PatchSelection
|
||||
@@ -63,6 +64,7 @@ data object SelectedAppInfo : ComplexParameter<SelectedAppInfo.ViewModelParams>
|
||||
data class ViewModelParams(
|
||||
val packageName: String,
|
||||
val version: String?,
|
||||
val selectedSource: SelectedSource,
|
||||
) : Parcelable
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ fun SelectedAppInfoScreen(
|
||||
onRequiredOptions: (packageName: String, version: String?, PatchSelection?, Options) -> Unit,
|
||||
onPatchClick: () -> Unit,
|
||||
onVersionClick: (packageName: String, patchSelection: PatchSelection, selectedVersion: SelectedVersion) -> Unit,
|
||||
onSourceClick: (packageName: String, version: String?) -> Unit,
|
||||
onSourceClick: (packageName: String, version: String?, SelectedSource) -> Unit,
|
||||
onBackClick: () -> Unit,
|
||||
vm: SelectedAppInfoViewModel
|
||||
) {
|
||||
@@ -173,7 +173,7 @@ fun SelectedAppInfoScreen(
|
||||
when (selectedSource) {
|
||||
else -> "Sourcing the source"
|
||||
},
|
||||
onClick = { onSourceClick(packageName, versionText) },
|
||||
onClick = { onSourceClick(packageName, versionText, selectedSource) },
|
||||
)
|
||||
|
||||
error?.let {
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
package app.revanced.manager.ui.screen
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Save
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import app.revanced.manager.ui.component.AppTopBar
|
||||
import app.revanced.manager.ui.component.haptics.HapticExtendedFloatingActionButton
|
||||
import app.revanced.manager.ui.model.SelectedSource
|
||||
import app.revanced.manager.ui.viewmodel.SourceSelectorViewModel
|
||||
import app.revanced.manager.util.enabled
|
||||
import app.revanced.manager.util.transparentListItemColors
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -25,14 +34,87 @@ fun SourceSelectorScreen(
|
||||
title = { Text("Select source") },
|
||||
onBackClick = onBackClick,
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
HapticExtendedFloatingActionButton(
|
||||
text = { Text("Save") },
|
||||
icon = { Icon(Icons.Outlined.Save, null) },
|
||||
onClick = { onSave(viewModel.selectedSource) },
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier.padding(paddingValues)
|
||||
) {
|
||||
ListItem(
|
||||
headlineContent = { Text("Filtering for ${viewModel.input.packageName}: ${viewModel.input.version}") }
|
||||
SourceOption(
|
||||
source = SelectedSource.Auto,
|
||||
isSelected = viewModel.selectedSource == SelectedSource.Auto,
|
||||
onSelect = viewModel::selectSource,
|
||||
headlineContent = { Text("Auto (Recommended)") },
|
||||
supportingContent = { Text("Automatically select the best available source") }
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
SourceOption(
|
||||
source = SelectedSource.Installed,
|
||||
isSelected = viewModel.selectedSource == SelectedSource.Installed,
|
||||
onSelect = viewModel::selectSource,
|
||||
headlineContent = { Text("20.14.43") },
|
||||
supportingContent = { Text("Split APK's are not supported") },
|
||||
overlineContent = { Text("Installed") },
|
||||
enabled = false,
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
SourceOption(
|
||||
source = SelectedSource.Downloaded("path"),
|
||||
isSelected = viewModel.selectedSource == SelectedSource.Downloaded("path"),
|
||||
onSelect = viewModel::selectSource,
|
||||
headlineContent = { Text("20.14.43") },
|
||||
// supportingContent = { Text("") },
|
||||
overlineContent = { Text("Downloaded") },
|
||||
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
SourceOption(
|
||||
source = SelectedSource.Plugin("plugin-id"),
|
||||
isSelected = viewModel.selectedSource == SelectedSource.Plugin("plugin-id"),
|
||||
onSelect = viewModel::selectSource,
|
||||
headlineContent = { Text("APKMirror Downloader") },
|
||||
overlineContent = { Text("Plugin") },
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SourceOption(
|
||||
source: SelectedSource,
|
||||
isSelected: Boolean,
|
||||
onSelect: (SelectedSource) -> Unit,
|
||||
headlineContent: @Composable (() -> Unit),
|
||||
supportingContent: @Composable (() -> Unit)? = null,
|
||||
overlineContent: @Composable (() -> Unit)? = null,
|
||||
enabled: Boolean = true,
|
||||
) {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clickable(enabled) { onSelect(source) }
|
||||
.enabled(enabled),
|
||||
leadingContent = {
|
||||
RadioButton(
|
||||
selected = isSelected,
|
||||
onClick = null
|
||||
)
|
||||
},
|
||||
headlineContent = headlineContent,
|
||||
supportingContent = supportingContent,
|
||||
overlineContent = overlineContent,
|
||||
colors = transparentListItemColors
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.Save
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
@@ -40,6 +42,11 @@ fun VersionSelectorScreen(
|
||||
AppTopBar(
|
||||
title = { Text("Select version") },
|
||||
onBackClick = onBackClick,
|
||||
actions = {
|
||||
IconButton({}) {
|
||||
Icon(Icons.Outlined.MoreVert, contentDescription = null)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
@@ -112,5 +119,4 @@ private fun VersionOption(
|
||||
supportingContent = description,
|
||||
colors = transparentListItemColors
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,50 @@
|
||||
package app.revanced.manager.ui.viewmodel
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import app.revanced.manager.domain.repository.DownloadedAppRepository
|
||||
import app.revanced.manager.ui.model.SelectedSource
|
||||
import app.revanced.manager.ui.model.navigation.SelectedAppInfo
|
||||
import app.revanced.manager.util.PM
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.get
|
||||
|
||||
class SourceSelectorViewModel(
|
||||
val input: SelectedAppInfo.SourceSelector.ViewModelParams
|
||||
) : ViewModel(), KoinComponent {
|
||||
private val downloadedAppRepository: DownloadedAppRepository = get()
|
||||
private val pm: PM = get()
|
||||
|
||||
// val downloadedApps = downloadedAppRepository.get(input.packageName)
|
||||
// .map {
|
||||
// it.map {
|
||||
// SelectedSource.Downloaded(
|
||||
//
|
||||
// )
|
||||
// }.sortedByDescending { app -> app.version }
|
||||
// }
|
||||
|
||||
var selectedSource by mutableStateOf(input.selectedSource)
|
||||
private set
|
||||
|
||||
fun selectSource(source: SelectedSource) {
|
||||
selectedSource = source
|
||||
}
|
||||
|
||||
|
||||
|
||||
var installedApp: PackageInfo? = null
|
||||
private set
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
installedApp = pm.getPackageInfo(input.packageName)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@ class VersionSelectorViewModel(
|
||||
) : ViewModel(), KoinComponent {
|
||||
val patchBundleRepository: PatchBundleRepository = get()
|
||||
|
||||
|
||||
val patchCount = input.patchSelection.patchCount
|
||||
|
||||
val availableVersions = patchBundleRepository.suggestedVersions(input.packageName, input.patchSelection)
|
||||
@@ -37,6 +36,4 @@ class VersionSelectorViewModel(
|
||||
fun selectVersion(version: SelectedVersion) {
|
||||
selectedVersion = version
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user