From 4bb255e0bb679643c91a62574112e244ee8ae21a Mon Sep 17 00:00:00 2001 From: Grishka Date: Mon, 17 Jul 2023 20:25:08 +0300 Subject: [PATCH] Fix #619 --- .../android/fragments/ProfileFragment.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 2ccfcca52..4384062a4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -270,6 +270,12 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList refreshLayout.setOnRefreshListener(this); fab.setOnClickListener(this::onFabClick); + if(savedInstanceState!=null){ + featuredFragment=(ProfileFeaturedFragment) getChildFragmentManager().getFragment(savedInstanceState, "featured"); + timelineFragment=(AccountTimelineFragment) getChildFragmentManager().getFragment(savedInstanceState, "timeline"); + aboutFragment=(ProfileAboutFragment) getChildFragmentManager().getFragment(savedInstanceState, "about"); + } + if(loaded){ bindHeaderView(); dataLoaded(); @@ -354,15 +360,19 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList public void dataLoaded(){ if(getActivity()==null) return; + Bundle args=new Bundle(); + args.putString("account", accountID); + args.putParcelable("profileAccount", Parcels.wrap(account)); + args.putBoolean("__is_tab", true); + args.putBoolean("noAutoLoad", true); if(featuredFragment==null){ featuredFragment=new ProfileFeaturedFragment(); - Bundle args=new Bundle(); - args.putString("account", accountID); - args.putParcelable("profileAccount", Parcels.wrap(account)); - args.putBoolean("__is_tab", true); - args.putBoolean("noAutoLoad", true); featuredFragment.setArguments(args); + } + if(timelineFragment==null){ timelineFragment=AccountTimelineFragment.newInstance(accountID, account, true); + } + if(aboutFragment==null){ aboutFragment=new ProfileAboutFragment(); aboutFragment.setFields(fields); } @@ -428,6 +438,19 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList }); } + @Override + public void onSaveInstanceState(Bundle outState){ + super.onSaveInstanceState(outState); + if(featuredFragment==null) + return; + if(featuredFragment.isAdded()) + getChildFragmentManager().putFragment(outState, "featured", featuredFragment); + if(timelineFragment.isAdded()) + getChildFragmentManager().putFragment(outState, "timeline", timelineFragment); + if(aboutFragment.isAdded()) + getChildFragmentManager().putFragment(outState, "about", aboutFragment); + } + @Override public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig);