From 639c5bbc0818783255d092ad312d676d685c8b9c Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 7 Apr 2018 17:10:46 +0200 Subject: [PATCH] Can like comments. --- .idea/misc.xml | 2 +- .../comunic/client/data/likes/LikesHelper.java | 4 ++++ .../comunic/client/data/likes/LikesType.java | 7 ++++++- .../client/ui/adapters/CommentsAdapter.java | 14 ++++++++++++++ .../comunic/client/ui/adapters/PostsAdapter.java | 8 ++++++++ .../client/ui/fragments/PostsListFragment.java | 14 ++++++++++++++ app/src/main/res/layout/comment_item.xml | 7 +++++++ 7 files changed, 54 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 503aca7..33952c6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -55,7 +55,7 @@ - + diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/likes/LikesHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/likes/LikesHelper.java index 0683cf4..fcb9e5d 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/likes/LikesHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/likes/LikesHelper.java @@ -53,6 +53,10 @@ public class LikesHelper { params.addString("type", "post"); break; + case COMMENT: + params.addString("type", "comment"); + break; + default: throw new RuntimeException("Unrecognized kind of post !"); } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/likes/LikesType.java b/app/src/main/java/org/communiquons/android/comunic/client/data/likes/LikesType.java index 2f54dd1..055eadf 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/likes/LikesType.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/likes/LikesType.java @@ -12,6 +12,11 @@ public enum LikesType { /** * For the posts */ - POST + POST, + + /** + * For the comments + */ + COMMENT, } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/CommentsAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/CommentsAdapter.java index 112bde0..8eab1b5 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/CommentsAdapter.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/CommentsAdapter.java @@ -19,6 +19,7 @@ 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 org.communiquons.android.comunic.client.ui.views.LikeButtonView; import java.util.ArrayList; @@ -92,6 +93,19 @@ class CommentsAdapter extends ArrayAdapter { //Update comment content ((TextView) view.findViewById(R.id.comment_text)).setText(comment.getContent()); + + //Update comment likes + LikeButtonView like = view.findViewById(R.id.like_button); + like.setNumberLikes(comment.getLikes()); + like.setIsLiking(comment.isLiking()); + like.setUpdateListener(new LikeButtonView.OnLikeUpdateListener() { + @Override + public void OnLikeUpdate(boolean isLiking) { + listener.onCommentLikeUpdate(comment, isLiking); + } + }); + + //Update comment actions ImageView actions = view.findViewById(R.id.comment_actions_btn); 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 f1ff4a4..6d61203 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 @@ -312,6 +312,14 @@ public class PostsAdapter extends ArrayAdapter{ */ void showCommentActions(View button, Comment comment); + /** + * Handles the update of the likes of a comment + * + * @param comment The comment to update + * @param is_liking The new liking status + */ + void onCommentLikeUpdate(Comment comment, boolean is_liking); + /** * Handles the process of deletion of 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 9143472..2066241 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 @@ -405,6 +405,20 @@ public class PostsListFragment extends Fragment } + @Override + public void onCommentLikeUpdate(final Comment comment, final boolean is_liking) { + + //Perform the operation in the background + new AsyncTask(){ + + @Override + protected Boolean doInBackground(Void... params) { + return mLikesHelper.update(LikesType.COMMENT, comment.getId(), is_liking); + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + } + @Override public void deleteComment(final Comment comment) { diff --git a/app/src/main/res/layout/comment_item.xml b/app/src/main/res/layout/comment_item.xml index 6113135..baa95c2 100644 --- a/app/src/main/res/layout/comment_item.xml +++ b/app/src/main/res/layout/comment_item.xml @@ -31,6 +31,13 @@ android:layout_weight="2" android:layout_height="wrap_content" tools:text="A comment content" /> + + +