Search in sources :

Example 1 with MoneyView

use of org.thoughtcrime.securesms.payments.MoneyView in project Signal-Android by WhisperSystems.

the class PaymentsHomeFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.payments_home_fragment_toolbar);
    RecyclerView recycler = view.findViewById(R.id.payments_home_fragment_recycler);
    View header = view.findViewById(R.id.payments_home_fragment_header);
    MoneyView balance = view.findViewById(R.id.payments_home_fragment_header_balance);
    TextView exchange = view.findViewById(R.id.payments_home_fragment_header_exchange);
    View addMoney = view.findViewById(R.id.button_start_frame);
    View sendMoney = view.findViewById(R.id.button_end_frame);
    View refresh = view.findViewById(R.id.payments_home_fragment_header_refresh);
    LottieAnimationView refreshAnimation = view.findViewById(R.id.payments_home_fragment_header_refresh_animation);
    toolbar.setNavigationOnClickListener(v -> {
        viewModel.markAllPaymentsSeen();
        requireActivity().finish();
    });
    toolbar.setOnMenuItemClickListener(this::onMenuItemSelected);
    addMoney.setOnClickListener(v -> {
        if (SignalStore.paymentsValues().getPaymentsAvailability().isSendAllowed()) {
            SafeNavigation.safeNavigate(Navigation.findNavController(v), PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentsAddMoney());
        } else {
            showPaymentsDisabledDialog();
        }
    });
    sendMoney.setOnClickListener(v -> {
        if (SignalStore.paymentsValues().getPaymentsAvailability().isSendAllowed()) {
            SafeNavigation.safeNavigate(Navigation.findNavController(v), PaymentsHomeFragmentDirections.actionPaymentsHomeToPaymentRecipientSelectionFragment());
        } else {
            showPaymentsDisabledDialog();
        }
    });
    PaymentsHomeAdapter adapter = new PaymentsHomeAdapter(new HomeCallbacks());
    recycler.setAdapter(adapter);
    viewModel = ViewModelProviders.of(this, new PaymentsHomeViewModel.Factory()).get(PaymentsHomeViewModel.class);
    viewModel.getList().observe(getViewLifecycleOwner(), list -> {
        boolean hadPaymentItems = Stream.of(adapter.getCurrentList()).anyMatch(model -> model instanceof PaymentItem);
        if (!hadPaymentItems) {
            adapter.submitList(list, () -> recycler.scrollToPosition(0));
        } else {
            adapter.submitList(list);
        }
    });
    viewModel.getPaymentsEnabled().observe(getViewLifecycleOwner(), enabled -> {
        if (enabled) {
            toolbar.inflateMenu(R.menu.payments_home_fragment_menu);
        } else {
            toolbar.getMenu().clear();
        }
        header.setVisibility(enabled ? View.VISIBLE : View.GONE);
    });
    viewModel.getBalance().observe(getViewLifecycleOwner(), balance::setMoney);
    viewModel.getExchange().observe(getViewLifecycleOwner(), amount -> {
        if (amount != null) {
            exchange.setText(FiatMoneyUtil.format(getResources(), amount));
        } else {
            exchange.setText(R.string.PaymentsHomeFragment__unknown_amount);
        }
    });
    refresh.setOnClickListener(v -> viewModel.refreshExchangeRates(true));
    exchange.setOnClickListener(v -> viewModel.refreshExchangeRates(true));
    viewModel.getExchangeLoadState().observe(getViewLifecycleOwner(), loadState -> {
        switch(loadState) {
            case INITIAL:
            case LOADED:
                refresh.setVisibility(View.VISIBLE);
                refreshAnimation.cancelAnimation();
                refreshAnimation.setVisibility(View.GONE);
                break;
            case LOADING:
                refresh.setVisibility(View.INVISIBLE);
                refreshAnimation.playAnimation();
                refreshAnimation.setVisibility(View.VISIBLE);
                break;
            case ERROR:
                refresh.setVisibility(View.VISIBLE);
                refreshAnimation.cancelAnimation();
                refreshAnimation.setVisibility(View.GONE);
                exchange.setText(R.string.PaymentsHomeFragment__currency_conversion_not_available);
                Toast.makeText(view.getContext(), R.string.PaymentsHomeFragment__cant_display_currency_conversion, Toast.LENGTH_SHORT).show();
                break;
        }
    });
    viewModel.getPaymentStateEvents().observe(getViewLifecycleOwner(), paymentStateEvent -> {
        AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
        builder.setTitle(R.string.PaymentsHomeFragment__deactivate_payments_question);
        builder.setMessage(R.string.PaymentsHomeFragment__you_will_not_be_able_to_send);
        builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss());
        switch(paymentStateEvent) {
            case NO_BALANCE:
                Toast.makeText(requireContext(), R.string.PaymentsHomeFragment__balance_is_not_currently_available, Toast.LENGTH_SHORT).show();
                return;
            case DEACTIVATED:
                Snackbar.make(requireView(), R.string.PaymentsHomeFragment__payments_deactivated, Snackbar.LENGTH_SHORT).setTextColor(Color.WHITE).show();
                return;
            case DEACTIVATE_WITHOUT_BALANCE:
                builder.setPositiveButton(SpanUtil.color(ContextCompat.getColor(requireContext(), R.color.signal_alert_primary), getString(R.string.PaymentsHomeFragment__deactivate)), (dialog, which) -> {
                    viewModel.confirmDeactivatePayments();
                    dialog.dismiss();
                });
                break;
            case DEACTIVATE_WITH_BALANCE:
                builder.setPositiveButton(getString(R.string.PaymentsHomeFragment__continue), (dialog, which) -> {
                    dialog.dismiss();
                    SafeNavigation.safeNavigate(NavHostFragment.findNavController(this), R.id.deactivateWallet);
                });
                break;
            case ACTIVATED:
                return;
            default:
                throw new IllegalStateException("Unsupported event type: " + paymentStateEvent.name());
        }
        builder.show();
    });
    viewModel.getErrorEnablingPayments().observe(getViewLifecycleOwner(), errorEnabling -> {
        switch(errorEnabling) {
            case REGION:
                Toast.makeText(view.getContext(), R.string.PaymentsHomeFragment__payments_is_not_available_in_your_region, Toast.LENGTH_LONG).show();
                break;
            case NETWORK:
                Toast.makeText(view.getContext(), R.string.PaymentsHomeFragment__could_not_enable_payments, Toast.LENGTH_SHORT).show();
                break;
            default:
                throw new AssertionError();
        }
    });
    requireActivity().getOnBackPressedDispatcher().addCallback(onBackPressed);
}
Also used : AlertDialog(android.app.AlertDialog) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) LottieAnimationView(com.airbnb.lottie.LottieAnimationView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) PaymentItem(org.thoughtcrime.securesms.payments.preferences.model.PaymentItem) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) LottieAnimationView(com.airbnb.lottie.LottieAnimationView) Toolbar(androidx.appcompat.widget.Toolbar)

Example 2 with MoneyView

use of org.thoughtcrime.securesms.payments.MoneyView in project Signal-Android by signalapp.

the class PaymentDetailsFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.payments_details_toolbar);
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(v).popBackStack());
    PaymentDetailsParcelable details = PaymentDetailsFragmentArgs.fromBundle(requireArguments()).getPaymentDetails();
    AvatarImageView avatar = view.findViewById(R.id.payments_details_avatar);
    BadgeImageView badge = view.findViewById(R.id.payments_details_badge);
    TextView contactFromTo = view.findViewById(R.id.payments_details_contact_to_from);
    MoneyView amount = view.findViewById(R.id.payments_details_amount);
    TextView note = view.findViewById(R.id.payments_details_note);
    TextView status = view.findViewById(R.id.payments_details_status);
    View sentByHeader = view.findViewById(R.id.payments_details_sent_by_header);
    TextView sentBy = view.findViewById(R.id.payments_details_sent_by);
    LearnMoreTextView transactionInfo = view.findViewById(R.id.payments_details_info);
    TextView sentTo = view.findViewById(R.id.payments_details_sent_to_header);
    MoneyView sentToAmount = view.findViewById(R.id.payments_details_sent_to_amount);
    View sentFeeHeader = view.findViewById(R.id.payments_details_sent_fee_header);
    MoneyView sentFeeAmount = view.findViewById(R.id.payments_details_sent_fee_amount);
    Group sentViews = view.findViewById(R.id.payments_details_sent_views);
    View blockHeader = view.findViewById(R.id.payments_details_block_header);
    TextView blockNumber = view.findViewById(R.id.payments_details_block);
    if (details.hasPayment()) {
        Payment payment = details.requirePayment();
        avatar.disableQuickContact();
        avatar.setImageResource(R.drawable.ic_mobilecoin_avatar_24);
        contactFromTo.setText(getContactFromToTextFromDirection(payment.getDirection()));
        amount.setMoney(payment.getAmountPlusFeeWithDirection());
        note.setVisibility(View.GONE);
        status.setText(getStatusFromPayment(payment));
        sentByHeader.setVisibility(View.GONE);
        sentBy.setVisibility(View.GONE);
        transactionInfo.setLearnMoreVisible(true);
        transactionInfo.setText(R.string.PaymentsDetailsFragment__information);
        transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__information));
        sentTo.setVisibility(View.GONE);
        sentToAmount.setVisibility(View.GONE);
        blockHeader.setVisibility(View.VISIBLE);
        blockNumber.setVisibility(View.VISIBLE);
        blockNumber.setText(String.valueOf(payment.getBlockIndex()));
        if (payment.getDirection() == Direction.SENT) {
            sentFeeAmount.setMoney(payment.getFee());
            sentFeeHeader.setVisibility(View.VISIBLE);
            sentFeeAmount.setVisibility(View.VISIBLE);
        }
    } else {
        PaymentsDetailsViewModel viewModel = ViewModelProviders.of(this, new PaymentsDetailsViewModel.Factory(details.requireUuid())).get(PaymentsDetailsViewModel.class);
        viewModel.getViewState().observe(getViewLifecycleOwner(), state -> {
            if (state.getRecipient().getId().isUnknown() || state.getPayment().isDefrag()) {
                avatar.disableQuickContact();
                avatar.setImageResource(R.drawable.ic_mobilecoin_avatar_24);
            } else {
                avatar.setRecipient(state.getRecipient(), true);
                badge.setBadgeFromRecipient(state.getRecipient());
            }
            contactFromTo.setText(describeToOrFrom(state));
            if (state.getPayment().getState() == State.FAILED) {
                amount.setTextColor(ContextCompat.getColor(requireContext(), R.color.signal_text_primary_disabled));
                amount.setMoney(state.getPayment().getAmountPlusFeeWithDirection(), false);
                transactionInfo.setVisibility(View.GONE);
            } else {
                amount.setMoney(state.getPayment().getAmountPlusFeeWithDirection());
                if (state.getPayment().isDefrag()) {
                    transactionInfo.setLearnMoreVisible(true);
                    transactionInfo.setText(R.string.PaymentsDetailsFragment__coin_cleanup_information);
                    transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__cleanup_fee));
                } else {
                    transactionInfo.setLearnMoreVisible(true);
                    transactionInfo.setText(R.string.PaymentsDetailsFragment__information);
                    transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__information));
                }
                transactionInfo.setVisibility(View.VISIBLE);
            }
            String trimmedNote = state.getPayment().getNote().trim();
            note.setText(trimmedNote);
            note.setVisibility(TextUtils.isEmpty(trimmedNote) ? View.GONE : View.VISIBLE);
            status.setText(describeStatus(state.getPayment()));
            sentBy.setText(describeSentBy(state));
            if (state.getPayment().getDirection().isReceived()) {
                sentToAmount.setMoney(Money.MobileCoin.ZERO);
                sentFeeAmount.setMoney(Money.MobileCoin.ZERO);
                sentViews.setVisibility(View.GONE);
            } else {
                sentTo.setText(describeSentTo(state, state.getPayment()));
                sentToAmount.setMoney(state.getPayment().getAmount());
                sentFeeAmount.setMoney(state.getPayment().getFee());
                sentViews.setVisibility(View.VISIBLE);
            }
        });
        viewModel.getPaymentExists().observe(getViewLifecycleOwner(), exists -> {
            if (!exists) {
                Log.w(TAG, "Failed to find payment detail");
                FragmentActivity fragmentActivity = requireActivity();
                fragmentActivity.onBackPressed();
                Toast.makeText(fragmentActivity, R.string.PaymentsDetailsFragment__no_details_available, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : Group(androidx.constraintlayout.widget.Group) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) SpannableString(android.text.SpannableString) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) FragmentActivity(androidx.fragment.app.FragmentActivity) Payment(org.thoughtcrime.securesms.payments.Payment) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) Toolbar(androidx.appcompat.widget.Toolbar)

Example 3 with MoneyView

use of org.thoughtcrime.securesms.payments.MoneyView in project Signal-Android by signalapp.

the class DeactivateWalletFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.deactivate_wallet_fragment_toolbar);
    MoneyView balance = view.findViewById(R.id.deactivate_wallet_fragment_balance);
    View transferRemainingBalance = view.findViewById(R.id.deactivate_wallet_fragment_transfer);
    View deactivateWithoutTransfer = view.findViewById(R.id.deactivate_wallet_fragment_deactivate);
    LearnMoreTextView notice = view.findViewById(R.id.deactivate_wallet_fragment_notice);
    notice.setLearnMoreVisible(true);
    notice.setLink(getString(R.string.DeactivateWalletFragment__learn_more__we_recommend_transferring_your_funds));
    DeactivateWalletViewModel viewModel = ViewModelProviders.of(this).get(DeactivateWalletViewModel.class);
    viewModel.getBalance().observe(getViewLifecycleOwner(), balance::setMoney);
    viewModel.getDeactivationResults().observe(getViewLifecycleOwner(), r -> {
        if (r == DeactivateWalletViewModel.Result.SUCCESS) {
            Navigation.findNavController(requireView()).popBackStack();
        } else {
            Toast.makeText(requireContext(), R.string.DeactivateWalletFragment__error_deactivating_wallet, Toast.LENGTH_SHORT).show();
        }
    });
    transferRemainingBalance.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), R.id.action_deactivateWallet_to_paymentsTransfer));
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(requireView()).popBackStack());
    // noinspection CodeBlock2Expr
    deactivateWithoutTransfer.setOnClickListener(v -> {
        new AlertDialog.Builder(requireContext()).setTitle(R.string.DeactivateWalletFragment__deactivate_without_transferring_question).setMessage(R.string.DeactivateWalletFragment__your_balance_will_remain).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).setPositiveButton(SpanUtil.color(ContextCompat.getColor(requireContext(), R.color.signal_alert_primary), getString(R.string.DeactivateWalletFragment__deactivate)), (dialog, which) -> {
            viewModel.deactivateWallet();
            dialog.dismiss();
        }).show();
    });
}
Also used : AlertDialog(android.app.AlertDialog) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) SpanUtil(org.thoughtcrime.securesms.util.SpanUtil) R(org.thoughtcrime.securesms.R) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) Nullable(androidx.annotation.Nullable) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Navigation(androidx.navigation.Navigation) ContextCompat(androidx.core.content.ContextCompat) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar)

