Fix possible IllegalStateException

This commit is contained in:
Vitaliy 2020-05-18 16:45:55 +03:00
parent 82db8409f5
commit d90b2956c5

View file

@ -4,7 +4,6 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -167,8 +166,9 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
@Override @Override
public void setCategory(String name, int color) { public void setCategory(String name, int color) {
FavouritesDbHelper helper = getHelper(); FavouritesDbHelper helper = getHelper();
if (helper != null) { Context ctx = getContext();
FavoriteGroup group = helper.getGroup(FavoriteGroup.convertDisplayNameToGroupIdName(requireContext(), name)); if (helper != null && ctx != null) {
FavoriteGroup group = helper.getGroup(FavoriteGroup.convertDisplayNameToGroupIdName(ctx, name));
this.group = group; this.group = group;
super.setCategory(name, group != null ? group.getColor() : 0); super.setCategory(name, group != null ? group.getColor() : 0);
} }
@ -176,10 +176,13 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
@Override @Override
protected String getLastUsedGroup() { protected String getLastUsedGroup() {
OsmandApplication app = requireMyApplication(); String lastCategory = "";
String lastCategory = app.getSettings().LAST_FAV_CATEGORY_ENTERED.get(); OsmandApplication app = getMyApplication();
if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) { if (app != null) {
lastCategory = ""; lastCategory = app.getSettings().LAST_FAV_CATEGORY_ENTERED.get();
if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) {
lastCategory = "";
}
} }
return lastCategory; return lastCategory;
} }
@ -325,11 +328,14 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
private void doEditFavorite(FavouritePoint favorite, String name, String category, String description, private void doEditFavorite(FavouritePoint favorite, String name, String category, String description,
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, @ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId,
FavouritesDbHelper helper) { FavouritesDbHelper helper) {
requireMyApplication().getSettings().LAST_FAV_CATEGORY_ENTERED.set(category); OsmandApplication app = getMyApplication();
favorite.setColor(color); if (app != null) {
favorite.setBackgroundType(backgroundType); app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category);
favorite.setIconId(iconId); favorite.setColor(color);
helper.editFavouriteName(favorite, name, category, description); favorite.setBackgroundType(backgroundType);
favorite.setIconId(iconId);
helper.editFavouriteName(favorite, name, category, description);
}
} }
private void doAddFavorite(String name, String category, String description, @ColorInt int color, private void doAddFavorite(String name, String category, String description, @ColorInt int color,