configure map details dialog redesign

This commit is contained in:
veliymolfar 2020-06-02 13:17:33 +03:00
parent c49a7fb069
commit e884e04631
10 changed files with 619 additions and 47 deletions

View file

@ -8,6 +8,9 @@ import java.util.Map;
public class RenderingRuleStorageProperties {
public static final String UI_CATEGORY_HIDDEN = "ui_hidden";
public static final String UI_CATEGORY_DETAILS = "details";
public static final String UI_CATEGORY_HIDE = "hide";
public static final String UI_CATEGORY_ROUTES = "routes";
public static final String A_ENGINE_V1 = "engine_v1";
public static final String A_APP_MODE= "appMode";
public static final String A_BASE_APP_MODE = "baseAppMode";

View file

@ -1,16 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<LinearLayout xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:orientation="horizontal"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding">
android:paddingLeft="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
@ -18,7 +24,7 @@
android:layout_height="@dimen/standard_icon_size"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_coordinates_latitude"/>
tools:src="@drawable/ic_action_coordinates_latitude" />
<TextView
android:id="@+id/title"
@ -30,7 +36,7 @@
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Some Title"/>
tools:text="Some Title" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/compound_button"
@ -40,6 +46,71 @@
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
android:focusableInTouchMode="false"
android:saveEnabled="false" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_btns"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginTop="@dimen/text_margin_small"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding_small"
android:background="?attr/btn_bg_border_inactive"
android:baselineAligned="false"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<FrameLayout
android:id="@+id/left_btn_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/left_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:text="@string/shared_string_hillshade"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" />
</FrameLayout>
<FrameLayout
android:id="@+id/right_btn_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/right_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:text="@string/shared_string_slope"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" />
</FrameLayout>
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:background="?attr/dashboard_divider"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>

View file

@ -11,6 +11,9 @@
Thx - Hardy
-->
<string name="shared_string_all_time">All time</string>
<string name="shared_string_night_map">Night map</string>
<string name="details_dialog_decr">Control visibility of additional details showed on the map</string>
<string name="tiles_storage_descr">Choose how downloaded tiles will be stored.</string>
<string name="expire_time_descr">Expiration time in minutes. Cached tiles will be reloaded after specified time.
Leave this field empty to never refresh tiles for this source.

View file

@ -34,6 +34,8 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
Drawable background,
CharSequence title,
@ColorRes int titleColorId,
boolean iconHidden,
boolean showDivider,
CharSequence description,
@ColorRes int descriptionColorId,
int descriptionMaxLines,
@ -53,6 +55,8 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
background,
title,
titleColorId,
iconHidden,
showDivider,
description,
descriptionColorId,
descriptionMaxLines,
@ -128,6 +132,8 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
background,
title,
titleColorId,
iconHidden,
showDivider,
description,
descriptionColorId,
descriptionMaxLines,

View file

@ -0,0 +1,229 @@
package net.osmand.plus.base.bottomsheetmenu;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.helpers.AndroidUiHelper;
public class BottomSheetItemTwoChoicesButton extends BottomSheetItemWithCompoundButton {
private LinearLayout bottomButtons;
private FrameLayout leftBtnContainer;
private FrameLayout rightBtnContainer;
private TextView leftBtn;
private TextView rightBtn;
@StringRes
private int leftBtnTitleRes;
@StringRes
private int rightBtnTitleRes;
private boolean isLeftBtnSelected;
private OnBottomBtnClickListener onBottomBtnClickListener;
private int bottomBtnBgRadius;
private int bottomBtnTextColor;
private int activeColor;
private GradientDrawable bottomBtnBg;
public BottomSheetItemTwoChoicesButton(View customView,
int layoutId,
Object tag,
boolean disabled,
View.OnClickListener onClickListener,
int position,
Drawable icon,
Drawable background,
CharSequence title,
int titleColorId,
boolean iconHidden,
boolean showDivider,
CharSequence description,
int descriptionColorId,
int descriptionMaxLines,
boolean descriptionLinksClickable,
boolean checked,
ColorStateList buttonTintList,
CompoundButton.OnCheckedChangeListener onCheckedChangeListener,
int compoundButtonColorId,
boolean isLeftBtnSelected,
int leftBtnTitleRes,
int rightBtnTitleRes,
OnBottomBtnClickListener onBottomBtnClickListener) {
super(customView,
layoutId,
tag,
disabled,
onClickListener,
position,
icon,
background,
title,
titleColorId,
iconHidden,
showDivider,
description,
descriptionColorId,
descriptionMaxLines,
descriptionLinksClickable,
checked,
buttonTintList,
onCheckedChangeListener,
compoundButtonColorId);
this.leftBtnTitleRes = leftBtnTitleRes;
this.rightBtnTitleRes = rightBtnTitleRes;
this.isLeftBtnSelected = isLeftBtnSelected;
this.onBottomBtnClickListener = onBottomBtnClickListener;
}
@Override
public void inflate(Context context, ViewGroup container, boolean nightMode) {
super.inflate(context, container, nightMode);
bottomBtnBgRadius = AndroidUtils.dpToPx(context, 4);
bottomBtnTextColor = ContextCompat.getColor(context, nightMode
? R.color.text_color_primary_dark
: R.color.text_color_primary_light);
activeColor = ContextCompat.getColor(context, nightMode
? R.color.active_color_primary_dark
: R.color.active_color_primary_light);
bottomBtnBg = new GradientDrawable();
bottomBtnBg.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f));
bottomBtnBg.setStroke(AndroidUtils.dpToPx(context, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f));
bottomButtons = view.findViewById(R.id.bottom_btns);
leftBtnContainer = view.findViewById(R.id.left_btn_container);
rightBtnContainer = view.findViewById(R.id.right_btn_container);
leftBtn = view.findViewById(R.id.left_btn);
rightBtn = view.findViewById(R.id.right_btn);
AndroidUiHelper.updateVisibility(bottomButtons, isChecked());
if (leftBtn != null) {
leftBtn.setText(leftBtnTitleRes);
leftBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isLeftBtnSelected = true;
if (onBottomBtnClickListener != null) {
onBottomBtnClickListener.onBottomBtnClick(true);
}
updateBottomButtons();
}
});
}
if (rightBtn != null) {
rightBtn.setText(rightBtnTitleRes);
rightBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isLeftBtnSelected = false;
if (onBottomBtnClickListener != null) {
onBottomBtnClickListener.onBottomBtnClick(false);
}
updateBottomButtons();
}
});
}
updateBottomButtons();
}
@Override
public void setChecked(boolean checked) {
super.setChecked(checked);
AndroidUiHelper.updateVisibility(bottomButtons, checked);
updateBottomButtons();
}
private void updateBottomButtons() {
if (bottomBtnBg == null || rightBtn == null || rightBtnContainer == null || leftBtn == null || leftBtnContainer == null) {
return;
}
if (isLeftBtnSelected) {
bottomBtnBg.setCornerRadii(new float[]{bottomBtnBgRadius, bottomBtnBgRadius, 0, 0, 0, 0, bottomBtnBgRadius, bottomBtnBgRadius});
rightBtnContainer.setBackgroundColor(Color.TRANSPARENT);
rightBtn.setTextColor(activeColor);
leftBtnContainer.setBackgroundDrawable(bottomBtnBg);
leftBtn.setTextColor(bottomBtnTextColor);
} else {
bottomBtnBg.setCornerRadii(new float[]{0, 0, bottomBtnBgRadius, bottomBtnBgRadius, bottomBtnBgRadius, bottomBtnBgRadius, 0, 0});
rightBtnContainer.setBackgroundDrawable(bottomBtnBg);
rightBtn.setTextColor(bottomBtnTextColor);
leftBtnContainer.setBackgroundColor(Color.TRANSPARENT);
leftBtn.setTextColor(activeColor);
}
}
public static class Builder extends BottomSheetItemWithCompoundButton.Builder {
@StringRes
private int leftBtnTitleRes;
@StringRes
private int rightBtnTitleRes;
private boolean isLeftBtnSelected;
private OnBottomBtnClickListener onBottomBtnClickListener;
public Builder setLeftBtnTitleRes(int leftBtnTitleRes) {
this.leftBtnTitleRes = leftBtnTitleRes;
return this;
}
public Builder setRightBtnTitleRes(int rightBtnTitleRes) {
this.rightBtnTitleRes = rightBtnTitleRes;
return this;
}
public Builder setLeftBtnSelected(boolean leftBtnSelected) {
isLeftBtnSelected = leftBtnSelected;
return this;
}
public Builder setOnBottomBtnClickListener(OnBottomBtnClickListener onBottomBtnClickListener) {
this.onBottomBtnClickListener = onBottomBtnClickListener;
return this;
}
public BottomSheetItemTwoChoicesButton create() {
return new BottomSheetItemTwoChoicesButton(customView,
layoutId,
tag,
disabled,
onClickListener,
position,
icon,
background,
title,
titleColorId,
iconHidden,
showDivider,
description,
descriptionColorId,
descriptionMaxLines,
descriptionLinksClickable,
checked,
buttonTintList,
onCheckedChangeListener,
compoundButtonColorId,
isLeftBtnSelected,
leftBtnTitleRes,
rightBtnTitleRes,
onBottomBtnClickListener);
}
}
public interface OnBottomBtnClickListener {
void onBottomBtnClick(boolean onLeftClick);
}
}

View file

@ -39,6 +39,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
Drawable background,
CharSequence title,
@ColorRes int titleColorId,
boolean iconHidden,
boolean showDivider,
CharSequence description,
@ColorRes int descriptionColorId,
int descriptionMaxLines,
@ -57,6 +59,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
background,
title,
titleColorId,
iconHidden,
showDivider,
description,
descriptionColorId,
descriptionMaxLines,
@ -135,6 +139,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
background,
title,
titleColorId,
iconHidden,
showDivider,
description,
descriptionColorId,
descriptionMaxLines,

View file

@ -33,11 +33,13 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
Drawable background,
CharSequence title,
@ColorRes int titleColorId,
boolean iconHidden,
boolean showDivider,
CharSequence description,
@ColorRes int descriptionColorId,
int descriptionMaxLines,
boolean descriptionLinksClickable) {
super(customView, layoutId, tag, disabled, onClickListener, position, icon, background, title, titleColorId);
super(customView, layoutId, tag, disabled, onClickListener, position, icon, background, title, titleColorId, iconHidden, showDivider);
this.description = description;
this.descriptionColorId = descriptionColorId;
this.descriptionMaxLines = descriptionMaxLines;
@ -126,6 +128,8 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
background,
title,
titleColorId,
iconHidden,
showDivider,
description,
descriptionColorId,
descriptionMaxLines,

View file

@ -18,12 +18,15 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
private Drawable background;
private Drawable icon;
private boolean iconHidden;
private boolean showDivider;
protected CharSequence title;
@ColorRes
protected int titleColorId = INVALID_ID;
private TextView titleTv;
private ImageView iconView;
private View divider;
public SimpleBottomSheetItem(View customView,
@LayoutRes int layoutId,
@ -34,12 +37,16 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
Drawable icon,
Drawable background,
CharSequence title,
@ColorRes int titleColorId) {
@ColorRes int titleColorId,
boolean iconHidden,
boolean showDivider) {
super(customView, layoutId, tag, disabled, onClickListener, position);
this.icon = icon;
this.background = background;
this.title = title;
this.titleColorId = titleColorId;
this.iconHidden = iconHidden;
this.showDivider = showDivider;
}
protected SimpleBottomSheetItem() {
@ -67,6 +74,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
iconView = ((ImageView) view.findViewById(R.id.icon));
if (iconView != null) {
iconView.setImageDrawable(icon);
iconView.setVisibility(iconHidden ? View.GONE : View.VISIBLE);
}
titleTv = (TextView) view.findViewById(R.id.title);
if (title != null && titleTv != null) {
@ -78,6 +86,10 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
if (background != null) {
AndroidUtils.setBackground(view, background);
}
divider = view.findViewById(R.id.divider);
if (divider != null) {
divider.setVisibility(showDivider ? View.VISIBLE : View.GONE);
}
}
public static class Builder extends BaseBottomSheetItem.Builder {
@ -87,6 +99,8 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
protected CharSequence title;
@ColorRes
protected int titleColorId = INVALID_ID;
protected boolean iconHidden;
protected boolean showDivider;
public Builder setIcon(Drawable icon) {
this.icon = icon;
@ -108,6 +122,16 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
return this;
}
public Builder setIconHidden(boolean iconHidden) {
this.iconHidden = iconHidden;
return this;
}
public Builder setShowDivider(boolean showDivider) {
this.showDivider = showDivider;
return this;
}
public SimpleBottomSheetItem create() {
return new SimpleBottomSheetItem(customView,
layoutId,
@ -118,7 +142,9 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
icon,
background,
title,
titleColorId);
titleColorId,
iconHidden,
showDivider);
}
}
}

