Search in sources :

Example 1 with NavDirections

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);
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppCompatResources(androidx.appcompat.content.res.AppCompatResources) DecimalFormatSymbols(java.text.DecimalFormatSymbols) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) TransitionManager(androidx.transition.TransitionManager) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) HashMap(java.util.HashMap) Currency(java.util.Currency) DrawableCompat(androidx.core.graphics.drawable.DrawableCompat) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) FiatMoneyUtil(org.thoughtcrime.securesms.payments.FiatMoneyUtil) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) FormatterOptions(org.whispersystems.signalservice.api.payments.FormatterOptions) Map(java.util.Map) View(android.view.View) RecipientHasNotEnabledPaymentsDialog(org.thoughtcrime.securesms.payments.preferences.RecipientHasNotEnabledPaymentsDialog) ContextCompat(androidx.core.content.ContextCompat) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextUtils(android.text.TextUtils) SpanUtil(org.thoughtcrime.securesms.util.SpanUtil) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) ConstraintSet(androidx.constraintlayout.widget.ConstraintSet) AlertDialog(android.app.AlertDialog) Objects(java.util.Objects) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) Toolbar(androidx.appcompat.widget.Toolbar) Navigation(androidx.navigation.Navigation) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) Money(org.whispersystems.signalservice.api.payments.Money) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) TextView(android.widget.TextView) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) View(android.view.View) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections)

Example 2 with NavDirections

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;
    }
}
Also used : AlertDialog(android.app.AlertDialog) PayeeParcelable(org.thoughtcrime.securesms.payments.preferences.model.PayeeParcelable) MobileCoinPublicAddress(org.thoughtcrime.securesms.payments.MobileCoinPublicAddress) NavDirections(androidx.navigation.NavDirections)

Example 3 with NavDirections

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);
        }
    }
}
Also used : Bundle(android.os.Bundle) NavController(androidx.navigation.NavController) NavGraph(androidx.navigation.NavGraph) NavHostFragment(androidx.navigation.fragment.NavHostFragment) NavDirections(androidx.navigation.NavDirections)

Aggregations

NavDirections (androidx.navigation.NavDirections)3 AlertDialog (android.app.AlertDialog)2 Bundle (android.os.Bundle)2 Drawable (android.graphics.drawable.Drawable)1 TextUtils (android.text.TextUtils)1 View (android.view.View)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AppCompatResources (androidx.appcompat.content.res.AppCompatResources)1 Toolbar (androidx.appcompat.widget.Toolbar)1 ConstraintLayout (androidx.constraintlayout.widget.ConstraintLayout)1 ConstraintSet (androidx.constraintlayout.widget.ConstraintSet)1 ContextCompat (androidx.core.content.ContextCompat)1 DrawableCompat (androidx.core.graphics.drawable.DrawableCompat)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 NavController (androidx.navigation.NavController)1 NavGraph (androidx.navigation.NavGraph)1 Navigation (androidx.navigation.Navigation)1 NavHostFragment (androidx.navigation.fragment.NavHostFragment)1