Merge branch '822-group-creation-workflow' into 'master'

Revisit private group creation workflow

Closes #822

See merge request !553
This commit is contained in:
Torsten Grote
2017-07-04 17:19:11 +00:00
12 changed files with 175 additions and 165 deletions

View File

@@ -179,7 +179,7 @@
android:name=".android.forum.CreateForumActivity"
android:label="@string/create_forum_title"
android:parentActivityName=".android.navdrawer.NavDrawerActivity"
android:windowSoftInputMode="stateVisible">
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".android.navdrawer.NavDrawerActivity"

View File

@@ -39,7 +39,7 @@ import org.briarproject.briar.android.privategroup.conversation.GroupConversatio
import org.briarproject.briar.android.privategroup.creation.CreateGroupActivity;
import org.briarproject.briar.android.privategroup.creation.CreateGroupFragment;
import org.briarproject.briar.android.privategroup.creation.CreateGroupMessageFragment;
import org.briarproject.briar.android.privategroup.creation.GroupCreateModule;
import org.briarproject.briar.android.privategroup.creation.CreateGroupModule;
import org.briarproject.briar.android.privategroup.creation.GroupInviteActivity;
import org.briarproject.briar.android.privategroup.creation.GroupInviteFragment;
import org.briarproject.briar.android.privategroup.invitation.GroupInvitationActivity;
@@ -71,7 +71,7 @@ import dagger.Component;
@Component(
modules = {ActivityModule.class, ForumModule.class, SharingModule.class,
BlogModule.class, ContactModule.class, GroupListModule.class,
GroupCreateModule.class, GroupInvitationModule.class,
CreateGroupModule.class, GroupInvitationModule.class,
GroupConversationModule.class, GroupMemberModule.class,
GroupRevealModule.class},
dependencies = AndroidComponent.class)

View File

@@ -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,41 @@ 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) {
createForum();
}
});
progress = (ProgressBar) findViewById(R.id.createForumProgressBar);
}
@Override
public void onStart() {
super.onStart();
showSoftKeyboard(nameEntry);
}
@Override
@@ -95,16 +110,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 +125,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) {

View File

@@ -1,58 +0,0 @@
package org.briarproject.briar.android.privategroup.creation;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.android.contactselection.ContactSelectorActivity;
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
import org.briarproject.briar.android.sharing.BaseMessageFragment.MessageFragmentListener;
import java.util.Collection;
import javax.inject.Inject;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_MSG_LENGTH;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public abstract class BaseGroupInviteActivity
extends ContactSelectorActivity implements MessageFragmentListener {
@Inject
CreateGroupController controller;
@Override
public void contactsSelected(Collection<ContactId> contacts) {
super.contactsSelected(contacts);
showNextFragment(new CreateGroupMessageFragment());
}
@Override
public boolean onButtonClick(String message) {
if (groupId == null)
throw new IllegalStateException("GroupId was not initialized");
controller.sendInvitation(groupId, contacts, message,
new UiResultExceptionHandler<Void, DbException>(this) {
@Override
public void onResultUi(Void result) {
setResult(RESULT_OK);
supportFinishAfterTransition();
}
@Override
public void onExceptionUi(DbException exception) {
setResult(RESULT_CANCELED);
handleDbException(exception);
}
});
return true;
}
@Override
public int getMaximumMessageLength() {
return MAX_GROUP_INVITATION_MSG_LENGTH;
}
}

View File

@@ -9,16 +9,20 @@ import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
import org.briarproject.briar.android.sharing.BaseMessageFragment.MessageFragmentListener;
import javax.annotation.Nullable;
import javax.inject.Inject;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class CreateGroupActivity extends BaseGroupInviteActivity implements
CreateGroupListener, MessageFragmentListener {
public class CreateGroupActivity extends BriarActivity
implements CreateGroupListener {
@Inject
CreateGroupController controller;
@Override
public void injectActivity(ActivityComponent component) {
@@ -29,32 +33,20 @@ public class CreateGroupActivity extends BaseGroupInviteActivity implements
public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_fragment_container);
if (bundle == null) {
showInitialFragment(new CreateGroupFragment());
}
}
@Override
public void onBackPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
// At this point, the group had been created already,
// so don't allow to create it again.
openNewGroup();
overridePendingTransition(R.anim.screen_old_in,
R.anim.screen_new_out);
} else {
super.onBackPressed();
}
}
@Override
public void onGroupNameChosen(String name) {
controller.createGroup(name,
new UiResultExceptionHandler<GroupId, DbException>(this) {
@Override
public void onResultUi(GroupId g) {
groupId = g;
switchToContactSelectorFragment(g);
openNewGroup(g);
}
@Override
@@ -64,16 +56,10 @@ public class CreateGroupActivity extends BaseGroupInviteActivity implements
});
}
private void switchToContactSelectorFragment(GroupId g) {
showNextFragment(GroupInviteFragment.newInstance(g));
}
private void openNewGroup() {
private void openNewGroup(GroupId g) {
Intent i = new Intent(this, GroupActivity.class);
i.putExtra(GROUP_ID, groupId.getBytes());
i.putExtra(GROUP_ID, g.getBytes());
startActivity(i);
// finish this activity, so we can't come back to it
finish();
}
}

View File

@@ -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());
}
}

View File

@@ -6,7 +6,7 @@ import dagger.Module;
import dagger.Provides;
@Module
public class GroupCreateModule {
public class CreateGroupModule {
@ActivityScope
@Provides

View File

@@ -3,25 +3,43 @@ package org.briarproject.briar.android.privategroup.creation;
import android.content.Intent;
import android.os.Bundle;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.contactselection.ContactSelectorActivity;
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
import org.briarproject.briar.android.sharing.BaseMessageFragment.MessageFragmentListener;
public class GroupInviteActivity extends BaseGroupInviteActivity
import java.util.Collection;
import javax.annotation.Nullable;
import javax.inject.Inject;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_MSG_LENGTH;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class GroupInviteActivity extends ContactSelectorActivity
implements MessageFragmentListener {
@Inject
CreateGroupController controller;
@Override
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
@Override
public void onCreate(Bundle bundle) {
public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle);
Intent i = getIntent();
byte[] g = i.getByteArrayExtra(GROUP_ID);
if (g == null) throw new IllegalStateException("No GroupId in intent.");
if (g == null) throw new IllegalStateException("No GroupId in intent");
groupId = new GroupId(g);
if (bundle == null) {
@@ -29,4 +47,36 @@ public class GroupInviteActivity extends BaseGroupInviteActivity
}
}
@Override
public void contactsSelected(Collection<ContactId> contacts) {
super.contactsSelected(contacts);
showNextFragment(new CreateGroupMessageFragment());
}
@Override
public boolean onButtonClick(String message) {
if (groupId == null)
throw new IllegalStateException("GroupId was not initialized");
controller.sendInvitation(groupId, contacts, message,
new UiResultExceptionHandler<Void, DbException>(this) {
@Override
public void onResultUi(Void result) {
setResult(RESULT_OK);
supportFinishAfterTransition();
}
@Override
public void onExceptionUi(DbException exception) {
setResult(RESULT_CANCELED);
handleDbException(exception);
}
});
return true;
}
@Override
public int getMaximumMessageLength() {
return MAX_GROUP_INVITATION_MSG_LENGTH;
}
}

View File

@@ -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

View File

@@ -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"/>

View File

@@ -10,16 +10,16 @@
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_group_reveal"
android:icon="@drawable/ic_visibility_white"
android:title="@string/groups_reveal_contacts"
android:id="@+id/action_group_invite"
android:icon="@drawable/social_share_white"
android:title="@string/groups_invite_members"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_group_invite"
android:icon="@drawable/ic_add_white"
android:title="@string/groups_invite_members"
app:showAsAction="ifRoom"/>
android:id="@+id/action_group_reveal"
android:icon="@drawable/ic_visibility_white"
android:title="@string/groups_reveal_contacts"
app:showAsAction="never"/>
<item
android:id="@+id/action_group_leave"

View File

@@ -204,8 +204,8 @@
<!-- 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="create_forum_title">Create 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>