Fix fav group npe
This commit is contained in:
parent
38983accea
commit
9244cf81ae
3 changed files with 12 additions and 9 deletions
|
@ -81,7 +81,7 @@ public class FavouritesDbHelper {
|
||||||
return PERSONAL_CATEGORY.equals(name);
|
return PERSONAL_CATEGORY.equals(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPersonalCategoryDisplayName(Context ctx, String name){
|
public static boolean isPersonalCategoryDisplayName(Context ctx, String name) {
|
||||||
return name.equals(ctx.getString(R.string.personal_category_name));
|
return name.equals(ctx.getString(R.string.personal_category_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertDisplayNameToGroupIdName(Context context, String name) {
|
public static String convertDisplayNameToGroupIdName(Context context, String name) {
|
||||||
if (isPersonalCategoryDisplayName(context,name)) {
|
if (isPersonalCategoryDisplayName(context, name)) {
|
||||||
return PERSONAL_CATEGORY;
|
return PERSONAL_CATEGORY;
|
||||||
}
|
}
|
||||||
if (name.equals(context.getString(R.string.shared_string_favorites))) {
|
if (name.equals(context.getString(R.string.shared_string_favorites))) {
|
||||||
|
@ -589,7 +589,7 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEmptyCategory(String name, int color) {
|
public void addEmptyCategory(String name, int color) {
|
||||||
addEmptyCategory(name, color, true);
|
addEmptyCategory(name, color, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEmptyCategory(String name, int color, boolean visible) {
|
public void addEmptyCategory(String name, int color, boolean visible) {
|
||||||
|
@ -598,7 +598,7 @@ public class FavouritesDbHelper {
|
||||||
group.color = color;
|
group.color = color;
|
||||||
group.visible = visible;
|
group.visible = visible;
|
||||||
favoriteGroups.add(group);
|
favoriteGroups.add(group);
|
||||||
flatGroups.put(name, group);
|
flatGroups.put(group.name, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FavouritePoint> getFavouritePoints() {
|
public List<FavouritePoint> getFavouritePoints() {
|
||||||
|
@ -639,6 +639,7 @@ public class FavouritesDbHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public FavoriteGroup getGroup(FavouritePoint p) {
|
public FavoriteGroup getGroup(FavouritePoint p) {
|
||||||
if (flatGroups.containsKey(p.getCategory())) {
|
if (flatGroups.containsKey(p.getCategory())) {
|
||||||
return flatGroups.get(p.getCategory());
|
return flatGroups.get(p.getCategory());
|
||||||
|
@ -647,6 +648,7 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public FavoriteGroup getGroup(String nameId) {
|
public FavoriteGroup getGroup(String nameId) {
|
||||||
if (flatGroups.containsKey(nameId)) {
|
if (flatGroups.containsKey(nameId)) {
|
||||||
return flatGroups.get(nameId);
|
return flatGroups.get(nameId);
|
||||||
|
@ -655,6 +657,7 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private FavouritePoint findFavoriteByAllProperties(String category, String name, double lat, double lon) {
|
private FavouritePoint findFavoriteByAllProperties(String category, String name, double lat, double lon) {
|
||||||
if (flatGroups.containsKey(category)) {
|
if (flatGroups.containsKey(category)) {
|
||||||
FavoriteGroup fg = flatGroups.get(category);
|
FavoriteGroup fg = flatGroups.get(category);
|
||||||
|
|
|
@ -448,9 +448,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
|
||||||
List<LatLon> points = new ArrayList<>();
|
List<LatLon> points = new ArrayList<>();
|
||||||
List<PointDescription> names = new ArrayList<>();
|
List<PointDescription> names = new ArrayList<>();
|
||||||
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
||||||
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
FavoriteGroup group = helper.getGroup(entry.getKey());
|
||||||
if (entry.getValue().size() == favGr.getPoints().size()) {
|
if (group != null && entry.getValue().size() == group.getPoints().size()) {
|
||||||
markersHelper.addOrEnableGroup(favGr);
|
markersHelper.addOrEnableGroup(group);
|
||||||
} else {
|
} else {
|
||||||
for (FavouritePoint fp : entry.getValue()) {
|
for (FavouritePoint fp : entry.getValue()) {
|
||||||
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
||||||
|
|
|
@ -147,9 +147,9 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
||||||
public void setCategory(String name, int color) {
|
public void setCategory(String name, int color) {
|
||||||
FavouritesDbHelper helper = getHelper();
|
FavouritesDbHelper helper = getHelper();
|
||||||
if (helper != null) {
|
if (helper != null) {
|
||||||
FavoriteGroup group = helper.getGroup(FavouritesDbHelper.FavoriteGroup.convertDisplayNameToGroupIdName(requireContext(), name));
|
FavoriteGroup group = helper.getGroup(FavoriteGroup.convertDisplayNameToGroupIdName(requireContext(), name));
|
||||||
this.group = group;
|
this.group = group;
|
||||||
super.setCategory(name, group.getColor());
|
super.setCategory(name, group != null ? group.getColor() : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue