mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 15:59:29 +00:00
Created PostsListFragment.
This commit is contained in:
parent
066805df27
commit
06f5b7962b
@ -189,6 +189,11 @@ public class FriendsListFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(ArrayList<FriendUser> friendUsers) {
|
protected void onPostExecute(ArrayList<FriendUser> friendUsers) {
|
||||||
|
|
||||||
|
//Check the activity still exists
|
||||||
|
if(getActivity() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
apply_friends_list(friendUsers);
|
apply_friends_list(friendUsers);
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
@ -0,0 +1,100 @@
|
|||||||
|
package org.communiquons.android.comunic.client.ui.fragments;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.ArrayMap;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.R;
|
||||||
|
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
||||||
|
import org.communiquons.android.comunic.client.data.posts.PostsList;
|
||||||
|
import org.communiquons.android.comunic.client.ui.adapters.PostsAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Posts list fragment
|
||||||
|
*
|
||||||
|
* Note : this fragment IS NOT MADE to be used in standalone mode !!!
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
* Created by pierre on 3/18/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PostsListFragment extends Fragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of posts
|
||||||
|
*/
|
||||||
|
PostsList mPostsList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Informations about the related users
|
||||||
|
*/
|
||||||
|
ArrayMap<Integer, UserInfo> mUsersInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post adapter
|
||||||
|
*/
|
||||||
|
PostsAdapter mPostsAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of posts
|
||||||
|
*/
|
||||||
|
ListView mListView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the list of posts of the fragment
|
||||||
|
*
|
||||||
|
* @param list The list of post
|
||||||
|
*/
|
||||||
|
public void setPostsList(PostsList list) {
|
||||||
|
this.mPostsList = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the list of users informations
|
||||||
|
*
|
||||||
|
* @param list The list
|
||||||
|
*/
|
||||||
|
public void setUsersInfos(ArrayMap<Integer, UserInfo> list){
|
||||||
|
this.mUsersInfo = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
return inflater.inflate(R.layout.fragment_postslist, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
//Get the list view
|
||||||
|
mListView = view.findViewById(R.id.posts_list);
|
||||||
|
|
||||||
|
//Show the posts
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show(){
|
||||||
|
|
||||||
|
//Check if the list of posts is not null
|
||||||
|
if(mPostsList == null && mUsersInfo == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//Create posts adapter (if required)
|
||||||
|
if(mPostsAdapter == null) {
|
||||||
|
mPostsAdapter = new PostsAdapter(getActivity(), mPostsList, mUsersInfo);
|
||||||
|
|
||||||
|
//Connect the adapter to the view
|
||||||
|
mListView.setAdapter(mPostsAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Notify dataset update
|
||||||
|
mPostsAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
@ -2,22 +2,19 @@ package org.communiquons.android.comunic.client.ui.fragments;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
import android.os.AsyncTask;
|
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;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.ui.activities.MainActivity;
|
|
||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
import org.communiquons.android.comunic.client.data.Account.AccountUtils;
|
|
||||||
import org.communiquons.android.comunic.client.data.DatabaseHelper;
|
import org.communiquons.android.comunic.client.data.DatabaseHelper;
|
||||||
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.AdvancedUserInfo;
|
import org.communiquons.android.comunic.client.data.UsersInfo.AdvancedUserInfo;
|
||||||
@ -26,7 +23,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;
|
import org.communiquons.android.comunic.client.ui.activities.MainActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User page fragment
|
* User page fragment
|
||||||
@ -62,12 +59,12 @@ public class UserPageFragment extends Fragment {
|
|||||||
/**
|
/**
|
||||||
* User posts
|
* User posts
|
||||||
*/
|
*/
|
||||||
private PostsList postsList;
|
private PostsList mPostsList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User informations
|
* User informations
|
||||||
*/
|
*/
|
||||||
private ArrayMap<Integer, UserInfo> usersInfos;
|
private ArrayMap<Integer, UserInfo> mUsersInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user helper
|
* Get user helper
|
||||||
@ -77,7 +74,7 @@ public class UserPageFragment extends Fragment {
|
|||||||
/**
|
/**
|
||||||
* Posts helper
|
* Posts helper
|
||||||
*/
|
*/
|
||||||
private PostsHelper postsHelper;
|
private PostsHelper mPostsHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loading alert dialog
|
* Loading alert dialog
|
||||||
@ -95,14 +92,10 @@ public class UserPageFragment extends Fragment {
|
|||||||
private ImageView user_image;
|
private ImageView user_image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts list view
|
* Posts list fragment
|
||||||
*/
|
*/
|
||||||
private ListView postsListView;
|
private PostsListFragment mPostsListFragment;
|
||||||
|
|
||||||
/**
|
|
||||||
* Posts adapter
|
|
||||||
*/
|
|
||||||
private PostsAdapter postsAdapter;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@ -118,7 +111,7 @@ public class UserPageFragment extends Fragment {
|
|||||||
getUsersHelper = new GetUsersHelper(getActivity(), dbHelper);
|
getUsersHelper = new GetUsersHelper(getActivity(), dbHelper);
|
||||||
|
|
||||||
//Create posts helper instance
|
//Create posts helper instance
|
||||||
postsHelper = new PostsHelper(getActivity());
|
mPostsHelper = new PostsHelper(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -134,22 +127,19 @@ public class UserPageFragment extends Fragment {
|
|||||||
//Get the user views
|
//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
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
//Check if we got informations about the user
|
//Check if we got information about the user
|
||||||
if(userInfo == null){
|
if(userInfo == null){
|
||||||
|
|
||||||
//Show loading alert dialog
|
//Show loading alert dialog
|
||||||
loadingDialog = UiUtils.create_loading_dialog(getActivity());
|
loadingDialog = UiUtils.create_loading_dialog(getActivity());
|
||||||
|
|
||||||
//Fetch user informations
|
//Fetch user information
|
||||||
new AsyncTask<Integer, Void, AdvancedUserInfo>(){
|
new AsyncTask<Integer, Void, AdvancedUserInfo>(){
|
||||||
@Override
|
@Override
|
||||||
protected AdvancedUserInfo doInBackground(Integer... params) {
|
protected AdvancedUserInfo doInBackground(Integer... params) {
|
||||||
@ -166,6 +156,9 @@ public class UserPageFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
onGotUserInfo(userInfo);
|
onGotUserInfo(userInfo);
|
||||||
|
|
||||||
|
//Render the list of post (if available)
|
||||||
|
render_list_posts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -226,11 +219,11 @@ public class UserPageFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PostsList doInBackground(Void... params) {
|
protected PostsList doInBackground(Void... params) {
|
||||||
PostsList list = postsHelper.get_user(userID);
|
PostsList list = mPostsHelper.get_user(userID);
|
||||||
|
|
||||||
//Get the information about the users who created the posts
|
//Get the information about the users who created the posts
|
||||||
if(list != null)
|
if(list != null)
|
||||||
usersInfos = getUsersHelper.getMultiple(list.getUsersId());
|
mUsersInfo = getUsersHelper.getMultiple(list.getUsersId());
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -256,18 +249,40 @@ public class UserPageFragment extends Fragment {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check we didn't get user informations
|
//Check we didn't get user information
|
||||||
if(usersInfos == null){
|
if(mUsersInfo == null){
|
||||||
Toast.makeText(getActivity(), R.string.err_get_users_info, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), R.string.err_get_users_info, Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save posts posts
|
//Save the list of posts
|
||||||
postsList = list;
|
mPostsList = list;
|
||||||
|
|
||||||
//Create post adatper
|
//Render the list of posts
|
||||||
postsAdapter = new PostsAdapter(getActivity(), list, usersInfos);
|
render_list_posts();
|
||||||
postsListView.setAdapter(postsAdapter);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the list of posts
|
||||||
|
*/
|
||||||
|
private void render_list_posts(){
|
||||||
|
|
||||||
|
//Check we have got required information
|
||||||
|
if(mPostsList == null || mUsersInfo == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(mPostsListFragment == null) {
|
||||||
|
|
||||||
|
//Create post fragment if requiredand display it
|
||||||
|
mPostsListFragment = new PostsListFragment();
|
||||||
|
mPostsListFragment.setPostsList(mPostsList);
|
||||||
|
mPostsListFragment.setUsersInfos(mUsersInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set the fragment
|
||||||
|
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||||
|
transaction.replace(R.id.fragment_user_page, mPostsListFragment);
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
7
app/src/main/res/layout/fragment_postslist.xml
Normal file
7
app/src/main/res/layout/fragment_postslist.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ListView android:id="@+id/posts_list"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:listitem="@layout/post_item"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools" />
|
@ -2,6 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
android:id="@+id/fragment_user_page"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@ -34,10 +35,10 @@
|
|||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<!-- User posts -->
|
<!-- User posts -->
|
||||||
<ListView
|
<FrameLayout
|
||||||
android:id="@+id/user_posts"
|
android:id="@+id/user_posts"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"/>
|
android:layout_weight="1" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user