Example 4 with MoneyView

use of org.thoughtcrime.securesms.payments.MoneyView in project Signal-Android by WhisperSystems.

the class DeactivateWalletFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.deactivate_wallet_fragment_toolbar);
    MoneyView balance = view.findViewById(R.id.deactivate_wallet_fragment_balance);
    View transferRemainingBalance = view.findViewById(R.id.deactivate_wallet_fragment_transfer);
    View deactivateWithoutTransfer = view.findViewById(R.id.deactivate_wallet_fragment_deactivate);
    LearnMoreTextView notice = view.findViewById(R.id.deactivate_wallet_fragment_notice);
    notice.setLearnMoreVisible(true);
    notice.setLink(getString(R.string.DeactivateWalletFragment__learn_more__we_recommend_transferring_your_funds));
    DeactivateWalletViewModel viewModel = ViewModelProviders.of(this).get(DeactivateWalletViewModel.class);
    viewModel.getBalance().observe(getViewLifecycleOwner(), balance::setMoney);
    viewModel.getDeactivationResults().observe(getViewLifecycleOwner(), r -> {
        if (r == DeactivateWalletViewModel.Result.SUCCESS) {
            Navigation.findNavController(requireView()).popBackStack();
        } else {
            Toast.makeText(requireContext(), R.string.DeactivateWalletFragment__error_deactivating_wallet, Toast.LENGTH_SHORT).show();
        }
    });
    transferRemainingBalance.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), R.id.action_deactivateWallet_to_paymentsTransfer));
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(requireView()).popBackStack());
    // noinspection CodeBlock2Expr
    deactivateWithoutTransfer.setOnClickListener(v -> {
        new AlertDialog.Builder(requireContext()).setTitle(R.string.DeactivateWalletFragment__deactivate_without_transferring_question).setMessage(R.string.DeactivateWalletFragment__your_balance_will_remain).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).setPositiveButton(SpanUtil.color(ContextCompat.getColor(requireContext(), R.color.signal_alert_primary), getString(R.string.DeactivateWalletFragment__deactivate)), (dialog, which) -> {
            viewModel.deactivateWallet();
            dialog.dismiss();
        }).show();
    });
}
Also used : AlertDialog(android.app.AlertDialog) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) SpanUtil(org.thoughtcrime.securesms.util.SpanUtil) R(org.thoughtcrime.securesms.R) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) Nullable(androidx.annotation.Nullable) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Navigation(androidx.navigation.Navigation) ContextCompat(androidx.core.content.ContextCompat) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar)

