Prevent crash when opting out of PIN after fragment is detached.

This commit is contained in:
Greyson Parrelli 2026-06-11 14:07:01 +00:00
parent 8ddec63e31
commit 45a3c44d0c
4 changed files with 6 additions and 5 deletions

View File

@ -200,7 +200,7 @@ public abstract class BaseSvrPinFragment<ViewModel extends BaseSvrPinViewModel>
}
private void onPinSkipped() {
PinOptOutDialog.show(requireContext(), false, () -> {
PinOptOutDialog.show(requireContext(), getViewLifecycleOwner(), false, () -> {
RegistrationUtil.maybeMarkRegistrationComplete();
closeNavGraphBranch();
});

View File

@ -125,6 +125,6 @@ public final class SvrSplashFragment extends Fragment {
}
private void onPinSkipped() {
PinOptOutDialog.show(requireContext(), false, () -> requireActivity().finish());
PinOptOutDialog.show(requireContext(), getViewLifecycleOwner(), false, () -> requireActivity().finish());
}
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -21,7 +22,7 @@ public final class PinOptOutDialog {
* @param rotateAep If true, this will rotate the AEP as part of the process of opting out. Only do this if the user has not enabled backups! If the user
* has backups enabled, you should guide them through rotating the AEP first, and then call this with [rotateAep] = false.
*/
public static void show(@NonNull Context context, boolean rotateAep, @NonNull Runnable onSuccess) {
public static void show(@NonNull Context context, @NonNull LifecycleOwner lifecycleOwner, boolean rotateAep, @NonNull Runnable onSuccess) {
Log.i(TAG, "show()");
AlertDialog dialog = new MaterialAlertDialogBuilder(context)
.setTitle(R.string.PinOptOutDialog_warning)
@ -32,7 +33,7 @@ public final class PinOptOutDialog {
d.dismiss();
AlertDialog progress = SimpleProgressDialog.show(context);
SimpleTask.run(() -> {
SimpleTask.run(lifecycleOwner.getLifecycle(), () -> {
SvrRepository.optOutOfPin(rotateAep);
return null;
}, success -> {

View File

@ -59,7 +59,7 @@ class AdvancedPinSettingsFragment : ComposeFragment() {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
viewModel.event.collectLatest {
when (it) {
AdvancedPinSettingsViewModel.Event.SHOW_BACKUPS_DISABLED_OPT_OUT_DIALOG -> PinOptOutDialog.show(requireContext(), true) {
AdvancedPinSettingsViewModel.Event.SHOW_BACKUPS_DISABLED_OPT_OUT_DIALOG -> PinOptOutDialog.show(requireContext(), viewLifecycleOwner, true) {
viewModel.onPinOptOutSuccess()
displayOptOutSnackbar()
}