From 1f91d0b9bb925f8dbbb74df3450b974ffe6c1084 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 4 Apr 2018 18:09:30 +0200 Subject: [PATCH] Display like buttons. --- .../comunic/client/data/posts/Post.java | 30 +++- .../client/data/posts/PostsHelper.java | 10 ++ .../comunic/client/data/utils/UiUtils.java | 7 + .../client/ui/adapters/PostsAdapter.java | 6 + .../client/ui/views/LikeButtonView.java | 154 ++++++++++++++++++ app/src/main/res/drawable/like_down.xml | 4 + app/src/main/res/drawable/like_up.png | Bin 0 -> 3146 bytes app/src/main/res/layout/post_item.xml | 9 +- app/src/main/res/layout/view_like_button.xml | 27 +++ app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 7 + 11 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/communiquons/android/comunic/client/ui/views/LikeButtonView.java create mode 100644 app/src/main/res/drawable/like_down.xml create mode 100644 app/src/main/res/drawable/like_up.png create mode 100644 app/src/main/res/layout/view_like_button.xml diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/Post.java b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/Post.java index 29e2f2b..f851fae 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/Post.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/Post.java @@ -25,10 +25,18 @@ public class Post { private int page_id; private String content; private PostTypes type; + + //Related with visibility private PostVisibilityLevels visibilityLevel; - private ArrayList comments_list; private PostUserAccess user_access_level = PostUserAccess.NO_ACCESS; + //Likes + private int numberLike; + private boolean isLiking; + + //Comments + private ArrayList comments_list; + //Files specific private String file_path_url; @@ -129,6 +137,26 @@ public class Post { return user_access_level; } + + //Set and get the number of likes other the like + void setNumberLike(int numberLike) { + this.numberLike = numberLike; + } + + public int getNumberLike() { + return numberLike; + } + + + //Set and get the liking state over the post + void setLiking(boolean liking) { + isLiking = liking; + } + + public boolean isLiking() { + return isLiking; + } + /** * Check whether the user can delete the post or not * diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsHelper.java index 3c90c3e..f878385 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsHelper.java @@ -2,6 +2,7 @@ package org.communiquons.android.comunic.client.data.posts; import android.content.Context; import android.support.annotation.Nullable; +import android.util.Log; import org.communiquons.android.comunic.client.api.APIRequest; import org.communiquons.android.comunic.client.api.APIRequestParameters; @@ -22,6 +23,11 @@ import org.json.JSONObject; public class PostsHelper { + /** + * Debug tag + */ + private final static String TAG = "PostsHelper"; + /** * The context of the application */ @@ -287,6 +293,10 @@ public class PostsHelper { post.setUser_access_level(PostUserAccess.NO_ACCESS); } + //Get information about likes + post.setNumberLike(json.getInt("likes")); + post.setLiking(json.getBoolean("userlike")); + //Get file path url (if any) if(json.getString("file_path_url") != null){ post.setFile_path_url(json.getString("file_path_url")); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/utils/UiUtils.java b/app/src/main/java/org/communiquons/android/comunic/client/data/utils/UiUtils.java index 7f12f84..16e93e2 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/utils/UiUtils.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/utils/UiUtils.java @@ -43,6 +43,13 @@ public class UiUtils { return context.getResources().getDrawable(drawable_id, context.getTheme()); } + /** + * Get a string from ressources + */ + public static String getString(Context context, int res_id){ + return context.getResources().getString(res_id); + } + /** * Create and display a loading dialog * 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 658e404..e945a36 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 @@ -23,6 +23,7 @@ import org.communiquons.android.comunic.client.data.posts.PostsList; import org.communiquons.android.comunic.client.data.utils.UiUtils; import org.communiquons.android.comunic.client.data.utils.Utilities; import org.communiquons.android.comunic.client.ui.views.EditCommentContentView; +import org.communiquons.android.comunic.client.ui.views.LikeButtonView; import java.util.ArrayList; @@ -161,6 +162,11 @@ public class PostsAdapter extends ArrayAdapter{ ImageLoadManager.load(getContext(), post.getFile_path_url(), postImage); } + //Set posts likes + LikeButtonView likeButtonView = convertView.findViewById(R.id.like_button); + likeButtonView.setNumberLikes(post.getNumberLike()); + likeButtonView.setIsLiking(post.isLiking()); + //Process post comments ArrayList comments = post.getComments_list(); LinearLayout commentsView = convertView.findViewById(R.id.comments_list); 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 new file mode 100644 index 0000000..2b6d13f --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/LikeButtonView.java @@ -0,0 +1,154 @@ +package org.communiquons.android.comunic.client.ui.views; + +import android.content.Context; +import android.support.annotation.AttrRes; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.StyleRes; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.data.utils.StringsUtils; +import org.communiquons.android.comunic.client.data.utils.UiUtils; + +/** + * Like button view + * + * @author Pierre HUBERT + * Created by pierre on 4/1/18. + */ + +public class LikeButtonView extends FrameLayout implements View.OnClickListener { + + /** + * Like container + */ + private LinearLayout mContainer; + + /** + * Like image + */ + private ImageView mLikeImage; + + /** + * Like text + */ + private TextView mLikeText; + + /** + * Current user liking status + */ + private boolean mIsLiking = false; + + /** + * Number of likes + */ + private int numberLikes = 0; + + public LikeButtonView(@NonNull Context context) { + super(context); + initView(); + } + + public LikeButtonView(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + initView(); + } + + public LikeButtonView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { + super(context, attrs, defStyleAttr); + initView(); + } + + + /** + * Initialize view + */ + private void initView(){ + + //Inflate the view + View view = inflate(getContext(), R.layout.view_like_button, null); + + //Append the view + addView(view); + + //Get the views + mContainer = view.findViewById(R.id.like_container); + mLikeImage = view.findViewById(R.id.like_img); + mLikeText = view.findViewById(R.id.like_text); + + //Set the click listener + mContainer.setOnClickListener(this); + + //Refresh the view + refresh(); + } + + /** + * Get the number of likes + * + * @return The number of likes + */ + public int getNumberLikes() { + return numberLikes; + } + + /** + * Set the number of likes + * + * @param numberLikes The number of likes + */ + public void setNumberLikes(int numberLikes) { + this.numberLikes = numberLikes; + refresh(); + } + + /** + * Set the user liking state + * + * @param mIsLiking User liking state + */ + public void setIsLiking(boolean mIsLiking) { + this.mIsLiking = mIsLiking; + refresh(); + } + + /** + * Get user liking state + * + * @return TRUE if the user is liking / FALSE else + */ + public boolean ismIsLiking() { + return mIsLiking; + } + + /** + * Refresh the like view + */ + private void refresh(){ + + //Update the image + mLikeImage.setImageDrawable(UiUtils.getDrawable(getContext(), + mIsLiking ? R.drawable.like_down : R.drawable.like_up)); + + //Update the text + String text = UiUtils.getString(getContext(), mIsLiking ? R.string.like_view_liking : + R.string.like_view_like); + + if(numberLikes > 0) + text += "(" + numberLikes + ")"; + + mLikeText.setText(text); + + } + + @Override + public void onClick(View v) { + + } +} diff --git a/app/src/main/res/drawable/like_down.xml b/app/src/main/res/drawable/like_down.xml new file mode 100644 index 0000000..a1f0e3c --- /dev/null +++ b/app/src/main/res/drawable/like_down.xml @@ -0,0 +1,4 @@ + + diff --git a/app/src/main/res/drawable/like_up.png b/app/src/main/res/drawable/like_up.png new file mode 100644 index 0000000000000000000000000000000000000000..088120c2087e36eb896379a54edfc711f136fdf4 GIT binary patch literal 3146 zcmV-Q47Kx#P)=3k8-?ov{2Az#b5?%>u4$w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h6C~CA1O=BanSdRD{eY3cVZguw75@$3dPy_uraoP|R1)qK zcfSY41Cjo9Sj=XkEoYDCx%J$otDS^hh*k#nAzCHqPjvd!wpA>~N}>&zvxs)Zyj8dL z< - - @@ -87,6 +85,13 @@ android:layout_height="wrap_content" tools:text="Post content" /> + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6d55db8..f8fe6b3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -127,4 +127,7 @@ Notifications Friends list Notifications + Like + Like + Liking diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c4635b3..7a9e3bd 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -76,6 +76,13 @@ 2dp + + +