Merge pull request #8745 from osmandapp/Fix_1_edit_fav_icons

Fix 1 edit fav icons
This commit is contained in:
max-klaus 2020-04-01 17:57:22 +03:00 committed by GitHub
commit 1b8623a699
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 46 deletions

View file

@ -178,7 +178,7 @@
<color name="row_selection_color">#CC33BBE0</color>
<!-- GPX analysis colors -->
<color name="gpx_color_point">#d00d0d</color>
<color name="gpx_color_point">#b4d00d0d</color>
<color name="gpx_speed">#c79c00</color>
<color name="gpx_altitude_desc">#32CD32</color>
<color name="gpx_altitude_asc">#EE3232</color>

View file

@ -15,6 +15,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmandApplication;
@ -75,7 +76,8 @@ public class EditCategoryDialogFragment extends DialogFragment {
nameEdit = (EditText)v.findViewById(R.id.edit_name);
nameEdit.setText(name);
nameEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(nameEdit);
colorSpinner = (Spinner)v.findViewById(R.id.edit_color);
final TIntArrayList colors = new TIntArrayList();
final int intColor = color;
@ -151,7 +153,19 @@ public class EditCategoryDialogFragment extends DialogFragment {
}
@Override
public void onSaveInstanceState(Bundle outState) {
public void onStop() {
Dialog dialog = getDialog();
if (dialog != null) {
MapActivity mapActivity = (MapActivity) getDialog().getOwnerActivity();
if (mapActivity != null) {
AndroidUtils.hideSoftKeyboard(mapActivity, mapActivity.getCurrentFocus());
}
}
super.onStop();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
saveState(outState);
super.onSaveInstanceState(outState);
}

View file

@ -171,6 +171,16 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
}
}
@Override
protected String getLastUsedGroup() {
OsmandApplication app = requireMyApplication();
String lastCategory = app.getSettings().LAST_FAV_CATEGORY_ENTERED.get();
if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) {
lastCategory = "";
}
return lastCategory;
}
@Override
public void setColor(int color) {
this.color = color;
@ -290,10 +300,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
if (editor.isNew()) {
doAddFavorite(name, category, description, color, backgroundType, iconId);
} else {
favorite.setColor(color);
favorite.setBackgroundType(backgroundType);
favorite.setIconId(iconId);
helper.editFavouriteName(favorite, name, category, description);
doEditFavorite(favorite, name, category, description, color, backgroundType, iconId, helper);
}
}
MapActivity mapActivity = getMapActivity();
@ -312,6 +319,16 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
}
}
private void doEditFavorite(FavouritePoint favorite, String name, String category, String description,
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId,
FavouritesDbHelper helper) {
requireMyApplication().getSettings().LAST_FAV_CATEGORY_ENTERED.set(category);
favorite.setColor(color);
favorite.setBackgroundType(backgroundType);
favorite.setIconId(iconId);
helper.editFavouriteName(favorite, name, category, description);
}
private void doAddFavorite(String name, String category, String description, @ColorInt int color,
BackgroundType backgroundType, @DrawableRes int iconId) {
OsmandApplication app = getMyApplication();
@ -433,9 +450,22 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
public Set<String> getCategories() {
Set<String> categories = new LinkedHashSet<>();
FavouritesDbHelper helper = getHelper();
if (helper != null) {
for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) {
categories.add(fg.getDisplayName(getMyApplication()));
if (helper != null && editor != null) {
OsmandApplication app = getMyApplication();
if (editor.isNew()) {
FavoriteGroup lastUsedGroup = helper.getGroup(getLastUsedGroup());
if (lastUsedGroup != null) {
categories.add(lastUsedGroup.getDisplayName(app));
}
for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) {
if (lastUsedGroup != null && !fg.equals(lastUsedGroup)) {
categories.add(fg.getDisplayName(app));
}
}
} else {
for (FavoriteGroup fg : helper.getFavoriteGroups()) {
categories.add(fg.getDisplayName(app));
}
}
}
return categories;

View file

@ -102,7 +102,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
editor.updateLandscapePortrait(requireActivity());
editor.updateNightMode();
selectedColor = 0xb4FFFFFF & getPointColor();
selectedColor = getPointColor();
selectedShape = getBackgroundType();
selectedIcon = getIconId();
@ -128,10 +128,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
public void onScrollChanged() {
if (scrollViewY != scrollView.getScrollY()) {
scrollViewY = scrollView.getScrollY();
Activity activity = getActivity();
if (activity != null) {
AndroidUtils.hideSoftKeyboard(activity, view);
}
hideKeyboard();
}
}
});
@ -140,12 +137,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
ImageView toolbarAction = (ImageView) view.findViewById(R.id.toolbar_action);
view.findViewById(R.id.background_layout).setBackgroundResource(nightMode
? R.color.app_bar_color_dark : R.color.list_background_color_light);
ImageView groupListIcon = (ImageView) view.findViewById(R.id.group_list_button_icon);
groupListIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_group_select_all, activeColorResId));
ImageView replaceIcon = (ImageView) view.findViewById(R.id.replace_action_icon);
replaceIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_replace, activeColorResId));
ImageView deleteIcon = (ImageView) view.findViewById(R.id.delete_action_icon);
deleteIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId));
ImageView groupListIcon = (ImageView) view.findViewById(R.id.group_list_button_icon);
groupListIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_group_select_all, activeColorResId));
View groupList = view.findViewById(R.id.group_list_button);
groupList.setOnClickListener(new View.OnClickListener() {
@Override
@ -236,6 +233,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
deleteButton.setVisibility(View.GONE);
descriptionCaption.setVisibility(View.GONE);
deleteIcon.setVisibility(View.GONE);
nameEdit.selectAll();
nameEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(nameEdit);
} else {
toolbarAction.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId));
deleteButton.setVisibility(View.VISIBLE);
@ -542,17 +542,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
}
}
@Override
public void onResume() {
super.onResume();
PointEditor editor = getEditor();
if (editor != null && editor.isNew()) {
nameEdit.selectAll();
nameEdit.requestFocus();
AndroidUtils.softKeyboardDelayed(nameEdit);
}
}
@Override
public void onStop() {
super.onStop();
@ -618,14 +607,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
groupListAdapter.fillGroups();
groupListAdapter.setSelectedItemName(name);
groupListAdapter.notifyDataSetChanged();
int position;
if (getEditor().isNew()) {
String lastCategory = app.getSettings().LAST_FAV_CATEGORY_ENTERED.get();
if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) {
lastCategory = "";
}
position = groupListAdapter.getItemPosition(lastCategory);
} else {
int position = 0;
PointEditor editor = getEditor();
if (editor != null) {
position = groupListAdapter.items.size() == groupListAdapter.getItemPosition(name) + 1
? groupListAdapter.getItemPosition(name) + 1
: groupListAdapter.getItemPosition(name);
@ -633,6 +617,10 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
groupRecyclerView.scrollToPosition(position);
}
protected String getLastUsedGroup() {
return "";
}
protected String getDefaultCategoryName() {
return getString(R.string.shared_string_none);
}
@ -642,15 +630,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
return (MapActivity) getActivity();
}
@Nullable
@Override
protected OsmandApplication getMyApplication() {
if (getActivity() == null) {
return null;
}
return (OsmandApplication) getActivity().getApplication();
}
public void dismiss() {
dismiss(false);
}

View file

@ -359,7 +359,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
@Override
public void setBackgroundType(BackgroundType backgroundType) {
this.backgroundTypeName = backgroundType.name();
this.backgroundTypeName = backgroundType.getTypeName();
}
@Override