mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-28 14:39:00 +00:00
Display post actions context menu.
This commit is contained in:
parent
f8e2eefe68
commit
7a2177a45c
@ -88,7 +88,7 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
||||
.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<Post>{
|
||||
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<Post>{
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="@style/CommentContener"
|
||||
style="@style/CommentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="@style/PostContener"
|
||||
style="@style/PostContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Informations about user who created the post -->
|
||||
<!-- Information about user who created the post -->
|
||||
<LinearLayout
|
||||
style="@style/PostHeader"
|
||||
android:layout_width="match_parent"
|
||||
@ -58,6 +58,16 @@
|
||||
android:layout_height="wrap_content"
|
||||
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>
|
||||
|
||||
|
9
app/src/main/res/menu/menu_post_actions.xml
Normal file
9
app/src/main/res/menu/menu_post_actions.xml
Normal 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>
|
@ -15,6 +15,10 @@
|
||||
<dimen name="fragment_conversation_buttons_height">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 -->
|
||||
<dimen name="comment_options_btn_width">20dp</dimen>
|
||||
<dimen name="comment_options_btn_height">20dp</dimen>
|
||||
|
@ -112,4 +112,6 @@
|
||||
<string name="popup_deletecomment_confirm">Yes</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="post_action_btn_description">Actions on post</string>
|
||||
<string name="action_delete_post">Delete</string>
|
||||
</resources>
|
||||
|
@ -28,14 +28,20 @@
|
||||
</style>
|
||||
|
||||
<!-- Posts style -->
|
||||
<!-- Post contener -->
|
||||
<style name="PostContener">
|
||||
<!-- Post container -->
|
||||
<style name="PostContainer">
|
||||
<item name="android:paddingTop">5dp</item>
|
||||
<item name="android:paddingBottom">5dp</item>
|
||||
<item name="android:paddingStart">5dp</item>
|
||||
<item name="android:paddingEnd">5dp</item>
|
||||
</style>
|
||||
|
||||
<!-- Comment actions button -->
|
||||
<style name="PostActionsButton">
|
||||
<item name="android:padding">2dp</item>
|
||||
<item name="android:layout_gravity">center</item>
|
||||
</style>
|
||||
|
||||
<!-- Post header -->
|
||||
<style name="PostHeader">
|
||||
<item name="android:padding">2dp</item>
|
||||
@ -56,6 +62,7 @@
|
||||
<!-- Post visibility -->
|
||||
<style name="PostVisibility">
|
||||
<item name="android:paddingEnd">2dp</item>
|
||||
<item name="android:layout_gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
<!-- Post content -->
|
||||
@ -67,8 +74,8 @@
|
||||
|
||||
|
||||
<!-- Comments style -->
|
||||
<!-- Comments contener -->
|
||||
<style name="CommentContener">
|
||||
<!-- Comments container -->
|
||||
<style name="CommentContainer">
|
||||
<item name="android:paddingTop">0dp</item>
|
||||
<item name="android:paddingStart">5dp</item>
|
||||
<item name="android:paddingEnd">5dp</item>
|
||||
|
Loading…
Reference in New Issue
Block a user