mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-28 22:48:59 +00:00
Work progress on comments update.
This commit is contained in:
parent
5c6a38b49c
commit
066805df27
@ -22,6 +22,9 @@ public class Comment {
|
||||
private int likes;
|
||||
private boolean user_like;
|
||||
|
||||
//This field is used to indicate the corresponding comment has been deleted
|
||||
private boolean deleted = false;
|
||||
|
||||
|
||||
//Get and set comment ID
|
||||
public int getId() {
|
||||
@ -111,4 +114,13 @@ public class Comment {
|
||||
public void setUser_like(boolean user_like) {
|
||||
this.user_like = user_like;
|
||||
}
|
||||
|
||||
//Get and set the current deleted state of the comment
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,22 @@ package org.communiquons.android.comunic.client.ui.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.Account.AccountUtils;
|
||||
import org.communiquons.android.comunic.client.data.ImageLoad.ImageLoadManager;
|
||||
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
||||
import org.communiquons.android.comunic.client.data.comments.Comment;
|
||||
import org.communiquons.android.comunic.client.data.comments.CommentsHelper;
|
||||
import org.communiquons.android.comunic.client.data.utils.UiUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -26,6 +31,11 @@ import java.util.ArrayList;
|
||||
|
||||
public class CommentsAdapter extends ArrayAdapter<Comment> {
|
||||
|
||||
/**
|
||||
* Comment helper
|
||||
*/
|
||||
private static CommentsHelper mCHelper = null;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
@ -48,6 +58,11 @@ public class CommentsAdapter extends ArrayAdapter<Comment> {
|
||||
static View getInflatedView(Context context, Comment comment, @Nullable UserInfo user,
|
||||
ViewGroup viewGroup){
|
||||
|
||||
//Create comment helper if required
|
||||
if(mCHelper == null){
|
||||
mCHelper = new CommentsHelper(context.getApplicationContext());
|
||||
}
|
||||
|
||||
//Inflate a view
|
||||
View v = LayoutInflater.from(context).inflate(R.layout.comment_item, viewGroup, false);
|
||||
|
||||
@ -65,28 +80,49 @@ public class CommentsAdapter extends ArrayAdapter<Comment> {
|
||||
* @param user Information about the user (NULL for none)
|
||||
* @return Updated view
|
||||
*/
|
||||
private static View fillView(Context context, View view, Comment comment,
|
||||
@Nullable UserInfo user){
|
||||
private static View fillView(final Context context, View view, Comment comment,
|
||||
@Nullable UserInfo user) {
|
||||
|
||||
//Check wether the current user is the owner of the comment or not
|
||||
final boolean isOwner = AccountUtils.getID(context) == comment.getUserID();
|
||||
|
||||
//Update user name and account image
|
||||
ImageView accountImage = view.findViewById(R.id.user_account_image);
|
||||
TextView accountName = view.findViewById(R.id.user_account_name);
|
||||
|
||||
if(user == null){
|
||||
if (user == null) {
|
||||
accountImage.setImageDrawable(UiUtils.getDrawable(context,
|
||||
R.drawable.default_account_image));
|
||||
accountName.setText("");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ImageLoadManager.load(context, user.getAcountImageURL(), accountImage);
|
||||
accountName.setText(user.getDisplayFullName());
|
||||
}
|
||||
|
||||
//Update comment content
|
||||
((TextView)view.findViewById(R.id.comment_text)).setText(comment.getContent());
|
||||
((TextView) view.findViewById(R.id.comment_text)).setText(comment.getContent());
|
||||
|
||||
//Update comment actions
|
||||
ImageButton actions = view.findViewById(R.id.comment_actions_btn);
|
||||
|
||||
//Create context menu
|
||||
actions.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
|
||||
//Inflate the menu
|
||||
new MenuInflater(context).inflate(R.menu.menu_comments_actions, menu);
|
||||
|
||||
//Disable some entries accordingly to ownership status
|
||||
menu.findItem(R.id.action_delete).setEnabled(isOwner);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Return view
|
||||
return view;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -180,6 +180,10 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
||||
|
||||
for (Comment comment : comments) {
|
||||
|
||||
//Check if the comment has been deleted
|
||||
if(comment.isDeleted())
|
||||
continue; //Skip comment
|
||||
|
||||
//Try to find information about the user
|
||||
UserInfo commentUser = mUsersInfos.containsKey(comment.getUserID()) ?
|
||||
mUsersInfos.get(comment.getUserID()) : null;
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
<!-- User name and image-->
|
||||
<ImageView
|
||||
style="@style/CommentUserImage"
|
||||
android:id="@+id/user_account_image"
|
||||
android:layout_width="@dimen/account_image_small_width"
|
||||
android:layout_height="@dimen/account_image_small_height"
|
||||
@ -31,4 +32,12 @@
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="A comment content" />
|
||||
|
||||
<!-- Comment actions -->
|
||||
<ImageButton
|
||||
style="@style/CommentActionsButton"
|
||||
android:id="@+id/comment_actions_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@android:drawable/ic_menu_manage" />
|
||||
|
||||
</LinearLayout>
|
10
app/src/main/res/menu/menu_comments_actions.xml
Normal file
10
app/src/main/res/menu/menu_comments_actions.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- Delete comment -->
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:title="@string/action_delete_comment" />
|
||||
|
||||
</menu>
|
@ -105,4 +105,5 @@
|
||||
<string name="err_invalid_comment_content">Specified comment content seems to be invalid…</string>
|
||||
<string name="err_create_comment">An error occurred while trying to create comment!</string>
|
||||
<string name="action_send">Send</string>
|
||||
<string name="action_delete_comment">Delete</string>
|
||||
</resources>
|
||||
|
@ -75,6 +75,11 @@
|
||||
<item name="android:paddingBottom">2dp</item>
|
||||
</style>
|
||||
|
||||
<!-- Comment user account image -->
|
||||
<style name="CommentUserImage">
|
||||
<item name="android:layout_gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
<!-- Comment user name -->
|
||||
<style name="CommentUserName">
|
||||
<item name="android:layout_gravity">center</item>
|
||||
@ -87,4 +92,9 @@
|
||||
<item name="android:layout_gravity">center</item>
|
||||
<item name="android:textColor">@android:color/black</item>
|
||||
</style>
|
||||
|
||||
<!-- Comment actions button -->
|
||||
<style name="CommentActionsButton">
|
||||
<item name="android:padding">2dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user