From 2b717491997422268cbb442fb568a31ceba652d3 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 15 Feb 2021 12:31:54 +0200 Subject: [PATCH 1/8] init --- OsmAnd/res/layout/track_groups_card.xml | 15 +++++ .../osmand/plus/track/PointsGroupsCard.java | 64 +++++++++++++++++++ .../osmand/plus/track/TrackMenuFragment.java | 25 +++++++- .../osmand/plus/track/TrackPointsCard.java | 4 ++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 OsmAnd/res/layout/track_groups_card.xml create mode 100644 OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java diff --git a/OsmAnd/res/layout/track_groups_card.xml b/OsmAnd/res/layout/track_groups_card.xml new file mode 100644 index 0000000000..216c029bad --- /dev/null +++ b/OsmAnd/res/layout/track_groups_card.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java b/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java new file mode 100644 index 0000000000..c7265b882f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java @@ -0,0 +1,64 @@ +package net.osmand.plus.track; + +import android.text.TextUtils; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; +import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; +import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem; +import net.osmand.plus.routepreparationmenu.cards.BaseCard; + +import java.util.ArrayList; +import java.util.List; + +public class PointsGroupsCard extends BaseCard { + + private final TrackDisplayHelper displayHelper; + private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS}; + private final List displayGroups = new ArrayList<>(); + + public PointsGroupsCard(@NonNull MapActivity mapActivity, @NonNull TrackDisplayHelper displayHelper, + @NonNull List groups) { + super(mapActivity); + this.displayHelper = displayHelper; + displayGroups.addAll(groups); + } + + @Override + public int getCardLayoutId() { + return R.layout.track_groups_card; + } + + @Override + protected void updateContent() { + List groupNames = new ArrayList<>(); + for (GpxDisplayGroup group : displayGroups) { + String categoryName = group.getName(); + if (TextUtils.isEmpty(categoryName)) { + categoryName = app.getString(R.string.shared_string_gpx_points); + } + groupNames.add(categoryName); + } + HorizontalSelectionAdapter selectionAdapter = new HorizontalSelectionAdapter(app, nightMode); + selectionAdapter.setTitledItems(groupNames); + selectionAdapter.setSelectedItemByTitle(app.getString(R.string.shared_string_gpx_points)); + selectionAdapter.setListener(new HorizontalSelectionAdapterListener() { + @Override + public void onItemSelected(HorizontalSelectionItem item) { + + } + }); + + RecyclerView recyclerView = view.findViewById(R.id.recycler_view); + recyclerView.setAdapter(selectionAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false)); + selectionAdapter.notifyDataSetChanged(); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index ff2ec67140..e1fd0e7ea8 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -132,6 +132,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private DescriptionCard descriptionCard; private OverviewCard overviewCard; private TrackPointsCard pointsCard; + private PointsGroupsCard groupsCard; private TextView headerTitle; private ImageView headerIcon; @@ -331,8 +332,28 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card headerContainer.addView(overviewCard.build(getMapActivity())); } } else { - if (overviewCard != null && overviewCard.getView() != null) { - headerContainer.removeView(overviewCard.getView()); + if (menuType == TrackMenuType.POINTS) { + if (groupsCard != null && groupsCard.getView() != null) { + ViewGroup parent = ((ViewGroup) groupsCard.getView().getParent()); + if (parent != null) { + parent.removeView(groupsCard.getView()); + } + headerContainer.addView(groupsCard.getView()); + } else { + groupsCard = new PointsGroupsCard(getMapActivity(), displayHelper, pointsCard.getGroups()); + groupsCard.setListener(this); + headerContainer.addView(groupsCard.build(getMapActivity())); + } + if (overviewCard != null && overviewCard.getView() != null) { + headerContainer.removeView(overviewCard.getView()); + } + } else { + if (overviewCard != null && overviewCard.getView() != null) { + headerContainer.removeView(overviewCard.getView()); + } + if (groupsCard != null && groupsCard.getView() != null) { + headerContainer.removeView(groupsCard.getView()); + } } boolean isOptions = menuType == TrackMenuType.OPTIONS; setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java b/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java index 3978c83ded..7fda76003c 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java @@ -109,6 +109,10 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O expandAllGroups(); } + public List getGroups() { + return adapter.groups; + } + private void addActions(LayoutInflater inflater) { View view = inflater.inflate(R.layout.preference_category_with_descr, listView, false); TextView title = view.findViewById(android.R.id.title); From 457649210896122b7be71a1469db630ff83b5237 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Thu, 18 Feb 2021 18:56:27 +0200 Subject: [PATCH 2/8] Fix conflicts, minor UI fix, all categories add, HorizontalSelectionAdapterListener --- OsmAnd/res/layout/track_groups_card.xml | 5 ++++ .../osmand/plus/track/PointsGroupsCard.java | 23 +++++++++++++---- .../osmand/plus/track/TrackMenuFragment.java | 25 ++++++++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/OsmAnd/res/layout/track_groups_card.xml b/OsmAnd/res/layout/track_groups_card.xml index 216c029bad..ff070c1ed0 100644 --- a/OsmAnd/res/layout/track_groups_card.xml +++ b/OsmAnd/res/layout/track_groups_card.xml @@ -10,6 +10,11 @@ android:layout_height="@dimen/bottom_sheet_list_item_height" android:background="?attr/bg_color" android:orientation="horizontal" + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" + android:paddingStart="@dimen/content_padding" + android:paddingEnd="@dimen/content_padding" + android:clipToPadding="false" android:scrollbars="none" /> \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java b/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java index c7265b882f..d68b65fae6 100644 --- a/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java @@ -21,7 +21,7 @@ import java.util.List; public class PointsGroupsCard extends BaseCard { private final TrackDisplayHelper displayHelper; - private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS}; + private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS}; private final List displayGroups = new ArrayList<>(); public PointsGroupsCard(@NonNull MapActivity mapActivity, @NonNull TrackDisplayHelper displayHelper, @@ -38,7 +38,7 @@ public class PointsGroupsCard extends BaseCard { @Override protected void updateContent() { - List groupNames = new ArrayList<>(); + final List groupNames = new ArrayList<>(); for (GpxDisplayGroup group : displayGroups) { String categoryName = group.getName(); if (TextUtils.isEmpty(categoryName)) { @@ -46,13 +46,26 @@ public class PointsGroupsCard extends BaseCard { } groupNames.add(categoryName); } - HorizontalSelectionAdapter selectionAdapter = new HorizontalSelectionAdapter(app, nightMode); + if (groupNames.size() > 1) { + String categoryAll = app.getString(R.string.shared_string_all); + groupNames.add(0, categoryAll); + } + final HorizontalSelectionAdapter selectionAdapter = new HorizontalSelectionAdapter(app, nightMode); selectionAdapter.setTitledItems(groupNames); - selectionAdapter.setSelectedItemByTitle(app.getString(R.string.shared_string_gpx_points)); + selectionAdapter.setSelectedItemByTitle(groupNames.get(0)); selectionAdapter.setListener(new HorizontalSelectionAdapterListener() { @Override public void onItemSelected(HorizontalSelectionItem item) { - + selectionAdapter.setSelectedItem(item); + List trackPointsGroups = new ArrayList<>(); + List routePointsGroups = new ArrayList<>(); + for (GpxDisplayGroup group : displayGroups) { + if (group.getType() == GpxDisplayItemType.TRACK_POINTS) { + trackPointsGroups.add(group); + } else if (group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) { + routePointsGroups.add(group); + } + } } }); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index fb72c0a9c8..02a3ad6a5c 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -133,6 +133,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private DescriptionCard descriptionCard; private OverviewCard overviewCard; private TrackPointsCard pointsCard; + private PointsGroupsCard groupsCard; private TextView headerTitle; private ImageView headerIcon; @@ -341,7 +342,29 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } else { if (overviewCard != null && overviewCard.getView() != null) { overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks(); - headerContainer.removeView(overviewCard.getView()); + if (menuType == TrackMenuType.POINTS) { + if (groupsCard != null && groupsCard.getView() != null) { + ViewGroup parent = ((ViewGroup) groupsCard.getView().getParent()); + if (parent != null) { + parent.removeView(groupsCard.getView()); + } + headerContainer.addView(groupsCard.getView()); + } else { + groupsCard = new PointsGroupsCard(getMapActivity(), displayHelper, pointsCard.getGroups()); + groupsCard.setListener(this); + headerContainer.addView(groupsCard.build(getMapActivity())); + } + if (overviewCard != null && overviewCard.getView() != null) { + headerContainer.removeView(overviewCard.getView()); + } + } else { + if (overviewCard != null && overviewCard.getView() != null) { + headerContainer.removeView(overviewCard.getView()); + } + if (groupsCard != null && groupsCard.getView() != null) { + headerContainer.removeView(groupsCard.getView()); + } + } } boolean isOptions = menuType == TrackMenuType.OPTIONS; setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions); From e67395028a5c67df607d74411fc7e0559a55abc0 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 22 Feb 2021 12:22:21 +0200 Subject: [PATCH 3/8] Filtering on click chips --- .../osmand/plus/track/PointsGroupsCard.java | 54 ++++++++++--------- .../osmand/plus/track/TrackMenuFragment.java | 46 ++++++++-------- .../osmand/plus/track/TrackPointsCard.java | 35 ++++++------ 3 files changed, 70 insertions(+), 65 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java b/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java index d68b65fae6..be7fad749f 100644 --- a/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/PointsGroupsCard.java @@ -1,33 +1,30 @@ package net.osmand.plus.track; -import android.text.TextUtils; - import androidx.annotation.NonNull; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; -import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem; import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.util.Algorithms; import java.util.ArrayList; import java.util.List; public class PointsGroupsCard extends BaseCard { - private final TrackDisplayHelper displayHelper; - private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS}; + public static final int SELECT_GROUP_INDEX = 0; + + private GpxDisplayGroup selectedGroup; private final List displayGroups = new ArrayList<>(); - public PointsGroupsCard(@NonNull MapActivity mapActivity, @NonNull TrackDisplayHelper displayHelper, - @NonNull List groups) { + public PointsGroupsCard(@NonNull MapActivity mapActivity, @NonNull List groups) { super(mapActivity); - this.displayHelper = displayHelper; displayGroups.addAll(groups); } @@ -36,38 +33,43 @@ public class PointsGroupsCard extends BaseCard { return R.layout.track_groups_card; } + public GpxDisplayGroup getSelectedGroup() { + return selectedGroup; + } + @Override protected void updateContent() { - final List groupNames = new ArrayList<>(); + ArrayList items = new ArrayList<>(); + items.add(new HorizontalSelectionItem(app.getString(R.string.shared_string_all), null)); for (GpxDisplayGroup group : displayGroups) { String categoryName = group.getName(); - if (TextUtils.isEmpty(categoryName)) { + if (Algorithms.isEmpty(categoryName)) { categoryName = app.getString(R.string.shared_string_gpx_points); } - groupNames.add(categoryName); - } - if (groupNames.size() > 1) { - String categoryAll = app.getString(R.string.shared_string_all); - groupNames.add(0, categoryAll); + items.add(new HorizontalSelectionItem(categoryName, group)); } final HorizontalSelectionAdapter selectionAdapter = new HorizontalSelectionAdapter(app, nightMode); - selectionAdapter.setTitledItems(groupNames); - selectionAdapter.setSelectedItemByTitle(groupNames.get(0)); + selectionAdapter.setItems(items); selectionAdapter.setListener(new HorizontalSelectionAdapterListener() { @Override public void onItemSelected(HorizontalSelectionItem item) { - selectionAdapter.setSelectedItem(item); - List trackPointsGroups = new ArrayList<>(); - List routePointsGroups = new ArrayList<>(); - for (GpxDisplayGroup group : displayGroups) { - if (group.getType() == GpxDisplayItemType.TRACK_POINTS) { - trackPointsGroups.add(group); - } else if (group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) { - routePointsGroups.add(group); - } + selectedGroup = (GpxDisplayGroup) item.getObject(); + CardListener listener = getListener(); + if (listener != null) { + listener.onCardButtonPressed(PointsGroupsCard.this, SELECT_GROUP_INDEX); } + selectionAdapter.notifyDataSetChanged(); } }); + if (selectedGroup != null) { + String categoryName = selectedGroup.getName(); + if (Algorithms.isEmpty(categoryName)) { + categoryName = app.getString(R.string.shared_string_gpx_points); + } + selectionAdapter.setSelectedItemByTitle(categoryName); + } else { + selectionAdapter.setSelectedItemByTitle(app.getString(R.string.shared_string_all)); + } RecyclerView recyclerView = view.findViewById(R.id.recycler_view); recyclerView.setAdapter(selectionAdapter); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 02a3ad6a5c..15b42e0fb1 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -340,31 +340,24 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card blocksBuilder.runUpdatingStatBlocksIfNeeded(); } } else { + if (menuType == TrackMenuType.POINTS && !Algorithms.isEmpty(pointsCard.getGroups())) { + if (groupsCard != null && groupsCard.getView() != null) { + ViewGroup parent = ((ViewGroup) groupsCard.getView().getParent()); + if (parent != null) { + parent.removeView(groupsCard.getView()); + } + headerContainer.addView(groupsCard.getView()); + } else { + groupsCard = new PointsGroupsCard(getMapActivity(), pointsCard.getGroups()); + groupsCard.setListener(this); + headerContainer.addView(groupsCard.build(getMapActivity())); + } + } else if (groupsCard != null && groupsCard.getView() != null) { + headerContainer.removeView(groupsCard.getView()); + } if (overviewCard != null && overviewCard.getView() != null) { overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks(); - if (menuType == TrackMenuType.POINTS) { - if (groupsCard != null && groupsCard.getView() != null) { - ViewGroup parent = ((ViewGroup) groupsCard.getView().getParent()); - if (parent != null) { - parent.removeView(groupsCard.getView()); - } - headerContainer.addView(groupsCard.getView()); - } else { - groupsCard = new PointsGroupsCard(getMapActivity(), displayHelper, pointsCard.getGroups()); - groupsCard.setListener(this); - headerContainer.addView(groupsCard.build(getMapActivity())); - } - if (overviewCard != null && overviewCard.getView() != null) { - headerContainer.removeView(overviewCard.getView()); - } - } else { - if (overviewCard != null && overviewCard.getView() != null) { - headerContainer.removeView(overviewCard.getView()); - } - if (groupsCard != null && groupsCard.getView() != null) { - headerContainer.removeView(groupsCard.getView()); - } - } + headerContainer.removeView(overviewCard.getView()); } boolean isOptions = menuType == TrackMenuType.OPTIONS; setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions); @@ -853,6 +846,13 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } else if (buttonIndex == OPEN_WAYPOINT_INDEX) { dismiss(); } + } else if (card instanceof PointsGroupsCard) { + PointsGroupsCard groupsCard = (PointsGroupsCard) card; + GpxDisplayGroup group = groupsCard.getSelectedGroup(); + if (pointsCard != null) { + pointsCard.setSelectedGroup(group); + pointsCard.updateContent(); + } } } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java b/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java index 7fda76003c..fe824bafc8 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java @@ -64,6 +64,7 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O private final TrackDisplayHelper displayHelper; private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS}; + private GpxDisplayGroup selectedGroup; private final Set selectedGroups = new LinkedHashSet<>(); private final LinkedHashMap> selectedItems = new LinkedHashMap<>(); private boolean selectionMode; @@ -97,7 +98,7 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O listView.setOnChildClickListener(this); adapter.setFilterResults(null); - adapter.synchronizeGroups(getOriginalGroups()); + adapter.synchronizeGroups(getDisplayGroups()); if (listView.getAdapter() == null) { listView.setAdapter(adapter); } @@ -109,6 +110,10 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O expandAllGroups(); } + public void setSelectedGroup(GpxDisplayGroup selectedGroup) { + this.selectedGroup = selectedGroup; + } + public List getGroups() { return adapter.groups; } @@ -178,6 +183,10 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O return displayHelper.getOriginalGroups(filterTypes); } + private List getDisplayGroups() { + return selectedGroup != null ? Collections.singletonList(selectedGroup) : getOriginalGroups(); + } + @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { GpxDisplayItem item = adapter.getChild(groupPosition, childPosition); @@ -250,7 +259,7 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O public void onPointsDeleted() { selectedItems.clear(); selectedGroups.clear(); - adapter.synchronizeGroups(getOriginalGroups()); + adapter.synchronizeGroups(getDisplayGroups()); } public void filter(String text) { @@ -622,16 +631,13 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O } else { Set filter = new HashSet<>(); String cs = constraint.toString().toLowerCase(); - List groups = getOriginalGroups(); - if (groups != null) { - for (GpxDisplayGroup g : groups) { - for (GpxDisplayItem i : g.getModifiableList()) { - if (i.name.toLowerCase().contains(cs)) { - filter.add(i); - } else if (i.locationStart != null && !TextUtils.isEmpty(i.locationStart.category) - && i.locationStart.category.toLowerCase().contains(cs)) { - filter.add(i.locationStart.category); - } + for (GpxDisplayGroup g : getDisplayGroups()) { + for (GpxDisplayItem i : g.getModifiableList()) { + if (i.name.toLowerCase().contains(cs)) { + filter.add(i); + } else if (i.locationStart != null && !TextUtils.isEmpty(i.locationStart.category) + && i.locationStart.category.toLowerCase().contains(cs)) { + filter.add(i.locationStart.category); } } } @@ -645,10 +651,7 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O protected void publishResults(CharSequence constraint, FilterResults results) { synchronized (adapter) { adapter.setFilterResults((Set) results.values); - List groups = getOriginalGroups(); - if (groups != null) { - adapter.synchronizeGroups(groups); - } + adapter.synchronizeGroups(getDisplayGroups()); } adapter.notifyDataSetChanged(); expandAllGroups(); From 0767cf3d442e612d7e70b064b1ce7be983f354da Mon Sep 17 00:00:00 2001 From: Kseniia Date: Mon, 22 Feb 2021 14:45:11 +0200 Subject: [PATCH 4/8] fix description --- OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java index 7b72024b12..02f31efe8e 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java @@ -300,8 +300,9 @@ public class WikiArticleHelper { if (firstParagraphStart != -1 && firstParagraphEnd != -1 && firstParagraphEnd >= firstParagraphStart) { firstParagraphHtml = content.substring(firstParagraphStart, firstParagraphEnd + P_CLOSED.length()); - while (firstParagraphHtml.substring(P_OPENED.length(), firstParagraphHtml.length() - P_CLOSED.length()).trim().isEmpty() - && (firstParagraphEnd + P_CLOSED.length()) < content.length()) { + while ((firstParagraphHtml.substring(P_OPENED.length(), firstParagraphHtml.length() - P_CLOSED.length()).trim().isEmpty() + && (firstParagraphEnd + P_CLOSED.length()) < content.length()) + || Html.fromHtml(firstParagraphHtml.replaceAll("()|()", "")).toString().trim().length() == 0) { firstParagraphStart = content.indexOf(P_OPENED, firstParagraphEnd); firstParagraphEnd = firstParagraphStart == -1 ? -1 : content.indexOf(P_CLOSED, firstParagraphStart); if (firstParagraphStart != -1 && firstParagraphEnd != -1) { From 627cd967b11c903afdb4097587bc6bee122c2326 Mon Sep 17 00:00:00 2001 From: Skalii Date: Tue, 23 Feb 2021 01:42:59 +0200 Subject: [PATCH 5/8] fix adding unnamed waypoints to favorites --- OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index 9279a85ce5..3ba4d92cbd 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -673,6 +673,9 @@ public class ImportHelper { public static List asFavourites(OsmandApplication app, List wptPts, String fileName, boolean forceImportFavourites) { List favourites = new ArrayList<>(); for (WptPt p : wptPts) { + if (p.name == null) { + p.name = Algorithms.getFileNameWithoutExtension(fileName); + } if (p.name != null) { final String fpCat; if (p.category == null) { From 2561ee99e111fd3b55db8b35cb72b112bf59d541 Mon Sep 17 00:00:00 2001 From: Skalii Date: Tue, 23 Feb 2021 01:50:50 +0200 Subject: [PATCH 6/8] fix replace checks; --- OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index 3ba4d92cbd..3785331119 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -673,10 +673,10 @@ public class ImportHelper { public static List asFavourites(OsmandApplication app, List wptPts, String fileName, boolean forceImportFavourites) { List favourites = new ArrayList<>(); for (WptPt p : wptPts) { - if (p.name == null) { + if (Algorithms.isEmpty(p.name)) { p.name = Algorithms.getFileNameWithoutExtension(fileName); } - if (p.name != null) { + if (!Algorithms.isEmpty(p.name)) { final String fpCat; if (p.category == null) { if (forceImportFavourites) { From e420cdb3ec366ef52ac88dba9fa9982d294a4ec4 Mon Sep 17 00:00:00 2001 From: Skalii Date: Tue, 23 Feb 2021 10:46:11 +0200 Subject: [PATCH 7/8] fix name for unnamed waypoints --- OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index 3785331119..e65727b6c1 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -674,7 +674,7 @@ public class ImportHelper { List favourites = new ArrayList<>(); for (WptPt p : wptPts) { if (Algorithms.isEmpty(p.name)) { - p.name = Algorithms.getFileNameWithoutExtension(fileName); + p.name = app.getResources().getString(R.string.shared_string_waypoint); } if (!Algorithms.isEmpty(p.name)) { final String fpCat; From 2ea0f7302d49e51c374e3529271ed9cdb110f4f5 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 23 Feb 2021 12:06:04 +0200 Subject: [PATCH 8/8] Fix open on map, travel article svg image thumbs, show more progress. --- OsmAnd/.gitignore | 11 ++++++----- .../plus/wikivoyage/data/TravelArticle.java | 3 ++- .../plus/wikivoyage/data/TravelObfHelper.java | 1 + .../wikivoyage/explore/ExploreTabFragment.java | 12 ++++-------- .../explore/SavedArticlesTabFragment.java | 15 --------------- .../explore/WikivoyageExploreActivity.java | 14 +++++--------- 6 files changed, 18 insertions(+), 38 deletions(-) diff --git a/OsmAnd/.gitignore b/OsmAnd/.gitignore index 3149fb4209..a4e941e9d2 100644 --- a/OsmAnd/.gitignore +++ b/OsmAnd/.gitignore @@ -39,11 +39,7 @@ mx_* valgrind/ bin/ dist/ -assets/specialphrases/* -assets/voice/* -assets/fonts/* -assets/feature_articles/* -assets/World_basemap_mini* + gen/ local.properties raw/ @@ -56,6 +52,11 @@ out/ use/ osmand.properties osmand.xml +assets/specialphrases/* +assets/voice/* +assets/fonts/* +assets/feature_articles/* +assets/*.obf assets/style.css assets/poi_categories.json assets/help/*.html diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index a346f496eb..ca438b02eb 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -159,7 +159,8 @@ public class TravelArticle { System.err.println(e.getMessage()); } String prefix = thumbnail ? THUMB_PREFIX : REGULAR_PREFIX; - return IMAGE_ROOT_URL + "thumb/" + hash[0] + "/" + hash[1] + "/" + imageTitle + "/" + prefix + imageTitle; + String suffix = imageTitle.endsWith(".svg") ? ".png" : ""; + return IMAGE_ROOT_URL + "thumb/" + hash[0] + "/" + hash[1] + "/" + imageTitle + "/" + prefix + imageTitle + suffix; } @Size(2) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 6fb0bb8623..390100c7c7 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -943,6 +943,7 @@ public class TravelObfHelper implements TravelHelper { } if (!Algorithms.isEmpty(amenities)) { article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, readGpx, callback); + break; } } return article; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index 1d6d86daa2..396da70e43 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -49,7 +49,6 @@ import java.util.List; import static net.osmand.plus.download.DownloadResources.WIKIVOYAGE_FILE_FILTER; import static net.osmand.plus.resources.ResourceManager.DEFAULT_WIKIVOYAGE_TRAVEL_OBF; -import static net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity.*; public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents, TravelLocalDataHelper.Listener { @@ -95,10 +94,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv if (app != null) { app.getTravelHelper().getBookmarksHelper().addListener(this); } - WikivoyageExploreActivity exploreActivity = getExploreActivity(); - if (exploreActivity != null) { - exploreActivity.onTabFragmentResume(this); - } } @Override @@ -141,7 +136,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv app.getTravelHelper().initializeDataOnAppStartup(); WikivoyageExploreActivity exploreActivity = getExploreActivity(); if (exploreActivity != null) { - exploreActivity.populateData(); + exploreActivity.populateData(true); } } else { removeRedundantCards(); @@ -194,8 +189,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv travelButtonCard.setListener(new TravelNeededMapsCard.CardListener() { @Override public void onPrimaryButtonClick() { - if (activity instanceof WikivoyageExploreActivity) { - new LoadWikivoyageData((WikivoyageExploreActivity) activity, false).execute(); + WikivoyageExploreActivity exploreActivity = getExploreActivity(); + if (exploreActivity != null) { + exploreActivity.populateData(false); } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java index 95aec13970..6eec7fb9e3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.wikivoyage.explore; -import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -80,10 +79,6 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav if (dataHelper != null) { dataHelper.addListener(this); } - WikivoyageExploreActivity exploreActivity = getExploreActivity(); - if (exploreActivity != null) { - exploreActivity.onTabFragmentResume(this); - } } @Override @@ -105,16 +100,6 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav } } - @Nullable - private WikivoyageExploreActivity getExploreActivity() { - Activity activity = getActivity(); - if (activity != null && activity instanceof WikivoyageExploreActivity) { - return (WikivoyageExploreActivity) activity; - } else { - return null; - } - } - public void invalidateAdapter() { if (adapter != null) { adapter.notifyDataSetChanged(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java index 29add9c1a7..3bfa4b7a14 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java @@ -156,7 +156,7 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv }); updateSearchBarVisibility(); - populateData(); + populateData(true); } @Override @@ -249,7 +249,7 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv invalidateTabAdapters(); break; case WikivoyageOptionsBottomSheetDialogFragment.TRAVEL_BOOK_CHANGED: - populateData(); + populateData(true); break; } } @@ -313,7 +313,7 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv return ContextCompat.getColor(app, colorId); } - public void populateData() { + public void populateData(final boolean resetData) { switchProgressBarVisibility(true); if (app.isApplicationInitializing()) { final WeakReference activityRef = new WeakReference<>(this); @@ -326,12 +326,12 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv public void onFinish(AppInitializer init) { WikivoyageExploreActivity activity = activityRef.get(); if (AndroidUtils.isActivityNotDestroyed(activity)) { - new LoadWikivoyageData(activity,true).execute(); + new LoadWikivoyageData(activity, resetData).execute(); } } }); } else { - new LoadWikivoyageData(this,true).execute(); + new LoadWikivoyageData(this, resetData).execute(); } } @@ -371,10 +371,6 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv } } - public void onTabFragmentResume(Fragment fragment) { - updateFragments(); - } - @Override public void savedArticlesUpdated() { updateFragments();