Skip to content

Commit

Permalink
Retains the state of the bottom sheet on rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 committed Jul 12, 2017
1 parent 94d2234 commit f2597b3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
abstract class AppListActivity extends AppCompatActivity {
private static final String SELECTED_INSTANCES = "selectedInstances";
private static final String IS_SEARCH_BOX_SHOWN = "isSearchBoxShown";
private static final String IS_BOTTOM_DIALOG_SHOWN = "isBottomDialogShown";
protected final ActivityLogger logger = Collect.getInstance().getActivityLogger();
protected SimpleCursorAdapter listAdapter;
protected LinkedHashSet<Long> selectedInstances = new LinkedHashSet<>();
Expand All @@ -65,6 +66,7 @@ abstract class AppListActivity extends AppCompatActivity {
private LinearLayout searchBoxLayout;
private EditText inputSearch;
private boolean isSearchBoxShown;
private boolean isBottomDialogShown;
private BottomSheetDialog bottomSheetDialog;

// toggles to all checked or all unchecked
Expand Down Expand Up @@ -130,24 +132,23 @@ protected void onResume() {
searchBoxLayout = (LinearLayout) findViewById(R.id.searchBoxLayout);
restoreSelectedSortingOrder();
setupSearchBox();

if (bottomSheetDialog == null) {
setupBottomSheet();
}
setupBottomSheet();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(SELECTED_INSTANCES, selectedInstances);
outState.putBoolean(IS_SEARCH_BOX_SHOWN, searchBoxLayout.getVisibility() == View.VISIBLE);
outState.putBoolean(IS_BOTTOM_DIALOG_SHOWN, bottomSheetDialog.isShowing());
}

@Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
selectedInstances = (LinkedHashSet<Long>) state.getSerializable(SELECTED_INSTANCES);
isSearchBoxShown = state.getBoolean(IS_SEARCH_BOX_SHOWN);
isBottomDialogShown = state.getBoolean(IS_BOTTOM_DIALOG_SHOWN);
}

@Override
Expand Down Expand Up @@ -276,7 +277,7 @@ protected CharSequence getFilterText() {
}

private void setupBottomSheet() {
bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog = new BottomSheetDialog(this, R.style.MaterialDialogSheet);
View sheetView = getLayoutInflater().inflate(R.layout.bottom_sheet, null);
final RecyclerView recyclerView = (RecyclerView) sheetView.findViewById(R.id.recyclerView);

Expand All @@ -294,5 +295,9 @@ public void onItemClicked(SortDialogAdapter.ViewHolder holder, int position) {
recyclerView.setItemAnimator(new DefaultItemAnimator());

bottomSheetDialog.setContentView(sheetView);

if (isBottomDialogShown) {
bottomSheetDialog.show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void onResume() {
}

private void setupBottomSheet() {
bottomSheetDialog = new BottomSheetDialog(getActivity());
bottomSheetDialog = new BottomSheetDialog(getActivity(), R.style.MaterialDialogSheet);
View sheetView = getActivity().getLayoutInflater().inflate(R.layout.bottom_sheet, null);
final RecyclerView recyclerView = (RecyclerView) sheetView.findViewById(R.id.recyclerView);

Expand Down
8 changes: 8 additions & 0 deletions collect_app/src/main/res/anim/popup_hide.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="100%p" />
</set>
8 changes: 8 additions & 0 deletions collect_app/src/main/res/anim/popup_show.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0" />
</set>
16 changes: 16 additions & 0 deletions collect_app/src/main/res/values/style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<item name="android:textAllCaps">false</item>
<item name="android:padding">16dp</item>
</style>

<style name="emptyViewStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
Expand All @@ -19,4 +20,19 @@
<item name="android:textSize">21sp</item>
</style>

<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>

<style name="MaterialDialogSheetAnimation">
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>

</resources>

0 comments on commit f2597b3

Please sign in to comment.