Fix #9319 Move a favourite to hidden category,

fix #9060 changing color group of favourite,
This commit is contained in:
Dima-1 2020-07-08 16:17:41 +03:00
parent a3a1b047ac
commit 0f1d23ddfe
4 changed files with 60 additions and 19 deletions

View file

@ -679,6 +679,16 @@ public class FavouritesDbHelper {
return favoriteGroups;
}
public boolean isGroupVisible(String name) {
String nameLowercase = name.toLowerCase();
for (String groupName : flatGroups.keySet()) {
if (groupName.toLowerCase().equals(nameLowercase) || FavoriteGroup.getDisplayName(context, groupName).equals(name)) {
return flatGroups.get(groupName).isVisible();
}
}
return false;
}
public boolean groupExists(String name) {
String nameLowercase = name.toLowerCase();
for (String groupName : flatGroups.keySet()) {
@ -800,10 +810,12 @@ public class FavouritesDbHelper {
public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) {
if (color != 0 && group.color != color) {
FavoriteGroup gr = flatGroups.get(group.name);
group.color = color;
for (FavouritePoint p : gr.points) {
p.setColor(color);
if (p.getColor() == group.color) {
p.setColor(color);
}
}
group.color = color;
runSyncWithMarkers(gr);
}
if (group.visible != visible) {

View file

@ -97,7 +97,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
}
});
if (editor != null && editor.isNew()) {
ImageView toolbarAction = (ImageView) view.findViewById(R.id.toolbar_action);
ImageView toolbarAction = view.findViewById(R.id.toolbar_action);
toolbarAction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -460,30 +460,36 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
@Override
public Set<String> getCategories() {
Set<String> categories = new LinkedHashSet<>();
Set<String> categoriesHidden = new LinkedHashSet<>();
FavouritesDbHelper helper = getHelper();
if (helper != null && editor != null) {
OsmandApplication app = getMyApplication();
if (editor.isNew()) {
FavoriteGroup lastUsedGroup = helper.getGroup(getLastUsedGroup());
if (lastUsedGroup != null && lastUsedGroup.isVisible()) {
categories.add(lastUsedGroup.getDisplayName(app));
}
for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) {
if (!fg.equals(lastUsedGroup) && fg.isVisible()) {
categories.add(fg.getDisplayName(app));
}
}
} else {
for (FavoriteGroup fg : helper.getFavoriteGroups()) {
FavoriteGroup lastUsedGroup = helper.getGroup(getLastUsedGroup());
if (lastUsedGroup != null) {
categories.add(lastUsedGroup.getDisplayName(app));
}
for (FavouritesDbHelper.FavoriteGroup fg : helper.getFavoriteGroups()) {
if (!fg.equals(lastUsedGroup)) {
if (fg.isVisible()) {
categories.add(fg.getDisplayName(app));
} else {
categoriesHidden.add(fg.getDisplayName(app));
}
}
}
categories.addAll(categoriesHidden);
}
return categories;
}
@Override
public boolean isCategoryVisible(String name) {
if (getHelper() != null) {
return getHelper().isGroupVisible(name);
}
return true;
}
@Override
public int getCategoryPointsCount(String category) {
FavouritesDbHelper helper = getHelper();
@ -498,6 +504,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
}
@Override
@ColorInt
public int getCategoryColor(String category) {
FavouritesDbHelper helper = getHelper();
if (helper != null) {

View file

@ -5,6 +5,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
@ -675,6 +676,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public void setCategory(String name, int color) {
setSelectedItemWithScroll(name);
updateColorSelector(color, groupRecyclerView.getRootView());
}
private void setSelectedItemWithScroll(String name) {
@ -732,6 +734,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public abstract String getToolbarTitle();
@ColorInt
public abstract int getCategoryColor(String category);
public abstract int getCategoryPointsCount(String category);
@ -762,6 +765,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public abstract Set<String> getCategories();
protected boolean isCategoryVisible(String name) {
return true;
}
;
String getNameTextValue() {
EditText nameEdit = view.findViewById(R.id.name_edit);
return nameEdit.getText().toString().trim();
@ -885,16 +894,13 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public void onClick(View view) {
int previousSelectedPosition = getItemPosition(selectedItemName);
selectedItemName = items.get(holder.getAdapterPosition());
updateColorSelector(getCategoryColor(selectedItemName), groupRecyclerView.getRootView());
notifyItemChanged(holder.getAdapterPosition());
notifyItemChanged(previousSelectedPosition);
}
});
final String group = items.get(position);
holder.groupName.setText(group);
int categoryColor = getCategoryColor(group);
int color = categoryColor == 0 ? getDefaultColor() : categoryColor;
holder.groupIcon.setImageDrawable(UiUtilities.tintDrawable(
AppCompatResources.getDrawable(app, R.drawable.ic_action_folder), color));
holder.pointsCounter.setText(String.valueOf(getCategoryPointsCount(group)));
int strokeColor;
int strokeWidth;
@ -913,6 +919,20 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), strokeColor);
holder.groupButton.setImageDrawable(rectContourDrawable);
}
int color;
int iconID;
if (!isCategoryVisible(group)) {
color = ContextCompat.getColor(app, R.color.text_color_secondary_light);
iconID = R.drawable.ic_action_hide;
holder.groupName.setTypeface(null, Typeface.ITALIC);
} else {
int categoryColor = getCategoryColor(group);
color = categoryColor == 0 ? getDefaultColor() : categoryColor;
iconID = R.drawable.ic_action_folder;
holder.groupName.setTypeface(null, Typeface.NORMAL);
}
holder.groupIcon.setImageDrawable(UiUtilities.tintDrawable(
AppCompatResources.getDrawable(app, iconID), color));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, holder.groupButton, nightMode, R.drawable.ripple_solid_light_6dp,

View file

@ -8,6 +8,7 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
@ -454,6 +455,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
}
@Override
@ColorInt
public int getCategoryColor(String category) {
if (categoriesMap != null) {
Integer color = categoriesMap.get(category);