Skip to content

Commit

Permalink
keep state when screen orientation changed
Browse files Browse the repository at this point in the history
  • Loading branch information
REBOOTERS authored and gejiaheng committed May 2, 2018
1 parent 94318f0 commit 36737c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public abstract class BasePreviewActivity extends AppCompatActivity implements V
public static final String EXTRA_RESULT_BUNDLE = "extra_result_bundle";
public static final String EXTRA_RESULT_APPLY = "extra_result_apply";
public static final String EXTRA_RESULT_ORIGINAL_ENABLE = "extra_result_original_enable";
public static final String CHECK_STATE = "checkState";

protected final SelectedItemCollection mSelectedCollection = new SelectedItemCollection(this);
protected SelectionSpec mSpec;
Expand Down Expand Up @@ -80,10 +81,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

if (savedInstanceState == null) {
mSelectedCollection.onCreate(getIntent().getBundleExtra(EXTRA_DEFAULT_BUNDLE));
mOriginalEnable = getIntent().getBooleanExtra(EXTRA_RESULT_ORIGINAL_ENABLE, false);
} else {
mSelectedCollection.onCreate(savedInstanceState);
mOriginalEnable = savedInstanceState.getBoolean(CHECK_STATE);
}
mOriginalEnable = getIntent().getBooleanExtra(EXTRA_RESULT_ORIGINAL_ENABLE, false);
mButtonBack = (TextView) findViewById(R.id.button_back);
mButtonApply = (TextView) findViewById(R.id.button_apply);
mSize = (TextView) findViewById(R.id.size);
Expand Down Expand Up @@ -163,6 +165,7 @@ public void onClick(View v) {
@Override
protected void onSaveInstanceState(Bundle outState) {
mSelectedCollection.onSaveInstanceState(outState);
outState.putBoolean("checkState", mOriginalEnable);
super.onSaveInstanceState(outState);
}

Expand Down Expand Up @@ -252,7 +255,7 @@ private void updateOriginalState() {
int selectedCount = mSelectedCollection.count();
if (selectedCount == 0) {
// mOriginal.setChecked(false);
mOriginalEnable = false;
// mOriginalEnable = false;
} else if (countOverMaxSize() > 0) {

if (mOriginalEnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class MatisseActivity extends AppCompatActivity implements
public static final String EXTRA_RESULT_ORIGINAL_ENABLE = "extra_result_original_enable";
private static final int REQUEST_CODE_PREVIEW = 23;
private static final int REQUEST_CODE_CAPTURE = 24;
public static final String CHECK_STATE = "checkState";
private final AlbumCollection mAlbumCollection = new AlbumCollection();
private MediaStoreCompat mMediaStoreCompat;
private SelectedItemCollection mSelectedCollection = new SelectedItemCollection(this);
Expand Down Expand Up @@ -131,6 +132,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mOriginalLayout.setOnClickListener(this);

mSelectedCollection.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mOriginalEnable=savedInstanceState.getBoolean(CHECK_STATE);
}
updateBottomToolbar();

mAlbumsAdapter = new AlbumsAdapter(this, null, false);
Expand All @@ -149,6 +153,7 @@ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mSelectedCollection.onSaveInstanceState(outState);
mAlbumCollection.onSaveInstanceState(outState);
outState.putBoolean("checkState",mOriginalEnable);
}

@Override
Expand Down

0 comments on commit 36737c9

Please sign in to comment.