compose: details: Better handle purchase state
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -274,12 +274,14 @@ private fun ScreenContentApp(
|
||||
@Composable
|
||||
fun SetupActions() {
|
||||
when (state) {
|
||||
is AppState.Purchasing,
|
||||
is AppState.Downloading -> {
|
||||
Actions(
|
||||
primaryActionDisplayName = stringResource(R.string.action_open),
|
||||
secondaryActionDisplayName = stringResource(R.string.action_cancel),
|
||||
isPrimaryActionEnabled = false,
|
||||
onSecondaryAction = onCancelDownload
|
||||
onSecondaryAction = onCancelDownload,
|
||||
isSecondaryActionEnabled = state !is AppState.Purchasing
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,10 @@ fun Details(
|
||||
)
|
||||
}
|
||||
|
||||
AppState.Purchasing::class -> {
|
||||
stringResource(R.string.preparing_to_install)
|
||||
}
|
||||
|
||||
else -> {
|
||||
stringResource(R.string.version, versionName, versionCode)
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ sealed class AppState {
|
||||
val timeRemaining: Long
|
||||
) : AppState()
|
||||
|
||||
data object Purchasing : AppState()
|
||||
data class Installing(val progress: Float) : AppState()
|
||||
data class Error(val message: String?) : AppState()
|
||||
data class Installed(val versionName: String, val versionCode: Long) : AppState()
|
||||
@@ -67,7 +68,7 @@ sealed class AppState {
|
||||
* Whether there is some sort of ongoing process related to the app
|
||||
*/
|
||||
fun inProgress(): Boolean {
|
||||
return this is Downloading || this is Installing
|
||||
return this is Downloading || this is Installing || this is Purchasing
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -222,7 +222,7 @@ class AppDetailsViewModel @Inject constructor(
|
||||
fun purchase(app: App) {
|
||||
viewModelScope.launch(NonCancellable + Dispatchers.IO) {
|
||||
try {
|
||||
_state.value = AppState.Downloading(0F, 0 ,0)
|
||||
_state.value = AppState.Purchasing
|
||||
val files = purchaseHelper.purchase(app.packageName, app.versionCode, app.offerType)
|
||||
_purchaseStatus.emit(files.isNotEmpty())
|
||||
if (files.isNotEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user