use of org.thoughtcrime.securesms.util.text.AfterTextChanged in project Signal-Android by WhisperSystems.
the class EditProfileNameFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
this.givenName = view.findViewById(R.id.edit_profile_name_given_name);
this.familyName = view.findViewById(R.id.edit_profile_name_family_name);
this.saveButton = view.findViewById(R.id.edit_profile_name_save);
initializeViewModel();
this.givenName.setText(Recipient.self().getProfileName().getGivenName());
this.familyName.setText(Recipient.self().getProfileName().getFamilyName());
viewModel.onGivenNameChanged(this.givenName.getText().toString());
view.<Toolbar>findViewById(R.id.toolbar).setNavigationOnClickListener(v -> Navigation.findNavController(view).popBackStack());
EditTextUtil.addGraphemeClusterLimitFilter(givenName, NAME_MAX_GLYPHS);
EditTextUtil.addGraphemeClusterLimitFilter(familyName, NAME_MAX_GLYPHS);
this.givenName.addTextChangedListener(new AfterTextChanged(s -> {
trimFieldToMaxByteLength(s);
viewModel.onGivenNameChanged(s.toString());
}));
this.familyName.addTextChangedListener(new AfterTextChanged(EditProfileNameFragment::trimFieldToMaxByteLength));
saveButton.setOnClickListener(v -> viewModel.onSaveClicked(requireContext(), givenName.getText().toString(), familyName.getText().toString()));
ViewUtil.focusAndMoveCursorToEndAndOpenKeyboard(this.givenName);
}
use of org.thoughtcrime.securesms.util.text.AfterTextChanged in project Signal-Android by WhisperSystems.
the class PaymentsRecoveryPhraseConfirmFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Toolbar toolbar = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_toolbar);
EditText word1 = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_word_1);
EditText word2 = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_word_2);
View seePhraseAgain = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_see_again);
View done = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_done);
TextInputLayout wordWrapper1 = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_word1_wrapper);
TextInputLayout wordWrapper2 = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_word2_wrapper);
PaymentsRecoveryPhraseConfirmFragmentArgs args = PaymentsRecoveryPhraseConfirmFragmentArgs.fromBundle(requireArguments());
validWordCheckMark = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_check_circle_24);
invalidWordX = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_circle_x_24);
DrawableCompat.setTint(validWordCheckMark, ContextCompat.getColor(requireContext(), R.color.signal_accent_green));
DrawableCompat.setTint(invalidWordX, ContextCompat.getColor(requireContext(), R.color.signal_alert_primary));
PaymentsRecoveryPhraseConfirmViewModel viewModel = ViewModelProviders.of(requireActivity()).get(PaymentsRecoveryPhraseConfirmViewModel.class);
toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(requireView()).popBackStack());
word1.addTextChangedListener(new AfterTextChanged(e -> viewModel.validateWord1(e.toString())));
word2.addTextChangedListener(new AfterTextChanged(e -> viewModel.validateWord2(e.toString())));
seePhraseAgain.setOnClickListener(v -> Navigation.findNavController(requireView()).popBackStack());
done.setOnClickListener(v -> {
SignalStore.paymentsValues().setUserConfirmedMnemonic(true);
ViewUtil.hideKeyboard(requireContext(), view);
Toast.makeText(requireContext(), R.string.PaymentRecoveryPhraseConfirmFragment__recovery_phrase_confirmed, Toast.LENGTH_SHORT).show();
if (args.getFinishOnConfirm()) {
requireActivity().setResult(Activity.RESULT_OK);
requireActivity().finish();
} else {
Navigation.findNavController(view).popBackStack(R.id.paymentsHome, false);
}
});
viewModel.getViewState().observe(getViewLifecycleOwner(), viewState -> {
updateValidity(word1, viewState.isWord1Valid());
updateValidity(word2, viewState.isWord2Valid());
done.setEnabled(viewState.areAllWordsValid());
String hint1 = getString(R.string.PaymentRecoveryPhraseConfirmFragment__word_d, viewState.getWord1Index() + 1);
String hint2 = getString(R.string.PaymentRecoveryPhraseConfirmFragment__word_d, viewState.getWord2Index() + 1);
wordWrapper1.setHint(hint1);
wordWrapper2.setHint(hint2);
});
viewModel.updateRandomIndices();
}
use of org.thoughtcrime.securesms.util.text.AfterTextChanged in project Signal-Android by WhisperSystems.
the class ShareInterstitialActivity method initializeViews.
private void initializeViews(@NonNull MultiShareArgs args) {
confirm = findViewById(R.id.share_confirm);
toolbar = findViewById(R.id.toolbar);
preview = findViewById(R.id.link_preview);
confirm.setOnClickListener(unused -> onConfirm());
SelectionAwareEmojiEditText text = findViewById(R.id.text);
toolbar.setNavigationOnClickListener(unused -> finish());
text.addTextChangedListener(new AfterTextChanged(editable -> {
linkPreviewViewModel.onTextChanged(this, editable.toString(), text.getSelectionStart(), text.getSelectionEnd());
viewModel.onDraftTextChanged(editable.toString());
}));
// noinspection CodeBlock2Expr
text.setOnSelectionChangedListener(((selStart, selEnd) -> {
linkPreviewViewModel.onTextChanged(this, text.getText().toString(), text.getSelectionStart(), text.getSelectionEnd());
}));
preview.setCloseClickedListener(linkPreviewViewModel::onUserCancel);
int defaultRadius = getResources().getDimensionPixelSize(R.dimen.thumbnail_default_radius);
preview.setCorners(defaultRadius, defaultRadius);
text.setText(args.getDraftText());
ViewUtil.focusAndMoveCursorToEndAndOpenKeyboard(text);
contactsRecycler = findViewById(R.id.selected_list);
contactsRecycler.setAdapter(adapter);
RecyclerView.ItemAnimator itemAnimator = Objects.requireNonNull(contactsRecycler.getItemAnimator());
ShareFlowConstants.applySelectedContactsRecyclerAnimationSpeeds(itemAnimator);
confirm.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
int pad = Math.abs(v.getWidth() + ViewUtil.dpToPx(16));
ViewUtil.setPaddingEnd(contactsRecycler, pad);
});
}
use of org.thoughtcrime.securesms.util.text.AfterTextChanged 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());
}
use of org.thoughtcrime.securesms.util.text.AfterTextChanged in project Signal-Android by WhisperSystems.
the class AddGroupDetailsFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
create = view.findViewById(R.id.create);
name = view.findViewById(R.id.name);
toolbar = view.findViewById(R.id.toolbar);
disappearingMessagesRow = view.findViewById(R.id.group_disappearing_messages_row);
setCreateEnabled(false, false);
GroupMemberListView members = view.findViewById(R.id.member_list);
ImageView avatar = view.findViewById(R.id.group_avatar);
View mmsWarning = view.findViewById(R.id.mms_warning);
LearnMoreTextView gv2Warning = view.findViewById(R.id.gv2_warning);
View addLater = view.findViewById(R.id.add_later);
TextView disappearingMessageValue = view.findViewById(R.id.group_disappearing_messages_value);
members.initializeAdapter(getViewLifecycleOwner());
avatarPlaceholder = VectorDrawableCompat.create(getResources(), R.drawable.ic_camera_outline_32_ultramarine, requireActivity().getTheme());
if (savedInstanceState == null) {
avatar.setImageDrawable(new InsetDrawable(avatarPlaceholder, ViewUtil.dpToPx(AVATAR_PLACEHOLDER_INSET_DP)));
}
initializeViewModel();
avatar.setOnClickListener(v -> showAvatarPicker());
members.setRecipientClickListener(this::handleRecipientClick);
EditTextUtil.addGraphemeClusterLimitFilter(name, FeatureFlags.getMaxGroupNameGraphemeLength());
name.addTextChangedListener(new AfterTextChanged(editable -> viewModel.setName(editable.toString())));
toolbar.setNavigationOnClickListener(unused -> callback.onNavigationButtonPressed());
create.setOnClickListener(v -> handleCreateClicked());
viewModel.getMembers().observe(getViewLifecycleOwner(), list -> {
addLater.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
members.setMembers(list);
});
viewModel.getCanSubmitForm().observe(getViewLifecycleOwner(), isFormValid -> setCreateEnabled(isFormValid, true));
viewModel.getIsMms().observe(getViewLifecycleOwner(), isMms -> {
disappearingMessagesRow.setVisibility(isMms ? View.GONE : View.VISIBLE);
mmsWarning.setVisibility(isMms ? View.VISIBLE : View.GONE);
name.setHint(isMms ? R.string.AddGroupDetailsFragment__group_name_optional : R.string.AddGroupDetailsFragment__group_name_required);
toolbar.setTitle(isMms ? R.string.AddGroupDetailsFragment__create_group : R.string.AddGroupDetailsFragment__name_this_group);
});
viewModel.getNonGv2CapableMembers().observe(getViewLifecycleOwner(), nonGv2CapableMembers -> {
gv2Warning.setVisibility(nonGv2CapableMembers.isEmpty() ? View.GONE : View.VISIBLE);
gv2Warning.setText(requireContext().getResources().getQuantityString(R.plurals.AddGroupDetailsFragment__d_members_do_not_support_new_groups_so_this_group_cannot_be_created, nonGv2CapableMembers.size(), nonGv2CapableMembers.size()));
gv2Warning.setLearnMoreVisible(true);
gv2Warning.setOnLinkClickListener(v -> NonGv2MemberDialog.showNonGv2Members(requireContext(), getViewLifecycleOwner(), nonGv2CapableMembers));
});
viewModel.getAvatar().observe(getViewLifecycleOwner(), avatarBytes -> {
if (avatarBytes == null) {
avatar.setImageDrawable(new InsetDrawable(avatarPlaceholder, ViewUtil.dpToPx(AVATAR_PLACEHOLDER_INSET_DP)));
} else {
GlideApp.with(this).load(avatarBytes).circleCrop().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(avatar);
}
});
viewModel.getDisappearingMessagesTimer().observe(getViewLifecycleOwner(), timer -> disappearingMessageValue.setText(ExpirationUtil.getExpirationDisplayValue(requireContext(), timer)));
disappearingMessagesRow.setOnClickListener(v -> {
startActivityForResult(RecipientDisappearingMessagesActivity.forCreateGroup(requireContext(), viewModel.getDisappearingMessagesTimer().getValue()), REQUEST_DISAPPEARING_TIMER);
});
name.requestFocus();
getParentFragmentManager().setFragmentResultListener(AvatarPickerFragment.REQUEST_KEY_SELECT_AVATAR, getViewLifecycleOwner(), (key, bundle) -> handleMediaResult(bundle));
}
Aggregations