diff --git a/app/src/main/java/org/thoughtcrime/securesms/devicetransfer/olddevice/OldDeviceTransferInstructionsFragment.java b/app/src/main/java/org/thoughtcrime/securesms/devicetransfer/olddevice/OldDeviceTransferInstructionsFragment.java index bb4ec5b8a7..89ae9ad332 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/devicetransfer/olddevice/OldDeviceTransferInstructionsFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/devicetransfer/olddevice/OldDeviceTransferInstructionsFragment.java @@ -3,12 +3,15 @@ package org.thoughtcrime.securesms.devicetransfer.olddevice; import android.os.Bundle; import android.view.View; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.navigation.Navigation; import androidx.navigation.fragment.NavHostFragment; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.greenrobot.eventbus.EventBus; import org.signal.devicetransfer.DeviceToDeviceTransferService; import org.signal.devicetransfer.TransferStatus; @@ -28,14 +31,18 @@ public final class OldDeviceTransferInstructionsFragment extends LoggingFragment @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { Toolbar toolbar = view.findViewById(R.id.old_device_transfer_instructions_fragment_toolbar); - toolbar.setNavigationOnClickListener(v -> { - if (!Navigation.findNavController(v).popBackStack()) { - requireActivity().finish(); - } - }); + toolbar.setNavigationOnClickListener(v -> showConfirmExitDialog()); view.findViewById(R.id.old_device_transfer_instructions_fragment_continue) .setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(v), R.id.action_oldDeviceTransferInstructions_to_oldDeviceTransferSetup)); + + requireActivity().getOnBackPressedDispatcher() + .addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + showConfirmExitDialog(); + } + }); } @Override @@ -48,4 +55,19 @@ public final class OldDeviceTransferInstructionsFragment extends LoggingFragment DeviceToDeviceTransferService.stop(requireContext()); } } + + private void showConfirmExitDialog() { + new MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.OldDeviceTransferInstructions__confirm_exit_title) + .setMessage(R.string.OldDeviceTransferInstructions__confirm_exit_message) + .setPositiveButton(R.string.OldDeviceTransferInstructions__stop_transfer, (d, w) -> exit()) + .setNegativeButton(R.string.OldDeviceTransferInstructions__continue_transfer, null) + .show(); + } + + private void exit() { + if (!Navigation.findNavController(requireView()).popBackStack()) { + requireActivity().finish(); + } + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d8edcd33b2..5e679ade70 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4972,6 +4972,14 @@ 3. Select "Transfer from Android device" when prompted and then "Continue". Keep both devices nearby. Continue + + Stop device transfer? + + No data has been transferred to your new device. + + Stop transfer + + Continue transfer Go to your new device @@ -8654,9 +8662,9 @@ Continue transferring your account on your other device. - Restore complete + Finish on your other device - Your Signal account and messages have started transferring to your other device. Signal is now inactive on this device. + Your Signal account and messages are ready to restore on your other device. Signal is now inactive on this device. Transfer complete