android: frontend: gamelist: Save PlatformGamesFragment state.

- Fixes weird duplication of game list on rotation.
This commit is contained in:
bunnei 2019-08-30 13:50:32 -04:00
parent 9e4e54cbd7
commit 6226463109
2 changed files with 16 additions and 12 deletions

View File

@ -6,6 +6,7 @@ import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
@ -46,23 +47,27 @@ public final class MainActivity extends AppCompatActivity implements MainView {
setSupportActionBar(mToolbar);
mFrameLayoutId = R.id.games_platform_frame;
// Set up the FAB.
mFab.setOnClickListener(view -> mPresenter.onFabClick());
mPresenter.onCreate();
// Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
if (savedInstanceState == null)
if (savedInstanceState == null) {
StartupHandler.HandleInit(this);
if (PermissionsHandler.hasWriteAccess(this)) {
mPlatformGamesFragment = new PlatformGamesFragment();
getSupportFragmentManager().beginTransaction().add(mFrameLayoutId, mPlatformGamesFragment)
.commit();
if (PermissionsHandler.hasWriteAccess(this)) {
mPlatformGamesFragment = new PlatformGamesFragment();
getSupportFragmentManager().beginTransaction().add(mFrameLayoutId, mPlatformGamesFragment)
.commit();
}
} else {
mPlatformGamesFragment = (PlatformGamesFragment) getSupportFragmentManager().getFragment(savedInstanceState, "mPlatformGamesFragment");
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, "mPlatformGamesFragment", mPlatformGamesFragment);
}
@Override
protected void onResume() {
super.onResume();

View File

@ -47,8 +47,7 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(6));
mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(8));
// Add swipe down to refresh gesture
final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.refresh_grid_games);