Example 5 with MoneyView

use of org.thoughtcrime.securesms.payments.MoneyView in project Signal-Android by WhisperSystems.

the class PaymentDetailsFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.payments_details_toolbar);
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(v).popBackStack());
    PaymentDetailsParcelable details = PaymentDetailsFragmentArgs.fromBundle(requireArguments()).getPaymentDetails();
    AvatarImageView avatar = view.findViewById(R.id.payments_details_avatar);
    BadgeImageView badge = view.findViewById(R.id.payments_details_badge);
    TextView contactFromTo = view.findViewById(R.id.payments_details_contact_to_from);
    MoneyView amount = view.findViewById(R.id.payments_details_amount);
    TextView note = view.findViewById(R.id.payments_details_note);
    TextView status = view.findViewById(R.id.payments_details_status);
    View sentByHeader = view.findViewById(R.id.payments_details_sent_by_header);
    TextView sentBy = view.findViewById(R.id.payments_details_sent_by);
    LearnMoreTextView transactionInfo = view.findViewById(R.id.payments_details_info);
    TextView sentTo = view.findViewById(R.id.payments_details_sent_to_header);
    MoneyView sentToAmount = view.findViewById(R.id.payments_details_sent_to_amount);
    View sentFeeHeader = view.findViewById(R.id.payments_details_sent_fee_header);
    MoneyView sentFeeAmount = view.findViewById(R.id.payments_details_sent_fee_amount);
    Group sentViews = view.findViewById(R.id.payments_details_sent_views);
    View blockHeader = view.findViewById(R.id.payments_details_block_header);
    TextView blockNumber = view.findViewById(R.id.payments_details_block);
    if (details.hasPayment()) {
        Payment payment = details.requirePayment();
        avatar.disableQuickContact();
        avatar.setImageResource(R.drawable.ic_mobilecoin_avatar_24);
        contactFromTo.setText(getContactFromToTextFromDirection(payment.getDirection()));
        amount.setMoney(payment.getAmountPlusFeeWithDirection());
        note.setVisibility(View.GONE);
        status.setText(getStatusFromPayment(payment));
        sentByHeader.setVisibility(View.GONE);
        sentBy.setVisibility(View.GONE);
        transactionInfo.setLearnMoreVisible(true);
        transactionInfo.setText(R.string.PaymentsDetailsFragment__information);
        transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__information));
        sentTo.setVisibility(View.GONE);
        sentToAmount.setVisibility(View.GONE);
        blockHeader.setVisibility(View.VISIBLE);
        blockNumber.setVisibility(View.VISIBLE);
        blockNumber.setText(String.valueOf(payment.getBlockIndex()));
        if (payment.getDirection() == Direction.SENT) {
            sentFeeAmount.setMoney(payment.getFee());
            sentFeeHeader.setVisibility(View.VISIBLE);
            sentFeeAmount.setVisibility(View.VISIBLE);
        }
    } else {
        PaymentsDetailsViewModel viewModel = ViewModelProviders.of(this, new PaymentsDetailsViewModel.Factory(details.requireUuid())).get(PaymentsDetailsViewModel.class);
        viewModel.getViewState().observe(getViewLifecycleOwner(), state -> {
            if (state.getRecipient().getId().isUnknown() || state.getPayment().isDefrag()) {
                avatar.disableQuickContact();
                avatar.setImageResource(R.drawable.ic_mobilecoin_avatar_24);
            } else {
                avatar.setRecipient(state.getRecipient(), true);
                badge.setBadgeFromRecipient(state.getRecipient());
            }
            contactFromTo.setText(describeToOrFrom(state));
            if (state.getPayment().getState() == State.FAILED) {
                amount.setTextColor(ContextCompat.getColor(requireContext(), R.color.signal_text_primary_disabled));
                amount.setMoney(state.getPayment().getAmountPlusFeeWithDirection(), false);
                transactionInfo.setVisibility(View.GONE);
            } else {
                amount.setMoney(state.getPayment().getAmountPlusFeeWithDirection());
                if (state.getPayment().isDefrag()) {
                    transactionInfo.setLearnMoreVisible(true);
                    transactionInfo.setText(R.string.PaymentsDetailsFragment__coin_cleanup_information);
                    transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__cleanup_fee));
                } else {
                    transactionInfo.setLearnMoreVisible(true);
                    transactionInfo.setText(R.string.PaymentsDetailsFragment__information);
                    transactionInfo.setLink(getString(R.string.PaymentsDetailsFragment__learn_more__information));
                }
                transactionInfo.setVisibility(View.VISIBLE);
            }
            String trimmedNote = state.getPayment().getNote().trim();
            note.setText(trimmedNote);
            note.setVisibility(TextUtils.isEmpty(trimmedNote) ? View.GONE : View.VISIBLE);
            status.setText(describeStatus(state.getPayment()));
            sentBy.setText(describeSentBy(state));
            if (state.getPayment().getDirection().isReceived()) {
                sentToAmount.setMoney(Money.MobileCoin.ZERO);
                sentFeeAmount.setMoney(Money.MobileCoin.ZERO);
                sentViews.setVisibility(View.GONE);
            } else {
                sentTo.setText(describeSentTo(state, state.getPayment()));
                sentToAmount.setMoney(state.getPayment().getAmount());
                sentFeeAmount.setMoney(state.getPayment().getFee());
                sentViews.setVisibility(View.VISIBLE);
            }
        });
        viewModel.getPaymentExists().observe(getViewLifecycleOwner(), exists -> {
            if (!exists) {
                Log.w(TAG, "Failed to find payment detail");
                FragmentActivity fragmentActivity = requireActivity();
                fragmentActivity.onBackPressed();
                Toast.makeText(fragmentActivity, R.string.PaymentsDetailsFragment__no_details_available, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : Group(androidx.constraintlayout.widget.Group) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) SpannableString(android.text.SpannableString) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) FragmentActivity(androidx.fragment.app.FragmentActivity) Payment(org.thoughtcrime.securesms.payments.Payment) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) TextView(android.widget.TextView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

View (android.view.View)6 Toolbar (androidx.appcompat.widget.Toolbar)6 MoneyView (org.thoughtcrime.securesms.payments.MoneyView)6 AlertDialog (android.app.AlertDialog)4 TextView (android.widget.TextView)4 LearnMoreTextView (org.thoughtcrime.securesms.util.views.LearnMoreTextView)4 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 LayoutInflater (android.view.LayoutInflater)2 ViewGroup (android.view.ViewGroup)2 Toast (android.widget.Toast)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 Group (androidx.constraintlayout.widget.Group)2 ContextCompat (androidx.core.content.ContextCompat)2 Fragment (androidx.fragment.app.Fragment)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 ViewModelProviders (androidx.lifecycle.ViewModelProviders)2 Navigation (androidx.navigation.Navigation)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2