diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/CommentsAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/CommentsAdapter.java new file mode 100644 index 0000000..984271b --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/CommentsAdapter.java @@ -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 { + + /** + * Class constructor + * + * @param context The context of the target activity + * @param list The comments list + */ + public CommentsAdapter(Context context, ArrayList 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; + + } +} 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 a13f080..ae71137 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 @@ -4,22 +4,28 @@ import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.ArrayMap; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import org.communiquons.android.comunic.client.R; 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.comments.Comment; 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.PostsList; import org.communiquons.android.comunic.client.data.utils.UiUtils; import org.communiquons.android.comunic.client.data.utils.Utilities; +import java.util.ArrayList; + /** * Posts adapter * @@ -29,6 +35,11 @@ import org.communiquons.android.comunic.client.data.utils.Utilities; public class PostsAdapter extends ArrayAdapter{ + /** + * Debug tag + */ + private static final String TAG = "PostsAdapter"; + /** * Informations about the users */ @@ -116,7 +127,6 @@ public class PostsAdapter extends ArrayAdapter{ //Set post content ((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent())); - //Set post image (if any) ImageView postImage = convertView.findViewById(R.id.post_image); postImage.setVisibility(View.GONE); @@ -131,6 +141,32 @@ public class PostsAdapter extends ArrayAdapter{ ImageLoadManager.load(getContext(), post.getFile_path_url(), postImage); } + //Process post comments + ArrayList 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; } } diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml index 2c7f826..b0a4b55 100644 --- a/app/src/main/res/layout/post_item.xml +++ b/app/src/main/res/layout/post_item.xml @@ -66,7 +66,8 @@ android:id="@+id/post_image" android:layout_width="match_parent" android:layout_height="wrap_content" - android:scaleType="fitCenter"/> + android:scaleType="fitCenter" + android:contentDescription="@string/post_image_description"/> + + + \ 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 a002a38..d9b10da 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -100,4 +100,5 @@ public friends private + Post image (if any)