Search in sources :

Example 1 with MaterialAutoCompleteTextView

use of com.google.android.material.textfield.MaterialAutoCompleteTextView 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 2 with MaterialAutoCompleteTextView

use of com.google.android.material.textfield.MaterialAutoCompleteTextView 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

Bundle (android.os.Bundle)2 TextUtils (android.text.TextUtils)2 View (android.view.View)2 ArrayAdapter (android.widget.ArrayAdapter)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 Toolbar (androidx.appcompat.widget.Toolbar)2 Fragment (androidx.fragment.app.Fragment)2 ViewModelProviders (androidx.lifecycle.ViewModelProviders)2 Navigation (androidx.navigation.Navigation)2 MaterialAutoCompleteTextView (com.google.android.material.textfield.MaterialAutoCompleteTextView)2 TextInputLayout (com.google.android.material.textfield.TextInputLayout)2 R (org.thoughtcrime.securesms.R)2 Mnemonic (org.thoughtcrime.securesms.payments.Mnemonic)2 Util (org.thoughtcrime.securesms.util.Util)2 SafeNavigation (org.thoughtcrime.securesms.util.navigation.SafeNavigation)2 AfterTextChanged (org.thoughtcrime.securesms.util.text.AfterTextChanged)2