mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 11:34:06 +00:00 
			
		
		
		
	Can like comments.
This commit is contained in:
		@@ -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 !");
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,11 @@ public enum LikesType {
 | 
			
		||||
    /**
 | 
			
		||||
     * For the posts
 | 
			
		||||
     */
 | 
			
		||||
    POST
 | 
			
		||||
    POST,
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * For the comments
 | 
			
		||||
     */
 | 
			
		||||
    COMMENT,
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Comment> {
 | 
			
		||||
        //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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -312,6 +312,14 @@ public class PostsAdapter extends ArrayAdapter<Post>{
 | 
			
		||||
         */
 | 
			
		||||
        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.
 | 
			
		||||
         *
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Void, Void, Boolean>(){
 | 
			
		||||
 | 
			
		||||
            @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) {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,13 @@
 | 
			
		||||
        android:layout_weight="2"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        tools:text="A comment content" />
 | 
			
		||||
    
 | 
			
		||||
    <!-- Comment like button -->
 | 
			
		||||
    <org.communiquons.android.comunic.client.ui.views.LikeButtonView
 | 
			
		||||
        android:id="@+id/like_button"
 | 
			
		||||
        android:layout_width="wrap_content"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:layout_gravity="center_vertical"/>
 | 
			
		||||
 | 
			
		||||
    <!-- Comment actions -->
 | 
			
		||||
    <ImageView
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user