Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9590 from JosJuice/android-recreate-main
Android: Fix recreating main activity
  • Loading branch information
leoetlino committed Mar 16, 2021
2 parents 13f7932 + fcb19a2 commit 064a006
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Expand Up @@ -40,7 +40,11 @@ public PlatformPagerAdapter(FragmentManager fm, Context context,
@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
Expand Down
Expand Up @@ -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);
Expand All @@ -38,11 +37,6 @@ public static PlatformGamesFragment newInstance(Platform platform,
return fragment;
}

public PlatformGamesFragment(SwipeRefreshLayout.OnRefreshListener onRefreshListener)
{
mOnRefreshListener = onRefreshListener;
}

@Override
public void onCreate(Bundle savedInstanceState)
{
Expand Down Expand Up @@ -110,6 +104,14 @@ public void refetchMetadata()
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);
Expand Down

0 comments on commit 064a006

Please sign in to comment.