Restore current tab right after downloads and episodes views creation

This commit is contained in:
Ebrahim Byagowi 2020-04-11 02:16:13 +04:30
parent 77dc78dfe8
commit 1b9937c2be
2 changed files with 10 additions and 20 deletions

View File

@ -67,6 +67,11 @@ public class DownloadsFragment extends Fragment {
}
}).attach();
// restore our last position
SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
viewPager.setCurrentItem(lastPosition);
return root;
}
@ -89,16 +94,6 @@ public class DownloadsFragment extends Fragment {
editor.apply();
}
@Override
public void onStart() {
super.onStart();
// restore our last position
SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
viewPager.setCurrentItem(lastPosition);
}
public static class DownloadsPagerAdapter extends FragmentStateAdapter {
DownloadsPagerAdapter(@NonNull Fragment fragment) {

View File

@ -71,6 +71,11 @@ public class EpisodesFragment extends Fragment {
}
}).attach();
// restore our last position
SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
viewPager.setCurrentItem(lastPosition);
return rootView;
}
@ -84,16 +89,6 @@ public class EpisodesFragment extends Fragment {
editor.apply();
}
@Override
public void onStart() {
super.onStart();
// restore our last position
SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
viewPager.setCurrentItem(lastPosition);
}
static class EpisodesPagerAdapter extends FragmentStateAdapter {
EpisodesPagerAdapter(@NonNull Fragment fragment) {