mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +00:00
Display comments content.
This commit is contained in:
parent
115db81956
commit
588ae5a680
@ -0,0 +1,74 @@
|
|||||||
|
package org.communiquons.android.comunic.client.ui.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.R;
|
||||||
|
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
||||||
|
import org.communiquons.android.comunic.client.data.comments.Comment;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comments adapter
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
* Created by pierre on 3/11/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CommentsAdapter extends ArrayAdapter<Comment> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
*
|
||||||
|
* @param context The context of the target activity
|
||||||
|
* @param list The comments list
|
||||||
|
*/
|
||||||
|
public CommentsAdapter(Context context, ArrayList<Comment> list){
|
||||||
|
super(context, 0, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inflate and return a filled comment object
|
||||||
|
*
|
||||||
|
* @param context The context of the application
|
||||||
|
* @param comment The comment to fill
|
||||||
|
* @param user Information about the user (NULL for none)
|
||||||
|
* @param viewGroup Target view group
|
||||||
|
* @return Generated view
|
||||||
|
*/
|
||||||
|
static View getInflatedView(Context context, Comment comment, @Nullable UserInfo user,
|
||||||
|
ViewGroup viewGroup){
|
||||||
|
|
||||||
|
//Inflate a view
|
||||||
|
View v = LayoutInflater.from(context).inflate(R.layout.comment_item, viewGroup, false);
|
||||||
|
|
||||||
|
//Return filled view
|
||||||
|
return fillView(v, comment, user);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill a view with a specified comments informations
|
||||||
|
*
|
||||||
|
* @param view The view to update
|
||||||
|
* @param comment The comment to update
|
||||||
|
* @param user Information about the user (NULL for none)
|
||||||
|
* @return Updated view
|
||||||
|
*/
|
||||||
|
private static View fillView(View view, Comment comment, @Nullable UserInfo user){
|
||||||
|
|
||||||
|
|
||||||
|
//Update comment content
|
||||||
|
((TextView)view.findViewById(R.id.comment_text)).setText(comment.getContent());
|
||||||
|
|
||||||
|
//Return view
|
||||||
|
return view;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -4,22 +4,28 @@ import android.content.Context;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
|
import android.util.Log;
|
||||||
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.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
import org.communiquons.android.comunic.client.data.ImageLoad.ImageLoadManager;
|
import org.communiquons.android.comunic.client.data.ImageLoad.ImageLoadManager;
|
||||||
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
||||||
|
import org.communiquons.android.comunic.client.data.comments.Comment;
|
||||||
import org.communiquons.android.comunic.client.data.posts.Post;
|
import org.communiquons.android.comunic.client.data.posts.Post;
|
||||||
import org.communiquons.android.comunic.client.data.posts.PostTypes;
|
import org.communiquons.android.comunic.client.data.posts.PostTypes;
|
||||||
import org.communiquons.android.comunic.client.data.posts.PostsList;
|
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 java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts adapter
|
* Posts adapter
|
||||||
*
|
*
|
||||||
@ -29,6 +35,11 @@ import org.communiquons.android.comunic.client.data.utils.Utilities;
|
|||||||
|
|
||||||
public class PostsAdapter extends ArrayAdapter<Post>{
|
public class PostsAdapter extends ArrayAdapter<Post>{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug tag
|
||||||
|
*/
|
||||||
|
private static final String TAG = "PostsAdapter";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Informations about the users
|
* Informations about the users
|
||||||
*/
|
*/
|
||||||
@ -116,7 +127,6 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
|||||||
//Set post content
|
//Set post content
|
||||||
((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent()));
|
((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent()));
|
||||||
|
|
||||||
|
|
||||||
//Set post image (if any)
|
//Set post image (if any)
|
||||||
ImageView postImage = convertView.findViewById(R.id.post_image);
|
ImageView postImage = convertView.findViewById(R.id.post_image);
|
||||||
postImage.setVisibility(View.GONE);
|
postImage.setVisibility(View.GONE);
|
||||||
@ -131,6 +141,32 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
|||||||
ImageLoadManager.load(getContext(), post.getFile_path_url(), postImage);
|
ImageLoadManager.load(getContext(), post.getFile_path_url(), postImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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
|
||||||
|
convertView.findViewById(R.id.comments_list).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
for (Comment comment : comments) {
|
||||||
|
|
||||||
|
//Try to find information about the user
|
||||||
|
UserInfo commentUser = mUsersInfos.containsKey(comment.getUserID()) ?
|
||||||
|
mUsersInfos.get(comment.getUserID()) : null;
|
||||||
|
|
||||||
|
//Inflate the view
|
||||||
|
View commentView = CommentsAdapter.getInflatedView(getContext(), comment,
|
||||||
|
commentUser, commentsView);
|
||||||
|
commentsView.addView(commentView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//Hide comments list
|
||||||
|
convertView.findViewById(R.id.comments_list).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,8 @@
|
|||||||
android:id="@+id/post_image"
|
android:id="@+id/post_image"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:scaleType="fitCenter"/>
|
android:scaleType="fitCenter"
|
||||||
|
android:contentDescription="@string/post_image_description"/>
|
||||||
|
|
||||||
<!-- Post content -->
|
<!-- Post content -->
|
||||||
<TextView
|
<TextView
|
||||||
@ -76,5 +77,12 @@
|
|||||||
tools:text="Post content"
|
tools:text="Post content"
|
||||||
style="@style/PostContent" />
|
style="@style/PostContent" />
|
||||||
|
|
||||||
|
<!-- Post comments -->
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:id="@+id/comments_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -100,4 +100,5 @@
|
|||||||
<string name="post_visibility_public">public</string>
|
<string name="post_visibility_public">public</string>
|
||||||
<string name="post_visibility_friends">friends</string>
|
<string name="post_visibility_friends">friends</string>
|
||||||
<string name="post_visibility_private">private</string>
|
<string name="post_visibility_private">private</string>
|
||||||
|
<string name="post_image_description">Post image (if any)</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user