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:
@@ -221,12 +221,14 @@ class AppDetailsViewModel @Inject constructor(
|
|||||||
fun purchase(app: App) {
|
fun purchase(app: App) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
|
_state.value = AppState.Downloading(0F, 0 ,0)
|
||||||
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()) {
|
||||||
downloadHelper.enqueueApp(app.copy(fileList = files.toMutableList()))
|
downloadHelper.enqueueApp(app.copy(fileList = files.toMutableList()))
|
||||||
}
|
}
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
|
_state.value = defaultAppState
|
||||||
_purchaseStatus.emit(false)
|
_purchaseStatus.emit(false)
|
||||||
Log.e(TAG, "Failed to purchase the app", exception)
|
Log.e(TAG, "Failed to purchase the app", exception)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user