diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index b138bee19f..afb6319e41 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -53,6 +53,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { public void setDescription(CharSequence description) { this.description = description; descriptionTv.setText(description); + changeDescriptionVisibility(); } public void setDescriptionMaxLines(int maxLines) { @@ -76,11 +77,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { super.inflate(context, container, nightMode); descriptionTv = view.findViewById(R.id.description); if (descriptionTv != null) { - if (Algorithms.isEmpty(description)) { - descriptionTv.setVisibility(View.GONE); - } else { - descriptionTv.setVisibility(View.VISIBLE); - } + changeDescriptionVisibility(); descriptionTv.setText(description); if (descriptionColorId != INVALID_ID) { descriptionTv.setTextColor(ContextCompat.getColor(context, descriptionColorId)); @@ -94,6 +91,14 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { } } + private void changeDescriptionVisibility() { + if (Algorithms.isEmpty(description)) { + descriptionTv.setVisibility(View.GONE); + } else { + descriptionTv.setVisibility(View.VISIBLE); + } + } + public static class Builder extends SimpleBottomSheetItem.Builder { protected CharSequence description; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index d786417301..eb0a69fe06 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool; import android.content.res.ColorStateList; import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; import android.text.Editable; @@ -113,22 +114,14 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.dialog_content_margin))); } + int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; - int backgroundColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode), - R.attr.activity_background_color); - GradientDrawable background = (GradientDrawable) AppCompatResources.getDrawable(app, - R.drawable.bg_select_group_button_outline); - if (background != null) { - background = (GradientDrawable) background.mutate(); - background.setStroke(0, Color.TRANSPARENT); - background.setColor(backgroundColor); - } final BottomSheetItemWithCompoundButton[] simplifiedTrackItem = new BottomSheetItemWithCompoundButton[1]; simplifiedTrackItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() .setChecked(simplifiedTrack) .setCompoundButtonColorId(activeColorRes) - .setDescription(getString(R.string.simplified_track_description)) - .setBackground(background) + .setDescription(getSimplifiedTrackDescription()) + .setBackground(getBackground(simplifiedTrack)) .setTitle(getString(R.string.simplified_track)) .setLayoutId(R.layout.bottom_sheet_item_with_switch_and_descr) .setOnClickListener(new View.OnClickListener() { @@ -136,6 +129,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial public void onClick(View v) { simplifiedTrack = !simplifiedTrack; simplifiedTrackItem[0].setChecked(simplifiedTrack); + AndroidUtils.setBackground(simplifiedTrackItem[0].getView(), getBackground(simplifiedTrack)); + simplifiedTrackItem[0].setDescription(getSimplifiedTrackDescription()); } }) .create(); @@ -143,16 +138,11 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.content_padding))); - background = (GradientDrawable) AppCompatResources.getDrawable(app, R.drawable.bg_select_group_button_outline); - if (background != null) { - background = (GradientDrawable) background.mutate(); - background.setStroke(app.getResources().getDimensionPixelSize(R.dimen.map_button_stroke), backgroundColor); - } final BottomSheetItemWithCompoundButton[] showOnMapItem = new BottomSheetItemWithCompoundButton[1]; showOnMapItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() .setCompoundButtonColorId(activeColorRes) .setChecked(showOnMap) - .setBackground(background) + .setBackground(getBackground(showOnMap)) .setTitle(getString(R.string.shared_string_show_on_map)) .setLayoutId(R.layout.bottom_sheet_item_with_switch_and_descr) .setOnClickListener(new View.OnClickListener() { @@ -160,6 +150,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial public void onClick(View v) { showOnMap = !showOnMap; showOnMapItem[0].setChecked(showOnMap); + AndroidUtils.setBackground(showOnMapItem[0].getView(), getBackground(showOnMap)); } }) .create(); @@ -168,6 +159,31 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial items.add(new DividerSpaceItem(app, contentPaddingSmall)); } + private String getSimplifiedTrackDescription() { + return simplifiedTrack ? getString(R.string.simplified_track_description) : ""; + } + + private Drawable getBackground(boolean checked) { + OsmandApplication app = getMyApplication(); + if (app != null) { + GradientDrawable background = (GradientDrawable) AppCompatResources.getDrawable(app, + R.drawable.bg_select_group_button_outline); + if (background != null) { + int backgroundColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode), + R.attr.activity_background_color); + background = (GradientDrawable) background.mutate(); + if (checked) { + background.setStroke(0, Color.TRANSPARENT); + background.setColor(backgroundColor); + } else { + background.setStroke(app.getResources().getDimensionPixelSize(R.dimen.map_button_stroke), backgroundColor); + } + } + return background; + } + return null; + } + private FolderListAdapter.FolderListAdapterListener createFolderSelectListener() { return new FolderListAdapter.FolderListAdapterListener() { @Override