mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 07:49:28 +00:00
Friends List is displayed
This commit is contained in:
parent
81c2e390c2
commit
3a54768224
@ -0,0 +1,69 @@
|
||||
package org.communiquons.android.comunic.client.data.friendsList;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
||||
|
||||
/**
|
||||
* This class contains information about a friend but also about user himself
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
* Created by pierre on 11/15/17.
|
||||
*/
|
||||
|
||||
public class FriendUser {
|
||||
|
||||
/**
|
||||
* Friendship informations
|
||||
*/
|
||||
private Friend friend;
|
||||
|
||||
/**
|
||||
* Informations about the user
|
||||
*/
|
||||
private UserInfo userInfo;
|
||||
|
||||
/**
|
||||
* Create a FriendUser object
|
||||
*
|
||||
* @param friend Informations about the friend
|
||||
*/
|
||||
public FriendUser(Friend friend){
|
||||
this.friend = friend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new user informations
|
||||
*
|
||||
* @param userInfo Informations about the user
|
||||
*/
|
||||
public void setUserInfo(UserInfo userInfo) {
|
||||
this.userInfo = userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get informations about the user
|
||||
*
|
||||
* @return User informations
|
||||
*/
|
||||
public UserInfo getUserInfo() {
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get informations about the friendship
|
||||
*
|
||||
* @return Informations about the friendship
|
||||
*/
|
||||
public Friend getFriend() {
|
||||
return friend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set friendship informations
|
||||
*
|
||||
* @param friend New friendship informations
|
||||
*/
|
||||
public void setFriend(Friend friend) {
|
||||
this.friend = friend;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.communiquons.android.comunic.client.data.friendsList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
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.ImageLoadTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Adapter that render the list of friend on the friends list fragment
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
* Created by pierre on 11/15/17.
|
||||
*/
|
||||
|
||||
public class FriendsAdapter extends ArrayAdapter<FriendUser> {
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param context The context of execution of the application
|
||||
* @param friendsList The list of friends to display (with user information)
|
||||
*/
|
||||
public FriendsAdapter(Activity context, ArrayList<FriendUser> friendsList){
|
||||
super(context, 0, friendsList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
View listItemView = convertView;
|
||||
|
||||
//Check if the view has to be created
|
||||
if(listItemView == null){
|
||||
listItemView = LayoutInflater.from(getContext())
|
||||
.inflate(R.layout.fragment_friends_list_friend_item, parent, false);
|
||||
}
|
||||
|
||||
//Get friend information
|
||||
FriendUser friendUser = getItem(position);
|
||||
|
||||
//Update user account image
|
||||
ImageView user_image = listItemView.findViewById(R.id.fragment_friendslist_item_accountimage);
|
||||
new ImageLoadTask(getContext(), friendUser.getUserInfo().getAcountImageURL(), user_image)
|
||||
.execute();
|
||||
|
||||
//Update user name
|
||||
TextView user_name = listItemView.findViewById(R.id.fragment_friendslist_item_fullname);
|
||||
user_name.setText(friendUser.getUserInfo().getFullName());
|
||||
|
||||
return listItemView;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package org.communiquons.android.comunic.client.data.friendsList;
|
||||
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Friends utilities
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
* Created by pierre on 11/15/17.
|
||||
*/
|
||||
|
||||
public class FriendsUtils {
|
||||
|
||||
/**
|
||||
* Given a friend list, it will return the IDs of the friends
|
||||
*
|
||||
* @param friendsList the friends list to process
|
||||
* @return The list of the id of the friend
|
||||
*/
|
||||
public static ArrayList<Integer> getFriendsIDs(ArrayList<Friend> friendsList){
|
||||
ArrayList<Integer> IDs = new ArrayList<>();
|
||||
|
||||
for(Friend friend : friendsList)
|
||||
IDs.add(friend.getId());
|
||||
|
||||
return IDs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge a friends user list with a user info list, return the result by a FriendUser list
|
||||
*
|
||||
* @param friendsList The list of friend of the user
|
||||
* @param userInfos Informations about the user
|
||||
* @return The result of the operation
|
||||
*/
|
||||
public static ArrayList<FriendUser> merge_friends_user_infos_list(ArrayList<Friend> friendsList,
|
||||
ArrayMap<Integer, UserInfo> userInfos){
|
||||
|
||||
ArrayList<FriendUser> list = new ArrayList<>();
|
||||
|
||||
//Process the list
|
||||
for(Friend friend : friendsList){
|
||||
|
||||
UserInfo userInfo;
|
||||
|
||||
if((userInfo = userInfos.get(friend.getId())) != null){
|
||||
FriendUser item = new FriendUser(friend);
|
||||
item.setUserInfo(userInfo);
|
||||
list.add(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
package org.communiquons.android.comunic.client.fragments;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
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;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
@ -15,6 +16,9 @@ import org.communiquons.android.comunic.client.data.DatabaseHelper;
|
||||
import org.communiquons.android.comunic.client.data.UsersInfo.GetUsersInfos;
|
||||
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
||||
import org.communiquons.android.comunic.client.data.friendsList.Friend;
|
||||
import org.communiquons.android.comunic.client.data.friendsList.FriendUser;
|
||||
import org.communiquons.android.comunic.client.data.friendsList.FriendsAdapter;
|
||||
import org.communiquons.android.comunic.client.data.friendsList.FriendsUtils;
|
||||
import org.communiquons.android.comunic.client.data.friendsList.GetFriendsListTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -28,16 +32,38 @@ import java.util.ArrayList;
|
||||
|
||||
public class FriendsListFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* The root view of the fragment
|
||||
*/
|
||||
View rootView;
|
||||
|
||||
/**
|
||||
* Application context
|
||||
*/
|
||||
Context mContext;
|
||||
|
||||
/**
|
||||
* Database helper
|
||||
*/
|
||||
DatabaseHelper mDbHelper;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
//Save application context
|
||||
mContext = getActivity().getApplicationContext();
|
||||
|
||||
//Create database helper
|
||||
mDbHelper = new DatabaseHelper(mContext);
|
||||
|
||||
//Retain the fragment
|
||||
//setRetainInstance(true);
|
||||
|
||||
//Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_friendslist, container, false);
|
||||
rootView = inflater.inflate(R.layout.fragment_friendslist, container, false);
|
||||
return rootView;
|
||||
|
||||
}
|
||||
|
||||
@ -53,21 +79,78 @@ public class FriendsListFragment extends Fragment {
|
||||
* Refresh the friend list
|
||||
*/
|
||||
void refresh_friend_list(){
|
||||
|
||||
//Display loading bar
|
||||
display_progress_bar(true);
|
||||
|
||||
new GetFriendsListTask(getActivity().getApplicationContext()){
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayList<Friend> friendsList) {
|
||||
|
||||
//Display informations in the console
|
||||
for(Friend friend : friendsList){
|
||||
Log.v("FriendsListFragment", "Friend: " + friend.getId() + " " +
|
||||
(friend.isAccepted() ? 1 : 0 ) + " " + (friend.isFollowing() ? 1 : 0) +
|
||||
" " + friend.getLast_activity() + " "
|
||||
);
|
||||
}
|
||||
//Remote progress bar
|
||||
display_progress_bar(false);
|
||||
|
||||
//Check for errors
|
||||
if(friendsList == null){
|
||||
Toast.makeText(mContext, R.string.fragment_friendslist_err_refresh,
|
||||
Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else
|
||||
//Update the friends list
|
||||
update_friends_list(friendsList);
|
||||
}
|
||||
|
||||
}.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the the list of friend attached to the list adapter
|
||||
*
|
||||
* @param friendsList The friends list to apply
|
||||
*/
|
||||
private void update_friends_list(final ArrayList<Friend> friendsList){
|
||||
|
||||
//Get user informations
|
||||
new GetUsersInfos(mContext, mDbHelper).
|
||||
getMultiple(FriendsUtils.getFriendsIDs(friendsList), new GetUsersInfos.getMultipleUserInfosCallback() {
|
||||
@Override
|
||||
public void callback(ArrayMap<Integer, UserInfo> info) {
|
||||
//Check for errors
|
||||
if(info == null){
|
||||
Toast.makeText(mContext, R.string.fragment_friendslist_err_get_userinfos,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
//Merge the user informations list and friends List into FriendInfo list
|
||||
ArrayList<FriendUser> friendsUserList = FriendsUtils.merge_friends_user_infos_list(
|
||||
friendsList,
|
||||
info
|
||||
);
|
||||
|
||||
//Set the adapter
|
||||
FriendsAdapter friendsAdapter = new FriendsAdapter(getActivity(), friendsUserList);
|
||||
ListView listView = rootView.findViewById(R.id.fragment_friendslist_listview);
|
||||
listView.setAdapter(friendsAdapter);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide (or display) progress bar
|
||||
*
|
||||
* @param display Specify whether the loading bar has to be shown or not
|
||||
*/
|
||||
private void display_progress_bar(boolean display){
|
||||
|
||||
//Get the view
|
||||
rootView.findViewById(R.id.fragment_friendslist_progressbar).setVisibility(
|
||||
display ? View.VISIBLE : View.GONE
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
<?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="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fragment_friendslist_item_accountimage"
|
||||
android:layout_width="@dimen/account_image_default_width"
|
||||
android:layout_height="@dimen/account_image_default_height"
|
||||
android:src="@drawable/default_account_image"
|
||||
android:contentDescription="User account image"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="4dp"
|
||||
android:layout_gravity="center"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_friendslist_item_fullname"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Full user name"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Online"
|
||||
android:textColor="@android:color/holo_green_dark"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
@ -1,11 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
<!-- Progress bar - when loading the list of friends -->
|
||||
<ProgressBar
|
||||
android:id="@+id/fragment_friendslist_progressbar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello from friends list"/>
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
</LinearLayout>
|
||||
<ListView
|
||||
android:id="@+id/fragment_friendslist_listview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:numColumns="auto_fit" />
|
||||
|
||||
</RelativeLayout>
|
7
app/src/main/res/values/dimens.xml
Normal file
7
app/src/main/res/values/dimens.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<resources>
|
||||
<!-- The default size of an account image -->
|
||||
<dimen name="account_image_default_width">64dp</dimen>
|
||||
<dimen name="account_image_default_height">64dp</dimen>
|
||||
|
||||
|
||||
</resources>
|
@ -16,4 +16,6 @@
|
||||
<string name="popup_signout_cancel_button">Cancel</string>
|
||||
<string name="navigation_bottom_friends_item">Friends</string>
|
||||
<string name="navigation_bottom_me_item">Me</string>
|
||||
<string name="fragment_friendslist_err_refresh">Couldn\'t refresh friends list !</string>
|
||||
<string name="fragment_friendslist_err_get_userinfos">Couldn\'t get information about your friends!</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user