mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-30 17:26:36 +00:00
Display like buttons.
This commit is contained in:
parent
e29f33d696
commit
1f91d0b9bb
@ -25,10 +25,18 @@ public class Post {
|
|||||||
private int page_id;
|
private int page_id;
|
||||||
private String content;
|
private String content;
|
||||||
private PostTypes type;
|
private PostTypes type;
|
||||||
|
|
||||||
|
//Related with visibility
|
||||||
private PostVisibilityLevels visibilityLevel;
|
private PostVisibilityLevels visibilityLevel;
|
||||||
private ArrayList<Comment> comments_list;
|
|
||||||
private PostUserAccess user_access_level = PostUserAccess.NO_ACCESS;
|
private PostUserAccess user_access_level = PostUserAccess.NO_ACCESS;
|
||||||
|
|
||||||
|
//Likes
|
||||||
|
private int numberLike;
|
||||||
|
private boolean isLiking;
|
||||||
|
|
||||||
|
//Comments
|
||||||
|
private ArrayList<Comment> comments_list;
|
||||||
|
|
||||||
//Files specific
|
//Files specific
|
||||||
private String file_path_url;
|
private String file_path_url;
|
||||||
|
|
||||||
@ -129,6 +137,26 @@ public class Post {
|
|||||||
return user_access_level;
|
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
|
* Check whether the user can delete the post or not
|
||||||
*
|
*
|
||||||
|
@ -2,6 +2,7 @@ package org.communiquons.android.comunic.client.data.posts;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.api.APIRequest;
|
import org.communiquons.android.comunic.client.api.APIRequest;
|
||||||
import org.communiquons.android.comunic.client.api.APIRequestParameters;
|
import org.communiquons.android.comunic.client.api.APIRequestParameters;
|
||||||
@ -22,6 +23,11 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
public class PostsHelper {
|
public class PostsHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug tag
|
||||||
|
*/
|
||||||
|
private final static String TAG = "PostsHelper";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The context of the application
|
* The context of the application
|
||||||
*/
|
*/
|
||||||
@ -287,6 +293,10 @@ public class PostsHelper {
|
|||||||
post.setUser_access_level(PostUserAccess.NO_ACCESS);
|
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)
|
//Get file path url (if any)
|
||||||
if(json.getString("file_path_url") != null){
|
if(json.getString("file_path_url") != null){
|
||||||
post.setFile_path_url(json.getString("file_path_url"));
|
post.setFile_path_url(json.getString("file_path_url"));
|
||||||
|
@ -43,6 +43,13 @@ public class UiUtils {
|
|||||||
return context.getResources().getDrawable(drawable_id, context.getTheme());
|
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
|
* Create and display a loading dialog
|
||||||
*
|
*
|
||||||
|
@ -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.UiUtils;
|
||||||
import org.communiquons.android.comunic.client.data.utils.Utilities;
|
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.EditCommentContentView;
|
||||||
|
import org.communiquons.android.comunic.client.ui.views.LikeButtonView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -161,6 +162,11 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
|||||||
ImageLoadManager.load(getContext(), post.getFile_path_url(), postImage);
|
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
|
//Process post comments
|
||||||
ArrayList<Comment> comments = post.getComments_list();
|
ArrayList<Comment> comments = post.getComments_list();
|
||||||
LinearLayout commentsView = convertView.findViewById(R.id.comments_list);
|
LinearLayout commentsView = convertView.findViewById(R.id.comments_list);
|
||||||
|
@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
4
app/src/main/res/drawable/like_down.xml
Normal file
4
app/src/main/res/drawable/like_down.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:drawable="@drawable/like_up"
|
||||||
|
android:fromDegrees="180" />
|
BIN
app/src/main/res/drawable/like_up.png
Normal file
BIN
app/src/main/res/drawable/like_up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
@ -67,8 +67,6 @@
|
|||||||
android:contentDescription="@string/post_action_btn_description"/>
|
android:contentDescription="@string/post_action_btn_description"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Post image (if any) -->
|
<!-- Post image (if any) -->
|
||||||
@ -87,6 +85,13 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Post content" />
|
tools:text="Post content" />
|
||||||
|
|
||||||
|
<!-- 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"
|
||||||
|
style="@style/PostLikeButton"/>
|
||||||
|
|
||||||
<!-- Post comments -->
|
<!-- Post comments -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/comments_list"
|
android:id="@+id/comments_list"
|
||||||
|
27
app/src/main/res/layout/view_like_button.xml
Normal file
27
app/src/main/res/layout/view_like_button.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:id="@+id/like_container">
|
||||||
|
|
||||||
|
<!-- Like image -->
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/like_img"
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:contentDescription="@string/like_button_img"
|
||||||
|
android:src="@drawable/like_up"
|
||||||
|
android:layout_marginEnd="3dp"/>
|
||||||
|
|
||||||
|
<!-- Title -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/like_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
tools:text="Like" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -127,4 +127,7 @@
|
|||||||
<string name="navigation_bottom_notif_item">Notifications</string>
|
<string name="navigation_bottom_notif_item">Notifications</string>
|
||||||
<string name="main_menu_friends_list">Friends list</string>
|
<string name="main_menu_friends_list">Friends list</string>
|
||||||
<string name="fragment_notifications_title">Notifications</string>
|
<string name="fragment_notifications_title">Notifications</string>
|
||||||
|
<string name="like_button_img">Like</string>
|
||||||
|
<string name="like_view_like">Like</string>
|
||||||
|
<string name="like_view_liking">Liking</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -76,6 +76,13 @@
|
|||||||
<item name="android:layout_marginBottom">2dp</item>
|
<item name="android:layout_marginBottom">2dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- Post like button -->
|
||||||
|
<style name="PostLikeButton">
|
||||||
|
<item name="android:layout_gravity">center</item>
|
||||||
|
<item name="android:layout_marginTop">2dp</item>
|
||||||
|
<item name="android:layout_marginBottom">2dp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
<!-- Comments style -->
|
<!-- Comments style -->
|
||||||
<!-- Comments container -->
|
<!-- Comments container -->
|
||||||
|
Loading…
Reference in New Issue
Block a user