From 7a2177a45c6833a6e84db1321e9a9554cbcab1d0 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 25 Mar 2018 09:56:09 +0200 Subject: [PATCH] Display post actions context menu. --- .../client/ui/adapters/PostsAdapter.java | 20 ++++++++++- .../ui/fragments/PostsListFragment.java | 33 +++++++++++++++++++ app/src/main/res/layout/comment_item.xml | 2 +- app/src/main/res/layout/post_item.xml | 14 ++++++-- app/src/main/res/menu/menu_post_actions.xml | 9 +++++ app/src/main/res/values/dimens.xml | 4 +++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/values/styles.xml | 15 ++++++--- 8 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/menu/menu_post_actions.xml diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java index ba4b480..933f8f9 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java @@ -88,7 +88,7 @@ public class PostsAdapter extends ArrayAdapter{ .inflate(R.layout.post_item, parent, false); //Get information about the post and the user - Post post = getItem(position); + final Post post = getItem(position); assert post != null; UserInfo userInfo = null; if(mUsersInfos.containsKey(post.getUserID())) @@ -134,6 +134,15 @@ public class PostsAdapter extends ArrayAdapter{ break; } + //Set post actions + convertView.findViewById(R.id.post_actions_btn).setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + mListener.showPostActions(v, position, post); + } + }); + //Set post content ((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent())); @@ -258,6 +267,15 @@ public class PostsAdapter extends ArrayAdapter{ */ void onCreateComment(int pos, View button, Post post, EditCommentContentView input); + /** + * Show the available actions for a post + * + * @param button The button that provoked event + * @param pos The position of the comment + * @param post the target post + */ + void showPostActions(View button, int pos, Post post); + /** * Show the available actions for a comment * diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/PostsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/PostsListFragment.java index 40fbb83..8934fe7 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/PostsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/PostsListFragment.java @@ -54,6 +54,11 @@ public class PostsListFragment extends Fragment */ private int MENU_ACTION_COMMENTS = 1; + /** + * Menu action : post actions + */ + private int MENU_ACTIONS_POST = 2; + /** * The current menu action */ @@ -64,6 +69,11 @@ public class PostsListFragment extends Fragment */ private Comment mCurrCommentInContextMenu; + /** + * Current processed post that context menu displays actions for + */ + private int mNumCurrPostInContextMenu; + /** * The list of posts */ @@ -241,6 +251,29 @@ public class PostsListFragment extends Fragment }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + @Override + public void showPostActions(View button, final int pos, Post post) { + + button.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenu.ContextMenuInfo menuInfo) { + + //Inflate the menu + MenuInflater inflater = getActivity().getMenuInflater(); + inflater.inflate(R.menu.menu_post_actions, menu); + + //Save information about the post + MENU_ACTION = MENU_ACTIONS_POST; + mNumCurrPostInContextMenu = pos; + + } + }); + + //Show context menu + button.showContextMenu(); + } + @Override public void showCommentActions(View button, final Comment comment) { diff --git a/app/src/main/res/layout/comment_item.xml b/app/src/main/res/layout/comment_item.xml index 1aadd3d..6113135 100644 --- a/app/src/main/res/layout/comment_item.xml +++ b/app/src/main/res/layout/comment_item.xml @@ -1,7 +1,7 @@ diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml index fcba39c..6a5eac8 100644 --- a/app/src/main/res/layout/post_item.xml +++ b/app/src/main/res/layout/post_item.xml @@ -1,12 +1,12 @@ - + + + + + diff --git a/app/src/main/res/menu/menu_post_actions.xml b/app/src/main/res/menu/menu_post_actions.xml new file mode 100644 index 0000000..127eca2 --- /dev/null +++ b/app/src/main/res/menu/menu_post_actions.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index fd9cfc1..faed028 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -15,6 +15,10 @@ 50dp 50dp + + 20dp + 20dp + 20dp 20dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4f3a01c..4c152e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -112,4 +112,6 @@ Yes An error occurred while trying to delete the comment ! Actions on comment + Actions on post + Delete diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9cec9b0..15b8777 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -28,14 +28,20 @@ - - + + + @@ -67,8 +74,8 @@ - -