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
|
@Composable
|
||||||
fun SetupActions() {
|
fun SetupActions() {
|
||||||
when (state) {
|
when (state) {
|
||||||
|
is AppState.Purchasing,
|
||||||
is AppState.Downloading -> {
|
is AppState.Downloading -> {
|
||||||
Actions(
|
Actions(
|
||||||
primaryActionDisplayName = stringResource(R.string.action_open),
|
primaryActionDisplayName = stringResource(R.string.action_open),
|
||||||
secondaryActionDisplayName = stringResource(R.string.action_cancel),
|
secondaryActionDisplayName = stringResource(R.string.action_cancel),
|
||||||
isPrimaryActionEnabled = false,
|
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 -> {
|
else -> {
|
||||||
stringResource(R.string.version, versionName, versionCode)
|
stringResource(R.string.version, versionName, versionCode)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ sealed class AppState {
|
|||||||
val timeRemaining: Long
|
val timeRemaining: Long
|
||||||
) : AppState()
|
) : AppState()
|
||||||
|
|
||||||
|
data object Purchasing : AppState()
|
||||||
data class Installing(val progress: Float) : AppState()
|
data class Installing(val progress: Float) : AppState()
|
||||||
data class Error(val message: String?) : AppState()
|
data class Error(val message: String?) : AppState()
|
||||||
data class Installed(val versionName: String, val versionCode: Long) : 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
|
* Whether there is some sort of ongoing process related to the app
|
||||||
*/
|
*/
|
||||||
fun inProgress(): Boolean {
|
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) {
|
fun purchase(app: App) {
|
||||||
viewModelScope.launch(NonCancellable + Dispatchers.IO) {
|
viewModelScope.launch(NonCancellable + Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
_state.value = AppState.Downloading(0F, 0 ,0)
|
_state.value = AppState.Purchasing
|
||||||
val files = purchaseHelper.purchase(app.packageName, app.versionCode, app.offerType)
|
val files = purchaseHelper.purchase(app.packageName, app.versionCode, app.offerType)
|
||||||
_purchaseStatus.emit(files.isNotEmpty())
|
_purchaseStatus.emit(files.isNotEmpty())
|
||||||
if (files.isNotEmpty()) {
|
if (files.isNotEmpty()) {
|
||||||
|
|||||||
@@ -508,6 +508,7 @@
|
|||||||
<string name="details_compatibility_status_limited">Limited: Works with limited features</string>
|
<string name="details_compatibility_status_limited">Limited: Works with limited features</string>
|
||||||
<string name="details_compatibility_status_unsupported">Unsupported: Not functional</string>
|
<string name="details_compatibility_status_unsupported">Unsupported: Not functional</string>
|
||||||
<string name="details_compatibility_status_unknown">Unknown: Not checked yet</string>
|
<string name="details_compatibility_status_unknown">Unknown: Not checked yet</string>
|
||||||
|
<string name="preparing_to_install">Preparing to install</string>
|
||||||
|
|
||||||
<!-- AppsGamesFragment -->
|
<!-- AppsGamesFragment -->
|
||||||
<string name="installed_apps_size"><xliff:g id="installed_apps_size">%1$d</xliff:g> apps installed</string>
|
<string name="installed_apps_size"><xliff:g id="installed_apps_size">%1$d</xliff:g> apps installed</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user