Fix illegal argument navigation exceptions.

This commit is contained in:
Cody Henthorne
2021-12-15 16:07:54 -05:00
committed by Greyson Parrelli
parent ba54051f8c
commit a4f44a96fd
70 changed files with 337 additions and 207 deletions

View File

@@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
import org.thoughtcrime.securesms.util.text.AfterTextChanged;
import org.whispersystems.signalservice.api.payments.PaymentsConstants;
@@ -47,7 +48,7 @@ public class PaymentsRecoveryPasteFragment extends Fragment {
return;
}
Navigation.findNavController(v).navigate(PaymentsRecoveryPasteFragmentDirections.actionPaymentsRecoveryEntryToPaymentsRecoveryPhrase(false).setWords(words));
SafeNavigation.safeNavigate(Navigation.findNavController(v), PaymentsRecoveryPasteFragmentDirections.actionPaymentsRecoveryEntryToPaymentsRecoveryPhrase(false).setWords(words));
});
}

View File

@@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
import org.thoughtcrime.securesms.util.views.LearnMoreTextView;
import org.whispersystems.signalservice.api.payments.PaymentsConstants;
@@ -37,15 +38,15 @@ public class PaymentsRecoveryStartFragment extends Fragment {
title.setText(R.string.PaymentsRecoveryStartFragment__enter_recovery_phrase);
message.setText(getString(R.string.PaymentsRecoveryStartFragment__your_recovery_phrase_is_a, PaymentsConstants.MNEMONIC_LENGTH));
message.setLink(getString(R.string.PaymentsRecoveryStartFragment__learn_more__restore));
startButton.setOnClickListener(v -> Navigation.findNavController(requireView()).navigate(PaymentsRecoveryStartFragmentDirections.actionPaymentsRecoveryStartToPaymentsRecoveryEntry()));
startButton.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), PaymentsRecoveryStartFragmentDirections.actionPaymentsRecoveryStartToPaymentsRecoveryEntry()));
startButton.setText(R.string.PaymentsRecoveryStartFragment__enter_manually);
pasteButton.setVisibility(View.VISIBLE);
pasteButton.setOnClickListener(v -> Navigation.findNavController(v).navigate(PaymentsRecoveryStartFragmentDirections.actionPaymentsRecoveryStartToPaymentsRecoveryPaste()));
pasteButton.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(v), PaymentsRecoveryStartFragmentDirections.actionPaymentsRecoveryStartToPaymentsRecoveryPaste()));
} else {
title.setText(R.string.PaymentsRecoveryStartFragment__view_recovery_phrase);
message.setText(getString(R.string.PaymentsRecoveryStartFragment__your_balance_will_automatically_restore, PaymentsConstants.MNEMONIC_LENGTH));
message.setLink(getString(R.string.PaymentsRecoveryStartFragment__learn_more__view));
startButton.setOnClickListener(v -> Navigation.findNavController(requireView()).navigate(PaymentsRecoveryStartFragmentDirections.actionPaymentsRecoveryStartToPaymentsRecoveryPhrase(args.getFinishOnConfirm())));
startButton.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), PaymentsRecoveryStartFragmentDirections.actionPaymentsRecoveryStartToPaymentsRecoveryPhrase(args.getFinishOnConfirm())));
startButton.setText(R.string.PaymentsRecoveryStartFragment__start);
pasteButton.setVisibility(View.GONE);
}

View File

