Add ability to using non-scrollable container for BottomSheetMenu items
This commit is contained in:
parent
f16f1a3ac8
commit
fd43a3c59e
3 changed files with 32 additions and 11 deletions
|
@ -14,7 +14,7 @@
|
|||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/items_container"
|
||||
android:id="@+id/scrollable_items_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
|
@ -22,6 +22,13 @@
|
|||
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/non_scrollable_items_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/bottom_row_divider"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -62,7 +62,13 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
View mainView = View.inflate(new ContextThemeWrapper(app, themeRes), R.layout.bottom_sheet_menu_base, null);
|
||||
itemsContainer = (LinearLayout) mainView.findViewById(R.id.items_container);
|
||||
if (useScrollableItemsContainer()) {
|
||||
itemsContainer = (LinearLayout) mainView.findViewById(R.id.scrollable_items_container);
|
||||
} else {
|
||||
mainView.findViewById(R.id.scroll_view).setVisibility(View.GONE);
|
||||
itemsContainer = (LinearLayout) mainView.findViewById(R.id.non_scrollable_items_container);
|
||||
itemsContainer.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
for (BaseBottomSheetItem item : items) {
|
||||
item.inflate(app, itemsContainer, nightMode);
|
||||
|
@ -130,21 +136,20 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
|
||||
protected void setupHeightAndBackground(final View mainView) {
|
||||
final Activity activity = getActivity();
|
||||
|
||||
final int screenHeight = AndroidUtils.getScreenHeight(activity);
|
||||
final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity);
|
||||
final int navBarHeight = AndroidUtils.getNavBarHeight(activity);
|
||||
final int availableHeight = screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(activity)
|
||||
- AndroidUtils.dpToPx(getContext(), 1) // divider height
|
||||
- getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); // bottom row height
|
||||
|
||||
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
final View scrollView = mainView.findViewById(R.id.scroll_view);
|
||||
int scrollViewHeight = scrollView.getHeight();
|
||||
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
|
||||
int bottomRowHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
|
||||
int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - bottomRowHeight;
|
||||
if (scrollViewHeight > spaceForScrollView) {
|
||||
scrollView.getLayoutParams().height = spaceForScrollView;
|
||||
scrollView.requestLayout();
|
||||
final View viewToAdjust = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer;
|
||||
if (viewToAdjust.getHeight() > availableHeight) {
|
||||
viewToAdjust.getLayoutParams().height = availableHeight;
|
||||
viewToAdjust.requestLayout();
|
||||
}
|
||||
|
||||
// 8dp is the shadow height
|
||||
|
@ -165,6 +170,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
});
|
||||
}
|
||||
|
||||
protected boolean useScrollableItemsContainer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
protected int getBottomDividerColorId() {
|
||||
return -1;
|
||||
|
|
|
@ -77,6 +77,11 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useScrollableItemsContainer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showProgressBar() {
|
||||
mainView.findViewById(R.id.groups_recycler_view).setVisibility(View.GONE);
|
||||
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
||||
|
|
Loading…
Reference in a new issue