Fix background type.

This commit is contained in:
Dima-1 2020-03-17 14:49:20 +02:00
parent 0ff96f333b
commit 889ac143d3
7 changed files with 117 additions and 56 deletions

View file

@ -0,0 +1,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@android:color/transparent" />
<stroke
android:width="2dp"
android:color="@color/divider_color_light" />
</shape>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M21.7071,0.7071L39.2929,18.2929C39.7456,18.7456 40,19.3597 40,20C40,20.6403 39.7456,21.2544 39.2929,21.7071L21.7071,39.2929C21.2544,39.7456 20.6403,40 20,40C19.3597,40 18.7456,39.7456 18.2929,39.2929L0.7071,21.7071C0.2544,21.2544 0,20.6403 0,20C0,19.3597 0.2544,18.7456 0.7071,18.2929L18.2929,0.7071C18.7456,0.2544 19.3597,0 20,0C20.6403,0 21.2544,0.2544 21.7071,0.7071Z"
android:strokeWidth="2"
android:strokeColor="#e6e6e6" />
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M4,1L36,1A3,3 0,0 1,39 4L39,36A3,3 0,0 1,36 39L4,39A3,3 0,0 1,1 36L1,4A3,3 0,0 1,4 1z"
android:strokeWidth="2"
android:strokeColor="#e6e6e6"/>
</vector>

View file

@ -206,7 +206,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
return backgroundType; return backgroundType;
} }
private void setBackgroundType(BackgroundType backgroundType) { public void setBackgroundType(BackgroundType backgroundType) {
this.backgroundType = backgroundType; this.backgroundType = backgroundType;
} }

View file

@ -302,8 +302,10 @@ public class FavouritesDbHelper {
if (FavouritePoint.SpecialPointType.PARKING.equals(p.getSpecialPointType())) { if (FavouritePoint.SpecialPointType.PARKING.equals(p.getSpecialPointType())) {
p.setColor(ContextCompat.getColor(context, R.color.map_widget_blue)); p.setColor(ContextCompat.getColor(context, R.color.map_widget_blue));
} else { } else {
if (p.getColor() == 0) {
p.setColor(group.color); p.setColor(group.color);
} }
}
group.points.add(p); group.points.add(p);
cachedFavoritePoints.add(p); cachedFavoritePoints.add(p);
} }
@ -440,8 +442,10 @@ public class FavouritesDbHelper {
if (FavouritePoint.SpecialPointType.PARKING.equals(p.getSpecialPointType())) { if (FavouritePoint.SpecialPointType.PARKING.equals(p.getSpecialPointType())) {
p.setColor(ContextCompat.getColor(context, R.color.map_widget_blue)); p.setColor(ContextCompat.getColor(context, R.color.map_widget_blue));
} else { } else {
if (p.getColor() == 0) {
p.setColor(pg.color); p.setColor(pg.color);
} }
}
pg.points.add(p); pg.points.add(p);
} }
sortAll(); sortAll();

View file

