use of androidx.navigation.NavDirections in project Signal-Android by WhisperSystems.
the class CreatePaymentFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Toolbar toolbar = view.findViewById(R.id.create_payment_fragment_toolbar);
toolbar.setNavigationOnClickListener(this::goBack);
CreatePaymentFragmentArgs arguments = CreatePaymentFragmentArgs.fromBundle(requireArguments());
CreatePaymentViewModel.Factory factory = new CreatePaymentViewModel.Factory(arguments.getPayee(), arguments.getNote());
CreatePaymentViewModel viewModel = new ViewModelProvider(Navigation.findNavController(view).getViewModelStoreOwner(R.id.payments_create), factory).get(CreatePaymentViewModel.class);
constraintLayout = view.findViewById(R.id.create_payment_fragment_amount_header);
request = view.findViewById(R.id.create_payment_fragment_request);
amount = view.findViewById(R.id.create_payment_fragment_amount);
exchange = view.findViewById(R.id.create_payment_fragment_exchange);
pay = view.findViewById(R.id.create_payment_fragment_pay);
balance = view.findViewById(R.id.create_payment_fragment_balance);
note = view.findViewById(R.id.create_payment_fragment_note);
addNote = view.findViewById(R.id.create_payment_fragment_add_note);
toggle = view.findViewById(R.id.create_payment_fragment_toggle);
TextView decimal = view.findViewById(R.id.create_payment_fragment_keyboard_decimal);
decimal.setText(String.valueOf(DecimalFormatSymbols.getInstance().getDecimalSeparator()));
View infoTapTarget = view.findViewById(R.id.create_payment_fragment_info_tap_region);
// noinspection CodeBlock2Expr
infoTapTarget.setOnClickListener(v -> {
new AlertDialog.Builder(requireContext()).setMessage(R.string.CreatePaymentFragment__conversions_are_just_estimates).setPositiveButton(android.R.string.ok, (dialog, which) -> dialog.dismiss()).setNegativeButton(R.string.LearnMoreTextView_learn_more, (dialog, which) -> {
dialog.dismiss();
CommunicationActions.openBrowserLink(requireContext(), getString(R.string.CreatePaymentFragment__learn_more__conversions));
}).show();
});
initializeInfoIcon();
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());
SafeNavigation.safeNavigate(Navigation.findNavController(v), directions);
});
toggle.setOnClickListener(v -> viewModel.toggleMoneyInputTarget());
initializeConstraintSets();
initializeKeyboardButtons(view, viewModel);
viewModel.getInputState().observe(getViewLifecycleOwner(), inputState -> {
updateAmount(inputState);
updateExchange(inputState);
updateMoneyInputTarget(inputState.getInputTarget());
});
viewModel.getIsPaymentsSupportedByPayee().observe(getViewLifecycleOwner(), isSupported -> {
if (!isSupported)
RecipientHasNotEnabledPaymentsDialog.show(requireContext(), () -> goBack(requireView()));
});
viewModel.isValidAmount().observe(getViewLifecycleOwner(), this::updateRequestAmountButtons);
viewModel.getNote().observe(getViewLifecycleOwner(), this::updateNote);
viewModel.getSpendableBalance().observe(getViewLifecycleOwner(), this::updateBalance);
viewModel.getCanSendPayment().observe(getViewLifecycleOwner(), this::updatePayAmountButtons);
}
use of androidx.navigation.NavDirections in project Signal-Android by WhisperSystems.
the class PaymentsTransferFragment method next.
private boolean next(@NonNull MobileCoinPublicAddress ownAddress) {
try {
String base58Address = address.getText().toString();
MobileCoinPublicAddress publicAddress = MobileCoinPublicAddress.fromBase58(base58Address);
if (ownAddress.equals(publicAddress)) {
new AlertDialog.Builder(requireContext()).setTitle(R.string.PaymentsTransferFragment__invalid_address).setMessage(R.string.PaymentsTransferFragment__you_cant_transfer_to_your_own_signal_wallet_address).setPositiveButton(android.R.string.ok, null).show();
return false;
}
NavDirections action = PaymentsTransferFragmentDirections.actionPaymentsTransferToCreatePayment(new PayeeParcelable(publicAddress)).setFinishOnConfirm(PaymentsTransferFragmentArgs.fromBundle(requireArguments()).getFinishOnConfirm());
SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), action);
return true;
} catch (MobileCoinPublicAddress.AddressException e) {
Log.w(TAG, "Address is not valid", e);
new AlertDialog.Builder(requireContext()).setTitle(R.string.PaymentsTransferFragment__invalid_address).setMessage(R.string.PaymentsTransferFragment__check_the_wallet_address).setPositiveButton(android.R.string.ok, null).show();
return false;
}
}
use of androidx.navigation.NavDirections in project Signal-Android by WhisperSystems.
the class ManageProfileActivity method onCreate.
@Override
public void onCreate(Bundle bundle, boolean ready) {
dynamicTheme.onCreate(this);
setContentView(R.layout.manage_profile_activity);
if (bundle == null) {
Bundle extras = getIntent().getExtras();
// noinspection ConstantConditions
NavController navController = ((NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment)).getNavController();
NavGraph graph = navController.getGraph();
navController.setGraph(graph, extras != null ? extras : new Bundle());
if (extras != null && extras.getBoolean(START_AT_USERNAME, false)) {
NavDirections action = ManageProfileFragmentDirections.actionManageUsername();
SafeNavigation.safeNavigate(navController, action);
}
if (extras != null && extras.getBoolean(START_AT_AVATAR, false)) {
NavDirections action = ManageProfileFragmentDirections.actionManageProfileFragmentToAvatarPicker(null, null);
SafeNavigation.safeNavigate(navController, action);
}
}
}
Aggregations