mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 07:49:28 +00:00
Use bundle to provide information to UserPostsFragment.
This commit is contained in:
parent
483cf40cec
commit
9058d059d8
@ -190,8 +190,12 @@ public class UserPageFragment extends Fragment {
|
|||||||
R.string.tab_user_advanced_info));
|
R.string.tab_user_advanced_info));
|
||||||
|
|
||||||
//Posts fragment
|
//Posts fragment
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt(UserPostsFragment.ARGUMENT_USER_ID, userInfo.getId());
|
||||||
|
args.putBoolean(UserPostsFragment.ARGUMENT_CAN_POST_TEXT, userInfo.isCanPostText());
|
||||||
|
|
||||||
UserPostsFragment postsFragment = new UserPostsFragment();
|
UserPostsFragment postsFragment = new UserPostsFragment();
|
||||||
postsFragment.setAdvancedUserInfo(userInfo);
|
postsFragment.setArguments(args);
|
||||||
adapter.addFragment(postsFragment, UiUtils.getString(getActivity(),
|
adapter.addFragment(postsFragment, UiUtils.getString(getActivity(),
|
||||||
R.string.tab_posts));
|
R.string.tab_posts));
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ import org.communiquons.android.comunic.client.R;
|
|||||||
import org.communiquons.android.comunic.client.data.arrays.PostsList;
|
import org.communiquons.android.comunic.client.data.arrays.PostsList;
|
||||||
import org.communiquons.android.comunic.client.data.helpers.GetUsersHelper;
|
import org.communiquons.android.comunic.client.data.helpers.GetUsersHelper;
|
||||||
import org.communiquons.android.comunic.client.data.helpers.PostsHelper;
|
import org.communiquons.android.comunic.client.data.helpers.PostsHelper;
|
||||||
import org.communiquons.android.comunic.client.data.models.AdvancedUserInfo;
|
|
||||||
import org.communiquons.android.comunic.client.data.models.Post;
|
import org.communiquons.android.comunic.client.data.models.Post;
|
||||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||||
|
|
||||||
@ -30,9 +29,20 @@ public class UserPostsFragment extends Fragment
|
|||||||
implements PostsCreateFormFragment.OnPostCreated {
|
implements PostsCreateFormFragment.OnPostCreated {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the user
|
* Bundle arguments
|
||||||
*/
|
*/
|
||||||
private AdvancedUserInfo mAdvancedUserInfo;
|
public static final String ARGUMENT_USER_ID = "user_id";
|
||||||
|
public static final String ARGUMENT_CAN_POST_TEXT = "can_post_text";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the user
|
||||||
|
*/
|
||||||
|
private int mUserID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify whether the user is allowed to create posts on user page or not
|
||||||
|
*/
|
||||||
|
private boolean mCanPostsText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of posts of the user
|
* The list of posts of the user
|
||||||
@ -74,16 +84,16 @@ public class UserPostsFragment extends Fragment
|
|||||||
*/
|
*/
|
||||||
private PostsListFragment mPostsListFragment;
|
private PostsListFragment mPostsListFragment;
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Specify advanced user information
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
*
|
super.onCreate(savedInstanceState);
|
||||||
* Warning ! This method must absolutely be called before the fragment
|
|
||||||
* is attached to an activity !
|
//Get arguments
|
||||||
*
|
Bundle bundle = getArguments();
|
||||||
* @param advancedUserInfo Information about the user
|
assert bundle != null;
|
||||||
*/
|
|
||||||
public void setAdvancedUserInfo(AdvancedUserInfo advancedUserInfo) {
|
mUserID = bundle.getInt(ARGUMENT_USER_ID);
|
||||||
this.mAdvancedUserInfo = advancedUserInfo;
|
mCanPostsText = bundle.getBoolean(ARGUMENT_CAN_POST_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -96,8 +106,6 @@ public class UserPostsFragment extends Fragment
|
|||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
if(mAdvancedUserInfo == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
//Get the views
|
//Get the views
|
||||||
mCreatePostButton = view.findViewById(R.id.create_post_btn);
|
mCreatePostButton = view.findViewById(R.id.create_post_btn);
|
||||||
@ -116,7 +124,7 @@ public class UserPostsFragment extends Fragment
|
|||||||
mUserHelper = new GetUsersHelper(getActivity());
|
mUserHelper = new GetUsersHelper(getActivity());
|
||||||
|
|
||||||
//Add create post fragment, if possible
|
//Add create post fragment, if possible
|
||||||
if(mAdvancedUserInfo.isCanPostText())
|
if(mCanPostsText)
|
||||||
init_create_post_fragment();
|
init_create_post_fragment();
|
||||||
else
|
else
|
||||||
mCreatePostButton.setVisibility(View.GONE);
|
mCreatePostButton.setVisibility(View.GONE);
|
||||||
@ -136,7 +144,7 @@ public class UserPostsFragment extends Fragment
|
|||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
//Get the list of posts of the user
|
//Get the list of posts of the user
|
||||||
mPostsList.addAll(mPostsHelper.get_user(mAdvancedUserInfo.getId()));
|
mPostsList.addAll(mPostsHelper.get_user(mUserID));
|
||||||
|
|
||||||
if(mPostsList != null)
|
if(mPostsList != null)
|
||||||
mUsersInfo = mUserHelper.getMultiple(mPostsList.getUsersId());
|
mUsersInfo = mUserHelper.getMultiple(mPostsList.getUsersId());
|
||||||
@ -187,7 +195,7 @@ public class UserPostsFragment extends Fragment
|
|||||||
//Create bundle
|
//Create bundle
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt(PostsCreateFormFragment.PAGE_TYPE_ARG, PostsCreateFormFragment.PAGE_TYPE_USER);
|
args.putInt(PostsCreateFormFragment.PAGE_TYPE_ARG, PostsCreateFormFragment.PAGE_TYPE_USER);
|
||||||
args.putInt(PostsCreateFormFragment.PAGE_ID_ARG, mAdvancedUserInfo.getId());
|
args.putInt(PostsCreateFormFragment.PAGE_ID_ARG, mUserID);
|
||||||
|
|
||||||
//Create fragment
|
//Create fragment
|
||||||
PostsCreateFormFragment fragment = new PostsCreateFormFragment();
|
PostsCreateFormFragment fragment = new PostsCreateFormFragment();
|
||||||
|
Loading…
Reference in New Issue
Block a user