From aec2704f155a774f7b3e1181ac0bd6802b611c54 Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 16 Jan 2023 14:46:12 +0100 Subject: [PATCH] restore current tab --- .../android/fragments/HomeTabFragment.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java index effb0cf2e..d95d6fd23 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -338,7 +338,11 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab } private void navigateTo(int i) { - pager.setCurrentItem(i); + navigateTo(i, !GlobalUserPreferences.reduceMotion); + } + + private void navigateTo(int i, boolean smooth) { + pager.setCurrentItem(i, smooth); updateSwitcherIcon(i); } @@ -484,6 +488,19 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab } } + @Override + public void onViewStateRestored(Bundle savedInstanceState) { + super.onViewStateRestored(savedInstanceState); + if (savedInstanceState == null) return; + navigateTo(savedInstanceState.getInt("selectedTab"), false); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt("selectedTab", pager.getCurrentItem()); + } + private class HomePagerAdapter extends RecyclerView.Adapter { @NonNull @Override