Can like comments.

This commit is contained in:
Pierre 2018-04-07 17:10:46 +02:00
parent b14c13d90e
commit 639c5bbc08
7 changed files with 54 additions and 2 deletions

View File

@ -55,7 +55,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -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 !");
}

View File

@ -12,6 +12,11 @@ public enum LikesType {
/**
* For the posts
*/
POST
POST,
/**
* For the comments
*/
COMMENT,
}

View File

@ -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);

View File

@ -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.
*

View File

@ -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) {

View File

@ -32,6 +32,13 @@
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
style="@style/CommentActionsButton"