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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.helpers.ImageLoadHelper;
|
||||
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.models.Comment;
|
||||
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.arrays.PostsList;
|
||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||
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.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.EnlargeableWebImageView;
|
||||
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.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.WebUserAccountImage;
|
||||
|
||||
@ -42,22 +39,36 @@ import java.util.ArrayList;
|
||||
* Created by pierre on 1/21/18.
|
||||
*/
|
||||
|
||||
public class PostsAdapter extends ArrayAdapter<Post>{
|
||||
public class PostsAdapter extends BaseRecyclerViewAdapter {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private ArrayMap<Integer, UserInfo> mUsersInfos;
|
||||
private ArrayMap<Integer, UserInfo> mUsersInfo;
|
||||
|
||||
/**
|
||||
* Utilities object
|
||||
*/
|
||||
private Utilities utils;
|
||||
private Utilities mUtils;
|
||||
|
||||
/**
|
||||
* Actions update listener
|
||||
@ -69,268 +80,354 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
||||
*
|
||||
* @param context The context of execution of the application
|
||||
* @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
|
||||
* for example
|
||||
*/
|
||||
public PostsAdapter(Context context, PostsList list, ArrayMap<Integer, UserInfo> usersInfos,
|
||||
public PostsAdapter(Context context, PostsList list, ArrayMap<Integer, UserInfo> usersInfo,
|
||||
onPostUpdateListener listener){
|
||||
super(context, 0, list);
|
||||
super(context);
|
||||
|
||||
//Save the users info object
|
||||
mUsersInfos = usersInfos;
|
||||
mList = list;
|
||||
mUsersInfo = usersInfo;
|
||||
|
||||
//Create utilities object
|
||||
utils = new Utilities(getContext());
|
||||
//Utilities
|
||||
mUtils = new Utilities(getContext());
|
||||
|
||||
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
|
||||
@Override
|
||||
public View getView(final int position, @Nullable View convertView,
|
||||
@NonNull ViewGroup parent) {
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int type) {
|
||||
|
||||
//Check if the view has to be inflated
|
||||
if(convertView == null)
|
||||
convertView = LayoutInflater.from(getContext())
|
||||
.inflate(R.layout.post_item, parent, false);
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.post_item, viewGroup,
|
||||
false);
|
||||
|
||||
//Get information about the post and the user
|
||||
final Post post = getItem(position);
|
||||
assert post != null;
|
||||
UserInfo userInfo = null;
|
||||
if(mUsersInfos.containsKey(post.getUserID()))
|
||||
userInfo = mUsersInfos.get(post.getUserID());
|
||||
switch (type){
|
||||
case VIEW_TYPE_POST_IMAGE:
|
||||
return new ImagePostHolder(view);
|
||||
|
||||
//Get the views related to user Information
|
||||
WebUserAccountImage userAccountImage = convertView.findViewById(R.id.user_account_image);
|
||||
TextView userAccountName = convertView.findViewById(R.id.user_account_name);
|
||||
case VIEW_TYPE_POST_PDF:
|
||||
return new PDFPostHolder(view);
|
||||
|
||||
//Set user information if available
|
||||
if(userInfo != null){
|
||||
userAccountName.setText(userInfo.getDisplayFullName());
|
||||
userAccountImage.setUser(userInfo);
|
||||
case VIEW_TYPE_POST_WEBLINK:
|
||||
return new WebLinkPostHolder(view);
|
||||
|
||||
case VIEW_TYPE_POST_MOVIE:
|
||||
return new MoviePostHolder(view);
|
||||
|
||||
default:
|
||||
return new TextPostHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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){
|
||||
return mList.get(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Additional views container
|
||||
*/
|
||||
FrameLayout getAdditionnalViewsLayout(){
|
||||
return mAdditionnalViews;
|
||||
}
|
||||
|
||||
@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 {
|
||||
//Reset user information
|
||||
userAccountName.setText("");
|
||||
userAccountImage.removeUser();
|
||||
mUserAccountImage.removeUser();
|
||||
mUserAccountName.setText("");
|
||||
}
|
||||
|
||||
|
||||
//Set post creation time
|
||||
((TextView) convertView.findViewById(R.id.post_creation_time)).setText(utils.
|
||||
timeToString(Utilities.time() - post.getPost_time()));
|
||||
//Post date
|
||||
mPostDate.setText(mUtils.timeToString(Utilities.time() - post.getPost_time()));
|
||||
|
||||
|
||||
//Set post visibility level
|
||||
TextView visibilityLevel = convertView.findViewById(R.id.post_visibility);
|
||||
//Display post visibility
|
||||
switch (post.getVisibilityLevel()){
|
||||
|
||||
case PUBLIC:
|
||||
visibilityLevel.setText(R.string.post_visibility_public);
|
||||
mPostVisibility.setText(R.string.post_visibility_public);
|
||||
break;
|
||||
|
||||
case FRIENDS:
|
||||
visibilityLevel.setText(R.string.post_visibility_friends);
|
||||
mPostVisibility.setText(R.string.post_visibility_friends);
|
||||
break;
|
||||
|
||||
case MEMBERS:
|
||||
visibilityLevel.setText(R.string.post_visibility_members);
|
||||
mPostVisibility.setText(R.string.post_visibility_members);
|
||||
break;
|
||||
|
||||
case PRIVATE:
|
||||
default:
|
||||
visibilityLevel.setText(R.string.post_visibility_private);
|
||||
mPostVisibility.setText(R.string.post_visibility_private);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//Set post actions
|
||||
convertView.findViewById(R.id.post_actions_btn).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
mPostActions.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mListener.showPostActions(v, position, post);
|
||||
mListener.showPostActions(v, position, getPost(position));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//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();
|
||||
|
||||
}
|
||||
mPostContent.setText(Utilities.prepareStringTextView(post.getContent()));
|
||||
|
||||
|
||||
//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() {
|
||||
//Post likes
|
||||
mLikeButton.setNumberLikes(post.getNumberLike());
|
||||
mLikeButton.setIsLiking(post.isLiking());
|
||||
mLikeButton.setUpdateListener(new LikeButtonView.OnLikeUpdateListener() {
|
||||
@Override
|
||||
public void OnLikeUpdate(boolean isLiking) {
|
||||
//Call listener
|
||||
mListener.onPostLikeUpdate(post, isLiking);
|
||||
mListener.onPostLikeUpdate(getPost(position), isLiking);
|
||||
}
|
||||
});
|
||||
|
||||
//Process post comments
|
||||
|
||||
//Post comments
|
||||
ArrayList<Comment> comments = post.getComments_list();
|
||||
LinearLayout commentsView = convertView.findViewById(R.id.comments_list);
|
||||
commentsView.removeAllViews();
|
||||
if(comments != null) {
|
||||
mCommentsList.removeAllViews();
|
||||
if(comments != null){
|
||||
//Show list
|
||||
mCommentsList.setVisibility(View.VISIBLE);
|
||||
|
||||
//Show comments list
|
||||
convertView.findViewById(R.id.comments_list).setVisibility(View.VISIBLE);
|
||||
for(Comment comment : comments){
|
||||
|
||||
for (Comment comment : comments) {
|
||||
|
||||
//Check if the comment has been deleted
|
||||
if(comment.isDeleted())
|
||||
continue; //Skip comment
|
||||
continue;
|
||||
|
||||
//Try to find information about the user
|
||||
UserInfo commentUser = mUsersInfos.containsKey(comment.getUserID()) ?
|
||||
mUsersInfos.get(comment.getUserID()) : null;
|
||||
UserInfo commentUser = mUsersInfo.containsKey(comment.getUserID()) ?
|
||||
mUsersInfo.get(comment.getUserID()) : null;
|
||||
|
||||
//Inflate the view
|
||||
View commentView = CommentsAdapter.getInflatedView(getContext(), comment,
|
||||
mListener, commentUser, commentsView);
|
||||
commentsView.addView(commentView);
|
||||
mListener, commentUser, mCommentsList);
|
||||
mCommentsList.addView(commentView);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
//Hide comments list
|
||||
convertView.findViewById(R.id.comments_list).setVisibility(View.GONE);
|
||||
}
|
||||
mCommentsList.setVisibility(View.GONE);
|
||||
|
||||
|
||||
//Update comment creation form
|
||||
View commentCreationForm = convertView.findViewById(R.id.create_comment_form);
|
||||
EditCommentContentView input_comment = convertView.findViewById(R.id.input_comment_content);
|
||||
if(comments == null){
|
||||
|
||||
//Hide comment creation form
|
||||
commentCreationForm.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
//Comments creation form
|
||||
if(comments == null)
|
||||
mCreateCommentForm.setVisibility(View.GONE);
|
||||
else {
|
||||
mCreateCommentForm.setVisibility(View.VISIBLE);
|
||||
|
||||
//Display comment creation form
|
||||
commentCreationForm.setVisibility(View.VISIBLE);
|
||||
if(mEditCommentContentView.getPostID() != post.getId()){
|
||||
|
||||
//Make sure the form is correctly set up
|
||||
if(input_comment.getPostID() != post.getId()){
|
||||
mEditCommentContentView.setPostID(post.getId());
|
||||
mEditCommentContentView.setText("");
|
||||
|
||||
//Reset input comment
|
||||
input_comment.setPostID(post.getId());
|
||||
input_comment.setText("");
|
||||
|
||||
//Make the send button lives
|
||||
final View finalConvertView = convertView;
|
||||
convertView.findViewById(R.id.comment_send_button)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
mSendCommentButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sendComment(position, finalConvertView);
|
||||
sendComment();
|
||||
}
|
||||
});
|
||||
|
||||
//Make the comment input behaves like the send button when the user hit the
|
||||
//enter key
|
||||
input_comment.setOnKeyListener(new View.OnKeyListener() {
|
||||
}
|
||||
|
||||
mEditCommentContentView.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
|
||||
if(event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& keyCode == KeyEvent.KEYCODE_ENTER){
|
||||
sendComment(position, finalConvertView);
|
||||
}
|
||||
&& keyCode == KeyEvent.KEYCODE_ENTER)
|
||||
sendComment();
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return convertView;
|
||||
private void sendComment(){
|
||||
mListener.onCreateComment(getLayoutPosition(), mSendCommentButton,
|
||||
getPost(getLayoutPosition()), mEditCommentContentView);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intend to send a new comment to the server
|
||||
*
|
||||
* @param pos The position of the post to update
|
||||
* @param container The container of the post item
|
||||
* Image posts holder
|
||||
*/
|
||||
private void sendComment(int pos, View container){
|
||||
private class ImagePostHolder extends TextPostHolder {
|
||||
|
||||
//Get post information
|
||||
final Post post = getItem(pos);
|
||||
if(post==null)
|
||||
return;
|
||||
private EnlargeableWebImageView mPostImage;
|
||||
|
||||
//Get view about the comment
|
||||
final EditCommentContentView commentInput = container.findViewById(R.id.input_comment_content);
|
||||
final ImageView sendButton = container.findViewById(R.id.comment_send_button);
|
||||
|
||||
//Call interface
|
||||
mListener.onCreateComment(pos, sendButton, post, commentInput);
|
||||
ImagePostHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
mPostImage = new EnlargeableWebImageView(getContext());
|
||||
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.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Pair;
|
||||
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.onPostUpdateListener;
|
||||
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;
|
||||
|
||||
@ -105,7 +106,7 @@ public class PostsListFragment extends Fragment
|
||||
/**
|
||||
* The list of posts
|
||||
*/
|
||||
ScrollListView mListView;
|
||||
ScrollRecyclerView mRecyclerView;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -173,8 +174,8 @@ public class PostsListFragment extends Fragment
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
//Get the list view
|
||||
mListView = view.findViewById(R.id.posts_list);
|
||||
mListView.setOnScrollChangeDetectListener(this);
|
||||
mRecyclerView = view.findViewById(R.id.posts_list);
|
||||
mRecyclerView.setOnScrollChangeDetectListener(this);
|
||||
|
||||
//Show the posts
|
||||
show();
|
||||
@ -194,7 +195,8 @@ public class PostsListFragment extends Fragment
|
||||
mPostsAdapter = new PostsAdapter(getActivity(), mPostsList, mUsersInfo, this);
|
||||
|
||||
//Connect the adapter to the view
|
||||
mListView.setAdapter(mPostsAdapter);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mRecyclerView.setAdapter(mPostsAdapter);
|
||||
}
|
||||
|
||||
//Notify data set update
|
||||
|
@ -4,6 +4,7 @@ import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
|
||||
@ -84,4 +85,15 @@ public class UiUtils {
|
||||
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.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.AbsListView;
|
||||
|
||||
import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener;
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.communiquons.android.comunic.client.ui.views.ScrollListView android:id="@+id/posts_list"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<org.communiquons.android.comunic.client.ui.views.ScrollRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/posts_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/post_item"
|
||||
xmlns:tools="http://schemas.android.com/tools" />
|
||||
android:layout_height="match_parent" />
|
@ -3,7 +3,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="@style/PostContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Information about user who created the post -->
|
||||
@ -59,45 +59,22 @@
|
||||
tools:text="Public" />
|
||||
|
||||
<ImageView
|
||||
style="@style/PostActionsButton"
|
||||
android:id="@+id/post_actions_btn"
|
||||
style="@style/PostActionsButton"
|
||||
android:layout_width="@dimen/post_options_btn_width"
|
||||
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>
|
||||
|
||||
<!-- Post image (if any) -->
|
||||
<org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView
|
||||
android:id="@+id/post_image"
|
||||
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"
|
||||
<!-- Additional views -->
|
||||
<FrameLayout
|
||||
android:id="@+id/additional_views"
|
||||
android:layout_width="match_parent"
|
||||
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 -->
|
||||
<TextView
|
||||
android:id="@+id/post_content"
|
||||
@ -109,9 +86,9 @@
|
||||
<!-- Like button -->
|
||||
<org.communiquons.android.comunic.client.ui.views.LikeButtonView
|
||||
android:id="@+id/like_button"
|
||||
style="@style/PostLikeButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/PostLikeButton"/>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- Post comments -->
|
||||
<LinearLayout
|
||||
@ -130,10 +107,10 @@
|
||||
<!-- Comment hint -->
|
||||
<org.communiquons.android.comunic.client.ui.views.EditCommentContentView
|
||||
android:id="@+id/input_comment_content"
|
||||
style="@style/TextAppearance.AppCompat"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
style="@style/TextAppearance.AppCompat"
|
||||
android:hint="@string/new_comment_hint"
|
||||
android:inputType="text" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user