Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.splashscreen.SplashScreen;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
Expand Down Expand Up @@ -62,15 +63,7 @@
public class MainActivity extends AppCompatActivity {

private static final long BACK_PRESS_INTERVAL = 2000;
private final ActivityResultLauncher<IntentSenderRequest> updateActivityResultLauncher =
registerForActivityResult(
new ActivityResultContracts.StartIntentSenderForResult(),
result -> {
if (result.getResultCode() != Activity.RESULT_OK) {
Log.d("MainActivity", "In-app update flow failed! " + result.getResultCode());
}
}
);
private ActivityResultLauncher<IntentSenderRequest> updateActivityResultLauncher;
private final SparseIntArray navOrder = new SparseIntArray();
private ActivityMainBinding mBinding;
private final DefaultLifecycleObserver lifecycleObserver = new DefaultLifecycleObserver() {
Expand Down Expand Up @@ -101,6 +94,15 @@ public void onResume(@NonNull LifecycleOwner owner) {
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.installSplashScreen(this);
super.onCreate(savedInstanceState);

updateActivityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartIntentSenderForResult(),
result -> {
if (result.getResultCode() != Activity.RESULT_OK) {
Log.d("MainActivity", "In-app update flow failed! " + result.getResultCode());
}
}
);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!prefs.getBoolean(getString(R.string.key_onboarding_complete), false)) {
startActivity(new Intent(this, StartupActivity.class));
Expand Down Expand Up @@ -315,21 +317,24 @@ protected void onResume() {
}

private void checkForFlexibleOrImmediateUpdate() {
appUpdateManager.getAppUpdateInfo().addOnSuccessListener(appUpdateInfo -> {
boolean updateAvailable = appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE;
if (updateAvailable) {
appUpdateManager
.getAppUpdateInfo()
.addOnSuccessListener(this, appUpdateInfo -> {
boolean updateAvailable =
appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE;
if (updateAvailable && getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
startImmediateUpdate(appUpdateInfo);
}
})
.addOnFailureListener(e -> {
.addOnFailureListener(this, e -> {
if (!BuildConfig.DEBUG) {
Snackbar.make(
findViewById(android.R.id.content),
getString(R.string.snack_general_error),
Snackbar.LENGTH_LONG
).show();
}
});
});
}

private void checkInAppReview() {
Expand All @@ -348,6 +353,11 @@ private void checkInAppReview() {
}

private void startImmediateUpdate(AppUpdateInfo appUpdateInfo) {
if (updateActivityResultLauncher == null
|| !getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
Log.w("MainActivity", "Update launcher not ready");
return;
}
try {
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
Expand Down