From 1096b98bd647b018f71a45301fc37f7ca825fd5e Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 7 Apr 2018 17:24:57 +0200 Subject: [PATCH] Update comment like buttons style. --- .../client/ui/adapters/CommentsAdapter.java | 1 + .../client/ui/views/LikeButtonView.java | 46 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) 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 8eab1b5..52db03c 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 @@ -96,6 +96,7 @@ class CommentsAdapter extends ArrayAdapter { //Update comment likes LikeButtonView like = view.findViewById(R.id.like_button); + like.setSmallButton(true); like.setNumberLikes(comment.getLikes()); like.setIsLiking(comment.isLiking()); like.setUpdateListener(new LikeButtonView.OnLikeUpdateListener() { diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/LikeButtonView.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/LikeButtonView.java index 2651488..c4e61d5 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/LikeButtonView.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/LikeButtonView.java @@ -48,6 +48,11 @@ public class LikeButtonView extends FrameLayout implements View.OnClickListener */ private int numberLikes = 0; + /** + * Display mode : small + */ + private boolean mSmallButton = false; + /** * Like Update listener */ @@ -139,24 +144,47 @@ public class LikeButtonView extends FrameLayout implements View.OnClickListener this.mUpdateListener = updateListener; } + /** + * Set whether the like button should appear as a small button or not + * + * @param smallButton TRUE if the button is a small button / FALSE else + */ + public void setSmallButton(boolean smallButton) { + this.mSmallButton = smallButton; + refresh(); + } + /** * Refresh the like view */ private void refresh(){ - //Update the image - mLikeImage.setImageDrawable(UiUtils.getDrawable(getContext(), - mIsLiking ? R.drawable.like_down : R.drawable.like_up)); + if(!mSmallButton) { - //Update the text - String text = UiUtils.getString(getContext(), mIsLiking ? R.string.like_view_liking : - R.string.like_view_like); + //Update the image + mLikeImage.setImageDrawable(UiUtils.getDrawable(getContext(), R.drawable.like_up)); - if(numberLikes > 0) - text += " (" + numberLikes + ")"; + //Update the text + String text = UiUtils.getString(getContext(), mIsLiking ? R.string.like_view_liking : + R.string.like_view_like); - mLikeText.setText(text); + if (numberLikes > 0) + text += " (" + numberLikes + ")"; + mLikeText.setText(text); + + } + else { + + //Update the text + mLikeText.setText(numberLikes > 0 ? ""+numberLikes : ""); + + //Update the image + mLikeImage.setImageDrawable(UiUtils.getDrawable(getContext(), + mIsLiking ? R.drawable.like_down : R.drawable.like_up)); + + + } } @Override