From d18db9bbb1e9846049880c575f598e75f7c169f5 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 3 Apr 2017 12:40:05 +0300 Subject: [PATCH] Fix icon and search favs. Work on edit favs dialog --- OsmAnd/res/layout/edit_fav_fragment.xml | 217 ++++++++++++++++ OsmAnd/res/values/strings.xml | 3 + .../EditFavoriteGroupDialogFragment.java | 241 ++++++++++++++++++ .../activities/FavoritesTreeFragment.java | 4 +- .../osmand/plus/search/QuickSearchHelper.java | 35 ++- .../search/listitems/QuickSearchListItem.java | 4 +- 6 files changed, 493 insertions(+), 11 deletions(-) create mode 100644 OsmAnd/res/layout/edit_fav_fragment.xml create mode 100644 OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java diff --git a/OsmAnd/res/layout/edit_fav_fragment.xml b/OsmAnd/res/layout/edit_fav_fragment.xml new file mode 100644 index 0000000000..a03b7a9028 --- /dev/null +++ b/OsmAnd/res/layout/edit_fav_fragment.xml @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 731b2fcb61..c2af16f8b9 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Group name + Change color + Edit name Animate my location Enable animation of my location on the map Overview diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java new file mode 100644 index 0000000000..16eb28d126 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -0,0 +1,241 @@ +package net.osmand.plus.activities; + +import android.app.Activity; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.FragmentManager; +import android.support.v7.app.AlertDialog; +import android.support.v7.widget.ListPopupWindow; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.AndroidUtils; +import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; +import net.osmand.plus.IconsCache; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.ColorDialogs; +import net.osmand.util.Algorithms; + +public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment { + + public static final String TAG = "EditFavoriteGroupDialogFragment"; + private static final String GROUP_NAME_KEY = "group_name_key"; + + private OsmandApplication app; + private FavoriteGroup group; + private FavouritesDbHelper helper; + + @Override + public void onStart() { + super.onStart(); + + final Window window = getDialog().getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + params.height = ViewGroup.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.BOTTOM; + params.width = ViewGroup.LayoutParams.MATCH_PARENT; + window.setAttributes(params); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + final Activity activity = getActivity(); + app = (OsmandApplication) activity.getApplicationContext(); + helper = app.getFavorites(); + + Bundle args = null; + if (savedInstanceState != null) { + args = savedInstanceState; + } else if (getArguments() != null) { + args = getArguments(); + } + + if (args != null) { + String groupName = args.getString(GROUP_NAME_KEY); + if (groupName != null) { + group = helper.getGroup(groupName); + } + } + + final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container, + false); + if (group == null) { + return view; + } + + IconsCache ic = app.getIconsCache(); + + View editNameView = view.findViewById(R.id.edit_name_view); + ((ImageView) view.findViewById(R.id.edit_name_icon)) + .setImageDrawable(ic.getIcon(R.drawable.ic_action_edit_dark)); + editNameView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + AlertDialog.Builder b = new AlertDialog.Builder(activity); + b.setTitle(R.string.favorite_group_name); + final EditText nameEditText = new EditText(activity); + nameEditText.setText(group.name); + int leftPadding = AndroidUtils.dpToPx(activity, 24f); + int topPadding = AndroidUtils.dpToPx(activity, 4f); + b.setView(nameEditText, leftPadding, topPadding, leftPadding, topPadding); + b.setNegativeButton(R.string.shared_string_cancel, null); + b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String name = nameEditText.getText().toString(); + boolean nameChanged = !Algorithms.objectEquals(group.name, name); + if (nameChanged) { + getMyApplication().getFavorites() + .editFavouriteGroup(group, name, group.color, group.visible); + } + } + }); + b.show(); + } + }); + + final View changeColorView = view.findViewById(R.id.change_color_view); + ((ImageView) view.findViewById(R.id.change_color_icon)) + .setImageDrawable(ic.getIcon(R.drawable.ic_action_appearance)); + updateColorView(changeColorView); + changeColorView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final ListPopupWindow popup = new ListPopupWindow(getActivity()); + popup.setAnchorView(changeColorView); + popup.setContentWidth(AndroidUtils.dpToPx(app, 200f)); + popup.setModal(true); + popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP); + popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f)); + popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f)); + final FavoriteColorAdapter colorAdapter = new FavoriteColorAdapter(getActivity()); + popup.setAdapter(colorAdapter); + popup.setOnItemClickListener(new AdapterView.OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Integer color = colorAdapter.getItem(position); + if (color != null) { + if (color != group.color) { + getMyApplication().getFavorites() + .editFavouriteGroup(group, group.name, color, group.visible); + } + } + popup.dismiss(); + updateColorView(changeColorView); + } + }); + popup.show(); + } + }); + + View showOnMapView = view.findViewById(R.id.show_on_map_view); + ((ImageView) view.findViewById(R.id.show_on_map_icon)) + .setImageDrawable(ic.getIcon(R.drawable.ic_map)); + showOnMapView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //todo + } + }); + + View addToMarkersView = view.findViewById(R.id.add_to_markers_view); + ((ImageView) view.findViewById(R.id.add_to_markers_icon)) + .setImageDrawable(ic.getIcon(R.drawable.ic_action_flag_dark)); + addToMarkersView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //todo + } + }); + + View shareView = view.findViewById(R.id.share_view); + ((ImageView) view.findViewById(R.id.share_icon)) + .setImageDrawable(ic.getIcon(R.drawable.ic_action_gshare_dark)); + shareView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //todo + } + }); + + return view; + } + + @Override + public void onResume() { + super.onResume(); + if (group == null) { + dismiss(); + } + } + + private void updateColorView(View colorView) { + ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage); + int color = group.color == 0 ? getResources().getColor(R.color.color_favorite) : group.color; + if (color == 0) { + colorImageView.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_circle)); + } else { + colorImageView.setImageDrawable(app.getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color)); + } + } + + public static void showInstance(FragmentManager fragmentManager, String groupName) { + EditFavoriteGroupDialogFragment f = new EditFavoriteGroupDialogFragment(); + Bundle args = new Bundle(); + args.putString(GROUP_NAME_KEY, groupName); + f.setArguments(args); + f.show(fragmentManager, EditFavoriteGroupDialogFragment.TAG); + } + + public static class FavoriteColorAdapter extends ArrayAdapter { + + private OsmandApplication app; + + public FavoriteColorAdapter(Context context) { + super(context, R.layout.rendering_prop_menu_item); + this.app = (OsmandApplication) getContext().getApplicationContext(); + init(); + } + + public void init() { + for (int color : ColorDialogs.pallette) { + add(color); + } + } + + @NonNull + @Override + public View getView(int position, View convertView, @NonNull ViewGroup parent) { + Integer color = getItem(position); + View v = convertView; + if (v == null) { + v = LayoutInflater.from(getContext()).inflate(R.layout.rendering_prop_menu_item, null); + } + if (color != null) { + TextView textView = (TextView) v.findViewById(R.id.text1); + textView.setText(app.getString(ColorDialogs.paletteColors[position])); + textView.setCompoundDrawablesWithIntrinsicBounds(null, null, + app.getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color), null); + textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(getContext(), 10f)); + v.findViewById(R.id.divider).setVisibility(View.GONE); + } + return v; + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 83ea4e37ee..ae56350139 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.activities; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.Drawable; @@ -745,8 +746,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { int enabledColor = light ? R.color.primary_text_light : R.color.primary_text_dark; int disabledColor = light ? R.color.secondary_text_light : R.color.secondary_text_dark; row.findViewById(R.id.group_divider).setVisibility(groupPosition == 0 ? View.GONE : View.VISIBLE); + int color = model.color == 0 || model.color == Color.BLACK ? getResources().getColor(R.color.color_favorite) : model.color; setCategoryIcon(app, app.getIconsCache().getPaintedIcon( - R.drawable.ic_action_fav_dark, visible ? (model.color | 0xff000000) : getResources().getColor(disabledColor)), + R.drawable.ic_action_fav_dark, visible ? (color | 0xff000000) : getResources().getColor(disabledColor)), groupPosition, isExpanded, row, light); adjustIndicator(app, groupPosition, isExpanded, row, light); TextView label = (TextView) row.findViewById(R.id.category_name); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 8397db42c8..4f97f07c11 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -8,6 +8,7 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.resources.ResourceManager.ResourceListener; @@ -18,6 +19,7 @@ import net.osmand.search.core.ObjectType; import net.osmand.search.core.SearchCoreFactory.SearchBaseAPI; import net.osmand.search.core.SearchPhrase; import net.osmand.search.core.SearchResult; +import net.osmand.util.Algorithms; import java.io.IOException; import java.util.Arrays; @@ -164,18 +166,31 @@ public class QuickSearchHelper implements ResourceListener { @Override public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) throws IOException { - List favList = app.getFavorites().getFavouritePoints(); - for (FavouritePoint point : favList) { - FavoriteGroup group = helper.getGroup(point); - if (group != null && group.visible) { + String baseGroupName = app.getString(R.string.shared_string_favorites); + List groups = app.getFavorites().getFavoriteGroups(); + for (FavoriteGroup group : groups) { + if (group.visible) { SearchResult sr = new SearchResult(phrase); - sr.localeName = group.name; + sr.localeName = Algorithms.isEmpty(group.name) ? baseGroupName : group.name; sr.object = group; sr.priority = SEARCH_FAVORITE_CATEGORY_PRIORITY; sr.objectType = ObjectType.FAVORITE_GROUP; sr.preferredZoom = 17; if (phrase.getNameStringMatcher().matches(sr.localeName)) { - resultMatcher.publish(sr); + if (group.points.size() < 5) { + for (FavouritePoint point : group.points) { + SearchResult srp = new SearchResult(phrase); + srp.localeName = point.getName(); + srp.object = point; + srp.priority = SEARCH_FAVORITE_OBJECT_PRIORITY; + srp.objectType = ObjectType.FAVORITE; + srp.location = new LatLon(point.getLatitude(), point.getLongitude()); + srp.preferredZoom = 17; + resultMatcher.publish(srp); + } + } else { + resultMatcher.publish(sr); + } } } } @@ -219,9 +234,11 @@ public class QuickSearchHelper implements ResourceListener { sr.objectType = ObjectType.FAVORITE; sr.location = new LatLon(point.getLatitude(), point.getLongitude()); sr.preferredZoom = 17; - if (phrase.isLastWord(ObjectType.FAVORITE_GROUP) - && !point.getCategory().equals(phrase.getLastSelectedWord().getResult().localeName)) { - continue; + if (phrase.isLastWord(ObjectType.FAVORITE_GROUP)) { + FavoriteGroup group = (FavoriteGroup) phrase.getLastSelectedWord().getResult().object; + if (group != null && !point.getCategory().equals(group.name)) { + continue; + } } if (phrase.getUnknownSearchWordLength() <= 1 && (phrase.isNoSelectedType() || phrase.isLastWord(ObjectType.FAVORITE_GROUP))) { diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java index c864eb1048..eb56672a68 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java @@ -1,6 +1,7 @@ package net.osmand.plus.search.listitems; import android.content.Context; +import android.graphics.Color; import android.graphics.drawable.Drawable; import android.text.Spannable; @@ -370,7 +371,8 @@ public class QuickSearchListItem { return FavoriteImageDrawable.getOrCreate(app, fav.getColor(), false); case FAVORITE_GROUP: FavoriteGroup group = (FavoriteGroup) searchResult.object; - return app.getIconsCache().getPaintedIcon(R.drawable.ic_action_fav_dark, group.color | 0xff000000); + int color = group.color == 0 || group.color == Color.BLACK ? app.getResources().getColor(R.color.color_favorite) : group.color; + return app.getIconsCache().getPaintedIcon(R.drawable.ic_action_fav_dark, color | 0xff000000); case REGION: return app.getIconsCache().getIcon(R.drawable.ic_world_globe_dark, app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);