View file

@ -107,6 +107,9 @@ import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_ATTR;
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_SCHEME_ATTR;
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_WIDTH_ATTR;
import static net.osmand.plus.transport.TransportLinesMenu.RENDERING_CATEGORY_TRANSPORT;
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_DETAILS;
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_HIDE;
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_ROUTES;
public class ConfigureMapMenu {
private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class);
@ -784,12 +787,12 @@ public class ConfigureMapMenu {
.createItem());
props = createProperties(customRules, null, R.string.rendering_category_details, R.drawable.ic_action_layers,
"details", null, adapter, activity, true, DETAILS_ID, themeRes, nightMode, selectedProfileColor);
UI_CATEGORY_DETAILS, null, adapter, activity, true, DETAILS_ID, themeRes, nightMode, selectedProfileColor);
if (props != null) {
adapter.addItem(props);
}
props = createProperties(customRules, null, R.string.rendering_category_hide, R.drawable.ic_action_hide,
"hide", null, adapter, activity, true, HIDE_ID, themeRes, nightMode, selectedProfileColor);
UI_CATEGORY_HIDE, null, adapter, activity, true, HIDE_ID, themeRes, nightMode, selectedProfileColor);
if (props != null) {
adapter.addItem(props);
}
@ -801,7 +804,7 @@ public class ConfigureMapMenu {
}
}
props = createProperties(customRules, customRulesIncluded, R.string.rendering_category_routes, R.drawable.ic_action_map_routes,
"routes", null, adapter, activity, true, ROUTES_ID, themeRes, nightMode, selectedProfileColor);
UI_CATEGORY_ROUTES, null, adapter, activity, true, ROUTES_ID, themeRes, nightMode, selectedProfileColor);
if (props != null) {
adapter.addItem(props);
}
@ -859,7 +862,7 @@ public class ConfigureMapMenu {
final List<RenderingRuleProperty> customRulesIncluded,
@StringRes final int strId,
@DrawableRes final int icon,
String category,
final String category,
final ListStringPreference defaultSettings,
final ContextMenuAdapter adapter,
final MapActivity activity,
@ -914,10 +917,14 @@ public class ConfigureMapMenu {
a.notifyDataSetInvalidated();
refreshMapComplete(activity);
activity.getMapLayers().updateLayers(activity.getMapView());
} else {
if (UI_CATEGORY_DETAILS.equals(category)) {
DetailsBottomSheet.showInstance(activity.getSupportFragmentManager(), ps, prefs, a, adapter, pos);
} else {
showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs,
useDescription, defaultSettings, true, customRulesIncluded, themeRes, nightMode, selectedProfileColor);
}
}
return false;
}

View file

@ -0,0 +1,217 @@
package net.osmand.plus.dialogs;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.fragment.app.FragmentManager;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTwoChoicesButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import net.osmand.render.RenderingRule;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRuleStorageProperties;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static net.osmand.plus.transport.TransportLinesMenu.RENDERING_CATEGORY_TRANSPORT;
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_DETAILS;
public class DetailsBottomSheet extends BasePreferenceBottomSheet {
public static final String TAG = DetailsBottomSheet.class.getName();
private List<RenderingRuleProperty> properties;
private List<CommonPreference<Boolean>> preferences;
private ArrayAdapter<?> arrayAdapter;
private ContextMenuAdapter adapter;
private int position;
public static void showInstance(@NonNull FragmentManager fm,
List<RenderingRuleProperty> properties,
List<CommonPreference<Boolean>> preferences,
ArrayAdapter<?> arrayAdapter,
ContextMenuAdapter adapter,
int position) {
DetailsBottomSheet bottomSheet = new DetailsBottomSheet();
bottomSheet.setProperties(properties);
bottomSheet.setPreferences(preferences);
bottomSheet.setAdapter(adapter);
bottomSheet.setPosition(position);
bottomSheet.setArrayAdapter(arrayAdapter);
bottomSheet.show(fm, TAG);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (properties == null || preferences == null) {
properties = new ArrayList<>();
preferences = new ArrayList<>();
List<RenderingRuleProperty> customRules = ConfigureMapMenu.getCustomRules(requiredMyApplication(),
RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN, RENDERING_CATEGORY_TRANSPORT);
for (RenderingRuleProperty pr : customRules) {
if (UI_CATEGORY_DETAILS.equals(pr.getCategory()) && pr.isBoolean()) {
properties.add(pr);
final OsmandSettings.CommonPreference<Boolean> pref = requiredMyApplication().getSettings()
.getCustomRenderBooleanProperty(pr.getAttrName());
preferences.add(pref);
}
}
}
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
int selectedProfileColorRes = requiredMyApplication().getSettings().APPLICATION_MODE.get().getIconColorInfo().getColor(nightMode);
TitleItem titleItem = new TitleItem(getString(R.string.rendering_category_details));
items.add(titleItem);
ShortDescriptionItem descriptionItem = new ShortDescriptionItem(getString(R.string.details_dialog_decr));
items.add(descriptionItem);
if (preferences != null && properties != null) {
for (int i = 0; i < properties.size(); i++) {
RenderingRuleProperty property = properties.get(i);
RenderingRuleProperty nextProperty = i + 1 < properties.size() - 1 ? properties.get(i + 1) : null;
final CommonPreference<Boolean> pref = preferences.get(i);
final CommonPreference<Boolean> nextPref = i + 1 < preferences.size() - 1 ? preferences.get(i + 1) : null;
final int tag = i;
String attrName = property.getAttrName();
boolean showDivider = "moreDetailed".equals(attrName) || "showSurfaceGrade".equals(attrName) || "coloredBuildings".equals(attrName) || "streetLighting".equals(attrName);
if ("streetLighting".equals(property.getAttrName())
&& nextProperty != null
&& "streetLightingNight".equals(nextProperty.getAttrName())
&& nextPref != null) {
BaseBottomSheetItem item = new BottomSheetItemTwoChoicesButton.Builder()
.setLeftBtnSelected(!nextPref.get())
.setLeftBtnTitleRes(R.string.shared_string_all_time)
.setRightBtnTitleRes(R.string.shared_string_night_map)
.setOnBottomBtnClickListener(new BottomSheetItemTwoChoicesButton.OnBottomBtnClickListener() {
@Override
public void onBottomBtnClick(boolean onLeftClick) {
nextPref.set(!onLeftClick);
}
})
.setCompoundButtonColorId(selectedProfileColorRes)
.setChecked(pref.get())
.setTitle(property.getName())
.setIconHidden(true)
.setShowDivider(showDivider)
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean checked = !pref.get();
pref.set(checked);
nextPref.set(false);
updateItem(tag);
}
})
.setTag(tag)
.create();
items.add(item);
} else if (!"streetLightingNight".equals(property.getAttrName())) {
BaseBottomSheetItem item = new BottomSheetItemWithCompoundButton.Builder()
.setCompoundButtonColorId(selectedProfileColorRes)
.setChecked(pref.get())
.setTitle(property.getName())
.setIconHidden(true)
.setShowDivider(showDivider)
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean checked = !pref.get();
pref.set(checked);
updateItem(tag);
}
})
.setTag(tag)
.create();
items.add(item);
}
}
}
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_close;
}
@Override
public void onDismiss(@NonNull DialogInterface dialog) {
boolean checked = false;
int selected = 0;
for (int i = 0; i < preferences.size(); i++) {
boolean active = preferences.get(i).get();
checked |= active;
if (active) {
selected++;
}
}
if (adapter != null) {
adapter.getItem(position).setSelected(checked);
adapter.getItem(position).setColorRes(checked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.getItem(position).setDescription(getString(
R.string.ltr_or_rtl_combine_via_slash,
String.valueOf(selected),
String.valueOf(preferences.size())));
}
if (arrayAdapter != null) {
arrayAdapter.notifyDataSetInvalidated();
}
Activity activity = getActivity();
if (activity instanceof MapActivity) {
MapActivity a = (MapActivity) activity;
a.getMyApplication().getResourceManager().getRenderer().clearCache();
a.updateMapSettings();
a.getMapView().refreshMap(true);
a.getMapLayers().updateLayers(a.getMapView());
}
super.onDismiss(dialog);
}
private void updateItem(int tag) {
for (BaseBottomSheetItem item : items) {
Object itemTag = item.getTag();
if (itemTag instanceof Integer && ((Integer) itemTag) == tag) {
((BottomSheetItemWithCompoundButton) item).setChecked(preferences.get(tag).get());
}
}
}
public void setProperties(List<RenderingRuleProperty> properties) {
this.properties = properties;
}
public void setPreferences(List<CommonPreference<Boolean>> preferences) {
this.preferences = preferences;
}
public void setAdapter(ContextMenuAdapter adapter) {
this.adapter = adapter;
}
public void setPosition(int position) {
this.position = position;
}
public void setArrayAdapter(ArrayAdapter<?> arrayAdapter) {
this.arrayAdapter = arrayAdapter;
}
}