Search in sources :

Example 1 with WarningType

use of de.schildbach.wallet.ui.TransactionsAdapter.WarningType in project bitcoin-wallet by bitcoin-wallet.

the class WalletTransactionsFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.fragmentManager = getChildFragmentManager();
    setHasOptionsMenu(true);
    activityViewModel = new ViewModelProvider(activity).get(WalletActivityViewModel.class);
    viewModel = new ViewModelProvider(this).get(WalletTransactionsViewModel.class);
    viewModel.direction.observe(this, direction -> activity.invalidateOptionsMenu());
    viewModel.transactions.observe(this, transactions -> {
        if (transactions.isEmpty()) {
            viewGroup.setDisplayedChild(0);
            final WalletTransactionsViewModel.Direction direction = viewModel.direction.getValue();
            final WarningType warning = viewModel.warning.getValue();
            final SpannableStringBuilder emptyText = new SpannableStringBuilder(getString(direction == WalletTransactionsViewModel.Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received));
            emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK);
            if (direction != WalletTransactionsViewModel.Direction.SENT)
                emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));
            if (warning == WarningType.BACKUP) {
                final int start = emptyText.length();
                emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_remind_backup));
                emptyText.setSpan(new StyleSpan(Typeface.BOLD), start, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK);
            }
            emptyView.setText(emptyText);
        } else {
            viewGroup.setDisplayedChild(1);
        }
    });
    viewModel.selectedTransaction.observe(this, transactionId -> {
        adapter.setSelectedTransaction(transactionId);
        final int position = adapter.positionOf(transactionId);
        if (position != RecyclerView.NO_POSITION)
            recyclerView.smoothScrollToPosition(position);
    });
    viewModel.list.observe(this, listItems -> {
        adapter.submitList(listItems);
        activityViewModel.transactionsLoadingFinished();
    });
    viewModel.showBitmapDialog.observe(this, new Event.Observer<Bitmap>() {

        @Override
        protected void onEvent(final Bitmap bitmap) {
            BitmapFragment.show(fragmentManager, bitmap);
        }
    });
    viewModel.showEditAddressBookEntryDialog.observe(this, new Event.Observer<Address>() {

        @Override
        protected void onEvent(final Address address) {
            EditAddressBookEntryFragment.edit(fragmentManager, address);
        }
    });
    viewModel.showReportIssueDialog.observe(this, new Event.Observer<Sha256Hash>() {

        @Override
        protected void onEvent(final Sha256Hash transactionHash) {
            ReportIssueDialogFragment.show(fragmentManager, R.string.report_issue_dialog_title_transaction, R.string.report_issue_dialog_message_issue, Constants.REPORT_SUBJECT_ISSUE, transactionHash);
        }
    });
    adapter = new TransactionsAdapter(activity, this, this);
}
Also used : Address(org.bitcoinj.core.Address) Sha256Hash(org.bitcoinj.core.Sha256Hash) WarningType(de.schildbach.wallet.ui.TransactionsAdapter.WarningType) Bitmap(android.graphics.Bitmap) StyleSpan(android.text.style.StyleSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

Bitmap (android.graphics.Bitmap)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 StyleSpan (android.text.style.StyleSpan)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 WarningType (de.schildbach.wallet.ui.TransactionsAdapter.WarningType)1 Address (org.bitcoinj.core.Address)1 Sha256Hash (org.bitcoinj.core.Sha256Hash)1