mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 11:34:06 +00:00 
			
		
		
		
	Created PostsListFragment.
This commit is contained in:
		@@ -189,6 +189,11 @@ public class FriendsListFragment extends Fragment
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            protected void onPostExecute(ArrayList<FriendUser> friendUsers) {
 | 
			
		||||
 | 
			
		||||
                //Check the activity still exists
 | 
			
		||||
                if(getActivity() == null)
 | 
			
		||||
                    return;
 | 
			
		||||
 | 
			
		||||
                apply_friends_list(friendUsers);
 | 
			
		||||
            }
 | 
			
		||||
        }.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.Fragment;
 | 
			
		||||
import android.app.FragmentTransaction;
 | 
			
		||||
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;
 | 
			
		||||
import android.widget.ImageView;
 | 
			
		||||
import android.widget.ListView;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
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.data.Account.AccountUtils;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.DatabaseHelper;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.ImageLoad.ImageLoadManager;
 | 
			
		||||
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.PostsList;
 | 
			
		||||
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
 | 
			
		||||
@@ -62,12 +59,12 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
    /**
 | 
			
		||||
     * User posts
 | 
			
		||||
     */
 | 
			
		||||
    private PostsList postsList;
 | 
			
		||||
    private PostsList mPostsList;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * User informations
 | 
			
		||||
     */
 | 
			
		||||
    private ArrayMap<Integer, UserInfo> usersInfos;
 | 
			
		||||
    private ArrayMap<Integer, UserInfo> mUsersInfo;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get user helper
 | 
			
		||||
@@ -77,7 +74,7 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
    /**
 | 
			
		||||
     * Posts helper
 | 
			
		||||
     */
 | 
			
		||||
    private PostsHelper postsHelper;
 | 
			
		||||
    private PostsHelper mPostsHelper;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Loading alert dialog
 | 
			
		||||
@@ -95,14 +92,10 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
    private ImageView user_image;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Posts list view
 | 
			
		||||
     * Posts list fragment
 | 
			
		||||
     */
 | 
			
		||||
    private ListView postsListView;
 | 
			
		||||
    private PostsListFragment mPostsListFragment;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Posts adapter
 | 
			
		||||
     */
 | 
			
		||||
    private PostsAdapter postsAdapter;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
@@ -118,7 +111,7 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
        getUsersHelper = new GetUsersHelper(getActivity(), dbHelper);
 | 
			
		||||
 | 
			
		||||
        //Create posts helper instance
 | 
			
		||||
        postsHelper = new PostsHelper(getActivity());
 | 
			
		||||
        mPostsHelper = new PostsHelper(getActivity());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
@@ -134,22 +127,19 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
        //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
 | 
			
		||||
    public void onResume() {
 | 
			
		||||
        super.onResume();
 | 
			
		||||
 | 
			
		||||
        //Check if we got informations about the user
 | 
			
		||||
        //Check if we got information about the user
 | 
			
		||||
        if(userInfo == null){
 | 
			
		||||
 | 
			
		||||
            //Show loading alert dialog
 | 
			
		||||
            loadingDialog = UiUtils.create_loading_dialog(getActivity());
 | 
			
		||||
 | 
			
		||||
            //Fetch user informations
 | 
			
		||||
            //Fetch user information
 | 
			
		||||
            new AsyncTask<Integer, Void, AdvancedUserInfo>(){
 | 
			
		||||
                @Override
 | 
			
		||||
                protected AdvancedUserInfo doInBackground(Integer... params) {
 | 
			
		||||
@@ -166,6 +156,9 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            onGotUserInfo(userInfo);
 | 
			
		||||
 | 
			
		||||
        //Render the list of post (if available)
 | 
			
		||||
        render_list_posts();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -226,11 +219,11 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            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
 | 
			
		||||
                if(list != null)
 | 
			
		||||
                    usersInfos = getUsersHelper.getMultiple(list.getUsersId());
 | 
			
		||||
                    mUsersInfo = getUsersHelper.getMultiple(list.getUsersId());
 | 
			
		||||
 | 
			
		||||
                return list;
 | 
			
		||||
            }
 | 
			
		||||
@@ -256,18 +249,40 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Check we didn't get user informations
 | 
			
		||||
        if(usersInfos == null){
 | 
			
		||||
        //Check we didn't get user information
 | 
			
		||||
        if(mUsersInfo == null){
 | 
			
		||||
            Toast.makeText(getActivity(), R.string.err_get_users_info, Toast.LENGTH_SHORT).show();
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Save posts posts
 | 
			
		||||
        postsList = list;
 | 
			
		||||
        //Save the list of posts
 | 
			
		||||
        mPostsList = list;
 | 
			
		||||
 | 
			
		||||
        //Create post adatper
 | 
			
		||||
        postsAdapter = new PostsAdapter(getActivity(), list, usersInfos);
 | 
			
		||||
        postsListView.setAdapter(postsAdapter);
 | 
			
		||||
        //Render the list of posts
 | 
			
		||||
        render_list_posts();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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"
 | 
			
		||||
    xmlns:tools="http://schemas.android.com/tools"
 | 
			
		||||
    android:orientation="vertical"
 | 
			
		||||
    android:id="@+id/fragment_user_page"
 | 
			
		||||
    android:layout_width="match_parent"
 | 
			
		||||
    android:layout_height="match_parent">
 | 
			
		||||
 | 
			
		||||
@@ -34,10 +35,10 @@
 | 
			
		||||
    </FrameLayout>
 | 
			
		||||
 | 
			
		||||
    <!-- User posts -->
 | 
			
		||||
    <ListView
 | 
			
		||||
    <FrameLayout
 | 
			
		||||
        android:id="@+id/user_posts"
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="0dp"
 | 
			
		||||
        android:layout_weight="1"/>
 | 
			
		||||
        android:layout_weight="1" />
 | 
			
		||||
 | 
			
		||||
</LinearLayout>
 | 
			
		||||
		Reference in New Issue
	
	Block a user