Display post actions context menu.

This commit is contained in:
Pierre 2018-03-25 09:56:09 +02:00
parent f8e2eefe68
commit 7a2177a45c
8 changed files with 91 additions and 8 deletions

View File

@ -88,7 +88,7 @@ public class PostsAdapter extends ArrayAdapter<Post>{
.inflate(R.layout.post_item, parent, false); .inflate(R.layout.post_item, parent, false);
//Get information about the post and the user //Get information about the post and the user
Post post = getItem(position); final Post post = getItem(position);
assert post != null; assert post != null;
UserInfo userInfo = null; UserInfo userInfo = null;
if(mUsersInfos.containsKey(post.getUserID())) if(mUsersInfos.containsKey(post.getUserID()))
@ -134,6 +134,15 @@ public class PostsAdapter extends ArrayAdapter<Post>{
break; 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 //Set post content
((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent())); ((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent()));
@ -258,6 +267,15 @@ public class PostsAdapter extends ArrayAdapter<Post>{
*/ */
void onCreateComment(int pos, View button, Post post, EditCommentContentView input); 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 * Show the available actions for a comment
* *

View File

@ -54,6 +54,11 @@ public class PostsListFragment extends Fragment
*/ */
private int MENU_ACTION_COMMENTS = 1; private int MENU_ACTION_COMMENTS = 1;
/**
* Menu action : post actions
*/
private int MENU_ACTIONS_POST = 2;
/** /**
* The current menu action * The current menu action
*/ */
@ -64,6 +69,11 @@ public class PostsListFragment extends Fragment
*/ */
private Comment mCurrCommentInContextMenu; private Comment mCurrCommentInContextMenu;
/**
* Current processed post that context menu displays actions for
*/
private int mNumCurrPostInContextMenu;
/** /**
* The list of posts * The list of posts
*/ */
@ -241,6 +251,29 @@ public class PostsListFragment extends Fragment
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }.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 @Override
public void showCommentActions(View button, final Comment comment) { public void showCommentActions(View button, final Comment comment) {

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
style="@style/CommentContener" style="@style/CommentContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
style="@style/PostContener" style="@style/PostContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<!-- Informations about user who created the post --> <!-- Information about user who created the post -->
<LinearLayout <LinearLayout
style="@style/PostHeader" style="@style/PostHeader"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -58,6 +58,16 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:text="Public" /> tools:text="Public" />
<ImageView
style="@style/PostActionsButton"
android:id="@+id/post_actions_btn"
android:layout_width="@dimen/post_options_btn_width"
android:layout_height="@dimen/post_options_btn_height"
android:src="@android:drawable/ic_menu_manage"
android:contentDescription="@string/post_action_btn_description"/>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Delete the post -->
<item
android:id="@+id/action_delete"
android:title="@string/action_delete_post"/>
</menu>

View File

@ -15,6 +15,10 @@
<dimen name="fragment_conversation_buttons_height">50dp</dimen> <dimen name="fragment_conversation_buttons_height">50dp</dimen>
<dimen name="fragment_conversation_buttons_width">50dp</dimen> <dimen name="fragment_conversation_buttons_width">50dp</dimen>
<!-- Dimensions for the posts options button -->
<dimen name="post_options_btn_width">20dp</dimen>
<dimen name="post_options_btn_height">20dp</dimen>
<!-- Dimensions for the comments options button --> <!-- Dimensions for the comments options button -->
<dimen name="comment_options_btn_width">20dp</dimen> <dimen name="comment_options_btn_width">20dp</dimen>
<dimen name="comment_options_btn_height">20dp</dimen> <dimen name="comment_options_btn_height">20dp</dimen>

View File

@ -112,4 +112,6 @@
<string name="popup_deletecomment_confirm">Yes</string> <string name="popup_deletecomment_confirm">Yes</string>
<string name="err_delete_comment">An error occurred while trying to delete the comment !</string> <string name="err_delete_comment">An error occurred while trying to delete the comment !</string>
<string name="comment_action_btn_description">Actions on comment</string> <string name="comment_action_btn_description">Actions on comment</string>
<string name="post_action_btn_description">Actions on post</string>
<string name="action_delete_post">Delete</string>
</resources> </resources>

View File

@ -28,14 +28,20 @@
</style> </style>
<!-- Posts style --> <!-- Posts style -->
<!-- Post contener --> <!-- Post container -->
<style name="PostContener"> <style name="PostContainer">
<item name="android:paddingTop">5dp</item> <item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item> <item name="android:paddingBottom">5dp</item>
<item name="android:paddingStart">5dp</item> <item name="android:paddingStart">5dp</item>
<item name="android:paddingEnd">5dp</item> <item name="android:paddingEnd">5dp</item>
</style> </style>
<!-- Comment actions button -->
<style name="PostActionsButton">
<item name="android:padding">2dp</item>
<item name="android:layout_gravity">center</item>
</style>
<!-- Post header --> <!-- Post header -->
<style name="PostHeader"> <style name="PostHeader">
<item name="android:padding">2dp</item> <item name="android:padding">2dp</item>
@ -56,6 +62,7 @@
<!-- Post visibility --> <!-- Post visibility -->
<style name="PostVisibility"> <style name="PostVisibility">
<item name="android:paddingEnd">2dp</item> <item name="android:paddingEnd">2dp</item>
<item name="android:layout_gravity">center_vertical</item>
</style> </style>
<!-- Post content --> <!-- Post content -->
@ -67,8 +74,8 @@
<!-- Comments style --> <!-- Comments style -->
<!-- Comments contener --> <!-- Comments container -->
<style name="CommentContener"> <style name="CommentContainer">
<item name="android:paddingTop">0dp</item> <item name="android:paddingTop">0dp</item>
<item name="android:paddingStart">5dp</item> <item name="android:paddingStart">5dp</item>
<item name="android:paddingEnd">5dp</item> <item name="android:paddingEnd">5dp</item>