android: frontend: gamelist: Save PlatformGamesFragment state.
- Fixes weird duplication of game list on rotation.
This commit is contained in:
parent
e24ec7bb0d
commit
5749f94692
@ -6,6 +6,7 @@ import android.database.Cursor;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -46,23 +47,27 @@ public final class MainActivity extends AppCompatActivity implements MainView {
|
|||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
|
|
||||||
mFrameLayoutId = R.id.games_platform_frame;
|
mFrameLayoutId = R.id.games_platform_frame;
|
||||||
|
|
||||||
// Set up the FAB.
|
|
||||||
mFab.setOnClickListener(view -> mPresenter.onFabClick());
|
mFab.setOnClickListener(view -> mPresenter.onFabClick());
|
||||||
|
|
||||||
mPresenter.onCreate();
|
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);
|
StartupHandler.HandleInit(this);
|
||||||
|
if (PermissionsHandler.hasWriteAccess(this)) {
|
||||||
if (PermissionsHandler.hasWriteAccess(this)) {
|
mPlatformGamesFragment = new PlatformGamesFragment();
|
||||||
mPlatformGamesFragment = new PlatformGamesFragment();
|
getSupportFragmentManager().beginTransaction().add(mFrameLayoutId, mPlatformGamesFragment)
|
||||||
getSupportFragmentManager().beginTransaction().add(mFrameLayoutId, mPlatformGamesFragment)
|
.commit();
|
||||||
.commit();
|
}
|
||||||
|
} else {
|
||||||
|
mPlatformGamesFragment = (PlatformGamesFragment) getSupportFragmentManager().getFragment(savedInstanceState, "mPlatformGamesFragment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
getSupportFragmentManager().putFragment(outState, "mPlatformGamesFragment", mPlatformGamesFragment);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -47,8 +47,7 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
|
|||||||
|
|
||||||
mRecyclerView.setLayoutManager(layoutManager);
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(8));
|
||||||
mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(6));
|
|
||||||
|
|
||||||
// Add swipe down to refresh gesture
|
// Add swipe down to refresh gesture
|
||||||
final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.refresh_grid_games);
|
final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.refresh_grid_games);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user