Android: Fix recreating main activity

4752ec8 broke this because I wasn't aware that a fragment
has to have a constructor with no parameters in order for
activity recreation to work.
This commit is contained in:
JosJuice 2021-03-15 21:44:09 +01:00
parent 72a6fff36c
commit fcb19a228b
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);