Add show all button

This commit is contained in:
PavelRatushny 2017-12-12 14:35:35 +02:00
parent 9be80bb8fc
commit ac7ea326a6
4 changed files with 63 additions and 16 deletions

View file

@ -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 {

View file

@ -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<FavouritePoint> 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<FavouritePoint> 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;
}

View file

@ -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);
}
}

View file

@ -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<WeakReference<Fragment>> 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);