From 44b3d4c14fa21323df984c7952d3b6f6ca160788 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 21 Apr 2016 12:05:25 -0300 Subject: [PATCH] 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 --- .../res/drawable/forum_item_create_white.xml | 9 ++ .../res/drawable/social_share_white.xml | 9 ++ briar-android/res/menu/forum_actions.xml | 18 ++++ briar-android/res/values/strings.xml | 3 +- .../AndroidNotificationManagerImpl.java | 5 +- .../briarproject/android/BriarActivity.java | 1 + .../android/contact/ContactListFragment.java | 3 +- .../android/forum/CreateForumActivity.java | 5 +- .../android/forum/ForumActivity.java | 97 +++++++++---------- .../android/forum/ForumListFragment.java | 6 +- .../android/forum/ReadForumPostActivity.java | 14 +-- .../android/forum/ShareForumActivity.java | 7 +- .../android/forum/WriteForumPostActivity.java | 8 +- 13 files changed, 112 insertions(+), 73 deletions(-) create mode 100644 briar-android/res/drawable/forum_item_create_white.xml create mode 100644 briar-android/res/drawable/social_share_white.xml create mode 100644 briar-android/res/menu/forum_actions.xml diff --git a/briar-android/res/drawable/forum_item_create_white.xml b/briar-android/res/drawable/forum_item_create_white.xml new file mode 100644 index 000000000..2a963d9ab --- /dev/null +++ b/briar-android/res/drawable/forum_item_create_white.xml @@ -0,0 +1,9 @@ + + + diff --git a/briar-android/res/drawable/social_share_white.xml b/briar-android/res/drawable/social_share_white.xml new file mode 100644 index 000000000..a7bbe2860 --- /dev/null +++ b/briar-android/res/drawable/social_share_white.xml @@ -0,0 +1,9 @@ + + + diff --git a/briar-android/res/menu/forum_actions.xml b/briar-android/res/menu/forum_actions.xml new file mode 100644 index 000000000..a4ff00a86 --- /dev/null +++ b/briar-android/res/menu/forum_actions.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/briar-android/res/values/strings.xml b/briar-android/res/values/strings.xml index ca1e962f4..a6dbd4c95 100644 --- a/briar-android/res/values/strings.xml +++ b/briar-android/res/values/strings.xml @@ -79,7 +79,8 @@ Forum created Share this forum with all contacts Share this forum with chosen contacts - Share Forum + Share Forum + New Forum Post From: Anonymous New identity\u2026 diff --git a/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java b/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java index 17f8fbac7..0a7b1ea2b 100644 --- a/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java +++ b/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java @@ -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); diff --git a/briar-android/src/org/briarproject/android/BriarActivity.java b/briar-android/src/org/briarproject/android/BriarActivity.java index 80d33959e..3b4e7c4c6 100644 --- a/briar-android/src/org/briarproject/android/BriarActivity.java +++ b/briar-android/src/org/briarproject/android/BriarActivity.java @@ -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; diff --git a/briar-android/src/org/briarproject/android/contact/ContactListFragment.java b/briar-android/src/org/briarproject/android/contact/ContactListFragment.java index 18d3295eb..f3737bd1d 100644 --- a/briar-android/src/org/briarproject/android/contact/ContactListFragment.java +++ b/briar-android/src/org/briarproject/android/contact/ContactListFragment.java @@ -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 = diff --git a/briar-android/src/org/briarproject/android/forum/CreateForumActivity.java b/briar-android/src/org/briarproject/android/forum/CreateForumActivity.java index 9307bbb43..ac5d79068 100644 --- a/briar-android/src/org/briarproject/android/forum/CreateForumActivity.java +++ b/briar-android/src/org/briarproject/android/forum/CreateForumActivity.java @@ -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(); diff --git a/briar-android/src/org/briarproject/android/forum/ForumActivity.java b/briar-android/src/org/briarproject/android/forum/ForumActivity.java index 522449158..8f2f58d34 100644 --- a/briar-android/src/org/briarproject/android/forum/ForumActivity.java +++ b/briar-android/src/org/briarproject/android/forum/ForumActivity.java @@ -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); } diff --git a/briar-android/src/org/briarproject/android/forum/ForumListFragment.java b/briar-android/src/org/briarproject/android/forum/ForumListFragment.java index 1684a14fc..d3bec0aee 100644 --- a/briar-android/src/org/briarproject/android/forum/ForumListFragment.java +++ b/briar-android/src/org/briarproject/android/forum/ForumListFragment.java @@ -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); } diff --git a/briar-android/src/org/briarproject/android/forum/ReadForumPostActivity.java b/briar-android/src/org/briarproject/android/forum/ReadForumPostActivity.java index 890cc0398..f320ed6ef 100644 --- a/briar-android/src/org/briarproject/android/forum/ReadForumPostActivity.java +++ b/briar-android/src/org/briarproject/android/forum/ReadForumPostActivity.java @@ -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(); diff --git a/briar-android/src/org/briarproject/android/forum/ShareForumActivity.java b/briar-android/src/org/briarproject/android/forum/ShareForumActivity.java index cf252102e..fd8e805f1 100644 --- a/briar-android/src/org/briarproject/android/forum/ShareForumActivity.java +++ b/briar-android/src/org/briarproject/android/forum/ShareForumActivity.java @@ -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); diff --git a/briar-android/src/org/briarproject/android/forum/WriteForumPostActivity.java b/briar-android/src/org/briarproject/android/forum/WriteForumPostActivity.java index 59b5b4c39..4087115e0 100644 --- a/briar-android/src/org/briarproject/android/forum/WriteForumPostActivity.java +++ b/briar-android/src/org/briarproject/android/forum/WriteForumPostActivity.java @@ -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);