Search in sources :

Example 51 with Toolbar

use of androidx.appcompat.widget.Toolbar in project Signal-Android by WhisperSystems.

the class PaymentsRecoveryPhraseFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.payments_recovery_phrase_fragment_toolbar);
    RecyclerView recyclerView = view.findViewById(R.id.payments_recovery_phrase_fragment_recycler);
    TextView message = view.findViewById(R.id.payments_recovery_phrase_fragment_message);
    View next = view.findViewById(R.id.payments_recovery_phrase_fragment_next);
    View edit = view.findViewById(R.id.payments_recovery_phrase_fragment_edit);
    View copy = view.findViewById(R.id.payments_recovery_phrase_fragment_copy);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(requireContext(), SPAN_COUNT);
    PaymentsRecoveryPhraseFragmentArgs args = PaymentsRecoveryPhraseFragmentArgs.fromBundle(requireArguments());
    final List<String> words;
    if (args.getWords() != null) {
        words = Arrays.asList(args.getWords());
        setUpForConfirmation(message, next, edit, copy, words);
    } else {
        Mnemonic mnemonic = SignalStore.paymentsValues().getPaymentsMnemonic();
        words = mnemonic.getWords();
        setUpForDisplay(message, next, edit, copy, words, args);
    }
    List<MnemonicPart> parts = Stream.of(words).mapIndexed(MnemonicPart::new).sorted(new MnemonicPartComparator(words.size(), SPAN_COUNT)).toList();
    MnemonicPartAdapter adapter = new MnemonicPartAdapter();
    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerView.setAdapter(adapter);
    recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    toolbar.setNavigationOnClickListener(v -> {
        if (args.getFinishOnConfirm()) {
            requireActivity().finish();
        } else {
            toolbar.setNavigationOnClickListener(t -> Navigation.findNavController(view).popBackStack(R.id.paymentsHome, false));
        }
    });
    adapter.submitList(parts);
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Mnemonic(org.thoughtcrime.securesms.payments.Mnemonic) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar)

Example 52 with Toolbar

use of androidx.appcompat.widget.Toolbar in project Signal-Android by WhisperSystems.

the class EditNoteFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    viewModel = new ViewModelProvider(Navigation.findNavController(view).getViewModelStoreOwner(R.id.payments_create)).get(CreatePaymentViewModel.class);
    Toolbar toolbar = view.findViewById(R.id.edit_note_fragment_toolbar);
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(v).popBackStack());
    noteEditText = view.findViewById(R.id.edit_note_fragment_edit_text);
    viewModel.getNote().observe(getViewLifecycleOwner(), note -> {
        noteEditText.setText(note);
        if (!TextUtils.isEmpty(note)) {
            noteEditText.setSelection(note.length());
        }
    });
    noteEditText.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            saveNote();
            return true;
        }
        return false;
    });
    View fab = view.findViewById(R.id.edit_note_fragment_fab);
    fab.setOnClickListener(v -> saveNote());
    ViewUtil.focusAndMoveCursorToEndAndOpenKeyboard(noteEditText);
}
Also used : View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Toolbar(androidx.appcompat.widget.Toolbar)

Example 53 with Toolbar

use of androidx.appcompat.widget.Toolbar in project Signal-Android by WhisperSystems.

the class PaymentsRecoveryEntryFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.payments_recovery_entry_fragment_toolbar);
    TextView message = view.findViewById(R.id.payments_recovery_entry_fragment_message);
    TextInputLayout wrapper = view.findViewById(R.id.payments_recovery_entry_fragment_word_wrapper);
    MaterialAutoCompleteTextView word = view.findViewById(R.id.payments_recovery_entry_fragment_word);
    View next = view.findViewById(R.id.payments_recovery_entry_fragment_next);
    PaymentsRecoveryEntryViewModel viewModel = ViewModelProviders.of(this).get(PaymentsRecoveryEntryViewModel.class);
    toolbar.setNavigationOnClickListener(t -> Navigation.findNavController(view).popBackStack(R.id.paymentsHome, false));
    viewModel.getState().observe(getViewLifecycleOwner(), state -> {
        message.setText(getString(R.string.PaymentsRecoveryEntryFragment__enter_word_d, state.getWordIndex() + 1));
        word.setHint(getString(R.string.PaymentsRecoveryEntryFragment__word_d, state.getWordIndex() + 1));
        wrapper.setError(state.canMoveToNext() || TextUtils.isEmpty(state.getCurrentEntry()) ? null : getString(R.string.PaymentsRecoveryEntryFragment__invalid_word));
        next.setEnabled(state.canMoveToNext());
        String inTextView = word.getText().toString();
        String inState = Util.firstNonNull(state.getCurrentEntry(), "");
        if (!inTextView.equals(inState)) {
            word.setText(inState);
        }
    });
    viewModel.getEvents().observe(getViewLifecycleOwner(), event -> {
        if (event == PaymentsRecoveryEntryViewModel.Events.GO_TO_CONFIRM) {
            SafeNavigation.safeNavigate(Navigation.findNavController(view), PaymentsRecoveryEntryFragmentDirections.actionPaymentsRecoveryEntryToPaymentsRecoveryPhrase(false).setWords(viewModel.getWords()));
        }
    });
    ArrayAdapter<String> wordAdapter = new ArrayAdapter<>(requireContext(), R.layout.support_simple_spinner_dropdown_item, Mnemonic.BIP39_WORDS_ENGLISH);
    word.setAdapter(wordAdapter);
    word.addTextChangedListener(new AfterTextChanged(e -> viewModel.onWordChanged(e.toString())));
    next.setOnClickListener(v -> viewModel.onNextClicked());
}
Also used : MaterialAutoCompleteTextView(com.google.android.material.textfield.MaterialAutoCompleteTextView) Bundle(android.os.Bundle) Util(org.thoughtcrime.securesms.util.Util) NonNull(androidx.annotation.NonNull) TextInputLayout(com.google.android.material.textfield.TextInputLayout) AfterTextChanged(org.thoughtcrime.securesms.util.text.AfterTextChanged) TextUtils(android.text.TextUtils) Mnemonic(org.thoughtcrime.securesms.payments.Mnemonic) R(org.thoughtcrime.securesms.R) ArrayAdapter(android.widget.ArrayAdapter) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) MaterialAutoCompleteTextView(com.google.android.material.textfield.MaterialAutoCompleteTextView) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Navigation(androidx.navigation.Navigation) TextView(android.widget.TextView) MaterialAutoCompleteTextView(com.google.android.material.textfield.MaterialAutoCompleteTextView) TextInputLayout(com.google.android.material.textfield.TextInputLayout) TextView(android.widget.TextView) MaterialAutoCompleteTextView(com.google.android.material.textfield.MaterialAutoCompleteTextView) View(android.view.View) AfterTextChanged(org.thoughtcrime.securesms.util.text.AfterTextChanged) ArrayAdapter(android.widget.ArrayAdapter) Toolbar(androidx.appcompat.widget.Toolbar)

Example 54 with Toolbar

use of androidx.appcompat.widget.Toolbar in project Signal-Android by WhisperSystems.

the class PaymentsTransferQrScanFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    overlay = view.findViewById(R.id.overlay);
    scannerView = view.findViewById(R.id.scanner);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        overlay.setOrientation(LinearLayout.HORIZONTAL);
    } else {
        overlay.setOrientation(LinearLayout.VERTICAL);
    }
    viewModel = new ViewModelProvider(Navigation.findNavController(view).getViewModelStoreOwner(R.id.payments_transfer), new PaymentsTransferViewModel.Factory()).get(PaymentsTransferViewModel.class);
    Toolbar toolbar = view.findViewById(R.id.payments_transfer_scan_qr);
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(v).popBackStack());
}
Also used : ViewModelProvider(androidx.lifecycle.ViewModelProvider) Toolbar(androidx.appcompat.widget.Toolbar)

Example 55 with Toolbar

use of androidx.appcompat.widget.Toolbar 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)

Aggregations

Toolbar (androidx.appcompat.widget.Toolbar)284 View (android.view.View)116 TextView (android.widget.TextView)58 RecyclerView (androidx.recyclerview.widget.RecyclerView)44 Bundle (android.os.Bundle)43 Intent (android.content.Intent)39 NonNull (androidx.annotation.NonNull)36 Fragment (androidx.fragment.app.Fragment)33 ActionBar (androidx.appcompat.app.ActionBar)29 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)29 Nullable (androidx.annotation.Nullable)28 BarPainter (com.xabber.android.ui.color.BarPainter)26 R (org.thoughtcrime.securesms.R)26 Context (android.content.Context)25 ViewGroup (android.view.ViewGroup)25 EditText (android.widget.EditText)23 MenuItem (android.view.MenuItem)21 ImageView (android.widget.ImageView)20 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)20 Navigation (androidx.navigation.Navigation)20