Skip to content

Commit 118f740

Browse files
committed
Fix crash when no google services for market version by #1731
1 parent b869c63 commit 118f740

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

core/ui/src/market/java/ru/tech/imageresizershrinker/core/ui/utils/helper/ReviewHandler.kt

+14-11
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ object ReviewHandler {
2929
context: Context,
3030
onComplete: () -> Unit = {}
3131
) {
32-
val reviewManager = ReviewManagerFactory.create(context)
33-
reviewManager
34-
.requestReviewFlow()
35-
.addOnCompleteListener {
36-
if (it.isSuccessful) {
37-
reviewManager
38-
.launchReviewFlow(context as Activity, it.result)
39-
.addOnCompleteListener {
40-
onComplete()
41-
}
32+
runCatching {
33+
val reviewManager = ReviewManagerFactory.create(context)
34+
35+
reviewManager
36+
.requestReviewFlow()
37+
.addOnCompleteListener {
38+
if (it.isSuccessful) {
39+
reviewManager
40+
.launchReviewFlow(context as Activity, it.result)
41+
.addOnCompleteListener {
42+
onComplete()
43+
}
44+
}
4245
}
43-
}
46+
}
4447
}
4548

4649
fun notShowReviewAgain(context: Context) = Unit

core/ui/src/market/java/ru/tech/imageresizershrinker/core/ui/widget/UpdateSheet.kt

+25-16
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,36 @@ fun UpdateSheet(
7272
if (context.isInstalledFromPlayStore()) {
7373
LaunchedEffect(visible) {
7474
if (visible) {
75-
val appUpdateManager = AppUpdateManagerFactory.create(context)
75+
runCatching {
76+
val appUpdateManager = AppUpdateManagerFactory.create(context)
7677

77-
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
78+
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
7879

79-
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
80-
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
81-
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
82-
) {
83-
appUpdateManager.startUpdateFlow(
84-
appUpdateInfo,
85-
context as Activity,
86-
AppUpdateOptions.defaultOptions(AppUpdateType.IMMEDIATE)
87-
)
88-
} else {
89-
scope.launch {
90-
toastHostState.showToast(
91-
icon = Icons.Rounded.FileDownloadOff,
92-
message = context.getString(R.string.no_updates)
80+
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
81+
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
82+
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
83+
) {
84+
appUpdateManager.startUpdateFlow(
85+
appUpdateInfo,
86+
context as Activity,
87+
AppUpdateOptions.defaultOptions(AppUpdateType.IMMEDIATE)
9388
)
89+
} else {
90+
scope.launch {
91+
toastHostState.showToast(
92+
icon = Icons.Rounded.FileDownloadOff,
93+
message = context.getString(R.string.no_updates)
94+
)
95+
}
9496
}
9597
}
98+
}.onFailure {
99+
scope.launch {
100+
toastHostState.showToast(
101+
icon = Icons.Rounded.FileDownloadOff,
102+
message = context.getString(R.string.no_updates)
103+
)
104+
}
96105
}
97106
}
98107
}

0 commit comments

Comments
 (0)