@@ -19,6 +19,7 @@ import com.google.android.material.textfield.TextInputLayout;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.payments.Mnemonic;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
import org.thoughtcrime.securesms.util.text.AfterTextChanged;
public class PaymentsRecoveryEntryFragment extends Fragment {
@@ -54,8 +55,8 @@ public class PaymentsRecoveryEntryFragment extends Fragment {
viewModel.getEvents().observe(getViewLifecycleOwner(), event -> {
if (event == PaymentsRecoveryEntryViewModel.Events.GO_TO_CONFIRM) {
Navigation.findNavController(view).navigate(PaymentsRecoveryEntryFragmentDirections.actionPaymentsRecoveryEntryToPaymentsRecoveryPhrase(false)
.setWords(viewModel.getWords()));
SafeNavigation.safeNavigate(Navigation.findNavController(view), PaymentsRecoveryEntryFragmentDirections.actionPaymentsRecoveryEntryToPaymentsRecoveryPhrase(false)
.setWords(viewModel.getWords()));
}
});

View File

@@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.payments.Mnemonic;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
import java.util.Arrays;
import java.util.Comparator;
@@ -125,7 +126,7 @@ public class PaymentsRecoveryPhraseFragment extends Fragment {
@NonNull PaymentsRecoveryPhraseFragmentArgs args)
{
message.setText(getString(R.string.PaymentsRecoveryPhraseFragment__write_down_the_following_d_words, words.size()));
next.setOnClickListener(v -> Navigation.findNavController(v).navigate(PaymentsRecoveryPhraseFragmentDirections.actionPaymentsRecoveryPhraseToPaymentsRecoveryPhraseConfirm(args.getFinishOnConfirm())));
next.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(v), PaymentsRecoveryPhraseFragmentDirections.actionPaymentsRecoveryPhraseToPaymentsRecoveryPhraseConfirm(args.getFinishOnConfirm())));
edit.setVisibility(View.GONE);
copy.setVisibility(View.VISIBLE);
copy.setOnClickListener(v -> confirmCopy(words));

View File

@@ -35,6 +35,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.BottomSheetUtil;
import org.thoughtcrime.securesms.util.MappingModelList;
import org.thoughtcrime.securesms.util.StringUtil;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
import org.whispersystems.signalservice.api.payments.FormatterOptions;
import java.util.concurrent.TimeUnit;
@@ -49,7 +50,7 @@ public class ConfirmPaymentFragment extends BottomSheetDialogFragment {
requireActivity().setResult(Activity.RESULT_OK);
requireActivity().finish();
} else {
NavHostFragment.findNavController(this).navigate(R.id.action_directly_to_paymentsHome);
SafeNavigation.safeNavigate(NavHostFragment.findNavController(this), R.id.action_directly_to_paymentsHome);
}
};

View File

@@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.payments.preferences.RecipientHasNotEnabledPay
import org.thoughtcrime.securesms.util.CommunicationActions;
import org.thoughtcrime.securesms.util.SpanUtil;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
import org.whispersystems.signalservice.api.payments.FormatterOptions;
import org.whispersystems.signalservice.api.payments.Money;
@@ -113,13 +114,13 @@ public class CreatePaymentFragment extends LoggingFragment {
initializeInfoIcon();
note.setOnClickListener(v -> Navigation.findNavController(v).navigate(R.id.action_createPaymentFragment_to_editPaymentNoteFragment));
addNote.setOnClickListener(v -> Navigation.findNavController(v).navigate(R.id.action_createPaymentFragment_to_editPaymentNoteFragment));
note.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(v), R.id.action_createPaymentFragment_to_editPaymentNoteFragment));
addNote.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(v), R.id.action_createPaymentFragment_to_editPaymentNoteFragment));
pay.setOnClickListener(v -> {
NavDirections directions = CreatePaymentFragmentDirections.actionCreatePaymentFragmentToConfirmPaymentFragment(viewModel.getCreatePaymentDetails())
.setFinishOnConfirm(arguments.getFinishOnConfirm());
Navigation.findNavController(v).navigate(directions);
SafeNavigation.safeNavigate(Navigation.findNavController(v), directions);
});
toggle.setOnClickListener(v -> viewModel.toggleMoneyInputTarget());

View File

@@ -18,6 +18,7 @@ import androidx.navigation.Navigation;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.payments.MoneyView;
import org.thoughtcrime.securesms.util.SpanUtil;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
import org.thoughtcrime.securesms.util.views.LearnMoreTextView;
public class DeactivateWalletFragment extends Fragment {
@@ -49,7 +50,7 @@ public class DeactivateWalletFragment extends Fragment {
}
});
transferRemainingBalance.setOnClickListener(v -> Navigation.findNavController(requireView()).navigate(R.id.action_deactivateWallet_to_paymentsTransfer));
transferRemainingBalance.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), R.id.action_deactivateWallet_to_paymentsTransfer));
toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(requireView()).popBackStack());

View File

