mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 03:12:15 +00:00
Update: Revamp PackageState to taxonomical ComponentStates
This commit is contained in:
parent
9a74e003d9
commit
4a323ded0b
@ -89,34 +89,37 @@ enum class AntiFeature(val key: String, @StringRes val titleResId: Int) {
|
||||
NSFW("NSFW", R.string.not_safe_for_work)
|
||||
}
|
||||
|
||||
sealed interface PackageState {
|
||||
sealed interface ComponentState {
|
||||
val icon: ImageVector
|
||||
val textId: Int
|
||||
}
|
||||
|
||||
sealed class Cancelable(
|
||||
sealed class DownloadState(
|
||||
@StringRes override val textId: Int,
|
||||
override val icon: ImageVector = Icons.Rounded.Close
|
||||
) : PackageState
|
||||
) : ComponentState {
|
||||
|
||||
object Pending : Cancelable(R.string.pending)
|
||||
object Connecting : Cancelable(R.string.connecting)
|
||||
class Downloading(val downloaded: Long, val total: Long?) :
|
||||
Cancelable(R.string.downloading)
|
||||
object Pending : DownloadState(R.string.pending)
|
||||
object Connecting : DownloadState(R.string.connecting)
|
||||
class Downloading(val downloaded: Long, val total: Long?) :
|
||||
DownloadState(R.string.downloading)
|
||||
|
||||
object Installing : Cancelable(R.string.installing)
|
||||
object Installing : DownloadState(R.string.installing)
|
||||
}
|
||||
|
||||
sealed class ButtonWork(
|
||||
sealed class ActionState(
|
||||
@StringRes override val textId: Int,
|
||||
override val icon: ImageVector = Icons.Rounded.Download
|
||||
) : PackageState
|
||||
) : ComponentState {
|
||||
|
||||
object Install : ButtonWork(R.string.install, Icons.Rounded.Download)
|
||||
object Update : ButtonWork(R.string.update, Icons.Rounded.Download)
|
||||
object Uninstall : ButtonWork(R.string.uninstall, Icons.Rounded.Delete)
|
||||
object Launch : ButtonWork(R.string.launch, Icons.Rounded.Launch)
|
||||
object Details : ButtonWork(R.string.details, Icons.Rounded.Tune)
|
||||
object Share : ButtonWork(R.string.share, Icons.Rounded.Share)
|
||||
object Install : ActionState(R.string.install, Icons.Rounded.Download)
|
||||
object Update : ActionState(R.string.update, Icons.Rounded.Download)
|
||||
object Uninstall : ActionState(R.string.uninstall, Icons.Rounded.Delete)
|
||||
object Launch : ActionState(R.string.launch, Icons.Rounded.Launch)
|
||||
object Details : ActionState(R.string.details, Icons.Rounded.Tune)
|
||||
object Share : ActionState(R.string.share, Icons.Rounded.Share)
|
||||
class Cancel(@StringRes stateId: Int) : ActionState(stateId, Icons.Rounded.Close)
|
||||
}
|
||||
|
||||
open class LinkType(
|
||||
@DrawableRes val iconResId: Int,
|
||||
|
@ -17,18 +17,21 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.looker.droidify.entity.PackageState
|
||||
import com.looker.droidify.entity.ActionState
|
||||
import com.looker.droidify.entity.ComponentState
|
||||
import com.looker.droidify.entity.DownloadState
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
fun MainActionButton(
|
||||
modifier: Modifier = Modifier,
|
||||
packageState: PackageState,
|
||||
onClick: (PackageState) -> Unit
|
||||
actionState: ActionState,
|
||||
downloadState: DownloadState?,
|
||||
onClick: (ComponentState) -> Unit
|
||||
) {
|
||||
ElevatedButton(
|
||||
modifier = modifier,
|
||||
onClick = { onClick(packageState) }
|
||||
onClick = { onClick(actionState) }
|
||||
) {
|
||||
AnimatedContent(
|
||||
targetState = packageState,
|
||||
@ -66,7 +69,7 @@ fun MainActionButton(
|
||||
@Composable
|
||||
fun SecondaryActionButton(
|
||||
modifier: Modifier = Modifier,
|
||||
packageState: PackageState?,
|
||||
packageState: ComponentState?,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
packageState?.let {
|
||||
|
@ -32,8 +32,7 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.looker.droidify.database.entity.Installed
|
||||
import com.looker.droidify.database.entity.Repository
|
||||
import com.looker.droidify.entity.Install
|
||||
import com.looker.droidify.entity.Launch
|
||||
import com.looker.droidify.entity.ActionState
|
||||
import com.looker.droidify.entity.ProductItem
|
||||
import com.looker.droidify.network.CoilDownloader
|
||||
import com.looker.droidify.ui.compose.utils.ExpandableCard
|
||||
@ -155,8 +154,8 @@ fun ExpandedItemContent(
|
||||
onClick = { onActionClicked(item) }
|
||||
) {
|
||||
val action = when {
|
||||
installed != null -> Launch
|
||||
else -> Install
|
||||
installed != null -> ActionState.Launch
|
||||
else -> ActionState.Install
|
||||
}
|
||||
Icon(
|
||||
imageVector = action.icon,
|
||||
|
@ -26,10 +26,9 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.looker.droidify.R
|
||||
import com.looker.droidify.entity.Cancelable
|
||||
import com.looker.droidify.entity.Downloading
|
||||
import com.looker.droidify.entity.Install
|
||||
import com.looker.droidify.entity.PackageState
|
||||
import com.looker.droidify.entity.ActionState
|
||||
import com.looker.droidify.entity.ComponentState
|
||||
import com.looker.droidify.entity.DownloadState
|
||||
import com.looker.droidify.ui.compose.components.MainActionButton
|
||||
import com.looker.droidify.ui.compose.components.SecondaryActionButton
|
||||
import com.looker.droidify.ui.compose.utils.NetworkImage
|
||||
@ -41,8 +40,9 @@ fun AppInfoHeader(
|
||||
versionCode: String,
|
||||
appSize: String,
|
||||
appDev: String,
|
||||
state: PackageState? = Install,
|
||||
secondaryAction: PackageState? = null,
|
||||
mainAction: ActionState? = ActionState.Install,
|
||||
downloadState: DownloadState?,
|
||||
secondaryAction: ComponentState? = null,
|
||||
onSource: () -> Unit = { },
|
||||
onSourceLong: () -> Unit = { },
|
||||
onAction: () -> Unit = { },
|
||||
@ -73,10 +73,12 @@ fun AppInfoHeader(
|
||||
})
|
||||
MainActionButton(
|
||||
modifier = Modifier.weight(1f),
|
||||
packageState = state ?: Install,
|
||||
actionState = mainAction ?: ActionState.Install,
|
||||
downloadState = downloadState,
|
||||
onClick = {
|
||||
onAction()
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,7 +90,7 @@ fun TopBarHeader(
|
||||
icon: String? = null,
|
||||
appName: String,
|
||||
packageName: String,
|
||||
state: PackageState? = Install,
|
||||
state: DownloadState? = null,
|
||||
actions: @Composable () -> Unit = {}
|
||||
) {
|
||||
Surface(
|
||||
@ -118,12 +120,12 @@ fun TopBarHeader(
|
||||
Box { actions() }
|
||||
}
|
||||
|
||||
AnimatedVisibility(visible = state is Cancelable) {
|
||||
AnimatedVisibility(visible = state is DownloadState) {
|
||||
DownloadProgress(
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
totalSize = if (state is Downloading) state.total ?: 1L else 1L,
|
||||
isIndeterminate = state !is Downloading,
|
||||
downloaded = if (state is Downloading) state.downloaded else 0L,
|
||||
totalSize = if (state is DownloadState.Downloading) state.total ?: 1L else 1L,
|
||||
isIndeterminate = state !is DownloadState.Downloading,
|
||||
downloaded = if (state is DownloadState.Downloading) state.downloaded else 0L,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ package com.looker.droidify.ui.compose.utils
|
||||
|
||||
import android.net.Uri
|
||||
import com.looker.droidify.database.entity.Release
|
||||
import com.looker.droidify.entity.PackageState
|
||||
import com.looker.droidify.entity.ComponentState
|
||||
import com.looker.droidify.entity.ProductPreference
|
||||
import com.looker.droidify.entity.Screenshot
|
||||
|
||||
interface Callbacks {
|
||||
fun onActionClick(action: PackageState?)
|
||||
fun onActionClick(action: ComponentState?)
|
||||
fun onPreferenceChanged(preference: ProductPreference)
|
||||
fun onPermissionsClick(group: String?, permissions: List<String>)
|
||||
fun onScreenshotClick(screenshot: Screenshot)
|
||||
|
@ -8,7 +8,8 @@ import com.looker.droidify.database.DatabaseX
|
||||
import com.looker.droidify.database.entity.Installed
|
||||
import com.looker.droidify.database.entity.Product
|
||||
import com.looker.droidify.database.entity.Repository
|
||||
import com.looker.droidify.entity.PackageState
|
||||
import com.looker.droidify.entity.ActionState
|
||||
import com.looker.droidify.entity.DownloadState
|
||||
|
||||
class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
||||
|
||||
@ -21,9 +22,10 @@ class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
||||
set(value) {
|
||||
_productRepos.value = value
|
||||
}
|
||||
val state = MutableLiveData<PackageState>()
|
||||
val actions = MutableLiveData<Set<PackageState>>()
|
||||
val secondaryAction = MutableLiveData<PackageState>()
|
||||
val downloadState = MutableLiveData<DownloadState>()
|
||||
val mainAction = MutableLiveData<ActionState>()
|
||||
val actions = MutableLiveData<Set<ActionState>>()
|
||||
val secondaryAction = MutableLiveData<ActionState>()
|
||||
|
||||
init {
|
||||
products.addSource(db.productDao.getLive(packageName)) { products.setValue(it.filterNotNull()) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user