@ -10,6 +10,8 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@ -38,8 +40,10 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
private FavouritePoint favorite; private FavouritePoint favorite;
@Nullable @Nullable
private FavoriteGroup group; private FavoriteGroup group;
private int color; private int color;
private int iconId;
@NonNull
private FavouritePoint.BackgroundType backgroundType = FavouritePoint.BackgroundType.CIRCLE;
@Nullable @Nullable
FavouritesDbHelper helper; FavouritesDbHelper helper;
@ -71,6 +75,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
this.favorite = favorite; this.favorite = favorite;
this.group = helper.getGroup(favorite); this.group = helper.getGroup(favorite);
this.color = favorite.getColor(); this.color = favorite.getColor();
this.backgroundType = favorite.getBackgroundType();
this.iconId = favorite.getIconId();
} }
} }
@ -176,7 +182,16 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
@Override @Override
public void setColor(int color) { public void setColor(int color) {
this.color = color; this.color = color;
}
@Override
public void setBackgroundType(@NonNull FavouritePoint.BackgroundType backgroundType) {
this.backgroundType = backgroundType;
}
@Override
public void setIcon(int iconId) {
this.iconId = iconId;
} }
@Override @Override
@ -226,11 +241,12 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
getNameTextValue(), getCategoryTextValue()); getNameTextValue(), getCategoryTextValue());
point.setDescription(getDescriptionTextValue()); point.setDescription(getDescriptionTextValue());
point.setColor(color);
point.setBackgroundType(backgroundType);
point.setIconId(iconId);
AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity()); AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity());
if (favorite.getName().equals(point.getName()) && if (isChanged(favorite, point)) {
favorite.getCategory().equals(point.getCategory()) &&
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription())) {
if (needDismiss) { if (needDismiss) {
dismiss(false); dismiss(false);
@ -242,24 +258,39 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss); doSave(favorite, point.getName(), point.getCategory(), point.getDescription(),
point.getColor(), point.getBackgroundType(), point.getIconId(), needDismiss);
} }
}); });
builder.create().show(); builder.create().show();
} else { } else {
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss); doSave(favorite, point.getName(), point.getCategory(), point.getDescription(),
point.getColor(), point.getBackgroundType(), point.getIconId(), needDismiss);
} }
saved = true; saved = true;
} }
} }
private void doSave(FavouritePoint favorite, String name, String category, String description, boolean needDismiss) { private boolean isChanged(FavouritePoint favorite, FavouritePoint point) {
return favorite.getColor() == point.getColor() &&
favorite.getIconId() == point.getIconId() &&
favorite.getName().equals(point.getName()) &&
favorite.getCategory().equals(point.getCategory()) &&
favorite.getBackgroundType().equals(point.getBackgroundType()) &&
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription());
}
private void doSave(FavouritePoint favorite, String name, String category, String description,
@ColorInt int color, FavouritePoint.BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) {
FavouritesDbHelper helper = getHelper(); FavouritesDbHelper helper = getHelper();
FavoritePointEditor editor = getFavoritePointEditor(); FavoritePointEditor editor = getFavoritePointEditor();
if (editor != null && helper != null) { if (editor != null && helper != null) {
if (editor.isNew()) { if (editor.isNew()) {
doAddFavorite(name, category, description); doAddFavorite(name, category, description, color, backgroundType, iconId);
} else { } else {
favorite.setColor(color);
favorite.setBackgroundType(backgroundType);
favorite.setIconId(iconId);
helper.editFavouriteName(favorite, name, category, description); helper.editFavouriteName(favorite, name, category, description);
} }
} }
@ -279,7 +310,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
} }
} }
private void doAddFavorite(String name, String category, String description) { private void doAddFavorite(String name, String category, String description, @ColorInt int color,
FavouritePoint.BackgroundType backgroundType, @DrawableRes int iconId) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
FavouritesDbHelper helper = getHelper(); FavouritesDbHelper helper = getHelper();
FavouritePoint favorite = getFavorite(); FavouritePoint favorite = getFavorite();
@ -287,6 +319,9 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
favorite.setName(name); favorite.setName(name);
favorite.setCategory(category); favorite.setCategory(category);
favorite.setDescription(description); favorite.setDescription(description);
favorite.setColor(color);
favorite.setBackgroundType(backgroundType);
favorite.setIconId(iconId);
app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category); app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category);
helper.addFavourite(favorite); helper.addFavourite(favorite);
} }
@ -374,6 +409,12 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
return color; return color;
} }
@Override
@NonNull
public FavouritePoint.BackgroundType getBackgroundType() {
return backgroundType;
}
private int getColor() { private int getColor() {
return color; return color;
} }

View file

