Fix bottom sheet items context
This commit is contained in:
parent
38d7021c27
commit
0c71ba7aaf
11 changed files with 42 additions and 31 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue