Disallow visually-empty profile names.

This commit is contained in:
Greyson Parrelli
2022-01-24 17:32:39 -05:00
committed by Alex Hart
parent 523e21f3be
commit a0031298d8
4 changed files with 12 additions and 5 deletions

View File

@@ -53,7 +53,7 @@ public class EditProfileNameFragment extends Fragment {
this.givenName.setText(Recipient.self().getProfileName().getGivenName());
this.familyName.setText(Recipient.self().getProfileName().getFamilyName());
viewModel.onGivenNameLengthChanged(this.givenName.getText().length());
viewModel.onGivenNameChanged(this.givenName.getText().toString());
view.<Toolbar>findViewById(R.id.toolbar)
.setNavigationOnClickListener(v -> Navigation.findNavController(view)
@@ -64,7 +64,7 @@ public class EditProfileNameFragment extends Fragment {
this.givenName.addTextChangedListener(new AfterTextChanged(s -> {
trimFieldToMaxByteLength(s);
viewModel.onGivenNameLengthChanged(s.length());
viewModel.onGivenNameChanged(s.toString());
}));
this.familyName.addTextChangedListener(new AfterTextChanged(EditProfileNameFragment::trimFieldToMaxByteLength));

View File

@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.profiles.manage;
import android.content.Context;
import android.text.Editable;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
@@ -9,6 +10,7 @@ import androidx.lifecycle.ViewModel;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.thoughtcrime.securesms.util.SingleLiveEvent;
import org.thoughtcrime.securesms.util.StringUtil;
public final class EditProfileNameViewModel extends ViewModel {
@@ -22,8 +24,8 @@ public final class EditProfileNameViewModel extends ViewModel {
this.events = new SingleLiveEvent<>();
}
void onGivenNameLengthChanged(int length) {
if (length <= 0) {
void onGivenNameChanged(@NonNull String text) {
if (StringUtil.isVisuallyEmpty(text.toString())) {
saveState.setValue(SaveState.DISABLED);
} else {
saveState.setValue(SaveState.IDLE);

View File

@@ -17,7 +17,10 @@ public final class StringUtil {
private static final Set<Character> WHITESPACE = SetUtil.newHashSet('\u200E', // left-to-right mark
'\u200F', // right-to-left mark
'\u2007'); // figure space
'\u2007', // figure space
'\u200B', // zero-width space
'\u2800'); // braille blank
private static final class Bidi {
/** Override text direction */