diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 93f0275ae2..292f8e0fe3 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -8,7 +8,6 @@ import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.support.v4.content.FileProvider; @@ -191,6 +190,13 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { getGroupExpandedPreference(groupName).set(true); } }); + String groupNameToShow = ((FavoritesActivity) getActivity()).getGroupNameToShow(); + if (groupNameToShow != null) { + int position = favouritesAdapter.getGroupPosition(groupNameToShow); + if (position != -1) { + listView.setSelectedGroup(position); + } + } return view; } @@ -967,6 +973,16 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { public void setFilterResults(Set values) { this.filter = values; } + + public int getGroupPosition(String groupName) { + for (int i = 0; i < getGroupCount(); i++) { + FavoriteGroup group = getGroup(i); + if (group.name.equals(groupName)) { + return i; + } + } + return -1; + } } public class FavoritesFilter extends Filter { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 245613a779..fc623e09a1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -31,7 +31,9 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.osm.PoiCategory; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.IconsCache; +import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings.OsmandPreference; @@ -43,6 +45,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask; import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard; +import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; @@ -681,18 +684,17 @@ public class MenuBuilder { return new CollapsableView(textView, collapsed); } - protected CollapsableView getCollapsableFavouritesView(Context context, boolean collapsed, List points, FavouritePoint selectedPoint) { + protected CollapsableView getCollapsableFavouritesView(final Context context, boolean collapsed, @NonNull final FavoriteGroup group, FavouritePoint selectedPoint) { LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed); - for (final FavouritePoint point : points) { + List points = group.points; + for (int i = 0; i < points.size() && i < 10; i++) { + final FavouritePoint point = points.get(i); boolean selected = selectedPoint != null && selectedPoint.equals(point); TextViewEx button = buildButtonInCollapsableView(context, selected); String name = point.getName(); button.setText(name); - button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); - button.setSingleLine(true); - button.setEllipsize(TextUtils.TruncateAt.END); if (!selected) { button.setOnClickListener(new View.OnClickListener() { @Override @@ -706,6 +708,23 @@ public class MenuBuilder { view.addView(button); } + if (points.size() > 10) { + TextViewEx button = buildButtonInCollapsableView(context, false); + button.setText(context.getString(R.string.shared_string_show_all)); + button.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + OsmAndAppCustomization appCustomization = app.getAppCustomization(); + final Intent intent = new Intent(context, appCustomization.getFavoritesActivity()); + intent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true); + intent.putExtra(FavoritesActivity.GROUP_NAME_TO_SHOW, group.name); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + context.startActivity(intent); + } + }); + view.addView(button); + } + return new CollapsableView(view, collapsed); } @@ -717,9 +736,6 @@ public class MenuBuilder { String name = wiki.getName(preferredMapAppLang, transliterateNames); button.setText(name); - button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); - button.setSingleLine(true); - button.setEllipsize(TextUtils.TruncateAt.END); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -771,6 +787,9 @@ public class MenuBuilder { int paddingSides = (int) context.getResources().getDimension(R.dimen.context_menu_button_padding_x); button.setPadding(paddingSides, 0, paddingSides, 0); button.setTextColor(buttonColorStateList); + button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); + button.setSingleLine(true); + button.setEllipsize(TextUtils.TruncateAt.END); return button; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 2be55ef241..4f919d6b4d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -79,7 +79,7 @@ public class FavouritePointMenuBuilder extends MenuBuilder { color = favoriteGroup.visible ? (color | 0xff000000) : view.getResources().getColor(disabledColor); String name = view.getContext().getString(R.string.context_menu_points_of_group); buildRow(view, app.getIconsCache().getPaintedIcon(R.drawable.ic_action_folder, color), name, 0, - true, getCollapsableFavouritesView(view.getContext(), true, groupFavourites, fav), + true, getCollapsableFavouritesView(view.getContext(), true, favoriteGroup, fav), false, 0, false, null); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java index c290ac70bf..c7738766ad 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java @@ -44,6 +44,8 @@ public class FavoritesActivity extends TabActivity { private static final int OPEN_GPX_DOCUMENT_REQUEST = 1006; private static final int IMPORT_FAVOURITES_REQUEST = 1007; + public static final String GROUP_NAME_TO_SHOW = "group_name_to_show"; + public static final String OPEN_FAVOURITES_TAB = "open_favourites_tab"; public static final String OPEN_MY_PLACES_TAB = "open_my_places_tab"; @@ -52,6 +54,7 @@ public class FavoritesActivity extends TabActivity { protected List> fragList = new ArrayList<>(); private int tabSize; private GpxImportHelper gpxImportHelper; + private String groupNameToShow; @Override public void onCreate(Bundle icicle) { @@ -74,16 +77,25 @@ public class FavoritesActivity extends TabActivity { // setupHomeButton(); ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); - Intent intent = getIntent(); - if (intent != null) { - if (intent.hasExtra(OPEN_FAVOURITES_TAB) && intent.getBooleanExtra(OPEN_FAVOURITES_TAB, false)) { - mViewPager.setCurrentItem(0, false); - } else if (intent.hasExtra(OPEN_MY_PLACES_TAB) && intent.getBooleanExtra(OPEN_MY_PLACES_TAB, false)) { - mViewPager.setCurrentItem(1, false); + if (icicle == null) { + Intent intent = getIntent(); + if (intent != null) { + if (intent.hasExtra(OPEN_FAVOURITES_TAB) && intent.getBooleanExtra(OPEN_FAVOURITES_TAB, false)) { + if (intent.hasExtra(GROUP_NAME_TO_SHOW)) { + groupNameToShow = intent.getStringExtra(GROUP_NAME_TO_SHOW); + } + mViewPager.setCurrentItem(0, false); + } else if (intent.hasExtra(OPEN_MY_PLACES_TAB) && intent.getBooleanExtra(OPEN_MY_PLACES_TAB, false)) { + mViewPager.setCurrentItem(1, false); + } } } } + public String getGroupNameToShow() { + return groupNameToShow; + } + public void addTrack() { Intent intent = getImportGpxIntent(); startActivityForResult(intent, OPEN_GPX_DOCUMENT_REQUEST);