diff --git a/briar-android/src/main/java/org/briarproject/briar/android/forum/CreateForumActivity.java b/briar-android/src/main/java/org/briarproject/briar/android/forum/CreateForumActivity.java index 396746b2121ce0cdbceb9f16c7038f3ca47b7384..e53f263386b7e18386b14c0ed4d876ae66d61637 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/forum/CreateForumActivity.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/forum/CreateForumActivity.java @@ -38,8 +38,7 @@ import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LEN @MethodsNotNullByDefault @ParametersNotNullByDefault -public class CreateForumActivity extends BriarActivity - implements OnEditorActionListener, OnClickListener { +public class CreateForumActivity extends BriarActivity { private static final Logger LOG = Logger.getLogger(CreateForumActivity.class.getName()); @@ -60,11 +59,7 @@ public class CreateForumActivity extends BriarActivity setContentView(R.layout.activity_create_forum); nameEntry = (EditText) findViewById(R.id.createForumNameEntry); - TextWatcher nameEntryWatcher = new TextWatcher() { - - @Override - public void afterTextChanged(Editable s) { - } + nameEntry.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, @@ -72,21 +67,40 @@ public class CreateForumActivity extends BriarActivity } @Override - public void onTextChanged(CharSequence text, int start, + public void onTextChanged(CharSequence s, int start, int lengthBefore, int lengthAfter) { enableOrDisableCreateButton(); } - }; - nameEntry.setOnEditorActionListener(this); - nameEntry.addTextChangedListener(nameEntryWatcher); + + @Override + public void afterTextChanged(Editable s) { + } + }); + nameEntry.setOnEditorActionListener(new OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, + KeyEvent e) { + createForum(); + return true; + } + }); feedback = (TextView) findViewById(R.id.createForumFeedback); createForumButton = (Button) findViewById(R.id.createForumButton); - createForumButton.setOnClickListener(this); + createForumButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + } + }); progress = (ProgressBar) findViewById(R.id.createForumProgressBar); + } + @Override + public void onStart() { + super.onStart(); + showSoftKeyboard(nameEntry); } @Override @@ -95,16 +109,10 @@ public class CreateForumActivity extends BriarActivity } private void enableOrDisableCreateButton() { - if (progress == null) return; // Not created yet + if (createForumButton == null) return; // Not created yet createForumButton.setEnabled(validateName()); } - @Override - public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) { - hideSoftKeyboard(textView); - return true; - } - private boolean validateName() { String name = nameEntry.getText().toString(); int length = StringUtils.toUtf8(name).length; @@ -116,15 +124,12 @@ public class CreateForumActivity extends BriarActivity return length > 0; } - @Override - public void onClick(View view) { - if (view == createForumButton) { - hideSoftKeyboard(view); - if (!validateName()) return; - createForumButton.setVisibility(GONE); - progress.setVisibility(VISIBLE); - storeForum(nameEntry.getText().toString()); - } + private void createForum() { + if (!validateName()) return; + hideSoftKeyboard(nameEntry); + createForumButton.setVisibility(GONE); + progress.setVisibility(VISIBLE); + storeForum(nameEntry.getText().toString()); } private void storeForum(final String name) { diff --git a/briar-android/src/main/java/org/briarproject/briar/android/privategroup/creation/CreateGroupFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/privategroup/creation/CreateGroupFragment.java index afede5594b79d0a9336bee889109a869ba258e92..aea42e265746cda0360869b63ddb778674c8ceea 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/privategroup/creation/CreateGroupFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/privategroup/creation/CreateGroupFragment.java @@ -4,11 +4,15 @@ import android.content.Context; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; +import android.widget.TextView; +import android.widget.TextView.OnEditorActionListener; import org.briarproject.bramble.util.StringUtils; import org.briarproject.briar.R; @@ -22,8 +26,9 @@ public class CreateGroupFragment extends BaseFragment { public final static String TAG = CreateGroupFragment.class.getName(); private CreateGroupListener listener; - private EditText name; - private Button button; + private EditText nameEntry; + private Button createGroupButton; + private TextView feedback; @Override public void onAttach(Context context) { @@ -35,32 +40,42 @@ public class CreateGroupFragment extends BaseFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // inflate view View v = inflater.inflate(R.layout.fragment_create_group, container, false); - name = (EditText) v.findViewById(R.id.name); - name.addTextChangedListener(new TextWatcher() { + nameEntry = (EditText) v.findViewById(R.id.name); + nameEntry.addTextChangedListener(new TextWatcher() { + @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override - public void onTextChanged(CharSequence s, int start, int before, - int count) { - validateName(); + public void onTextChanged(CharSequence s, int start, + int lengthBefore, int lengthAfter) { + enableOrDisableCreateButton(); } @Override public void afterTextChanged(Editable s) { } }); - button = (Button) v.findViewById(R.id.button); - button.setOnClickListener(new View.OnClickListener() { + nameEntry.setOnEditorActionListener(new OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, + KeyEvent e) { + createGroup(); + return true; + } + }); + + feedback = (TextView) v.findViewById(R.id.feedback); + + createGroupButton = (Button) v.findViewById(R.id.button); + createGroupButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - listener.hideSoftKeyboard(name); - listener.onGroupNameChosen(name.getText().toString()); + createGroup(); } }); @@ -70,7 +85,7 @@ public class CreateGroupFragment extends BaseFragment { @Override public void onStart() { super.onStart(); - listener.showSoftKeyboard(name); + listener.showSoftKeyboard(nameEntry); } @Override @@ -83,12 +98,25 @@ public class CreateGroupFragment extends BaseFragment { return TAG; } - private void validateName() { - String name = this.name.getText().toString(); - if (name.length() < 1 || StringUtils.utf8IsTooLong(name, MAX_GROUP_NAME_LENGTH)) - button.setEnabled(false); - else if (!button.isEnabled()) - button.setEnabled(true); + private void enableOrDisableCreateButton() { + if (createGroupButton == null) return; // Not created yet + createGroupButton.setEnabled(validateName()); + } + + private boolean validateName() { + String name = nameEntry.getText().toString(); + int length = StringUtils.toUtf8(name).length; + if (length > MAX_GROUP_NAME_LENGTH) { + feedback.setText(R.string.name_too_long); + return false; + } + feedback.setText(""); + return length > 0; } + private void createGroup() { + if (!validateName()) return; + listener.hideSoftKeyboard(nameEntry); + listener.onGroupNameChosen(nameEntry.getText().toString()); + } } diff --git a/briar-android/src/main/res/layout/activity_create_forum.xml b/briar-android/src/main/res/layout/activity_create_forum.xml index 96afb47a99fdc2174122ccf0635077a185ef73e5..da0a858757ab85e87c5a465c75e8bd6ee27b8cb5 100644 --- a/briar-android/src/main/res/layout/activity_create_forum.xml +++ b/briar-android/src/main/res/layout/activity_create_forum.xml @@ -1,37 +1,30 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" - android:padding="20dp" > - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:gravity="center" - android:textSize="@dimen/text_size_medium" - android:text="@string/choose_forum_name" /> + android:orientation="vertical" + android:layout_margin="@dimen/margin_large"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/createForumNameEntry" android:maxLines="1" - android:inputType="text|textCapSentences" /> + android:inputType="text|textCapSentences" + android:hint="@string/choose_forum_hint" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/createForumFeedback" - android:gravity="center" - android:paddingLeft="50dp" - android:paddingRight="50dp" /> + android:gravity="center" /> <Button style="@style/BriarButton" android:id="@+id/createForumButton" + android:enabled="false" android:text="@string/create_forum_button" /> <ProgressBar diff --git a/briar-android/src/main/res/layout/fragment_create_group.xml b/briar-android/src/main/res/layout/fragment_create_group.xml index 67754dfd569a21756a8ed1e8d1af6ce4ba49e7a4..a16e07552066ee1038039b24a01608e1ca84728d 100644 --- a/briar-android/src/main/res/layout/fragment_create_group.xml +++ b/briar-android/src/main/res/layout/fragment_create_group.xml @@ -3,22 +3,27 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" + android:gravity="center_horizontal" android:orientation="vertical" - android:padding="@dimen/margin_medium"> + android:layout_margin="@dimen/margin_large"> <EditText android:id="@+id/name" android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="1" - android:gravity="bottom" + android:layout_height="wrap_content" android:maxLines="1" android:inputType="text|textCapSentences" android:hint="@string/groups_create_group_hint"/> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/feedback" + android:gravity="center" /> + <Button - android:id="@+id/button" style="@style/BriarButton" + android:id="@+id/button" android:enabled="false" android:text="@string/groups_create_group_button"/> diff --git a/briar-android/src/main/res/values/strings.xml b/briar-android/src/main/res/values/strings.xml index 68e51f192ce48ebaf2e47338c8c231c4e02516c9..6e2bbd8eb95c2fd5e1443ab12580e91c0bc11687 100644 --- a/briar-android/src/main/res/values/strings.xml +++ b/briar-android/src/main/res/values/strings.xml @@ -205,7 +205,7 @@ <!-- Forums --> <string name="no_forums">You don\'t have any forums yet.\n\nWhy don\'t you create a new one yourself by tapping the + icon at the top?\n\nYou can also ask your contacts to share forums with you.</string> <string name="create_forum_title">New Forum</string> - <string name="choose_forum_name">Choose a name for your forum:</string> + <string name="choose_forum_hint">Choose a name for your forum</string> <string name="create_forum_button">Create Forum</string> <string name="forum_created_toast">Forum created</string> <string name="no_forum_posts">This forum is empty.\n\nUse the pen icon at the top to compose the first post.\n\nFeeling lonely here? Share this forum with more of your contacts!</string>