compose: details: Emit downloading state during purchase

Purchase can take a while making user believe there is no progress happening.
Emit Downloading status with 0s to show loading indicator.

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-09-17 14:11:36 +05:30
parent acc8e5da4e
commit 4de974e7c4

View File

@@ -221,12 +221,14 @@ class AppDetailsViewModel @Inject constructor(
fun purchase(app: App) {
viewModelScope.launch(Dispatchers.IO) {
try {
_state.value = AppState.Downloading(0F, 0 ,0)
val files = purchaseHelper.purchase(app.packageName, app.versionCode, app.offerType)
_purchaseStatus.emit(files.isNotEmpty())
if (files.isNotEmpty()) {
downloadHelper.enqueueApp(app.copy(fileList = files.toMutableList()))
}
} catch (exception: Exception) {
_state.value = defaultAppState
_purchaseStatus.emit(false)
Log.e(TAG, "Failed to purchase the app", exception)
}