mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 11:34:06 +00:00 
			
		
		
		
	Put create post form into a fragment.
This commit is contained in:
		@@ -0,0 +1,69 @@
 | 
			
		||||
package org.communiquons.android.comunic.client.ui.fragments;
 | 
			
		||||
 | 
			
		||||
import android.app.Fragment;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.support.annotation.Nullable;
 | 
			
		||||
import android.view.LayoutInflater;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.view.ViewGroup;
 | 
			
		||||
 | 
			
		||||
import org.communiquons.android.comunic.client.R;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.posts.Post;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Posts creation form
 | 
			
		||||
 *
 | 
			
		||||
 * Created by pierre on 4/1/18.
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class PostsCreateFormFragment extends Fragment {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The argument that contains ID of the target page
 | 
			
		||||
     */
 | 
			
		||||
    public static final String PAGE_ID_ARG = "ID";
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The name of the argument that contains the type of the page
 | 
			
		||||
     */
 | 
			
		||||
    public static final String PAGE_TYPE_ARG = "PAGE_TYPE";
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Page type : user page
 | 
			
		||||
     */
 | 
			
		||||
    public static final int PAGE_TYPE_USER = 1;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * On post created interface
 | 
			
		||||
     */
 | 
			
		||||
    private OnPostCreated mOnPostCreated;
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    @Override
 | 
			
		||||
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
 | 
			
		||||
        return inflater.inflate(R.layout.fragment_post_create_form, container, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set the on post created class to trigger when an event occur
 | 
			
		||||
     *
 | 
			
		||||
     * @param onPostCreated The interface to call
 | 
			
		||||
     */
 | 
			
		||||
    public void setOnPostCreatedListener(OnPostCreated onPostCreated) {
 | 
			
		||||
        this.mOnPostCreated = onPostCreated;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This interface is called when a post is created
 | 
			
		||||
     */
 | 
			
		||||
    interface OnPostCreated{
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * This method is called with the created post
 | 
			
		||||
         *
 | 
			
		||||
         * @param post The created post
 | 
			
		||||
         */
 | 
			
		||||
        void onPostCreated(Post post);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -20,6 +20,7 @@ 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.GetUsersHelper;
 | 
			
		||||
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.PostsHelper;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.posts.PostsList;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.utils.UiUtils;
 | 
			
		||||
@@ -34,7 +35,7 @@ import org.communiquons.android.comunic.client.ui.activities.MainActivity;
 | 
			
		||||
 * Created by pierre on 1/13/18.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class UserPageFragment extends Fragment {
 | 
			
		||||
public class UserPageFragment extends Fragment implements PostsCreateFormFragment.OnPostCreated {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Debug tag
 | 
			
		||||
@@ -49,10 +50,10 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
    /**
 | 
			
		||||
     * The ID of the current user
 | 
			
		||||
     */
 | 
			
		||||
    private int userID;
 | 
			
		||||
    private int mUserID;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * User informations
 | 
			
		||||
     * Page's user information
 | 
			
		||||
     */
 | 
			
		||||
    private AdvancedUserInfo userInfo;
 | 
			
		||||
 | 
			
		||||
@@ -62,7 +63,7 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
    private PostsList mPostsList;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * User informations
 | 
			
		||||
     * User information
 | 
			
		||||
     */
 | 
			
		||||
    private ArrayMap<Integer, UserInfo> mUsersInfo;
 | 
			
		||||
 | 
			
		||||
@@ -112,7 +113,7 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
        //Save user ID
 | 
			
		||||
        userID = getArguments().getInt(ARGUMENT_USER_ID);
 | 
			
		||||
        mUserID = getArguments().getInt(ARGUMENT_USER_ID);
 | 
			
		||||
 | 
			
		||||
        //Get database helper
 | 
			
		||||
        DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
 | 
			
		||||
@@ -151,6 +152,9 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
                        mCreatePostForm.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        //Create the fragment
 | 
			
		||||
        init_create_post_fragment();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -176,7 +180,7 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
                    if(getActivity() != null)
 | 
			
		||||
                        onGotUserInfo(advancedUserInfo);
 | 
			
		||||
                }
 | 
			
		||||
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, userID);
 | 
			
		||||
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mUserID);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            onGotUserInfo(userInfo);
 | 
			
		||||
@@ -211,14 +215,14 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Save user informations
 | 
			
		||||
        //Save user information
 | 
			
		||||
        userInfo = info;
 | 
			
		||||
 | 
			
		||||
        //Set activity title
 | 
			
		||||
        getActivity().setTitle(userInfo.getDisplayFullName());
 | 
			
		||||
 | 
			
		||||
        //Update activity menu dock
 | 
			
		||||
        //if(AccountUtils.getID(getActivity()) == userID)
 | 
			
		||||
        //if(AccountUtils.getID(getActivity()) == mUserID)
 | 
			
		||||
            ((MainActivity) getActivity()).setSelectedNavigationItem(
 | 
			
		||||
                    R.id.main_bottom_navigation_me_view);
 | 
			
		||||
        /*else
 | 
			
		||||
@@ -243,7 +247,7 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            protected PostsList doInBackground(Void... params) {
 | 
			
		||||
                PostsList list = mPostsHelper.get_user(userID);
 | 
			
		||||
                PostsList list = mPostsHelper.get_user(mUserID);
 | 
			
		||||
 | 
			
		||||
                //Get the information about the users who created the posts
 | 
			
		||||
                if(list != null)
 | 
			
		||||
@@ -309,4 +313,32 @@ public class UserPageFragment extends Fragment {
 | 
			
		||||
        transaction.replace(R.id.fragment_user_page, mPostsListFragment);
 | 
			
		||||
        transaction.commit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create and create post fragment
 | 
			
		||||
     */
 | 
			
		||||
    private void init_create_post_fragment(){
 | 
			
		||||
 | 
			
		||||
        //Create bundle
 | 
			
		||||
        Bundle args = new Bundle();
 | 
			
		||||
        args.putInt(PostsCreateFormFragment.PAGE_TYPE_ARG, PostsCreateFormFragment.PAGE_TYPE_USER);
 | 
			
		||||
        args.putInt(PostsCreateFormFragment.PAGE_ID_ARG, mUserID);
 | 
			
		||||
 | 
			
		||||
        //Create fragment
 | 
			
		||||
        Fragment fragment = new PostsCreateFormFragment();
 | 
			
		||||
        fragment.setArguments(args);
 | 
			
		||||
 | 
			
		||||
        //Perform transaction
 | 
			
		||||
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
 | 
			
		||||
        transaction.replace(R.id.create_post_form, fragment);
 | 
			
		||||
        transaction.commit();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onPostCreated(Post post) {
 | 
			
		||||
        //Reload the list of post
 | 
			
		||||
        mPostsList = null;
 | 
			
		||||
        load_posts();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								app/src/main/res/layout/fragment_post_create_form.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								app/src/main/res/layout/fragment_post_create_form.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    android:layout_width="match_parent" android:layout_height="match_parent"
 | 
			
		||||
    android:orientation="vertical">
 | 
			
		||||
 | 
			
		||||
    <include layout="@layout/post_create_form"/>
 | 
			
		||||
 | 
			
		||||
</LinearLayout>
 | 
			
		||||
@@ -48,7 +48,9 @@
 | 
			
		||||
    </FrameLayout>
 | 
			
		||||
 | 
			
		||||
    <!-- Include post creation form -->
 | 
			
		||||
    <include
 | 
			
		||||
    <FrameLayout
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:id="@+id/create_post_form"
 | 
			
		||||
        layout="@layout/post_create_form" />
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user