mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
Use same layout and behaviour for creating groups and forums.
This commit is contained in:
@@ -38,8 +38,7 @@ import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LEN
|
|||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class CreateForumActivity extends BriarActivity
|
public class CreateForumActivity extends BriarActivity {
|
||||||
implements OnEditorActionListener, OnClickListener {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(CreateForumActivity.class.getName());
|
Logger.getLogger(CreateForumActivity.class.getName());
|
||||||
@@ -60,11 +59,7 @@ public class CreateForumActivity extends BriarActivity
|
|||||||
setContentView(R.layout.activity_create_forum);
|
setContentView(R.layout.activity_create_forum);
|
||||||
|
|
||||||
nameEntry = (EditText) findViewById(R.id.createForumNameEntry);
|
nameEntry = (EditText) findViewById(R.id.createForumNameEntry);
|
||||||
TextWatcher nameEntryWatcher = new TextWatcher() {
|
nameEntry.addTextChangedListener(new TextWatcher() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||||
@@ -72,21 +67,40 @@ public class CreateForumActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence text, int start,
|
public void onTextChanged(CharSequence s, int start,
|
||||||
int lengthBefore, int lengthAfter) {
|
int lengthBefore, int lengthAfter) {
|
||||||
enableOrDisableCreateButton();
|
enableOrDisableCreateButton();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
nameEntry.setOnEditorActionListener(this);
|
@Override
|
||||||
nameEntry.addTextChangedListener(nameEntryWatcher);
|
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);
|
feedback = (TextView) findViewById(R.id.createForumFeedback);
|
||||||
|
|
||||||
createForumButton = (Button) findViewById(R.id.createForumButton);
|
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);
|
progress = (ProgressBar) findViewById(R.id.createForumProgressBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
showSoftKeyboard(nameEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -95,16 +109,10 @@ public class CreateForumActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enableOrDisableCreateButton() {
|
private void enableOrDisableCreateButton() {
|
||||||
if (progress == null) return; // Not created yet
|
if (createForumButton == null) return; // Not created yet
|
||||||
createForumButton.setEnabled(validateName());
|
createForumButton.setEnabled(validateName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
|
||||||
hideSoftKeyboard(textView);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateName() {
|
private boolean validateName() {
|
||||||
String name = nameEntry.getText().toString();
|
String name = nameEntry.getText().toString();
|
||||||
int length = StringUtils.toUtf8(name).length;
|
int length = StringUtils.toUtf8(name).length;
|
||||||
@@ -116,15 +124,12 @@ public class CreateForumActivity extends BriarActivity
|
|||||||
return length > 0;
|
return length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void createForum() {
|
||||||
public void onClick(View view) {
|
if (!validateName()) return;
|
||||||
if (view == createForumButton) {
|
hideSoftKeyboard(nameEntry);
|
||||||
hideSoftKeyboard(view);
|
createForumButton.setVisibility(GONE);
|
||||||
if (!validateName()) return;
|
progress.setVisibility(VISIBLE);
|
||||||
createForumButton.setVisibility(GONE);
|
storeForum(nameEntry.getText().toString());
|
||||||
progress.setVisibility(VISIBLE);
|
|
||||||
storeForum(nameEntry.getText().toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeForum(final String name) {
|
private void storeForum(final String name) {
|
||||||
|
|||||||
@@ -4,11 +4,15 @@ import android.content.Context;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
|
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
@@ -22,8 +26,9 @@ public class CreateGroupFragment extends BaseFragment {
|
|||||||
public final static String TAG = CreateGroupFragment.class.getName();
|
public final static String TAG = CreateGroupFragment.class.getName();
|
||||||
|
|
||||||
private CreateGroupListener listener;
|
private CreateGroupListener listener;
|
||||||
private EditText name;
|
private EditText nameEntry;
|
||||||
private Button button;
|
private Button createGroupButton;
|
||||||
|
private TextView feedback;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
@@ -35,32 +40,42 @@ public class CreateGroupFragment extends BaseFragment {
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
// inflate view
|
|
||||||
View v = inflater.inflate(R.layout.fragment_create_group, container,
|
View v = inflater.inflate(R.layout.fragment_create_group, container,
|
||||||
false);
|
false);
|
||||||
name = (EditText) v.findViewById(R.id.name);
|
nameEntry = (EditText) v.findViewById(R.id.name);
|
||||||
name.addTextChangedListener(new TextWatcher() {
|
nameEntry.addTextChangedListener(new TextWatcher() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||||
int after) {
|
int after) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before,
|
public void onTextChanged(CharSequence s, int start,
|
||||||
int count) {
|
int lengthBefore, int lengthAfter) {
|
||||||
validateName();
|
enableOrDisableCreateButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
button = (Button) v.findViewById(R.id.button);
|
nameEntry.setOnEditorActionListener(new OnEditorActionListener() {
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
@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
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
listener.hideSoftKeyboard(name);
|
createGroup();
|
||||||
listener.onGroupNameChosen(name.getText().toString());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -70,7 +85,7 @@ public class CreateGroupFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
listener.showSoftKeyboard(name);
|
listener.showSoftKeyboard(nameEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,12 +98,25 @@ public class CreateGroupFragment extends BaseFragment {
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateName() {
|
private void enableOrDisableCreateButton() {
|
||||||
String name = this.name.getText().toString();
|
if (createGroupButton == null) return; // Not created yet
|
||||||
if (name.length() < 1 || StringUtils.utf8IsTooLong(name, MAX_GROUP_NAME_LENGTH))
|
createGroupButton.setEnabled(validateName());
|
||||||
button.setEnabled(false);
|
|
||||||
else if (!button.isEnabled())
|
|
||||||
button.setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:padding="20dp" >
|
android:orientation="vertical"
|
||||||
|
android:layout_margin="@dimen/margin_large">
|
||||||
<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" />
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/createForumNameEntry"
|
android:id="@+id/createForumNameEntry"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:inputType="text|textCapSentences" />
|
android:inputType="text|textCapSentences"
|
||||||
|
android:hint="@string/choose_forum_hint" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/createForumFeedback"
|
android:id="@+id/createForumFeedback"
|
||||||
android:gravity="center"
|
android:gravity="center" />
|
||||||
android:paddingLeft="50dp"
|
|
||||||
android:paddingRight="50dp" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
style="@style/BriarButton"
|
style="@style/BriarButton"
|
||||||
android:id="@+id/createForumButton"
|
android:id="@+id/createForumButton"
|
||||||
|
android:enabled="false"
|
||||||
android:text="@string/create_forum_button" />
|
android:text="@string/create_forum_button" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
|
|||||||
@@ -3,22 +3,27 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="@dimen/margin_medium">
|
android:layout_margin="@dimen/margin_large">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/name"
|
android:id="@+id/name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="bottom"
|
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:inputType="text|textCapSentences"
|
android:inputType="text|textCapSentences"
|
||||||
android:hint="@string/groups_create_group_hint"/>
|
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
|
<Button
|
||||||
android:id="@+id/button"
|
|
||||||
style="@style/BriarButton"
|
style="@style/BriarButton"
|
||||||
|
android:id="@+id/button"
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
android:text="@string/groups_create_group_button"/>
|
android:text="@string/groups_create_group_button"/>
|
||||||
|
|
||||||
|
|||||||
@@ -205,7 +205,7 @@
|
|||||||
<!-- Forums -->
|
<!-- 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="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="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="create_forum_button">Create Forum</string>
|
||||||
<string name="forum_created_toast">Forum created</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>
|
<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>
|
||||||
|
|||||||
Reference in New Issue
Block a user