From 0c71ba7aaf04977f134b2686ae754459b17f1939 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Sun, 29 Dec 2019 12:23:47 +0300 Subject: [PATCH] Fix bottom sheet items context --- .../plus/base/MenuBottomSheetDialogFragment.java | 4 ++-- .../plus/base/bottomsheetmenu/BaseBottomSheetItem.java | 9 +++++---- .../BottomSheetItemTitleWithDescrAndButton.java | 7 ++++--- .../BottomSheetItemWithCompoundButton.java | 7 ++++--- .../BottomSheetItemWithDescription.java | 7 ++++--- .../HorizontalRecyclerBottomSheetItem.java | 5 +++-- .../base/bottomsheetmenu/SimpleBottomSheetItem.java | 7 ++++--- .../base/bottomsheetmenu/simpleitems/DividerItem.java | 10 +++++----- .../base/bottomsheetmenu/simpleitems/TitleItem.java | 5 +++-- .../plus/dialogs/PluginInstalledBottomSheetDialog.java | 6 ++++-- .../routepreparationmenu/RouteOptionsBottomSheet.java | 6 ++++-- 11 files changed, 42 insertions(+), 31 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index d6045edec7..ef695674f4 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -145,9 +145,9 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra public abstract void createMenuItems(Bundle savedInstanceState); protected void inflateMenuItems() { - OsmandApplication app = getMyApplication(); + Activity activity = requireActivity(); for (BaseBottomSheetItem item : items) { - item.inflate(app, itemsContainer, nightMode); + item.inflate(activity, itemsContainer, nightMode); } } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java index ee0451ef20..f330d7e811 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -1,5 +1,6 @@ package net.osmand.plus.base.bottomsheetmenu; +import android.content.Context; import android.support.annotation.LayoutRes; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -49,8 +50,8 @@ public class BaseBottomSheetItem { } - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { - View view = getView(app, container, nightMode); + public void inflate(Context context, ViewGroup container, boolean nightMode) { + View view = getView(context, container, nightMode); if (tag != null) { view.setTag(tag); } @@ -67,13 +68,13 @@ public class BaseBottomSheetItem { } } - private View getView(OsmandApplication app, ViewGroup parent, boolean nightMode) { + private View getView(Context context, ViewGroup parent, boolean nightMode) { if (view != null) { return view; } if (layoutId != INVALID_ID) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - return view = LayoutInflater.from(new ContextThemeWrapper(app, themeRes)) + return view = LayoutInflater.from(new ContextThemeWrapper(context, themeRes)) .inflate(layoutId, parent, false); } throw new RuntimeException("BottomSheetItem must have specified view or layoutId."); diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemTitleWithDescrAndButton.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemTitleWithDescrAndButton.java index 9b17400b29..4bbb7e604f 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemTitleWithDescrAndButton.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemTitleWithDescrAndButton.java @@ -1,5 +1,6 @@ package net.osmand.plus.base.bottomsheetmenu; +import android.content.Context; import android.graphics.drawable.Drawable; import android.support.annotation.ColorRes; import android.support.annotation.LayoutRes; @@ -73,14 +74,14 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD } @Override - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { - super.inflate(app, container, nightMode); + public void inflate(Context context, ViewGroup container, boolean nightMode) { + super.inflate(context, container, nightMode); textButtonTV = (TextView) view.findViewById(R.id.text_button); textButtonTV.setOnClickListener(onButtonClickListener); textButtonTV.setCompoundDrawablesWithIntrinsicBounds(leftCompoundDrawable, null, rightCompoundDrawable, null); textButtonTV.setText(buttonTitle); if (buttonTextColor != INVALID_ID) { - textButtonTV.setTextColor(ContextCompat.getColor(app, buttonTextColor)); + textButtonTV.setTextColor(ContextCompat.getColor(context, buttonTextColor)); } } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java index ad37ad9e66..283abd6d63 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java @@ -1,5 +1,6 @@ package net.osmand.plus.base.bottomsheetmenu; +import android.content.Context; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.support.annotation.ColorRes; @@ -76,14 +77,14 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri } @Override - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { - super.inflate(app, container, nightMode); + public void inflate(Context context, ViewGroup container, boolean nightMode) { + super.inflate(context, container, nightMode); compoundButton = (CompoundButton) view.findViewById(R.id.compound_button); if (compoundButton != null) { compoundButton.setChecked(checked); compoundButton.setOnCheckedChangeListener(onCheckedChangeListener); if (compoundButtonColorId != INVALID_ID) { - UiUtilities.setupCompoundButton(nightMode, ContextCompat.getColor(app, compoundButtonColorId), compoundButton); + UiUtilities.setupCompoundButton(nightMode, ContextCompat.getColor(context, compoundButtonColorId), compoundButton); } else { CompoundButtonCompat.setButtonTintList(compoundButton, buttonTintList); } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index ae08050abf..ee0f69110f 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -1,5 +1,6 @@ package net.osmand.plus.base.bottomsheetmenu; +import android.content.Context; import android.graphics.drawable.Drawable; import android.support.annotation.ColorRes; import android.support.annotation.LayoutRes; @@ -68,13 +69,13 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { } @Override - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { - super.inflate(app, container, nightMode); + public void inflate(Context context, ViewGroup container, boolean nightMode) { + super.inflate(context, container, nightMode); descriptionTv = (TextView) view.findViewById(R.id.description); if (descriptionTv != null) { descriptionTv.setText(description); if (descriptionColorId != INVALID_ID) { - descriptionTv.setTextColor(ContextCompat.getColor(app, descriptionColorId)); + descriptionTv.setTextColor(ContextCompat.getColor(context, descriptionColorId)); } if (descriptionMaxLines != INVALID_VALUE) { descriptionTv.setMaxLines(descriptionMaxLines); diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/HorizontalRecyclerBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/HorizontalRecyclerBottomSheetItem.java index 76e3d835ac..890c2bb534 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/HorizontalRecyclerBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/HorizontalRecyclerBottomSheetItem.java @@ -1,5 +1,6 @@ package net.osmand.plus.base.bottomsheetmenu; +import android.content.Context; import android.support.annotation.LayoutRes; import android.support.v7.widget.RecyclerView; import android.view.View; @@ -35,8 +36,8 @@ public class HorizontalRecyclerBottomSheetItem extends BaseBottomSheetItem { } @Override - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { - super.inflate(app, container, nightMode); + public void inflate(Context context, ViewGroup container, boolean nightMode) { + super.inflate(context, container, nightMode); recyclerView = ((RecyclerView) view.findViewById(R.id.recycler_view)); if (recyclerView != null && adapter != null) { recyclerView.setAdapter(adapter); diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index cff7feb2e3..569a49f123 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -1,5 +1,6 @@ package net.osmand.plus.base.bottomsheetmenu; +import android.content.Context; import android.graphics.drawable.Drawable; import android.support.annotation.ColorRes; import android.support.annotation.LayoutRes; @@ -52,8 +53,8 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { } @Override - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { - super.inflate(app, container, nightMode); + public void inflate(Context context, ViewGroup container, boolean nightMode) { + super.inflate(context, container, nightMode); iconView = ((ImageView) view.findViewById(R.id.icon)); if (iconView != null) { iconView.setImageDrawable(icon); @@ -62,7 +63,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { if (title != null && titleTv != null) { titleTv.setText(title); if (titleColorId != INVALID_ID) { - titleTv.setTextColor(ContextCompat.getColor(app, titleColorId)); + titleTv.setTextColor(ContextCompat.getColor(context, titleColorId)); } } } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java index 797d3ce54b..f809e123e1 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java @@ -36,17 +36,17 @@ public class DividerItem extends BaseBottomSheetItem { } @Override - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { - super.inflate(app, container, nightMode); + public void inflate(Context context, ViewGroup container, boolean nightMode) { + super.inflate(context, container, nightMode); - int height = AndroidUtils.dpToPx(app, 1); + int height = AndroidUtils.dpToPx(context, 1); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); - params.setMargins(getLeftMargin(app), getTopMargin(app), 0, getBottomMargin(app)); + params.setMargins(getLeftMargin(context), getTopMargin(context), 0, getBottomMargin(context)); params.height = height; view.setMinimumHeight(height); - view.setBackgroundColor(ContextCompat.getColor(app, getBgColorId(nightMode))); + view.setBackgroundColor(ContextCompat.getColor(context, getBgColorId(nightMode))); } protected int getTopMargin(Context context) { diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java index 067bb8b7d6..79709828d3 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java @@ -1,5 +1,6 @@ package net.osmand.plus.base.bottomsheetmenu.simpleitems; +import android.content.Context; import android.support.annotation.ColorRes; import android.view.ViewGroup; @@ -21,10 +22,10 @@ public class TitleItem extends SimpleBottomSheetItem { } @Override - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { + public void inflate(Context context, ViewGroup container, boolean nightMode) { if (titleColorId == INVALID_ID) { titleColorId = nightMode ? R.color.text_color_primary_dark : INVALID_ID; } - super.inflate(app, container, nightMode); + super.inflate(context, container, nightMode); } } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java index c4170a886b..25d84a2735 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java @@ -1,5 +1,6 @@ package net.osmand.plus.dialogs; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; @@ -276,8 +277,9 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm } private void updateItems() { + Activity activity = getActivity(); View mainView = getView(); - if (mainView != null) { + if (activity != null && mainView != null) { LinearLayout itemsContainer = (LinearLayout) mainView.findViewById(useScrollableItemsContainer() ? R.id.scrollable_items_container : R.id.non_scrollable_items_container); if (itemsContainer != null) { @@ -286,7 +288,7 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm items.clear(); createMenuItems(null); for (BaseBottomSheetItem item : items) { - item.inflate(getMyApplication(), itemsContainer, nightMode); + item.inflate(activity, itemsContainer, nightMode); } setupHeightAndBackground(mainView); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 2c5f85b3dc..370c14a4c1 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -1,5 +1,6 @@ package net.osmand.plus.routepreparationmenu; +import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.annotation.ColorRes; @@ -474,8 +475,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { } private void updateParameters() { + Activity activity = getActivity(); View mainView = getView(); - if (mainView != null) { + if (activity != null && mainView != null) { LinearLayout itemsContainer = (LinearLayout) mainView.findViewById(useScrollableItemsContainer() ? R.id.scrollable_items_container : R.id.non_scrollable_items_container); if (itemsContainer != null) { @@ -484,7 +486,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { items.clear(); createMenuItems(null); for (BaseBottomSheetItem item : items) { - item.inflate(app, itemsContainer, nightMode); + item.inflate(activity, itemsContainer, nightMode); } setupHeightAndBackground(mainView); }