mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 07:49:28 +00:00
Display posts list using RecyclerView
This commit is contained in:
parent
323ddbf78f
commit
33e301fb22
@ -0,0 +1,35 @@
|
|||||||
|
package org.communiquons.android.comunic.client.ui.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base RecyclerView adapter
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public abstract class BaseRecyclerViewAdapter extends RecyclerView.Adapter {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize adapter
|
||||||
|
*
|
||||||
|
* @param context Activity context
|
||||||
|
*/
|
||||||
|
BaseRecyclerViewAdapter(Context context){
|
||||||
|
super();
|
||||||
|
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the activity context
|
||||||
|
*
|
||||||
|
* @return The activity contexts
|
||||||
|
*/
|
||||||
|
public Context getContext() {
|
||||||
|
return mContext;
|
||||||
|
}
|
||||||
|
}
|
@ -1,35 +1,32 @@
|
|||||||
package org.communiquons.android.comunic.client.ui.adapters;
|
package org.communiquons.android.comunic.client.ui.adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.CallSuper;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
import org.communiquons.android.comunic.client.data.helpers.ImageLoadHelper;
|
import org.communiquons.android.comunic.client.data.arrays.PostsList;
|
||||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
|
||||||
import org.communiquons.android.comunic.client.data.models.Comment;
|
import org.communiquons.android.comunic.client.data.models.Comment;
|
||||||
import org.communiquons.android.comunic.client.data.models.Post;
|
import org.communiquons.android.comunic.client.data.models.Post;
|
||||||
import org.communiquons.android.comunic.client.data.enums.PostTypes;
|
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||||
import org.communiquons.android.comunic.client.data.arrays.PostsList;
|
import org.communiquons.android.comunic.client.data.utils.Utilities;
|
||||||
import org.communiquons.android.comunic.client.ui.listeners.onPostUpdateListener;
|
import org.communiquons.android.comunic.client.ui.listeners.onPostUpdateListener;
|
||||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
import org.communiquons.android.comunic.client.ui.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.EditCommentContentView;
|
||||||
|
import org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView;
|
||||||
import org.communiquons.android.comunic.client.ui.views.LikeButtonView;
|
import org.communiquons.android.comunic.client.ui.views.LikeButtonView;
|
||||||
import org.communiquons.android.comunic.client.ui.views.MovieView;
|
import org.communiquons.android.comunic.client.ui.views.MovieView;
|
||||||
import org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView;
|
import org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView;
|
||||||
import org.communiquons.android.comunic.client.ui.views.WebImageView;
|
|
||||||
import org.communiquons.android.comunic.client.ui.views.WebLinkView;
|
import org.communiquons.android.comunic.client.ui.views.WebLinkView;
|
||||||
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
||||||
|
|
||||||
@ -42,22 +39,36 @@ import java.util.ArrayList;
|
|||||||
* Created by pierre on 1/21/18.
|
* Created by pierre on 1/21/18.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class PostsAdapter extends ArrayAdapter<Post>{
|
public class PostsAdapter extends BaseRecyclerViewAdapter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug tag
|
* Debug tag
|
||||||
*/
|
*/
|
||||||
private static final String TAG = "PostsAdapter";
|
private static final String TAG = PostsAdapter.class.getCanonicalName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View types
|
||||||
|
*/
|
||||||
|
private static final int VIEW_TYPE_POST_TEXT = 0;
|
||||||
|
private static final int VIEW_TYPE_POST_IMAGE = 1;
|
||||||
|
private static final int VIEW_TYPE_POST_MOVIE = 2;
|
||||||
|
private static final int VIEW_TYPE_POST_PDF = 3;
|
||||||
|
private static final int VIEW_TYPE_POST_WEBLINK = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Posts list
|
||||||
|
*/
|
||||||
|
private PostsList mList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the users
|
* Information about the users
|
||||||
*/
|
*/
|
||||||
private ArrayMap<Integer, UserInfo> mUsersInfos;
|
private ArrayMap<Integer, UserInfo> mUsersInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities object
|
* Utilities object
|
||||||
*/
|
*/
|
||||||
private Utilities utils;
|
private Utilities mUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actions update listener
|
* Actions update listener
|
||||||
@ -69,268 +80,354 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
|||||||
*
|
*
|
||||||
* @param context The context of execution of the application
|
* @param context The context of execution of the application
|
||||||
* @param list The list of posts
|
* @param list The list of posts
|
||||||
* @param usersInfos Informations about the user
|
* @param usersInfo Information about the user
|
||||||
* @param listener Specify the listener to perform callback actions such as create a comment
|
* @param listener Specify the listener to perform callback actions such as create a comment
|
||||||
* for example
|
* for example
|
||||||
*/
|
*/
|
||||||
public PostsAdapter(Context context, PostsList list, ArrayMap<Integer, UserInfo> usersInfos,
|
public PostsAdapter(Context context, PostsList list, ArrayMap<Integer, UserInfo> usersInfo,
|
||||||
onPostUpdateListener listener){
|
onPostUpdateListener listener){
|
||||||
super(context, 0, list);
|
super(context);
|
||||||
|
|
||||||
//Save the users info object
|
mList = list;
|
||||||
mUsersInfos = usersInfos;
|
mUsersInfo = usersInfo;
|
||||||
|
|
||||||
//Create utilities object
|
//Utilities
|
||||||
utils = new Utilities(getContext());
|
mUtils = new Utilities(getContext());
|
||||||
|
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
switch (mList.get(position).getType()){
|
||||||
|
|
||||||
|
case IMAGE:
|
||||||
|
return VIEW_TYPE_POST_IMAGE;
|
||||||
|
|
||||||
|
case PDF:
|
||||||
|
return VIEW_TYPE_POST_PDF;
|
||||||
|
|
||||||
|
case WEBLINK:
|
||||||
|
return VIEW_TYPE_POST_WEBLINK;
|
||||||
|
|
||||||
|
case MOVIE:
|
||||||
|
return VIEW_TYPE_POST_MOVIE;
|
||||||
|
|
||||||
|
case TEXT:
|
||||||
|
default:
|
||||||
|
return VIEW_TYPE_POST_TEXT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, @Nullable View convertView,
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int type) {
|
||||||
@NonNull ViewGroup parent) {
|
|
||||||
|
|
||||||
//Check if the view has to be inflated
|
View view = LayoutInflater.from(getContext()).inflate(R.layout.post_item, viewGroup,
|
||||||
if(convertView == null)
|
false);
|
||||||
convertView = LayoutInflater.from(getContext())
|
|
||||||
.inflate(R.layout.post_item, parent, false);
|
|
||||||
|
|
||||||
//Get information about the post and the user
|
switch (type){
|
||||||
final Post post = getItem(position);
|
case VIEW_TYPE_POST_IMAGE:
|
||||||
assert post != null;
|
return new ImagePostHolder(view);
|
||||||
UserInfo userInfo = null;
|
|
||||||
if(mUsersInfos.containsKey(post.getUserID()))
|
|
||||||
userInfo = mUsersInfos.get(post.getUserID());
|
|
||||||
|
|
||||||
//Get the views related to user Information
|
case VIEW_TYPE_POST_PDF:
|
||||||
WebUserAccountImage userAccountImage = convertView.findViewById(R.id.user_account_image);
|
return new PDFPostHolder(view);
|
||||||
TextView userAccountName = convertView.findViewById(R.id.user_account_name);
|
|
||||||
|
|
||||||
//Set user information if available
|
case VIEW_TYPE_POST_WEBLINK:
|
||||||
if(userInfo != null){
|
return new WebLinkPostHolder(view);
|
||||||
userAccountName.setText(userInfo.getDisplayFullName());
|
|
||||||
userAccountImage.setUser(userInfo);
|
case VIEW_TYPE_POST_MOVIE:
|
||||||
|
return new MoviePostHolder(view);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return new TextPostHolder(view);
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
//Reset user information
|
|
||||||
userAccountName.setText("");
|
@Override
|
||||||
userAccountImage.removeUser();
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
((TextPostHolder)viewHolder).bind(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text posts holder
|
||||||
|
*/
|
||||||
|
private class TextPostHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private WebUserAccountImage mUserAccountImage;
|
||||||
|
private TextView mUserAccountName;
|
||||||
|
private TextView mPostDate;
|
||||||
|
private TextView mPostVisibility;
|
||||||
|
private ImageView mPostActions;
|
||||||
|
private FrameLayout mAdditionnalViews;
|
||||||
|
private TextView mPostContent;
|
||||||
|
private LikeButtonView mLikeButton;
|
||||||
|
private LinearLayout mCommentsList;
|
||||||
|
private LinearLayout mCreateCommentForm;
|
||||||
|
private EditCommentContentView mEditCommentContentView;
|
||||||
|
private ImageView mSendCommentButton;
|
||||||
|
|
||||||
|
TextPostHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
mUserAccountImage = itemView.findViewById(R.id.user_account_image);
|
||||||
|
mUserAccountName = itemView.findViewById(R.id.user_account_name);
|
||||||
|
mPostDate = itemView.findViewById(R.id.post_creation_time);
|
||||||
|
mPostVisibility = itemView.findViewById(R.id.post_visibility);
|
||||||
|
mPostActions = itemView.findViewById(R.id.post_actions_btn);
|
||||||
|
mAdditionnalViews = itemView.findViewById(R.id.additional_views);
|
||||||
|
mPostContent = itemView.findViewById(R.id.post_content);
|
||||||
|
mLikeButton = itemView.findViewById(R.id.like_button);
|
||||||
|
mCommentsList = itemView.findViewById(R.id.comments_list);
|
||||||
|
mCreateCommentForm = itemView.findViewById(R.id.create_comment_form);
|
||||||
|
mEditCommentContentView = itemView.findViewById(R.id.input_comment_content);
|
||||||
|
mSendCommentButton = itemView.findViewById(R.id.comment_send_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Post getPost(int position){
|
||||||
//Set post creation time
|
return mList.get(position);
|
||||||
((TextView) convertView.findViewById(R.id.post_creation_time)).setText(utils.
|
|
||||||
timeToString(Utilities.time() - post.getPost_time()));
|
|
||||||
|
|
||||||
|
|
||||||
//Set post visibility level
|
|
||||||
TextView visibilityLevel = convertView.findViewById(R.id.post_visibility);
|
|
||||||
switch (post.getVisibilityLevel()){
|
|
||||||
|
|
||||||
case PUBLIC:
|
|
||||||
visibilityLevel.setText(R.string.post_visibility_public);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FRIENDS:
|
|
||||||
visibilityLevel.setText(R.string.post_visibility_friends);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MEMBERS:
|
|
||||||
visibilityLevel.setText(R.string.post_visibility_members);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PRIVATE:
|
|
||||||
default:
|
|
||||||
visibilityLevel.setText(R.string.post_visibility_private);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set post actions
|
/**
|
||||||
convertView.findViewById(R.id.post_actions_btn).setOnClickListener(
|
* @return Additional views container
|
||||||
new View.OnClickListener() {
|
*/
|
||||||
@Override
|
FrameLayout getAdditionnalViewsLayout(){
|
||||||
public void onClick(View v) {
|
return mAdditionnalViews;
|
||||||
mListener.showPostActions(v, position, post);
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
void bind(final int position){
|
||||||
|
|
||||||
|
Post post = getPost(position);
|
||||||
|
UserInfo user = null;
|
||||||
|
if(mUsersInfo.containsKey(post.getUserID()))
|
||||||
|
user = mUsersInfo.get(post.getUserID());
|
||||||
|
|
||||||
|
|
||||||
|
//Apply user information
|
||||||
|
if(user != null){
|
||||||
|
mUserAccountImage.setUser(user);
|
||||||
|
mUserAccountName.setText(user.getDisplayFullName());
|
||||||
}
|
}
|
||||||
});
|
else {
|
||||||
|
mUserAccountImage.removeUser();
|
||||||
|
mUserAccountName.setText("");
|
||||||
//Set post content
|
|
||||||
((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent()));
|
|
||||||
|
|
||||||
//Set post image (if any)
|
|
||||||
WebImageView postImage = convertView.findViewById(R.id.post_image);
|
|
||||||
if(post.getType() == PostTypes.IMAGE){
|
|
||||||
|
|
||||||
//Make image visible
|
|
||||||
postImage.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
//Load image
|
|
||||||
postImage.loadURL(post.getFile_path_url());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
//Hide the image
|
|
||||||
postImage.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
//Remove the image
|
|
||||||
postImage.removeImage();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Set post movie (if any)
|
|
||||||
MovieView movieView = convertView.findViewById(R.id.post_movie);
|
|
||||||
|
|
||||||
if(post.getType() == PostTypes.MOVIE){
|
|
||||||
movieView.setVisibility(View.VISIBLE);
|
|
||||||
movieView.setMovie(post.getMovie());
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
movieView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Set post weblink (if any)
|
|
||||||
WebLinkView webLinkView = convertView.findViewById(R.id.post_web_link);
|
|
||||||
|
|
||||||
if(post.hasWebLink()){
|
|
||||||
webLinkView.setVisibility(View.VISIBLE);
|
|
||||||
webLinkView.setLink(post.getWebLink());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
webLinkView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Set post file PDF (if any)
|
|
||||||
PDFLinkButtonView pdfLinkButtonView = convertView.findViewById(R.id.btn_pdf_link);
|
|
||||||
|
|
||||||
if(post.getType() != PostTypes.PDF)
|
|
||||||
pdfLinkButtonView.setVisibility(View.GONE);
|
|
||||||
else {
|
|
||||||
pdfLinkButtonView.setVisibility(View.VISIBLE);
|
|
||||||
pdfLinkButtonView.setPDFUrl(post.getFile_path_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Set posts likes
|
|
||||||
LikeButtonView likeButtonView = convertView.findViewById(R.id.like_button);
|
|
||||||
likeButtonView.setNumberLikes(post.getNumberLike());
|
|
||||||
likeButtonView.setIsLiking(post.isLiking());
|
|
||||||
likeButtonView.setUpdateListener(new LikeButtonView.OnLikeUpdateListener() {
|
|
||||||
@Override
|
|
||||||
public void OnLikeUpdate(boolean isLiking) {
|
|
||||||
//Call listener
|
|
||||||
mListener.onPostLikeUpdate(post, isLiking);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
//Process post comments
|
|
||||||
ArrayList<Comment> comments = post.getComments_list();
|
|
||||||
LinearLayout commentsView = convertView.findViewById(R.id.comments_list);
|
|
||||||
commentsView.removeAllViews();
|
|
||||||
if(comments != null) {
|
|
||||||
|
|
||||||
//Show comments list
|
//Post date
|
||||||
convertView.findViewById(R.id.comments_list).setVisibility(View.VISIBLE);
|
mPostDate.setText(mUtils.timeToString(Utilities.time() - post.getPost_time()));
|
||||||
|
|
||||||
for (Comment comment : comments) {
|
|
||||||
|
|
||||||
//Check if the comment has been deleted
|
//Display post visibility
|
||||||
if(comment.isDeleted())
|
switch (post.getVisibilityLevel()){
|
||||||
continue; //Skip comment
|
|
||||||
|
|
||||||
//Try to find information about the user
|
case PUBLIC:
|
||||||
UserInfo commentUser = mUsersInfos.containsKey(comment.getUserID()) ?
|
mPostVisibility.setText(R.string.post_visibility_public);
|
||||||
mUsersInfos.get(comment.getUserID()) : null;
|
break;
|
||||||
|
|
||||||
//Inflate the view
|
case FRIENDS:
|
||||||
View commentView = CommentsAdapter.getInflatedView(getContext(), comment,
|
mPostVisibility.setText(R.string.post_visibility_friends);
|
||||||
mListener, commentUser, commentsView);
|
break;
|
||||||
commentsView.addView(commentView);
|
|
||||||
|
case MEMBERS:
|
||||||
|
mPostVisibility.setText(R.string.post_visibility_members);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PRIVATE:
|
||||||
|
default:
|
||||||
|
mPostVisibility.setText(R.string.post_visibility_private);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
//Hide comments list
|
|
||||||
convertView.findViewById(R.id.comments_list).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Update comment creation form
|
//Set post actions
|
||||||
View commentCreationForm = convertView.findViewById(R.id.create_comment_form);
|
mPostActions.setOnClickListener(new View.OnClickListener() {
|
||||||
EditCommentContentView input_comment = convertView.findViewById(R.id.input_comment_content);
|
@Override
|
||||||
if(comments == null){
|
public void onClick(View v) {
|
||||||
|
mListener.showPostActions(v, position, getPost(position));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Hide comment creation form
|
|
||||||
commentCreationForm.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
}
|
//Set post content
|
||||||
else {
|
mPostContent.setText(Utilities.prepareStringTextView(post.getContent()));
|
||||||
|
|
||||||
//Display comment creation form
|
|
||||||
commentCreationForm.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
//Make sure the form is correctly set up
|
//Post likes
|
||||||
if(input_comment.getPostID() != post.getId()){
|
mLikeButton.setNumberLikes(post.getNumberLike());
|
||||||
|
mLikeButton.setIsLiking(post.isLiking());
|
||||||
|
mLikeButton.setUpdateListener(new LikeButtonView.OnLikeUpdateListener() {
|
||||||
|
@Override
|
||||||
|
public void OnLikeUpdate(boolean isLiking) {
|
||||||
|
mListener.onPostLikeUpdate(getPost(position), isLiking);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Reset input comment
|
|
||||||
input_comment.setPostID(post.getId());
|
|
||||||
input_comment.setText("");
|
|
||||||
|
|
||||||
//Make the send button lives
|
//Post comments
|
||||||
final View finalConvertView = convertView;
|
ArrayList<Comment> comments = post.getComments_list();
|
||||||
convertView.findViewById(R.id.comment_send_button)
|
mCommentsList.removeAllViews();
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
if(comments != null){
|
||||||
@Override
|
//Show list
|
||||||
public void onClick(View v) {
|
mCommentsList.setVisibility(View.VISIBLE);
|
||||||
sendComment(position, finalConvertView);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Make the comment input behaves like the send button when the user hit the
|
for(Comment comment : comments){
|
||||||
//enter key
|
|
||||||
input_comment.setOnKeyListener(new View.OnKeyListener() {
|
if(comment.isDeleted())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
UserInfo commentUser = mUsersInfo.containsKey(comment.getUserID()) ?
|
||||||
|
mUsersInfo.get(comment.getUserID()) : null;
|
||||||
|
|
||||||
|
View commentView = CommentsAdapter.getInflatedView(getContext(), comment,
|
||||||
|
mListener, commentUser, mCommentsList);
|
||||||
|
mCommentsList.addView(commentView);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
//Hide comments list
|
||||||
|
mCommentsList.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
|
||||||
|
//Comments creation form
|
||||||
|
if(comments == null)
|
||||||
|
mCreateCommentForm.setVisibility(View.GONE);
|
||||||
|
else {
|
||||||
|
mCreateCommentForm.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if(mEditCommentContentView.getPostID() != post.getId()){
|
||||||
|
|
||||||
|
mEditCommentContentView.setPostID(post.getId());
|
||||||
|
mEditCommentContentView.setText("");
|
||||||
|
|
||||||
|
mSendCommentButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
sendComment();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mEditCommentContentView.setOnKeyListener(new View.OnKeyListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||||
|
|
||||||
if(event.getAction() == KeyEvent.ACTION_DOWN
|
if(event.getAction() == KeyEvent.ACTION_DOWN
|
||||||
&& keyCode == KeyEvent.KEYCODE_ENTER){
|
&& keyCode == KeyEvent.KEYCODE_ENTER)
|
||||||
sendComment(position, finalConvertView);
|
sendComment();
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return convertView;
|
private void sendComment(){
|
||||||
|
mListener.onCreateComment(getLayoutPosition(), mSendCommentButton,
|
||||||
|
getPost(getLayoutPosition()), mEditCommentContentView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intend to send a new comment to the server
|
* Image posts holder
|
||||||
*
|
|
||||||
* @param pos The position of the post to update
|
|
||||||
* @param container The container of the post item
|
|
||||||
*/
|
*/
|
||||||
private void sendComment(int pos, View container){
|
private class ImagePostHolder extends TextPostHolder {
|
||||||
|
|
||||||
//Get post information
|
private EnlargeableWebImageView mPostImage;
|
||||||
final Post post = getItem(pos);
|
|
||||||
if(post==null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
//Get view about the comment
|
ImagePostHolder(@NonNull View itemView) {
|
||||||
final EditCommentContentView commentInput = container.findViewById(R.id.input_comment_content);
|
super(itemView);
|
||||||
final ImageView sendButton = container.findViewById(R.id.comment_send_button);
|
|
||||||
|
|
||||||
//Call interface
|
mPostImage = new EnlargeableWebImageView(getContext());
|
||||||
mListener.onCreateComment(pos, sendButton, post, commentInput);
|
getAdditionnalViewsLayout().addView(mPostImage,
|
||||||
|
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
UiUtils.GetPixel(getContext(), 200)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void bind(int position) {
|
||||||
|
super.bind(position);
|
||||||
|
|
||||||
|
mPostImage.loadURL(getPost(position).getFile_path_url());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF posts holder
|
||||||
|
*/
|
||||||
|
private class PDFPostHolder extends TextPostHolder {
|
||||||
|
|
||||||
|
private PDFLinkButtonView mPDFLinkButton;
|
||||||
|
|
||||||
|
PDFPostHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
mPDFLinkButton = new PDFLinkButtonView(getContext(), null, R.style.PostPDFButton);
|
||||||
|
getAdditionnalViewsLayout().addView(mPDFLinkButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void bind(int position) {
|
||||||
|
super.bind(position);
|
||||||
|
|
||||||
|
mPDFLinkButton.setPDFUrl(getPost(position).getFile_path_url());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web link post holder
|
||||||
|
*/
|
||||||
|
private class WebLinkPostHolder extends TextPostHolder {
|
||||||
|
|
||||||
|
private WebLinkView mWebLinkView;
|
||||||
|
|
||||||
|
WebLinkPostHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
mWebLinkView = new WebLinkView(getContext());
|
||||||
|
getAdditionnalViewsLayout().addView(mWebLinkView,
|
||||||
|
new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void bind(int position) {
|
||||||
|
super.bind(position);
|
||||||
|
|
||||||
|
mWebLinkView.setLink(getPost(position).getWebLink());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Movie post holder
|
||||||
|
*/
|
||||||
|
private class MoviePostHolder extends TextPostHolder {
|
||||||
|
|
||||||
|
MovieView mMovieView;
|
||||||
|
|
||||||
|
MoviePostHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
mMovieView = new MovieView(getContext(), null, R.style.PostMovie);
|
||||||
|
getAdditionnalViewsLayout().addView(mMovieView, new FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
UiUtils.GetPixel(getContext(), 200)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void bind(int position) {
|
||||||
|
super.bind(position);
|
||||||
|
|
||||||
|
mMovieView.setMovie(getPost(position).getMovie());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import android.content.DialogInterface;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
@ -36,7 +37,7 @@ import org.communiquons.android.comunic.client.ui.listeners.OnPostListFragmentsU
|
|||||||
import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener;
|
import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener;
|
||||||
import org.communiquons.android.comunic.client.ui.listeners.onPostUpdateListener;
|
import org.communiquons.android.comunic.client.ui.listeners.onPostUpdateListener;
|
||||||
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.ScrollListView;
|
import org.communiquons.android.comunic.client.ui.views.ScrollRecyclerView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ public class PostsListFragment extends Fragment
|
|||||||
/**
|
/**
|
||||||
* The list of posts
|
* The list of posts
|
||||||
*/
|
*/
|
||||||
ScrollListView mListView;
|
ScrollRecyclerView mRecyclerView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts helper
|
* Posts helper
|
||||||
@ -137,7 +138,7 @@ public class PostsListFragment extends Fragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the list of users informations
|
* Set the list of users information
|
||||||
*
|
*
|
||||||
* @param list The list
|
* @param list The list
|
||||||
*/
|
*/
|
||||||
@ -173,8 +174,8 @@ public class PostsListFragment extends Fragment
|
|||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
//Get the list view
|
//Get the list view
|
||||||
mListView = view.findViewById(R.id.posts_list);
|
mRecyclerView = view.findViewById(R.id.posts_list);
|
||||||
mListView.setOnScrollChangeDetectListener(this);
|
mRecyclerView.setOnScrollChangeDetectListener(this);
|
||||||
|
|
||||||
//Show the posts
|
//Show the posts
|
||||||
show();
|
show();
|
||||||
@ -194,7 +195,8 @@ public class PostsListFragment extends Fragment
|
|||||||
mPostsAdapter = new PostsAdapter(getActivity(), mPostsList, mUsersInfo, this);
|
mPostsAdapter = new PostsAdapter(getActivity(), mPostsList, mUsersInfo, this);
|
||||||
|
|
||||||
//Connect the adapter to the view
|
//Connect the adapter to the view
|
||||||
mListView.setAdapter(mPostsAdapter);
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
mRecyclerView.setAdapter(mPostsAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Notify data set update
|
//Notify data set update
|
||||||
|
@ -4,6 +4,7 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
|
|
||||||
@ -84,4 +85,15 @@ public class UiUtils {
|
|||||||
return builder.show();
|
return builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the amount of pixel matching to a dp
|
||||||
|
*
|
||||||
|
* @param context The context of the activity
|
||||||
|
* @param dp The number of dp to convert
|
||||||
|
* @return Matching number of pixel
|
||||||
|
*/
|
||||||
|
public static int GetPixel(Context context, int dp){
|
||||||
|
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
|
||||||
|
context.getResources().getDisplayMetrics());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import android.support.annotation.NonNull;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.AbsListView;
|
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener;
|
import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener;
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<org.communiquons.android.comunic.client.ui.views.ScrollListView android:id="@+id/posts_list"
|
<org.communiquons.android.comunic.client.ui.views.ScrollRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
android:id="@+id/posts_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" />
|
||||||
tools:listitem="@layout/post_item"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools" />
|
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
style="@style/PostContainer"
|
style="@style/PostContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<!-- Information about user who created the post -->
|
<!-- Information about user who created the post -->
|
||||||
@ -59,45 +59,22 @@
|
|||||||
tools:text="Public" />
|
tools:text="Public" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
style="@style/PostActionsButton"
|
|
||||||
android:id="@+id/post_actions_btn"
|
android:id="@+id/post_actions_btn"
|
||||||
|
style="@style/PostActionsButton"
|
||||||
android:layout_width="@dimen/post_options_btn_width"
|
android:layout_width="@dimen/post_options_btn_width"
|
||||||
android:layout_height="@dimen/post_options_btn_height"
|
android:layout_height="@dimen/post_options_btn_height"
|
||||||
android:src="@android:drawable/ic_menu_manage"
|
android:contentDescription="@string/post_action_btn_description"
|
||||||
android:contentDescription="@string/post_action_btn_description"/>
|
android:src="@android:drawable/ic_menu_manage" />
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Post image (if any) -->
|
<!-- Additional views -->
|
||||||
<org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView
|
<FrameLayout
|
||||||
android:id="@+id/post_image"
|
android:id="@+id/additional_views"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="200dp"
|
|
||||||
android:src="@drawable/img_placeholder"
|
|
||||||
android:contentDescription="@string/post_image_description"
|
|
||||||
android:scaleType="centerInside" />
|
|
||||||
|
|
||||||
<!-- Post related movie (if any) -->
|
|
||||||
<org.communiquons.android.comunic.client.ui.views.MovieView
|
|
||||||
android:id="@+id/post_movie"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="200dp"
|
|
||||||
style="@style/PostMovie"/>
|
|
||||||
|
|
||||||
<!-- Post Web link (if any) -->
|
|
||||||
<org.communiquons.android.comunic.client.ui.views.WebLinkView
|
|
||||||
android:id="@+id/post_web_link"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<!-- Related PDF (if any) -->
|
|
||||||
<org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView
|
|
||||||
android:id="@+id/btn_pdf_link"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
style="@style/PostPDFButton"/>
|
|
||||||
|
|
||||||
<!-- Post content -->
|
<!-- Post content -->
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/post_content"
|
android:id="@+id/post_content"
|
||||||
@ -109,9 +86,9 @@
|
|||||||
<!-- Like button -->
|
<!-- Like button -->
|
||||||
<org.communiquons.android.comunic.client.ui.views.LikeButtonView
|
<org.communiquons.android.comunic.client.ui.views.LikeButtonView
|
||||||
android:id="@+id/like_button"
|
android:id="@+id/like_button"
|
||||||
|
style="@style/PostLikeButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
style="@style/PostLikeButton"/>
|
|
||||||
|
|
||||||
<!-- Post comments -->
|
<!-- Post comments -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@ -130,10 +107,10 @@
|
|||||||
<!-- Comment hint -->
|
<!-- Comment hint -->
|
||||||
<org.communiquons.android.comunic.client.ui.views.EditCommentContentView
|
<org.communiquons.android.comunic.client.ui.views.EditCommentContentView
|
||||||
android:id="@+id/input_comment_content"
|
android:id="@+id/input_comment_content"
|
||||||
|
style="@style/TextAppearance.AppCompat"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
style="@style/TextAppearance.AppCompat"
|
|
||||||
android:hint="@string/new_comment_hint"
|
android:hint="@string/new_comment_hint"
|
||||||
android:inputType="text" />
|
android:inputType="text" />
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user