compose: details: Better handle purchase state

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-09-18 18:55:10 +05:30
parent 8212566dbf
commit 812d13cb44
5 changed files with 11 additions and 3 deletions

View File

@@ -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
)
}

View File

@@ -97,6 +97,10 @@ fun Details(
)
}
AppState.Purchasing::class -> {
stringResource(R.string.preparing_to_install)
}
else -> {
stringResource(R.string.version, versionName, versionCode)
}

View File

@@ -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
}
/**

View File

@@ -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()) {