@ -68,7 +68,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
private Button addDelDescription; private Button addDelDescription;
private boolean cancelled; private boolean cancelled;
private boolean nightMode; private boolean nightMode;
private String selectedIcon; private int selectedIcon;
@ColorInt @ColorInt
private int selectedColor; private int selectedColor;
private FavouritePoint.BackgroundType selectedShape = FavouritePoint.BackgroundType.CIRCLE; private FavouritePoint.BackgroundType selectedShape = FavouritePoint.BackgroundType.CIRCLE;
@ -91,6 +91,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
editor.updateNightMode(); editor.updateNightMode();
selectedColor = 0xb4FFFFFF & getPointColor(); selectedColor = 0xb4FFFFFF & getPointColor();
selectedShape = getBackgroundType();
selectedIcon = R.drawable.mx_special_star;
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(getToolbarTitle()); toolbar.setTitle(getToolbarTitle());
@ -115,10 +117,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
replaceIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_replace, activeColorResId)); replaceIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_replace, activeColorResId));
ImageView deleteIcon = (ImageView) view.findViewById(R.id.delete_action_icon); ImageView deleteIcon = (ImageView) view.findViewById(R.id.delete_action_icon);
deleteIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId)); deleteIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId));
// ((TextView)view.findViewById(R.id.replace_action_title)).setTextColor(ContextCompat.getColor(app,activeColorResId));
// ((TextView)view.findViewById(R.id.replace_action_description)).setTextColor(ContextCompat.getColor(app,activeColorResId));
// ((TextView)view.findViewById(R.id.delete_action_title)).setTextColor(ContextCompat.getColor(app,activeColorResId));
View groupList = view.findViewById(R.id.group_list_button); View groupList = view.findViewById(R.id.group_list_button);
groupList.setOnClickListener(new View.OnClickListener() { groupList.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -239,16 +237,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
private void createGroupSelector(OsmandApplication app) { private void createGroupSelector(OsmandApplication app) {
GroupAdapter groupListAdapter = new GroupAdapter(app); GroupAdapter groupListAdapter = new GroupAdapter(app);
groupListAdapter.setItemClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// int position = groupListAdapter.getChildAdapterPosition(v);
// if (position == RecyclerView.NO_POSITION) {
// return;
// }
// selectFavorite(favouritePoints.get(position));
}
});
groupListAdapter.setSelectedItemName(getCategoryInitValue()); groupListAdapter.setSelectedItemName(getCategoryInitValue());
RecyclerView groupRecyclerView = view.findViewById(R.id.group_recycler_view); RecyclerView groupRecyclerView = view.findViewById(R.id.group_recycler_view);
groupRecyclerView.setAdapter(groupListAdapter); groupRecyclerView.setAdapter(groupListAdapter);
@ -256,6 +244,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
groupListAdapter.notifyDataSetChanged(); groupListAdapter.notifyDataSetChanged();
} }
private void selectIconGroup() {
}
private void createColorSelector() { private void createColorSelector() {
FlowLayout selectColor = view.findViewById(R.id.select_color); FlowLayout selectColor = view.findViewById(R.id.select_color);
for (int color : ColorDialogs.pallette) { for (int color : ColorDialogs.pallette) {
@ -289,19 +280,13 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
icon.setImageDrawable(UiUtilities.tintDrawable(icon.getDrawable(), R.color.icon_color_default_light)); icon.setImageDrawable(UiUtilities.tintDrawable(icon.getDrawable(), R.color.icon_color_default_light));
} }
rootView.findViewWithTag(color).findViewById(R.id.outline).setVisibility(View.VISIBLE); rootView.findViewWithTag(color).findViewById(R.id.outline).setVisibility(View.VISIBLE);
View icon = rootView.findViewWithTag(selectedIcon);
if (icon != null) {
ImageView iconImage = icon.findViewById(R.id.icon);
iconImage.setImageDrawable(UiUtilities.tintDrawable(iconImage.getDrawable(), R.color.white_50_transparent));
ImageView backgroundCircle = view.findViewById(R.id.background);
AndroidUtils.setBackground(backgroundCircle,
UiUtilities.tintDrawable(ContextCompat.getDrawable(view.getContext(), selectedShape.getIconId()), color));
}
((TextView) view.findViewById(R.id.color_name)).setText(ColorDialogs.getColorName(color)); ((TextView) view.findViewById(R.id.color_name)).setText(ColorDialogs.getColorName(color));
selectedColor = color; selectedColor = color;
setColor(color); setColor(color);
updateNameIcon(); updateNameIcon();
updateShapeSelector(); updateShapeSelector(selectedShape, view);
updateIconSelector(selectedIcon, view);
} }
private void createShapeSelector() { private void createShapeSelector() {
@ -339,10 +324,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
return app.getUIUtilities().getIcon(iconRes, R.color.divider_color_light); return app.getUIUtilities().getIcon(iconRes, R.color.divider_color_light);
} }
private void updateShapeSelector() {
updateShapeSelector(selectedShape, view);
}
private void updateShapeSelector(FavouritePoint.BackgroundType backgroundType, View rootView) { private void updateShapeSelector(FavouritePoint.BackgroundType backgroundType, View rootView) {
View oldShape = rootView.findViewWithTag(selectedShape); View oldShape = rootView.findViewWithTag(selectedShape);
if (oldShape != null) { if (oldShape != null) {
@ -360,6 +341,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
UiUtilities.tintDrawable(ContextCompat.getDrawable(requireMyApplication(), backgroundType.getIconId()), UiUtilities.tintDrawable(ContextCompat.getDrawable(requireMyApplication(), backgroundType.getIconId()),
selectedColor)); selectedColor));
selectedShape = backgroundType; selectedShape = backgroundType;
setBackgroundType(backgroundType);
} }
private void createIconSelector() { private void createIconSelector() {
@ -375,7 +357,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
String selectedIconCategory = group.keySet().iterator().next(); String selectedIconCategory = group.keySet().iterator().next();
FlowLayout selectIcon = view.findViewById(R.id.select_icon); FlowLayout selectIcon = view.findViewById(R.id.select_icon);
JSONArray iconJsonArray = group.get(selectedIconCategory); JSONArray iconJsonArray = group.get(selectedIconCategory);
@ -388,14 +369,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
e.printStackTrace(); e.printStackTrace();
} }
} }
GroupNameAdapter groupNameListAdapter = new GroupNameAdapter(); GroupNameAdapter groupNameListAdapter = new GroupNameAdapter();
groupNameListAdapter.setItems(new ArrayList<>(group.keySet())); groupNameListAdapter.setItems(new ArrayList<>(group.keySet()));
RecyclerView groupNameRecyclerView = view.findViewById(R.id.group_name_recycler_view); RecyclerView groupNameRecyclerView = view.findViewById(R.id.group_name_recycler_view);
groupNameRecyclerView.setAdapter(groupNameListAdapter); groupNameRecyclerView.setAdapter(groupNameListAdapter);
groupNameRecyclerView.setLayoutManager(new LinearLayoutManager(requireMyApplication(), RecyclerView.HORIZONTAL, false)); groupNameRecyclerView.setLayoutManager(new LinearLayoutManager(requireMyApplication(), RecyclerView.HORIZONTAL, false));
groupNameListAdapter.notifyDataSetChanged(); groupNameListAdapter.notifyDataSetChanged();
for (String name : iconNameList) { for (String name : iconNameList) {
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0)); selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0));
} }
@ -420,24 +399,32 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
updateIconSelector(iconRes, rootView); updateIconSelector(iconRes, rootView);
} }
}); });
iconItemView.setTag(String.valueOf(iconRes)); iconItemView.setTag(iconRes);
return iconItemView; return iconItemView;
} }
private void updateIconSelector(int iconRes, ViewGroup rootView) { private void updateIconSelector(int iconRes, View rootView) {
// setIconNewColor(iconRes);
View oldIcon = rootView.findViewWithTag(selectedIcon); View oldIcon = rootView.findViewWithTag(selectedIcon);
if (oldIcon != null) { if (oldIcon != null) {
oldIcon.findViewById(R.id.outline).setVisibility(View.INVISIBLE); oldIcon.findViewById(R.id.outline).setVisibility(View.INVISIBLE);
ImageView background = oldIcon.findViewById(R.id.background);
AndroidUtils.setBackground(background,
UiUtilities.tintDrawable(ContextCompat.getDrawable(requireMyApplication(), R.drawable.bg_point_circle),
ContextCompat.getColor(requireMyApplication(), R.color.divider_color_light)));
} }
rootView.findViewWithTag(String.valueOf(iconRes)).findViewById(R.id.outline).setVisibility(View.VISIBLE);
// checkMark.setImageDrawable(app.getUIUtilities().getIcon(changedProfile.iconRes, R.color.icon_color_default_light)); View icon = rootView.findViewWithTag(iconRes);
// AndroidUtils.setBackground(oldIcon.findViewById(R.id.backgroundCircle), if (icon != null) {
// UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), ImageView iconImage = icon.findViewById(R.id.icon);
// UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f))); icon.findViewById(R.id.outline).setVisibility(View.VISIBLE);
selectedIcon = String.valueOf(iconRes); iconImage.setImageDrawable(UiUtilities.tintDrawable(iconImage.getDrawable(), R.color.white_50_transparent));
ImageView backgroundCircle = icon.findViewById(R.id.background);
AndroidUtils.setBackground(backgroundCircle,
UiUtilities.tintDrawable(ContextCompat.getDrawable(view.getContext(), R.drawable.bg_point_circle), selectedColor));
}
selectedIcon = iconRes;
updateNameIcon(); updateNameIcon();
setIcon(iconRes);
} }
private void updateNameIcon() { private void updateNameIcon() {
@ -586,6 +573,10 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public abstract void setColor(int color); public abstract void setColor(int color);
public abstract void setBackgroundType(FavouritePoint.BackgroundType backgroundType);
public abstract void setIcon(int iconId);
protected String getDefaultCategoryName() { protected String getDefaultCategoryName() {
return getString(R.string.shared_string_none); return getString(R.string.shared_string_none);
} }
@ -636,6 +627,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public abstract int getPointColor(); public abstract int getPointColor();
public abstract FavouritePoint.BackgroundType getBackgroundType();
public abstract Set<String> getCategories(); public abstract Set<String> getCategories();
String getNameTextValue() { String getNameTextValue() {
@ -759,10 +752,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
return items == null ? 0 : items.size() + 1; return items == null ? 0 : items.size() + 1;
} }
void setItemClickListener(View.OnClickListener listener) {
this.listener = listener;
}
String getSelectedItem() { String getSelectedItem() {
return selectedItemName; return selectedItemName;
} }