diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsList.java b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsList.java index e2f1af9..1445959 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsList.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsList.java @@ -11,6 +11,11 @@ import java.util.ArrayList; public class PostsList extends ArrayList { + /** + * Debug tag + */ + private static final String TAG = "PostsList"; + /** * Get the IDs of the users who created the posts * @@ -24,7 +29,7 @@ public class PostsList extends ArrayList { int userID = post.getUserID(); //Add User ID if required - if(ids.contains(userID)) + if(!ids.contains(userID)) ids.add(userID); } 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 new file mode 100644 index 0000000..62c200c --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java @@ -0,0 +1,86 @@ +package org.communiquons.android.comunic.client.ui.adapters; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.ArrayMap; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +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.posts.Post; +import org.communiquons.android.comunic.client.data.posts.PostsList; +import org.communiquons.android.comunic.client.data.utils.UiUtils; + +/** + * Posts adapter + * + * @author Pierre HUBERT + * Created by pierre on 1/21/18. + */ + +public class PostsAdapter extends ArrayAdapter{ + + /** + * Informations about the users + */ + private ArrayMap mUsersInfos; + + /** + * Create the Post Adapter + * + * @param context The context of execution of the application + * @param list The list of posts + * @param usersInfos Informations about the user + */ + public PostsAdapter(Context context, PostsList list, ArrayMap usersInfos){ + super(context, 0, list); + + //Save the users info object + mUsersInfos = usersInfos; + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + + //Check if the view has to be inflated + if(convertView == null) + convertView = LayoutInflater.from(getContext()) + .inflate(R.layout.post_item, parent, false); + + //Get informations about the post and the user + Post post = getItem(position); + assert post != null; + UserInfo userInfo = null; + if(mUsersInfos.containsKey(post.getUserID())) + userInfo = mUsersInfos.get(post.getUserID()); + + //Get the views related to user Informations + ImageView userAccountImage = convertView.findViewById(R.id.user_account_image); + TextView userAccountName = convertView.findViewById(R.id.user_account_name); + + //Reset user informations + userAccountName.setText(""); + ImageLoadManager.remove(userAccountImage); + userAccountImage.setImageDrawable(UiUtils.getDrawable(getContext(), + R.drawable.default_account_image)); + + //Set user informations if available + if(userInfo != null){ + userAccountName.setText(userInfo.getDisplayFullName()); + ImageLoadManager.load(getContext(), userInfo.getAcountImageURL(), userAccountImage); + } + + + + + return convertView; + } +} diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java index 619fafc..73952df 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java @@ -6,6 +6,7 @@ import android.os.AsyncTask; import android.os.Bundle; 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; @@ -25,6 +26,7 @@ import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo; import org.communiquons.android.comunic.client.data.posts.PostsHelper; import org.communiquons.android.comunic.client.data.posts.PostsList; import org.communiquons.android.comunic.client.data.utils.UiUtils; +import org.communiquons.android.comunic.client.ui.adapters.PostsAdapter; /** * User page fragment @@ -37,6 +39,11 @@ import org.communiquons.android.comunic.client.data.utils.UiUtils; public class UserPageFragment extends Fragment { + /** + * Debug tag + */ + private static final String TAG = "UserPageFragment"; + /** * The name of the argument that contains user id */ @@ -92,6 +99,11 @@ public class UserPageFragment extends Fragment { */ private ListView postsListView; + /** + * Posts adapter + */ + private PostsAdapter postsAdapter; + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -119,9 +131,12 @@ public class UserPageFragment extends Fragment { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - //Get the user + //Get the user views user_image = view.findViewById(R.id.user_account_image); user_name = view.findViewById(R.id.user_account_name); + + //Get the posts view + postsListView = view.findViewById(R.id.user_posts); } @Override @@ -247,7 +262,12 @@ public class UserPageFragment extends Fragment { return; } - Toast.makeText(getActivity(), "Got posts !", Toast.LENGTH_SHORT).show(); + //Save posts posts + postsList = list; + + //Create post adatper + postsAdapter = new PostsAdapter(getActivity(), list, usersInfos); + postsListView.setAdapter(postsAdapter); } } diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml new file mode 100644 index 0000000..f6bd9e8 --- /dev/null +++ b/app/src/main/res/layout/post_item.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 68d852c..34918ba 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -26,4 +26,15 @@ 5dp 5dp + + + + + + +