Added show all feature to route points

This commit is contained in:
Alexey Kulish 2018-05-12 23:18:55 +03:00
parent 1b8f0d106f
commit 83e4bf17be
3 changed files with 100 additions and 56 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:orientation="vertical">
<ExpandableListView <ExpandableListView
android:id="@android:id/list" android:id="@android:id/list"
@ -25,4 +25,4 @@
<include layout="@layout/my_places_fabs"/> <include layout="@layout/my_places_fabs"/>
</android.support.design.widget.CoordinatorLayout> </RelativeLayout>

View file

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background" android:background="?attr/expandable_list_item_background"
android:minHeight="@dimen/list_item_height" android:minHeight="@dimen/list_item_height"
@ -19,14 +20,15 @@
android:id="@+id/list_divider" android:id="@+id/list_divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:background="?attr/dashboard_divider"
android:layout_marginLeft="54dp" android:layout_marginLeft="54dp"
android:background="?attr/dashboard_divider"
android:visibility="gone"/> android:visibility="gone"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingLeft="@dimen/list_content_padding"> android:paddingLeft="@dimen/list_content_padding">
@ -34,7 +36,6 @@
android:id="@+id/toggle_item" android:id="@+id/toggle_item"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/list_content_padding" android:layout_marginRight="@dimen/list_content_padding"
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
@ -44,18 +45,16 @@
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size" android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size" android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/list_content_padding"/> android:layout_marginRight="@dimen/list_content_padding"/>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical" android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingRight="@dimen/list_content_padding" android:paddingRight="@dimen/list_content_padding"
android:paddingTop="8dp" android:paddingTop="8dp">
android:paddingBottom="8dp">
<TextView <TextView
android:id="@+id/label" android:id="@+id/label"
@ -65,6 +64,18 @@
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
tools:text="Point title"/> tools:text="Point title"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_sub_text_size"
android:visibility="gone"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"
tools:text="SHOW ALL"
tools:visibility="visible"/>
<TextView <TextView
android:id="@+id/description" android:id="@+id/description"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -78,14 +89,13 @@
<ImageButton <ImageButton
android:id="@+id/options" android:id="@+id/options"
android:contentDescription="@string/shared_string_more"
android:layout_width="@dimen/list_item_height" android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height" android:layout_height="@dimen/list_item_height"
android:layout_gravity="center_vertical"
android:background="?attr/dashboard_button" android:background="?attr/dashboard_button"
android:contentDescription="@string/shared_string_more"
android:src="@drawable/ic_overflow_menu_white" android:src="@drawable/ic_overflow_menu_white"
android:visibility="visible"/> android:visibility="visible"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </FrameLayout>

View file

