mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Update: Clean up actions management in AppSheet
This commit is contained in:
parent
24dd888e5b
commit
a64afc3d6a
@ -44,7 +44,6 @@ fun AppInfoHeader(
|
||||
appSize: String,
|
||||
appDev: String,
|
||||
mainAction: ActionState?,
|
||||
secondaryAction: ActionState? = null,
|
||||
possibleActions: Set<ActionState>,
|
||||
onSource: () -> Unit = { },
|
||||
onSourceLong: () -> Unit = { },
|
||||
@ -74,8 +73,8 @@ fun AppInfoHeader(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
if (possibleActions.size == 1) {
|
||||
SecondaryActionButton(packageState = secondaryAction, onClick = {
|
||||
onAction(secondaryAction)
|
||||
SecondaryActionButton(packageState = possibleActions.first(), onClick = {
|
||||
onAction(possibleActions.first())
|
||||
})
|
||||
} else if (possibleActions.size > 1) {
|
||||
SecondaryActionButton(
|
||||
|
@ -354,7 +354,6 @@ class AppSheetX() : FullscreenBottomSheetDialogFragment(), Callbacks {
|
||||
val downloadState by viewModel.downloadState.observeAsState(null)
|
||||
val mainAction by viewModel.mainAction.observeAsState(if (installed == null) ActionState.Install else ActionState.Launch)
|
||||
val actions by viewModel.actions.observeAsState()
|
||||
val secondaryAction by viewModel.secondaryAction.observeAsState()
|
||||
val extras by viewModel.extras.observeAsState(Extras(packageName))
|
||||
val productRepos = products?.mapNotNull { product ->
|
||||
repos?.firstOrNull { it.id == product.repositoryId }
|
||||
@ -425,7 +424,6 @@ class AppSheetX() : FullscreenBottomSheetDialogFragment(), Callbacks {
|
||||
appSize = product.displayRelease?.size?.formatSize().orEmpty(),
|
||||
appDev = product.author.name.replaceFirstChar { it.titlecase() },
|
||||
mainAction = mainAction,
|
||||
secondaryAction = secondaryAction,
|
||||
possibleActions = actions?.filter { it != mainAction }?.toSet()
|
||||
?: emptySet(),
|
||||
onSource = {
|
||||
|
@ -31,7 +31,6 @@ class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
||||
val downloadState: MutableLiveData<DownloadState> = MutableLiveData()
|
||||
val mainAction: MutableLiveData<ActionState> = MutableLiveData()
|
||||
val actions: MediatorLiveData<Set<ActionState>> = MediatorLiveData()
|
||||
val secondaryAction: MutableLiveData<ActionState> = MutableLiveData()
|
||||
val extras: MediatorLiveData<Extras> = MediatorLiveData()
|
||||
|
||||
init {
|
||||
@ -63,7 +62,7 @@ class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
||||
val canLaunch =
|
||||
product != null && installed != null && installed.launcherActivities.isNotEmpty()
|
||||
val canShare = product != null && productRepos[0].second.name == "F-Droid"
|
||||
val bookmarked = extras.value?.favorite
|
||||
val bookmarked = extras.value?.favorite ?: false
|
||||
|
||||
val actions = mutableSetOf<ActionState>()
|
||||
launch {
|
||||
@ -73,7 +72,7 @@ class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
||||
if (installed != null) actions += ActionState.Details
|
||||
if (canUninstall) actions += ActionState.Uninstall
|
||||
if (canShare) actions += ActionState.Share
|
||||
if (bookmarked == true) actions += ActionState.Bookmarked
|
||||
if (bookmarked) actions += ActionState.Bookmarked
|
||||
else actions += ActionState.Bookmark
|
||||
}
|
||||
val primaryAction = when {
|
||||
@ -81,15 +80,9 @@ class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
||||
canLaunch -> ActionState.Launch
|
||||
canInstall -> ActionState.Install
|
||||
canShare -> ActionState.Share
|
||||
bookmarked == true -> ActionState.Bookmarked
|
||||
bookmarked -> ActionState.Bookmarked
|
||||
else -> ActionState.Bookmark
|
||||
}
|
||||
val secondaryAction = when {
|
||||
primaryAction != ActionState.Share && canShare -> ActionState.Share
|
||||
primaryAction != ActionState.Launch && canLaunch -> ActionState.Launch
|
||||
installed != null && canUninstall -> ActionState.Uninstall
|
||||
else -> null
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
this@AppViewModelX.actions.value = actions
|
||||
@ -100,7 +93,7 @@ class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
||||
}
|
||||
else if (downloadState.value == null)
|
||||
mainAction.value = primaryAction
|
||||
this@AppViewModelX.secondaryAction.value = secondaryAction
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user