Move create forum post and share forum buttons in action bar

This also introduces constants for the GROUP_ID, FORUM_NAME and
MIN_TIMESTAMP as they were used for the two buttons.

Closes #313
This commit is contained in:
Torsten Grote
2016-04-21 12:05:25 -03:00
parent 5457588dbd
commit 44b3d4c14f
13 changed files with 112 additions and 73 deletions

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_forum_compose_post"
android:icon="@drawable/forum_item_create_white"
android:title="@string/forum_compose_post"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_forum_share"
android:icon="@drawable/social_share_white"
android:title="@string/forum_share_button"
app:showAsAction="ifRoom"/>
</menu>

View File

@@ -79,7 +79,8 @@
<string name="forum_created_toast">Forum created</string>
<string name="forum_share_with_all">Share this forum with all contacts</string>
<string name="forum_share_with_some">Share this forum with chosen contacts</string>
<string name="share_button">Share Forum</string>
<string name="forum_share_button">Share Forum</string>
<string name="forum_compose_post">New Forum Post</string>
<string name="from">From:</string>
<string name="anonymous">Anonymous</string>
<string name="new_identity_item">New identity\u2026</string>

View File

@@ -55,6 +55,7 @@ import static android.support.v4.app.NotificationCompat.CATEGORY_MESSAGE;
import static android.support.v4.app.NotificationCompat.CATEGORY_SOCIAL;
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.BriarActivity.GROUP_ID;
import static org.briarproject.android.fragment.SettingsFragment.SETTINGS_NAMESPACE;
class AndroidNotificationManagerImpl implements AndroidNotificationManager,
@@ -232,7 +233,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
if (contactCounts.size() == 1) {
Intent i = new Intent(appContext, ConversationActivity.class);
GroupId g = contactCounts.keySet().iterator().next();
i.putExtra("briar.GROUP_ID", g.getBytes());
i.putExtra(GROUP_ID, g.getBytes());
String idHex = StringUtils.toHexString(g.getBytes());
i.setData(Uri.parse(CONTACT_URI + "/" + idHex));
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
@@ -315,7 +316,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
if (forumCounts.size() == 1) {
Intent i = new Intent(appContext, ForumActivity.class);
GroupId g = forumCounts.keySet().iterator().next();
i.putExtra("briar.GROUP_ID", g.getBytes());
i.putExtra(GROUP_ID, g.getBytes());
String idHex = StringUtils.toHexString(g.getBytes());
i.setData(Uri.parse(FORUM_URI + "/" + idHex));
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);

View File

@@ -30,6 +30,7 @@ public abstract class BriarActivity extends BaseActivity {
public static final String KEY_LOCAL_AUTHOR_HANDLE =
"briar.LOCAL_AUTHOR_HANDLE";
public static final String KEY_STARTUP_FAILED = "briar.STARTUP_FAILED";
public static final String GROUP_ID = "briar.GROUP_ID";
public static final int REQUEST_PASSWORD = 1;

View File

@@ -48,6 +48,7 @@ import javax.inject.Inject;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.BriarActivity.GROUP_ID;
public class ContactListFragment extends BaseEventFragment {
@@ -108,7 +109,7 @@ public class ContactListFragment extends BaseEventFragment {
GroupId groupId = item.getGroupId();
Intent i = new Intent(getActivity(),
ConversationActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra(GROUP_ID, groupId.getBytes());
if (Build.VERSION.SDK_INT >= 16) {
ActivityOptionsCompat options =

View File

@@ -36,6 +36,7 @@ import static android.widget.LinearLayout.VERTICAL;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
import static org.briarproject.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH;
@@ -164,8 +165,8 @@ implements OnEditorActionListener, OnClickListener {
public void run() {
Intent i = new Intent(CreateForumActivity.this,
ForumActivity.class);
i.putExtra("briar.GROUP_ID", f.getId().getBytes());
i.putExtra("briar.FORUM_NAME", f.getName());
i.putExtra(GROUP_ID, f.getId().getBytes());
i.putExtra(FORUM_NAME, f.getName());
startActivity(i);
Toast.makeText(CreateForumActivity.this,
R.string.forum_created_toast, LENGTH_LONG).show();

View File

@@ -1,13 +1,13 @@
package org.briarproject.android.forum;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
@@ -15,10 +15,8 @@ import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.AndroidComponent;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.android.api.AndroidNotificationManager;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchGroupException;
import org.briarproject.api.db.NoSuchMessageException;
@@ -53,11 +51,13 @@ import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.forum.ReadForumPostActivity.RESULT_PREV_NEXT;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
public class ForumActivity extends BriarActivity implements EventListener,
OnClickListener, OnItemClickListener {
OnItemClickListener {
public static final String FORUM_NAME = "briar.FORUM_NAME";
public static final String MIN_TIMESTAMP = "briar.MIN_TIMESTAMP";
private static final int REQUEST_READ = 2;
private static final Logger LOG =
@@ -69,7 +69,6 @@ public class ForumActivity extends BriarActivity implements EventListener,
private ForumAdapter adapter = null;
private ListView list = null;
private ListLoadingProgressBar loading = null;
private ImageButton composeButton = null, shareButton = null;
// Fields that are accessed from background threads must be volatile
@Inject protected volatile ForumManager forumManager;
@@ -82,10 +81,10 @@ public class ForumActivity extends BriarActivity implements EventListener,
super.onCreate(state);
Intent i = getIntent();
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
byte[] b = i.getByteArrayExtra(GROUP_ID);
if (b == null) throw new IllegalStateException();
groupId = new GroupId(b);
String forumName = i.getStringExtra("briar.FORUM_NAME");
String forumName = i.getStringExtra(FORUM_NAME);
if (forumName != null) setTitle(forumName);
LinearLayout layout = new LinearLayout(this);
@@ -113,30 +112,6 @@ public class ForumActivity extends BriarActivity implements EventListener,
loading = new ListLoadingProgressBar(this);
layout.addView(loading);
layout.addView(new HorizontalBorder(this));
LinearLayout footer = new LinearLayout(this);
footer.setLayoutParams(MATCH_WRAP);
footer.setGravity(CENTER);
Resources res = getResources();
footer.setBackgroundColor(res.getColor(R.color.button_bar_background));
footer.addView(new ElasticHorizontalSpace(this));
composeButton = new ImageButton(this);
composeButton.setBackgroundResource(0);
composeButton.setImageResource(R.drawable.content_new_email);
composeButton.setOnClickListener(this);
footer.addView(composeButton);
footer.addView(new ElasticHorizontalSpace(this));
shareButton = new ImageButton(this);
shareButton.setBackgroundResource(0);
shareButton.setImageResource(R.drawable.social_share_old);
shareButton.setOnClickListener(this);
footer.addView(shareButton);
footer.addView(new ElasticHorizontalSpace(this));
layout.addView(footer);
setContentView(layout);
}
@@ -155,6 +130,37 @@ public class ForumActivity extends BriarActivity implements EventListener,
loadHeaders();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.forum_actions, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_forum_compose_post:
Intent i = new Intent(this, WriteForumPostActivity.class);
i.putExtra(GROUP_ID, groupId.getBytes());
i.putExtra(FORUM_NAME, forum.getName());
i.putExtra(MIN_TIMESTAMP, getMinTimestampForNewPost());
startActivity(i);
return true;
case R.id.action_forum_share:
Intent i2 = new Intent(this, ShareForumActivity.class);
i2.putExtra(GROUP_ID, groupId.getBytes());
i2.putExtra(FORUM_NAME, forum.getName());
startActivity(i2);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void loadForum() {
runOnDbThread(new Runnable() {
public void run() {
@@ -334,21 +340,6 @@ public class ForumActivity extends BriarActivity implements EventListener,
}
}
public void onClick(View view) {
if (view == composeButton) {
Intent i = new Intent(this, WriteForumPostActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra("briar.FORUM_NAME", forum.getName());
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewPost());
startActivity(i);
} else if (view == shareButton) {
Intent i = new Intent(this, ShareForumActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra("briar.FORUM_NAME", forum.getName());
startActivity(i);
}
}
private long getMinTimestampForNewPost() {
// Don't use an earlier timestamp than the newest post
long timestamp = 0;
@@ -368,8 +359,8 @@ public class ForumActivity extends BriarActivity implements EventListener,
private void displayPost(int position) {
ForumPostHeader header = adapter.getItem(position).getHeader();
Intent i = new Intent(this, ReadForumPostActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra("briar.FORUM_NAME", forum.getName());
i.putExtra(GROUP_ID, groupId.getBytes());
i.putExtra(FORUM_NAME, forum.getName());
i.putExtra("briar.MESSAGE_ID", header.getId().getBytes());
Author author = header.getAuthor();
if (author != null) {
@@ -379,7 +370,7 @@ public class ForumActivity extends BriarActivity implements EventListener,
i.putExtra("briar.AUTHOR_STATUS", header.getAuthorStatus().name());
i.putExtra("briar.CONTENT_TYPE", header.getContentType());
i.putExtra("briar.TIMESTAMP", header.getTimestamp());
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewPost());
i.putExtra(MIN_TIMESTAMP, getMinTimestampForNewPost());
i.putExtra("briar.POSITION", position);
startActivityForResult(i, REQUEST_READ);
}

View File

@@ -53,6 +53,8 @@ import static android.widget.LinearLayout.VERTICAL;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.BriarActivity.GROUP_ID;
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
@@ -373,8 +375,8 @@ public class ForumListFragment extends BaseEventFragment implements
long id) {
Intent i = new Intent(getContext(), ForumActivity.class);
Forum f = adapter.getItem(position).getForum();
i.putExtra("briar.GROUP_ID", f.getId().getBytes());
i.putExtra("briar.FORUM_NAME", f.getName());
i.putExtra(GROUP_ID, f.getId().getBytes());
i.putExtra(FORUM_NAME, f.getName());
startActivity(i);
}

View File

@@ -37,6 +37,8 @@ import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
import static org.briarproject.android.forum.ForumActivity.MIN_TIMESTAMP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
@@ -68,10 +70,10 @@ implements OnClickListener {
super.onCreate(state);
Intent i = getIntent();
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
byte[] b = i.getByteArrayExtra(GROUP_ID);
if (b == null) throw new IllegalStateException();
groupId = new GroupId(b);
forumName = i.getStringExtra("briar.FORUM_NAME");
forumName = i.getStringExtra(FORUM_NAME);
if (forumName == null) throw new IllegalStateException();
setTitle(forumName);
b = i.getByteArrayExtra("briar.MESSAGE_ID");
@@ -81,7 +83,7 @@ implements OnClickListener {
if (contentType == null) throw new IllegalStateException();
long timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
if (timestamp == -1) throw new IllegalStateException();
minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
minTimestamp = i.getLongExtra(MIN_TIMESTAMP, -1);
if (minTimestamp == -1) throw new IllegalStateException();
position = i.getIntExtra("briar.POSITION", -1);
if (position == -1) throw new IllegalStateException();
@@ -234,10 +236,10 @@ implements OnClickListener {
finish();
} else if (view == replyButton) {
Intent i = new Intent(this, WriteForumPostActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra("briar.FORUM_NAME", forumName);
i.putExtra(GROUP_ID, groupId.getBytes());
i.putExtra(FORUM_NAME, forumName);
i.putExtra("briar.PARENT_ID", messageId.getBytes());
i.putExtra("briar.MIN_TIMESTAMP", minTimestamp);
i.putExtra(MIN_TIMESTAMP, minTimestamp);
startActivity(i);
setResult(RESULT_REPLY);
finish();

View File

@@ -35,6 +35,7 @@ import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
@@ -63,10 +64,10 @@ SelectContactsDialog.Listener {
super.onCreate(state);
Intent i = getIntent();
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
byte[] b = i.getByteArrayExtra(GROUP_ID);
if (b == null) throw new IllegalStateException();
groupId = new GroupId(b);
String forumName = i.getStringExtra("briar.FORUM_NAME");
String forumName = i.getStringExtra(FORUM_NAME);
if (forumName == null) throw new IllegalStateException();
setTitle(forumName);
@@ -97,7 +98,7 @@ SelectContactsDialog.Listener {
shareButton = new Button(this);
shareButton.setLayoutParams(WRAP_WRAP);
shareButton.setText(R.string.share_button);
shareButton.setText(R.string.forum_share_button);
shareButton.setOnClickListener(this);
layout.addView(shareButton);

View File

@@ -59,6 +59,8 @@ import static android.widget.RelativeLayout.RIGHT_OF;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
import static org.briarproject.android.forum.ForumActivity.MIN_TIMESTAMP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
public class WriteForumPostActivity extends BriarActivity
@@ -91,13 +93,13 @@ implements OnItemSelectedListener, OnClickListener {
super.onCreate(state);
Intent i = getIntent();
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
byte[] b = i.getByteArrayExtra(GROUP_ID);
if (b == null) throw new IllegalStateException();
groupId = new GroupId(b);
String forumName = i.getStringExtra("briar.FORUM_NAME");
String forumName = i.getStringExtra(FORUM_NAME);
if (forumName == null) throw new IllegalStateException();
setTitle(forumName);
minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
minTimestamp = i.getLongExtra(MIN_TIMESTAMP, -1);
if (minTimestamp == -1) throw new IllegalStateException();
b = i.getByteArrayExtra("briar.PARENT_ID");
if (b != null) parentId = new MessageId(b);