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">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/items_container"
|
android:id="@+id/scrollable_items_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
@ -22,6 +22,13 @@
|
||||||
|
|
||||||
</ScrollView>
|
</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
|
<View
|
||||||
android:id="@+id/bottom_row_divider"
|
android:id="@+id/bottom_row_divider"
|
||||||
android:layout_width="match_parent"
|
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;
|
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);
|
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) {
|
for (BaseBottomSheetItem item : items) {
|
||||||
item.inflate(app, itemsContainer, nightMode);
|
item.inflate(app, itemsContainer, nightMode);
|
||||||
|
@ -130,21 +136,20 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
||||||
|
|
||||||
protected void setupHeightAndBackground(final View mainView) {
|
protected void setupHeightAndBackground(final View mainView) {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
|
|
||||||
final int screenHeight = AndroidUtils.getScreenHeight(activity);
|
final int screenHeight = AndroidUtils.getScreenHeight(activity);
|
||||||
final int statusBarHeight = AndroidUtils.getStatusBarHeight(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() {
|
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
final View scrollView = mainView.findViewById(R.id.scroll_view);
|
final View viewToAdjust = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer;
|
||||||
int scrollViewHeight = scrollView.getHeight();
|
if (viewToAdjust.getHeight() > availableHeight) {
|
||||||
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
|
viewToAdjust.getLayoutParams().height = availableHeight;
|
||||||
int bottomRowHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
|
viewToAdjust.requestLayout();
|
||||||
int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - bottomRowHeight;
|
|
||||||
if (scrollViewHeight > spaceForScrollView) {
|
|
||||||
scrollView.getLayoutParams().height = spaceForScrollView;
|
|
||||||
scrollView.requestLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8dp is the shadow height
|
// 8dp is the shadow height
|
||||||
|
@ -165,6 +170,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean useScrollableItemsContainer() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@ColorRes
|
@ColorRes
|
||||||
protected int getBottomDividerColorId() {
|
protected int getBottomDividerColorId() {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -77,6 +77,11 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean useScrollableItemsContainer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void showProgressBar() {
|
private void showProgressBar() {
|
||||||
mainView.findViewById(R.id.groups_recycler_view).setVisibility(View.GONE);
|
mainView.findViewById(R.id.groups_recycler_view).setVisibility(View.GONE);
|
||||||
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
||||||
|
|
Loading…
Reference in a new issue