mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +00:00
Display post creators name and avatar
This commit is contained in:
parent
e384aed527
commit
6280541829
@ -11,6 +11,11 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class PostsList extends ArrayList<Post> {
|
public class PostsList extends ArrayList<Post> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug tag
|
||||||
|
*/
|
||||||
|
private static final String TAG = "PostsList";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the IDs of the users who created the posts
|
* Get the IDs of the users who created the posts
|
||||||
*
|
*
|
||||||
@ -24,7 +29,7 @@ public class PostsList extends ArrayList<Post> {
|
|||||||
int userID = post.getUserID();
|
int userID = post.getUserID();
|
||||||
|
|
||||||
//Add User ID if required
|
//Add User ID if required
|
||||||
if(ids.contains(userID))
|
if(!ids.contains(userID))
|
||||||
ids.add(userID);
|
ids.add(userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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<Post>{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Informations about the users
|
||||||
|
*/
|
||||||
|
private ArrayMap<Integer, UserInfo> 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<Integer, UserInfo> 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;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import android.os.AsyncTask;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
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;
|
||||||
@ -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.PostsHelper;
|
||||||
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.ui.adapters.PostsAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User page fragment
|
* User page fragment
|
||||||
@ -37,6 +39,11 @@ import org.communiquons.android.comunic.client.data.utils.UiUtils;
|
|||||||
|
|
||||||
public class UserPageFragment extends Fragment {
|
public class UserPageFragment extends Fragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug tag
|
||||||
|
*/
|
||||||
|
private static final String TAG = "UserPageFragment";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the argument that contains user id
|
* The name of the argument that contains user id
|
||||||
*/
|
*/
|
||||||
@ -92,6 +99,11 @@ public class UserPageFragment extends Fragment {
|
|||||||
*/
|
*/
|
||||||
private ListView postsListView;
|
private ListView postsListView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Posts adapter
|
||||||
|
*/
|
||||||
|
private PostsAdapter postsAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -119,9 +131,12 @@ public class UserPageFragment extends Fragment {
|
|||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
//Get the user
|
//Get the user views
|
||||||
user_image = view.findViewById(R.id.user_account_image);
|
user_image = view.findViewById(R.id.user_account_image);
|
||||||
user_name = view.findViewById(R.id.user_account_name);
|
user_name = view.findViewById(R.id.user_account_name);
|
||||||
|
|
||||||
|
//Get the posts view
|
||||||
|
postsListView = view.findViewById(R.id.user_posts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -247,7 +262,12 @@ public class UserPageFragment extends Fragment {
|
|||||||
return;
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
app/src/main/res/layout/post_item.xml
Normal file
31
app/src/main/res/layout/post_item.xml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<!-- Informations about user who created the post -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/PostHeader">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/user_account_image"
|
||||||
|
android:src="@drawable/default_account_image"
|
||||||
|
android:layout_width="@dimen/account_image_default_width"
|
||||||
|
android:layout_height="@dimen/account_image_default_height" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/user_account_name"
|
||||||
|
style="@style/PostOwnerName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:text="User name"
|
||||||
|
android:layout_gravity="center"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -26,4 +26,15 @@
|
|||||||
<item name="android:paddingStart">5dp</item>
|
<item name="android:paddingStart">5dp</item>
|
||||||
<item name="android:paddingEnd">5dp</item>
|
<item name="android:paddingEnd">5dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- Posts style -->
|
||||||
|
<!-- Post header -->
|
||||||
|
<style name="PostHeader">
|
||||||
|
<item name="android:padding">2dp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- Post owner name -->
|
||||||
|
<style name="PostOwnerName">
|
||||||
|
<item name="android:paddingStart">10dp</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user