@ -21,6 +21,7 @@ import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MenuItem.OnActionExpandListener;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AbsListView; import android.widget.AbsListView;
@ -59,6 +60,7 @@ import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
@ -80,20 +82,22 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
public static final int DELETE_ACTION_ID = 3; public static final int DELETE_ACTION_ID = 3;
public static final int SHARE_ID = 4; public static final int SHARE_ID = 4;
public static final int SELECT_MAP_MARKERS_ID = 5; public static final int SELECT_MAP_MARKERS_ID = 5;
public static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6; //public static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6;
public static final int SELECT_FAVORITES_ID = 7; public static final int SELECT_FAVORITES_ID = 7;
public static final int SELECT_FAVORITES_ACTION_MODE_ID = 8; public static final int SELECT_FAVORITES_ACTION_MODE_ID = 8;
private static final int ROUTE_POINTS_LIMIT = 3;
private OsmandApplication app; private OsmandApplication app;
private TrackActivityFragmentAdapter fragmentAdapter; private TrackActivityFragmentAdapter fragmentAdapter;
final private PointGPXAdapter adapter = new PointGPXAdapter(); final private PointGPXAdapter adapter = new PointGPXAdapter();
private boolean selectionMode = false; private boolean selectionMode;
private LinkedHashMap<GpxDisplayItemType, Set<GpxDisplayItem>> selectedItems = new LinkedHashMap<>(); private LinkedHashMap<GpxDisplayItemType, Set<GpxDisplayItem>> selectedItems = new LinkedHashMap<>();
private Set<Integer> selectedGroups = new LinkedHashSet<>(); private Set<Integer> selectedGroups = new LinkedHashSet<>();
private ActionMode actionMode; private ActionMode actionMode;
private SearchView searchView;
private boolean updateEnable; private boolean updateEnable;
private boolean routePointsExpanded;
private View mainView; private View mainView;
private PopupMenu popupItemMenu; private PopupMenu popupItemMenu;
@ -300,10 +304,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
} }
MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark, MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark,
R.drawable.ic_action_search_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); R.drawable.ic_action_search_dark, MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
searchView = new SearchView(activity); SearchView searchView = new SearchView(activity);
FavoritesActivity.updateSearchView(activity, searchView); FavoritesActivity.updateSearchView(activity, searchView);
MenuItemCompat.setActionView(mi, searchView); mi.setActionView(searchView);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
@ -317,7 +321,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
return true; return true;
} }
}); });
MenuItemCompat.setOnActionExpandListener(mi, new MenuItemCompat.OnActionExpandListener() { mi.setOnActionExpandListener(new OnActionExpandListener() {
@Override @Override
public boolean onMenuItemActionExpand(MenuItem item) { public boolean onMenuItemActionExpand(MenuItem item) {
return true; return true;
@ -329,7 +333,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
List<GpxDisplayGroup> groups = getOriginalGroups(); List<GpxDisplayGroup> groups = getOriginalGroups();
if (groups != null) { if (groups != null) {
adapter.synchronizeGroups(groups); adapter.synchronizeGroups(groups);
adapter.notifyDataSetChanged();
} }
// Needed to hide intermediate progress bar after closing action mode // Needed to hide intermediate progress bar after closing action mode
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@ -341,22 +344,22 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
} }
}); });
if (!MenuItemCompat.isActionViewExpanded(mi)) { if (!mi.isActionViewExpanded()) {
createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark,
R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); R.drawable.ic_action_gshare_dark, MenuItem.SHOW_AS_ACTION_NEVER);
GPXFile gpxFile = getGpx(); GPXFile gpxFile = getGpx();
if (gpxFile != null && gpxFile.path != null) { if (gpxFile != null && gpxFile.path != null) {
final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
final boolean synced = markersHelper.getMarkersGroup(getGpx()) != null; final boolean synced = markersHelper.getMarkersGroup(getGpx()) != null;
createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers
: R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag_dark, : R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag_dark,
R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); R.drawable.ic_action_flag_dark, MenuItem.SHOW_AS_ACTION_NEVER);
} }
createMenuItem(menu, SELECT_FAVORITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_fav_dark, createMenuItem(menu, SELECT_FAVORITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_fav_dark,
R.drawable.ic_action_fav_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); R.drawable.ic_action_fav_dark, MenuItem.SHOW_AS_ACTION_NEVER);
createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark,
R.drawable.ic_action_delete_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); R.drawable.ic_action_delete_dark, MenuItem.SHOW_AS_ACTION_NEVER);
} }
this.optionsMenu = menu; this.optionsMenu = menu;
} }
@ -505,7 +508,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
setSelectionMode(true); setSelectionMode(true);
createMenuItem(menu, SELECT_FAVORITES_ACTION_MODE_ID, R.string.shared_string_add_to_favorites, createMenuItem(menu, SELECT_FAVORITES_ACTION_MODE_ID, R.string.shared_string_add_to_favorites,
R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_dark,
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); MenuItem.SHOW_AS_ACTION_IF_ROOM);
selectedItems.clear(); selectedItems.clear();
selectedGroups.clear(); selectedGroups.clear();
adapter.notifyDataSetInvalidated(); adapter.notifyDataSetInvalidated();
@ -587,9 +590,12 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (selectionMode) { final GpxDisplayItem item = adapter.getChild(groupPosition, childPosition);
if (item == null) {
routePointsExpanded = true;
adapter.notifyDataSetChanged();
} else if (selectionMode) {
CheckBox ch = (CheckBox) v.findViewById(R.id.toggle_item); CheckBox ch = (CheckBox) v.findViewById(R.id.toggle_item);
GpxDisplayItem item = adapter.getChild(groupPosition, childPosition);
ch.setChecked(!ch.isChecked()); ch.setChecked(!ch.isChecked());
if (ch.isChecked()) { if (ch.isChecked()) {
Set<GpxDisplayItem> set = selectedItems.get(item.group.getType()); Set<GpxDisplayItem> set = selectedItems.get(item.group.getType());
@ -608,8 +614,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
} }
updateSelectionMode(actionMode); updateSelectionMode(actionMode);
} else { } else {
final GpxDisplayItem item = adapter.getChild(groupPosition, childPosition);
if (item != null) {
if (item.group.getGpx() != null) { if (item.group.getGpx() != null) {
app.getSelectedGpxHelper().setGpxFileToDisplay(item.group.getGpx()); app.getSelectedGpxHelper().setGpxFileToDisplay(item.group.getGpx());
} }
@ -623,7 +627,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
}
return true; return true;
} }
@ -699,7 +702,14 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
@Override @Override
public GpxDisplayItem getChild(int groupPosition, int childPosition) { public GpxDisplayItem getChild(int groupPosition, int childPosition) {
final GpxDisplayGroup group = getGroup(groupPosition);
int count = itemGroups.get(group).size();
if (group.getType() == GpxDisplayItemType.TRACK_POINTS || routePointsExpanded
|| count <= ROUTE_POINTS_LIMIT + 1 || childPosition < ROUTE_POINTS_LIMIT) {
return itemGroups.get(groups.get(groupPosition)).get(childPosition); return itemGroups.get(groups.get(groupPosition)).get(childPosition);
} else {
return null;
}
} }
@Override @Override
@ -709,7 +719,13 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
@Override @Override
public int getChildrenCount(int groupPosition) { public int getChildrenCount(int groupPosition) {
return itemGroups.get(groups.get(groupPosition)).size(); int count = itemGroups.get(groups.get(groupPosition)).size();
final GpxDisplayGroup group = getGroup(groupPosition);
if (group.getType() == GpxDisplayItemType.TRACK_POINTS || routePointsExpanded || count <= ROUTE_POINTS_LIMIT + 1) {
return count;
} else {
return ROUTE_POINTS_LIMIT + 1;
}
} }
@Override @Override
@ -814,12 +830,17 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
ImageView icon = (ImageView) row.findViewById(R.id.icon); ImageView icon = (ImageView) row.findViewById(R.id.icon);
TextView title = (TextView) row.findViewById(R.id.label); TextView title = (TextView) row.findViewById(R.id.label);
TextViewEx button = (TextViewEx) row.findViewById(R.id.button);
TextView description = (TextView) row.findViewById(R.id.description); TextView description = (TextView) row.findViewById(R.id.description);
final GpxDisplayItem gpxItem = getChild(groupPosition, childPosition); final GpxDisplayItem gpxItem = getChild(groupPosition, childPosition);
boolean isWpt = gpxItem.group.getType() == GpxDisplayItemType.TRACK_POINTS; boolean isWpt = gpxItem != null && gpxItem.group.getType() == GpxDisplayItemType.TRACK_POINTS;
ImageView options = (ImageView) row.findViewById(R.id.options); ImageView options = (ImageView) row.findViewById(R.id.options);
if (isWpt) { if (isWpt) {
title.setVisibility(View.VISIBLE);
description.setVisibility(View.VISIBLE);
button.setVisibility(View.GONE);
options.setFocusable(false); options.setFocusable(false);
options.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon( options.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(
R.drawable.ic_overflow_menu_white)); R.drawable.ic_overflow_menu_white));
@ -865,10 +886,22 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
groupColor = ContextCompat.getColor(app, R.color.gpx_color_point); groupColor = ContextCompat.getColor(app, R.color.gpx_color_point);
} }
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), groupColor, false)); icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), groupColor, false));
} else {
boolean showAll = gpxItem == null;
title.setVisibility(showAll ? View.GONE : View.VISIBLE);
description.setVisibility(showAll ? View.GONE : View.VISIBLE);
button.setVisibility(!showAll ? View.GONE : View.VISIBLE);
if (showAll) {
int count = itemGroups.get(groups.get(groupPosition)).size();
button.setText(getString(R.string.shared_string_show_all) + " - " + count);
icon.setImageDrawable(null);
} else { } else {
icon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_marker_dark)); icon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_marker_dark));
}
options.setVisibility(View.GONE); options.setVisibility(View.GONE);
} }
if (gpxItem != null) {
title.setText(gpxItem.name); title.setText(gpxItem.name);
if (!Algorithms.isEmpty(gpxItem.description)) { if (!Algorithms.isEmpty(gpxItem.description)) {
description.setText(gpxItem.description); description.setText(gpxItem.description);
@ -876,9 +909,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
} else { } else {
description.setVisibility(View.GONE); description.setVisibility(View.GONE);
} }
}
final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item); final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item);
if (selectionMode) { if (selectionMode && gpxItem != null) {
ch.setVisibility(View.VISIBLE); ch.setVisibility(View.VISIBLE);
ch.setChecked(selectedItems.get(gpxItem.group.getType()) != null && selectedItems.get(gpxItem.group.getType()).contains(gpxItem)); ch.setChecked(selectedItems.get(gpxItem.group.getType()) != null && selectedItems.get(gpxItem.group.getType()).contains(gpxItem));
row.findViewById(R.id.icon).setVisibility(View.GONE); row.findViewById(R.id.icon).setVisibility(View.GONE);