Commit fc28e7aa authored by Torsten Grote's avatar Torsten Grote

Merge branch 'nickname-nitpicks' into 'master'

Nickname nitpicks

See merge request !1143
parents 78459499 9ab9e02f
Pipeline #3611 passed with stage
in 9 minutes and 26 seconds
...@@ -3,6 +3,7 @@ package org.briarproject.briar.android.account; ...@@ -3,6 +3,7 @@ package org.briarproject.briar.android.account;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.TextInputEditText; import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout; import android.support.design.widget.TextInputLayout;
import android.text.Editable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -10,7 +11,6 @@ import android.widget.Button; ...@@ -10,7 +11,6 @@ import android.widget.Button;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault; import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault; import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.activity.ActivityComponent;
...@@ -20,6 +20,7 @@ import static android.view.inputmethod.EditorInfo.IME_ACTION_NEXT; ...@@ -20,6 +20,7 @@ import static android.view.inputmethod.EditorInfo.IME_ACTION_NEXT;
import static android.view.inputmethod.EditorInfo.IME_ACTION_NONE; import static android.view.inputmethod.EditorInfo.IME_ACTION_NONE;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.util.StringUtils.toUtf8;
import static org.briarproject.briar.android.util.UiUtils.setError; import static org.briarproject.briar.android.util.UiUtils.setError;
import static org.briarproject.briar.android.util.UiUtils.showSoftKeyboard; import static org.briarproject.briar.android.util.UiUtils.showSoftKeyboard;
...@@ -77,7 +78,7 @@ public class AuthorNameFragment extends SetupFragment { ...@@ -77,7 +78,7 @@ public class AuthorNameFragment extends SetupFragment {
@Override @Override
public void onTextChanged(CharSequence authorName, int i, int i1, int i2) { public void onTextChanged(CharSequence authorName, int i, int i1, int i2) {
int authorNameLength = StringUtils.toUtf8(authorName.toString()).length; int authorNameLength = toUtf8(authorName.toString().trim()).length;
boolean error = authorNameLength > MAX_AUTHOR_NAME_LENGTH; boolean error = authorNameLength > MAX_AUTHOR_NAME_LENGTH;
setError(authorNameWrapper, getString(R.string.name_too_long), error); setError(authorNameWrapper, getString(R.string.name_too_long), error);
boolean enabled = authorNameLength > 0 && !error; boolean enabled = authorNameLength > 0 && !error;
...@@ -89,8 +90,11 @@ public class AuthorNameFragment extends SetupFragment { ...@@ -89,8 +90,11 @@ public class AuthorNameFragment extends SetupFragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
setupController.setAuthorName(authorNameInput.getText().toString()); Editable text = authorNameInput.getText();
setupController.showPasswordFragment(); if (text != null) {
setupController.setAuthorName(text.toString().trim());
setupController.showPasswordFragment();
}
} }
} }
...@@ -82,19 +82,20 @@ public class NicknameFragment extends BaseFragment { ...@@ -82,19 +82,20 @@ public class NicknameFragment extends BaseFragment {
@Nullable @Nullable
private String getNicknameOrNull() { private String getNicknameOrNull() {
Editable name = contactNameInput.getText(); Editable text = contactNameInput.getText();
if (name == null || name.toString().trim().length() == 0) { if (text == null || text.toString().trim().length() == 0) {
contactNameLayout.setError(getString(R.string.nickname_missing)); contactNameLayout.setError(getString(R.string.nickname_missing));
contactNameInput.requestFocus(); contactNameInput.requestFocus();
return null; return null;
} }
if (utf8IsTooLong(name.toString(), MAX_AUTHOR_NAME_LENGTH)) { String name = text.toString().trim();
if (utf8IsTooLong(name, MAX_AUTHOR_NAME_LENGTH)) {
contactNameLayout.setError(getString(R.string.name_too_long)); contactNameLayout.setError(getString(R.string.name_too_long));
contactNameInput.requestFocus(); contactNameInput.requestFocus();
return null; return null;
} }
contactNameLayout.setError(null); contactNameLayout.setError(null);
return name.toString().trim(); return name;
} }
private void onAddButtonClicked() { private void onAddButtonClicked() {
......
...@@ -82,7 +82,7 @@ public class AliasDialogFragment extends AppCompatDialogFragment { ...@@ -82,7 +82,7 @@ public class AliasDialogFragment extends AppCompatDialogFragment {
} }
private void onSetButtonClicked() { private void onSetButtonClicked() {
String alias = aliasEditText.getText().toString(); String alias = aliasEditText.getText().toString().trim();
if (toUtf8(alias).length > MAX_AUTHOR_NAME_LENGTH) { if (toUtf8(alias).length > MAX_AUTHOR_NAME_LENGTH) {
aliasEditLayout.setError(getString(R.string.name_too_long)); aliasEditLayout.setError(getString(R.string.name_too_long));
} else { } else {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:hint="@string/set_contact_alias_hint" android:hint="@string/set_contact_alias_hint"
android:inputType="textPersonName" android:inputType="text|textCapWords"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/text_size_medium"/> android:textSize="@dimen/text_size_medium"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment