Fix "Simplified track" and "Show on map" buttons

This commit is contained in:
Dima-1 2020-09-05 13:02:30 +03:00
parent 1b2e3203ad
commit 1d2dbfc10b
2 changed files with 43 additions and 22 deletions

View file

@ -53,6 +53,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
public void setDescription(CharSequence description) { public void setDescription(CharSequence description) {
this.description = description; this.description = description;
descriptionTv.setText(description); descriptionTv.setText(description);
changeDescriptionVisibility();
} }
public void setDescriptionMaxLines(int maxLines) { public void setDescriptionMaxLines(int maxLines) {
@ -76,11 +77,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
super.inflate(context, container, nightMode); super.inflate(context, container, nightMode);
descriptionTv = view.findViewById(R.id.description); descriptionTv = view.findViewById(R.id.description);
if (descriptionTv != null) { if (descriptionTv != null) {
if (Algorithms.isEmpty(description)) { changeDescriptionVisibility();
descriptionTv.setVisibility(View.GONE);
} else {
descriptionTv.setVisibility(View.VISIBLE);
}
descriptionTv.setText(description); descriptionTv.setText(description);
if (descriptionColorId != INVALID_ID) { if (descriptionColorId != INVALID_ID) {
descriptionTv.setTextColor(ContextCompat.getColor(context, descriptionColorId)); 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 { public static class Builder extends SimpleBottomSheetItem.Builder {
protected CharSequence description; protected CharSequence description;

View file

@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; 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))); 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 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]; final BottomSheetItemWithCompoundButton[] simplifiedTrackItem = new BottomSheetItemWithCompoundButton[1];
simplifiedTrackItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() simplifiedTrackItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setChecked(simplifiedTrack) .setChecked(simplifiedTrack)
.setCompoundButtonColorId(activeColorRes) .setCompoundButtonColorId(activeColorRes)
.setDescription(getString(R.string.simplified_track_description)) .setDescription(getSimplifiedTrackDescription())
.setBackground(background) .setBackground(getBackground(simplifiedTrack))
.setTitle(getString(R.string.simplified_track)) .setTitle(getString(R.string.simplified_track))
.setLayoutId(R.layout.bottom_sheet_item_with_switch_and_descr) .setLayoutId(R.layout.bottom_sheet_item_with_switch_and_descr)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@ -136,6 +129,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
public void onClick(View v) { public void onClick(View v) {
simplifiedTrack = !simplifiedTrack; simplifiedTrack = !simplifiedTrack;
simplifiedTrackItem[0].setChecked(simplifiedTrack); simplifiedTrackItem[0].setChecked(simplifiedTrack);
AndroidUtils.setBackground(simplifiedTrackItem[0].getView(), getBackground(simplifiedTrack));
simplifiedTrackItem[0].setDescription(getSimplifiedTrackDescription());
} }
}) })
.create(); .create();
@ -143,16 +138,11 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.content_padding))); 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]; final BottomSheetItemWithCompoundButton[] showOnMapItem = new BottomSheetItemWithCompoundButton[1];
showOnMapItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() showOnMapItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setCompoundButtonColorId(activeColorRes) .setCompoundButtonColorId(activeColorRes)
.setChecked(showOnMap) .setChecked(showOnMap)
.setBackground(background) .setBackground(getBackground(showOnMap))
.setTitle(getString(R.string.shared_string_show_on_map)) .setTitle(getString(R.string.shared_string_show_on_map))
.setLayoutId(R.layout.bottom_sheet_item_with_switch_and_descr) .setLayoutId(R.layout.bottom_sheet_item_with_switch_and_descr)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@ -160,6 +150,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
public void onClick(View v) { public void onClick(View v) {
showOnMap = !showOnMap; showOnMap = !showOnMap;
showOnMapItem[0].setChecked(showOnMap); showOnMapItem[0].setChecked(showOnMap);
AndroidUtils.setBackground(showOnMapItem[0].getView(), getBackground(showOnMap));
} }
}) })
.create(); .create();
@ -168,6 +159,31 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
items.add(new DividerSpaceItem(app, contentPaddingSmall)); 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() { private FolderListAdapter.FolderListAdapterListener createFolderSelectListener() {
return new FolderListAdapter.FolderListAdapterListener() { return new FolderListAdapter.FolderListAdapterListener() {
@Override @Override