@@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.function.Consumer;
@@ -106,7 +107,7 @@ public class PaymentRecipientSelectionFragment extends LoggingFragment implement
private void createPayment(@NonNull RecipientId recipientId) {
hideKeyboard();
Navigation.findNavController(requireView()).navigate(PaymentRecipientSelectionFragmentDirections.actionPaymentRecipientSelectionToCreatePayment(new PayeeParcelable(recipientId)));
SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), PaymentRecipientSelectionFragmentDirections.actionPaymentRecipientSelectionToCreatePayment(new PayeeParcelable(recipientId)));
}
private void showWarningDialog(@NonNull RecipientId recipientId) {

View File

@@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobs.PaymentLedgerUpdateJob;
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
public class PaymentsActivity extends PassphraseRequiredActivity {
@@ -31,7 +32,7 @@ public class PaymentsActivity extends PassphraseRequiredActivity {
int startingAction = getIntent().getIntExtra(EXTRA_PAYMENTS_STARTING_ACTION, R.id.paymentsHome);
if (startingAction != R.id.paymentsHome) {
controller.navigate(startingAction, getIntent().getBundleExtra(EXTRA_STARTING_ARGUMENTS));
SafeNavigation.safeNavigate(controller, startingAction, getIntent().getBundleExtra(EXTRA_STARTING_ARGUMENTS));
}
}

View File

@@ -1,7 +1,6 @@
package org.thoughtcrime.securesms.payments.preferences;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MenuItem;
@@ -37,6 +36,7 @@ import org.thoughtcrime.securesms.payments.MoneyView;
import org.thoughtcrime.securesms.payments.preferences.model.PaymentItem;
import org.thoughtcrime.securesms.util.CommunicationActions;
import org.thoughtcrime.securesms.util.SpanUtil;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
public class PaymentsHomeFragment extends LoggingFragment {
@@ -71,14 +71,14 @@ public class PaymentsHomeFragment extends LoggingFragment {
addMoney.setOnClickListener(v -> {
if (SignalStore.paymentsValues().getPaymentsAvailability().isSendAllowed()) {
Navigation.findNavController(v).navigate(PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentsAddMoney());
SafeNavigation.safeNavigate(Navigation.findNavController(v), PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentsAddMoney());
} else {
showPaymentsDisabledDialog();
}
});
sendMoney.setOnClickListener(v -> {
if (SignalStore.paymentsValues().getPaymentsAvailability().isSendAllowed()) {
Navigation.findNavController(v).navigate(PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentRecipientSelectionFragment());
SafeNavigation.safeNavigate(Navigation.findNavController(v), PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentRecipientSelectionFragment());
} else {
showPaymentsDisabledDialog();
}
@@ -169,7 +169,7 @@ public class PaymentsHomeFragment extends LoggingFragment {
case DEACTIVATE_WITH_BALANCE:
builder.setPositiveButton(getString(R.string.PaymentsHomeFragment__continue), (dialog, which) -> {
dialog.dismiss();
NavHostFragment.findNavController(this).navigate(R.id.deactivateWallet);
SafeNavigation.safeNavigate(NavHostFragment.findNavController(this), R.id.deactivateWallet);
});
break;
case ACTIVATED:
@@ -211,16 +211,16 @@ public class PaymentsHomeFragment extends LoggingFragment {
private boolean onMenuItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.payments_home_fragment_menu_transfer_to_exchange) {
NavHostFragment.findNavController(this).navigate(R.id.action_paymentsHome_to_paymentsTransfer);
SafeNavigation.safeNavigate(NavHostFragment.findNavController(this), R.id.action_paymentsHome_to_paymentsTransfer);
return true;
} else if (item.getItemId() == R.id.payments_home_fragment_menu_set_currency) {
NavHostFragment.findNavController(this).navigate(R.id.action_paymentsHome_to_setCurrency);
SafeNavigation.safeNavigate(NavHostFragment.findNavController(this), R.id.action_paymentsHome_to_setCurrency);
return true;
} else if (item.getItemId() == R.id.payments_home_fragment_menu_deactivate_wallet) {
viewModel.deactivatePayments();
return true;
} else if (item.getItemId() == R.id.payments_home_fragment_menu_view_recovery_phrase) {
NavHostFragment.findNavController(this).navigate(R.id.action_paymentsHome_to_paymentsBackup);
SafeNavigation.safeNavigate(NavHostFragment.findNavController(this), R.id.action_paymentsHome_to_paymentsBackup);
return true;
} else if (item.getItemId() == R.id.payments_home_fragment_menu_help) {
startActivity(AppSettingsActivity.help(requireContext(), HelpFragment.PAYMENT_INDEX));
@@ -255,20 +255,20 @@ public class PaymentsHomeFragment extends LoggingFragment {
@Override
public void onRestorePaymentsAccount() {
NavHostFragment.findNavController(PaymentsHomeFragment.this)
.navigate(PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentsBackup().setIsRestore(true));
SafeNavigation.safeNavigate(NavHostFragment.findNavController(PaymentsHomeFragment.this),
PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentsBackup().setIsRestore(true));
}
@Override
public void onSeeAll(@NonNull PaymentType paymentType) {
NavHostFragment.findNavController(PaymentsHomeFragment.this)
.navigate(PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentsAllActivity(paymentType));
SafeNavigation.safeNavigate(NavHostFragment.findNavController(PaymentsHomeFragment.this),
PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentsAllActivity(paymentType));
}
@Override
public void onPaymentItem(@NonNull PaymentItem model) {
NavHostFragment.findNavController(PaymentsHomeFragment.this)
.navigate(PaymentPreferencesDirections.actionDirectlyToPaymentDetails(model.getPaymentDetailsParcelable()));
SafeNavigation.safeNavigate(NavHostFragment.findNavController(PaymentsHomeFragment.this),
PaymentPreferencesDirections.actionDirectlyToPaymentDetails(model.getPaymentDetailsParcelable()));
}
@Override
@@ -283,7 +283,7 @@ public class PaymentsHomeFragment extends LoggingFragment {
@Override
public void onViewRecoveryPhrase() {
NavHostFragment.findNavController(PaymentsHomeFragment.this).navigate(R.id.action_paymentsHome_to_paymentsBackup);
SafeNavigation.safeNavigate(NavHostFragment.findNavController(PaymentsHomeFragment.this), R.id.action_paymentsHome_to_paymentsBackup);
}
}

View File

@@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.LoggingFragment;
import org.thoughtcrime.securesms.PaymentPreferencesDirections;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.payments.preferences.model.PaymentItem;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
public class PaymentsPagerItemFragment extends LoggingFragment {
@@ -62,8 +63,8 @@ public class PaymentsPagerItemFragment extends LoggingFragment {
private class Callbacks implements PaymentsHomeAdapter.Callbacks {
@Override
public void onPaymentItem(@NonNull PaymentItem model) {
NavHostFragment.findNavController(PaymentsPagerItemFragment.this)
.navigate(PaymentPreferencesDirections.actionDirectlyToPaymentDetails(model.getPaymentDetailsParcelable()));
SafeNavigation.safeNavigate(NavHostFragment.findNavController(PaymentsPagerItemFragment.this),
PaymentPreferencesDirections.actionDirectlyToPaymentDetails(model.getPaymentDetailsParcelable()));
}
}
}

View File

@@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.payments.MobileCoinPublicAddress;
import org.thoughtcrime.securesms.payments.preferences.model.PayeeParcelable;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
public final class PaymentsTransferFragment extends LoggingFragment {
@@ -77,7 +78,7 @@ public final class PaymentsTransferFragment extends LoggingFragment {
NavDirections action = PaymentsTransferFragmentDirections.actionPaymentsTransferToCreatePayment(new PayeeParcelable(publicAddress))
.setFinishOnConfirm(PaymentsTransferFragmentArgs.fromBundle(requireArguments()).getFinishOnConfirm());
Navigation.findNavController(requireView()).navigate(action);
SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), action);
return true;
} catch (MobileCoinPublicAddress.AddressException e) {
Log.w(TAG, "Address is not valid", e);
@@ -96,7 +97,7 @@ public final class PaymentsTransferFragment extends LoggingFragment {
.ifNecessary()
.withRationaleDialog(getString(R.string.PaymentsTransferFragment__to_scan_a_qr_code_signal_needs), R.drawable.ic_camera_24)
.onAnyPermanentlyDenied(this::onCameraPermissionPermanentlyDenied)
.onAllGranted(() -> Navigation.findNavController(requireView()).navigate(R.id.action_paymentsTransfer_to_paymentsScanQr))
.onAllGranted(() -> SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), R.id.action_paymentsTransfer_to_paymentsScanQr))
.onAnyDenied(() -> Toast.makeText(requireContext(), R.string.PaymentsTransferFragment__to_scan_a_qr_code_signal_needs_access_to_the_camera, Toast.LENGTH_LONG).show())
.execute();
}

View File

@@ -18,6 +18,7 @@ import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.camera.CameraView;
import org.thoughtcrime.securesms.payments.MobileCoinPublicAddress;
import org.thoughtcrime.securesms.qr.ScanningThread;
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
public final class PaymentsTransferQrScanFragment extends LoggingFragment {
@@ -56,7 +57,7 @@ public final class PaymentsTransferQrScanFragment extends LoggingFragment {
scanningThread.setScanListener(data -> ThreadUtil.runOnMain(() -> {
try {
viewModel.postQrData(MobileCoinPublicAddress.fromQr(data).getPaymentAddressBase58());
Navigation.findNavController(requireView()).navigate(R.id.action_paymentsScanQr_pop);
SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), R.id.action_paymentsScanQr_pop);
} catch (MobileCoinPublicAddress.AddressException e) {
Log.e(TAG, "Not a valid address");
}