Work progress on comments update.

This commit is contained in:
Pierre 2018-03-18 14:24:16 +01:00
parent 5c6a38b49c
commit 066805df27
7 changed files with 88 additions and 6 deletions

View File

@ -22,6 +22,9 @@ public class Comment {
private int likes; private int likes;
private boolean user_like; 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 //Get and set comment ID
public int getId() { public int getId() {
@ -111,4 +114,13 @@ public class Comment {
public void setUser_like(boolean user_like) { public void setUser_like(boolean user_like) {
this.user_like = 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;
}
} }

View File

@ -2,17 +2,22 @@ package org.communiquons.android.comunic.client.ui.adapters;
import android.content.Context; import android.content.Context;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.communiquons.android.comunic.client.R; 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.ImageLoad.ImageLoadManager;
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo; 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.Comment;
import org.communiquons.android.comunic.client.data.comments.CommentsHelper;
import org.communiquons.android.comunic.client.data.utils.UiUtils; import org.communiquons.android.comunic.client.data.utils.UiUtils;
import java.util.ArrayList; import java.util.ArrayList;
@ -26,6 +31,11 @@ import java.util.ArrayList;
public class CommentsAdapter extends ArrayAdapter<Comment> { public class CommentsAdapter extends ArrayAdapter<Comment> {
/**
* Comment helper
*/
private static CommentsHelper mCHelper = null;
/** /**
* Class constructor * Class constructor
* *
@ -48,6 +58,11 @@ public class CommentsAdapter extends ArrayAdapter<Comment> {
static View getInflatedView(Context context, Comment comment, @Nullable UserInfo user, static View getInflatedView(Context context, Comment comment, @Nullable UserInfo user,
ViewGroup viewGroup){ ViewGroup viewGroup){
//Create comment helper if required
if(mCHelper == null){
mCHelper = new CommentsHelper(context.getApplicationContext());
}
//Inflate a view //Inflate a view
View v = LayoutInflater.from(context).inflate(R.layout.comment_item, viewGroup, false); 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) * @param user Information about the user (NULL for none)
* @return Updated view * @return Updated view
*/ */
private static View fillView(Context context, View view, Comment comment, private static View fillView(final Context context, View view, Comment comment,
@Nullable UserInfo user){ @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 //Update user name and account image
ImageView accountImage = view.findViewById(R.id.user_account_image); ImageView accountImage = view.findViewById(R.id.user_account_image);
TextView accountName = view.findViewById(R.id.user_account_name); TextView accountName = view.findViewById(R.id.user_account_name);
if(user == null){ if (user == null) {
accountImage.setImageDrawable(UiUtils.getDrawable(context, accountImage.setImageDrawable(UiUtils.getDrawable(context,
R.drawable.default_account_image)); R.drawable.default_account_image));
accountName.setText(""); accountName.setText("");
} } else {
else {
ImageLoadManager.load(context, user.getAcountImageURL(), accountImage); ImageLoadManager.load(context, user.getAcountImageURL(), accountImage);
accountName.setText(user.getDisplayFullName()); accountName.setText(user.getDisplayFullName());
} }
//Update comment content //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
return view; return view;
} }
} }

View File

@ -180,6 +180,10 @@ public class PostsAdapter extends ArrayAdapter<Post>{
for (Comment comment : comments) { for (Comment comment : comments) {
//Check if the comment has been deleted
if(comment.isDeleted())
continue; //Skip comment
//Try to find information about the user //Try to find information about the user
UserInfo commentUser = mUsersInfos.containsKey(comment.getUserID()) ? UserInfo commentUser = mUsersInfos.containsKey(comment.getUserID()) ?
mUsersInfos.get(comment.getUserID()) : null; mUsersInfos.get(comment.getUserID()) : null;

View File

@ -8,6 +8,7 @@
<!-- User name and image--> <!-- User name and image-->
<ImageView <ImageView
style="@style/CommentUserImage"
android:id="@+id/user_account_image" android:id="@+id/user_account_image"
android:layout_width="@dimen/account_image_small_width" android:layout_width="@dimen/account_image_small_width"
android:layout_height="@dimen/account_image_small_height" android:layout_height="@dimen/account_image_small_height"
@ -31,4 +32,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:text="A comment 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> </LinearLayout>

View 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>

View File

@ -105,4 +105,5 @@
<string name="err_invalid_comment_content">Specified comment content seems to be invalid…</string> <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="err_create_comment">An error occurred while trying to create comment!</string>
<string name="action_send">Send</string> <string name="action_send">Send</string>
<string name="action_delete_comment">Delete</string>
</resources> </resources>

View File

@ -75,6 +75,11 @@
<item name="android:paddingBottom">2dp</item> <item name="android:paddingBottom">2dp</item>
</style> </style>
<!-- Comment user account image -->
<style name="CommentUserImage">
<item name="android:layout_gravity">center_vertical</item>
</style>
<!-- Comment user name --> <!-- Comment user name -->
<style name="CommentUserName"> <style name="CommentUserName">
<item name="android:layout_gravity">center</item> <item name="android:layout_gravity">center</item>
@ -87,4 +92,9 @@
<item name="android:layout_gravity">center</item> <item name="android:layout_gravity">center</item>
<item name="android:textColor">@android:color/black</item> <item name="android:textColor">@android:color/black</item>
</style> </style>
<!-- Comment actions button -->
<style name="CommentActionsButton">
<item name="android:padding">2dp</item>
</style>
</resources> </resources>