Search in sources :

Example 21 with TextInputLayout

use of com.google.android.material.textfield.TextInputLayout in project Signal-Android by signalapp.

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)

Aggregations

TextInputLayout (com.google.android.material.textfield.TextInputLayout)21 TextView (android.widget.TextView)13 View (android.view.View)12 EditText (android.widget.EditText)10 Bundle (android.os.Bundle)5 ImageView (android.widget.ImageView)5 NonNull (androidx.annotation.NonNull)5 DialogInterface (android.content.DialogInterface)4 Nullable (androidx.annotation.Nullable)4 AlertDialog (androidx.appcompat.app.AlertDialog)4 Toolbar (androidx.appcompat.widget.Toolbar)4 Fragment (androidx.fragment.app.Fragment)4 ViewModelProviders (androidx.lifecycle.ViewModelProviders)4 Navigation (androidx.navigation.Navigation)4 R (org.thoughtcrime.securesms.R)4 AfterTextChanged (org.thoughtcrime.securesms.util.text.AfterTextChanged)4 Activity (android.app.Activity)3 Drawable (android.graphics.drawable.Drawable)3 TextUtils (android.text.TextUtils)3 Button (android.widget.Button)3