Merge pull request #9590 from JosJuice/android-recreate-main

Android: Fix recreating main activity
This commit is contained in:
Léo Lam 2021-03-16 09:42:31 +01:00 committed by GitHub
commit 064a00634e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View File

@ -40,7 +40,11 @@ public class PlatformPagerAdapter extends FragmentPagerAdapter
@Override
public Fragment getItem(int position)
{
return PlatformGamesFragment.newInstance(Platform.fromPosition(position), mOnRefreshListener);
Platform platform = Platform.fromPosition(position);
PlatformGamesFragment fragment = PlatformGamesFragment.newInstance(platform);
fragment.setOnRefreshListener(mOnRefreshListener);
return fragment;
}
@Override

View File

@ -26,10 +26,9 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
private SwipeRefreshLayout mSwipeRefresh;
private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener;
public static PlatformGamesFragment newInstance(Platform platform,
SwipeRefreshLayout.OnRefreshListener onRefreshListener)
public static PlatformGamesFragment newInstance(Platform platform)
{
PlatformGamesFragment fragment = new PlatformGamesFragment(onRefreshListener);
PlatformGamesFragment fragment = new PlatformGamesFragment();
Bundle args = new Bundle();
args.putSerializable(ARG_PLATFORM, platform);
@ -38,11 +37,6 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
return fragment;
}
public PlatformGamesFragment(SwipeRefreshLayout.OnRefreshListener onRefreshListener)
{
mOnRefreshListener = onRefreshListener;
}
@Override
public void onCreate(Bundle savedInstanceState)
{
@ -110,6 +104,14 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
mAdapter.refetchMetadata();
}
public void setOnRefreshListener(@Nullable SwipeRefreshLayout.OnRefreshListener listener)
{
mOnRefreshListener = listener;
if (mSwipeRefresh != null)
mSwipeRefresh.setOnRefreshListener(listener);
}
public void setRefreshing(boolean refreshing)
{
mSwipeRefresh.setRefreshing(refreshing);