Move thread fragment from pane

pull/213/head
M66B 1 year ago
parent 7cbeb531f5
commit 4852aea444

@ -715,6 +715,27 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
content_pane.setVisibility(duo || open_pane ? View.INVISIBLE : View.GONE);
}
FragmentManager fm = getSupportFragmentManager();
int count = fm.getBackStackEntryCount();
if (count > 1 && "thread".equals(fm.getBackStackEntryAt(count - 1).getName())) {
Fragment fragment = fm.findFragmentByTag("thread");
if (fragment != null &&
fragment.getId() == (content_pane == null ? R.id.content_pane : R.id.content_frame)) {
Log.i("Moving pane=" + (content_pane != null) + " fragment=" + fragment);
fm.popBackStack("thread", FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fragment newFragment = Helper.recreateFragment(fragment, fm);
FragmentTransaction ft = fm.beginTransaction();
ft.replace(content_pane == null ? R.id.content_frame : R.id.content_pane, newFragment, "thread")
.addToBackStack("thread");
ft.commit();
if (content_pane != null) {
content_separator.setVisibility(View.VISIBLE);
content_pane.setVisibility(View.VISIBLE);
}
}
}
if (getSupportFragmentManager().getFragments().size() == 0 &&
!getIntent().hasExtra(Intent.EXTRA_PROCESS_TEXT))
init();
@ -2455,7 +2476,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(pane, fragment).addToBackStack("thread");
fragmentTransaction.replace(pane, fragment, "thread").addToBackStack("thread");
fragmentTransaction.commit();
}

@ -6372,7 +6372,7 @@ public class FragmentMessages extends FragmentBase
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getParentFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("thread");
fragmentTransaction.replace(R.id.content_frame, fragment, "thread").addToBackStack("thread");
fragmentTransaction.commit();
}
@ -7626,7 +7626,7 @@ public class FragmentMessages extends FragmentBase
int res = (pane ? R.id.content_pane : R.id.content_frame);
if (getActivity() != null && getActivity().findViewById(res) != null) {
FragmentTransaction fragmentTransaction = getParentFragmentManager().beginTransaction();
fragmentTransaction.replace(res, fragment).addToBackStack("thread");
fragmentTransaction.replace(res, fragment, "thread").addToBackStack("thread");
fragmentTransaction.commit();
}
}

@ -122,6 +122,7 @@ import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
@ -1779,6 +1780,21 @@ public class Helper {
return options.toBundle();
}
static Fragment recreateFragment(Fragment fragment, FragmentManager fm) {
try {
Fragment.SavedState savedState = fm.saveFragmentInstanceState(fragment);
Bundle args = fragment.getArguments();
Fragment newFragment = fragment.getClass().newInstance();
newFragment.setInitialSavedState(savedState);
newFragment.setArguments(args);
return newFragment;
} catch (Throwable e) {
throw new RuntimeException("Cannot recreate fragment=" + fragment, e);
}
}
// Graphics
static int dp2pixels(Context context, int dp) {

Loading…
Cancel
Save