From 98fcec67793c511e680f1b2906909f7538b55f90 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 4 Apr 2018 18:16:33 +0200 Subject: [PATCH] Like button reacts on click. --- .../comunic/client/ui/views/LikeButtonView.java | 17 +++++++++++++++-- app/src/main/res/layout/view_like_button.xml | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) 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 2b6d13f..7090263 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 @@ -123,7 +123,7 @@ public class LikeButtonView extends FrameLayout implements View.OnClickListener * * @return TRUE if the user is liking / FALSE else */ - public boolean ismIsLiking() { + public boolean isIsLiking() { return mIsLiking; } @@ -141,7 +141,7 @@ public class LikeButtonView extends FrameLayout implements View.OnClickListener R.string.like_view_like); if(numberLikes > 0) - text += "(" + numberLikes + ")"; + text += " (" + numberLikes + ")"; mLikeText.setText(text); @@ -150,5 +150,18 @@ public class LikeButtonView extends FrameLayout implements View.OnClickListener @Override public void onClick(View v) { + //Check if the user want to like or dislike component + if(mIsLiking){ + mIsLiking = false; + numberLikes--; + } + else { + mIsLiking = true; + numberLikes++; + } + + //Refresh display + refresh(); + } } diff --git a/app/src/main/res/layout/view_like_button.xml b/app/src/main/res/layout/view_like_button.xml index 1300785..bc00077 100644 --- a/app/src/main/res/layout/view_like_button.xml +++ b/app/src/main/res/layout/view_like_button.xml @@ -21,7 +21,7 @@ android:id="@+id/like_text" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="center" + android:layout_gravity="center_vertical" tools:text="Like" /> \ No newline at end of file