Skip to content

Commit 76a4d9d

Browse files
Merge pull request #24 from D4rK7355608/codex/convert-in-app-update-use-case-to-java
Update in-app update flow
2 parents 1ae82b0 + 0ad81ed commit 76a4d9d

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/main/MainActivity.java

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -259,30 +259,33 @@ protected void onResume() {
259259
AppUsageNotificationsManager appUsageNotificationsManager = new AppUsageNotificationsManager(this);
260260
appUsageNotificationsManager.scheduleAppUsageCheck();
261261
appUpdateNotificationsManager.checkAndSendUpdateNotification();
262-
checkForFlexibleOrImmediateUpdate();
262+
checkForImmediateUpdate();
263263
}
264264

265-
private void checkForFlexibleOrImmediateUpdate() {
266-
appUpdateManager.getAppUpdateInfo().addOnSuccessListener(appUpdateInfo -> {
267-
boolean updateAvailable = appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE;
268-
if (updateAvailable) {
269-
int priority = appUpdateInfo.updatePriority();
270-
if (priority >= 3 && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
271-
startImmediateUpdate(appUpdateInfo);
272-
} else if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
273-
startFlexibleUpdate(appUpdateInfo);
274-
}
275-
}
276-
})
277-
.addOnFailureListener(e -> {
278-
if (!BuildConfig.DEBUG) {
279-
Snackbar.make(
280-
findViewById(android.R.id.content),
281-
getString(R.string.snack_general_error),
282-
Snackbar.LENGTH_LONG
283-
).show();
284-
}
285-
});
265+
private void checkForImmediateUpdate() {
266+
appUpdateManager
267+
.getAppUpdateInfo()
268+
.addOnSuccessListener(
269+
appUpdateInfo -> {
270+
boolean updateAvailable =
271+
appUpdateInfo.updateAvailability()
272+
== UpdateAvailability.UPDATE_AVAILABLE;
273+
if (updateAvailable
274+
&& appUpdateInfo.isUpdateTypeAllowed(
275+
AppUpdateType.IMMEDIATE)) {
276+
startImmediateUpdate(appUpdateInfo);
277+
}
278+
})
279+
.addOnFailureListener(
280+
e -> {
281+
if (!BuildConfig.DEBUG) {
282+
Snackbar.make(
283+
findViewById(android.R.id.content),
284+
getString(R.string.snack_general_error),
285+
Snackbar.LENGTH_LONG)
286+
.show();
287+
}
288+
});
286289
}
287290

288291
private void startImmediateUpdate(AppUpdateInfo appUpdateInfo) {
@@ -293,14 +296,6 @@ private void startImmediateUpdate(AppUpdateInfo appUpdateInfo) {
293296
);
294297
}
295298

296-
private void startFlexibleUpdate(AppUpdateInfo appUpdateInfo) {
297-
appUpdateManager.startUpdateFlowForResult(
298-
appUpdateInfo,
299-
updateActivityResultLauncher,
300-
AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build()
301-
);
302-
}
303-
304299
private void registerInstallStateListener() {
305300
installStateUpdatedListener = state -> {
306301
if (state.installStatus() == InstallStatus.DOWNLOADED) {

0 commit comments

Comments
 (0)