From 4aa877f7f65b2b28566c7d5476466dceb992e3c6 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 29 Jan 2021 10:50:05 +0200 Subject: [PATCH 001/173] Travel - vehicle mode --- .../main/java/net/osmand/data/Amenity.java | 20 ++++ .../main/java/net/osmand/osm/MapPoiTypes.java | 8 +- .../res/layout/wikivoyage_travel_gpx_card.xml | 92 ++++++++++++++----- .../plus/wikivoyage/data/TravelGpx.java | 2 + .../plus/wikivoyage/data/TravelObfHelper.java | 2 + .../explore/travelcards/TravelGpxCard.java | 16 +++- 6 files changed, 113 insertions(+), 27 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 861a7c9b93..48e15df815 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -179,6 +179,26 @@ public class Amenity extends MapObject { } } + public void addProfileTag(Entry e) { + if (getAdditionalInfo("profile") == null) { + if (e.getKey().startsWith("tag_")) { + switch (e.getValue().trim()) { + case "bicycle": + case "cycling": + case "mtb": + setAdditionalInfo("profile", "bicycle"); + break; + case "hiking": + case "hike": + case "walking": + case "walk": + setAdditionalInfo("profile", "pedestrian"); + break; + } + } + } + } + @Override public String toStringEn() { return super.toStringEn() + ": " + type.getKeyName() + ":" + subType; diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index e273fa4e7f..70d35e24ae 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -915,14 +915,18 @@ public class MapPoiTypes { if (!otag.equals(tag) && !otag.equals("name")) { PoiType pat = poiTypesByTag.get(otag + "/" + e.getValue()); if (pat == null) { - for(String splValue : e.getValue().split(";")) { + for (String splValue : e.getValue().split(";")) { PoiType ps = poiTypesByTag.get(otag + "/" + splValue.trim()); - if(ps != null) { + if (ps != null) { a.setAdditionalInfo(ps.getKeyName(), splValue.trim()); } } pat = poiTypesByTag.get(otag); + if (pat == null && otag.startsWith("tag_")) { + a.addProfileTag(e); + } } + if (pat != null && pat.isAdditional()) { a.setAdditionalInfo(pat.getKeyName(), e.getValue()); } diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml index 44077a0dcd..2e11585264 100644 --- a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -139,31 +139,82 @@ - + android:background="?attr/btn_border_bg" + android:layout_marginLeft="@dimen/content_padding_half" + android:layout_marginStart="@dimen/content_padding_half"> + + + + + + + + + + + + @@ -172,7 +223,6 @@ diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index 185fdc922c..91d404510d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -6,8 +6,10 @@ public class TravelGpx extends TravelArticle { public static final String DIFF_ELE_UP = "diff_ele_up"; public static final String DIFF_ELE_DOWN = "diff_ele_down"; public static final String USER = "user"; + public static final String PROFILE = "profile"; public String user; + public String profile; public float totalDistance = 0; public double diffElevationUp = 0; public double diffElevationDown = 0; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index f230929f1d..8622ed0996 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -58,6 +58,7 @@ import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle; import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_DOWN; import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_UP; import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE; +import static net.osmand.plus.wikivoyage.data.TravelGpx.PROFILE; import static net.osmand.plus.wikivoyage.data.TravelGpx.USER; import static net.osmand.util.Algorithms.capitalizeFirstLetter; @@ -203,6 +204,7 @@ public class TravelObfHelper implements TravelHelper { LOG.debug(e.getMessage(), e); } res.user = Algorithms.emptyIfNull(amenity.getTagContent(USER)); + res.profile = Algorithms.emptyIfNull(amenity.getTagContent(PROFILE)); articles.put("en", res); return articles; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 1bc2409621..efd81315d3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -2,16 +2,17 @@ package net.osmand.plus.wikivoyage.explore.travelcards; import android.graphics.drawable.Drawable; import android.view.View; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; -import net.osmand.AndroidUtils; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.track.TrackMenuFragment; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; @@ -40,10 +41,11 @@ public class TravelGpxCard extends BaseTravelCard { if (viewHolder instanceof TravelGpxVH) { final TravelGpxVH holder = (TravelGpxVH) viewHolder; holder.title.setText(article.getTitle()); - Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16); - holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16)); holder.user.setText(article.user); - AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark); + ProfileIcons profileRes = ProfileIcons.valueOf(article.profile.toUpperCase()); + holder.profileIcon.setImageDrawable(getActiveIcon(profileRes.getResId())); + holder.profile.setText(profileRes.getTitleId()); holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app)); @@ -92,6 +94,9 @@ public class TravelGpxCard extends BaseTravelCard { public final TextView title; public final TextView user; + public final ImageView userIcon; + public final TextView profile; + public final ImageView profileIcon; public final TextView distance; public final TextView diffElevationUp; public final TextView diffElevationDown; @@ -104,6 +109,9 @@ public class TravelGpxCard extends BaseTravelCard { super(itemView); title = itemView.findViewById(R.id.title); user = itemView.findViewById(R.id.user_name); + userIcon = itemView.findViewById(R.id.user_icon); + profile = itemView.findViewById(R.id.profile); + profileIcon = itemView.findViewById(R.id.profile_icon); distance = itemView.findViewById(R.id.distance); diffElevationUp = itemView.findViewById(R.id.diff_ele_up); diffElevationDown = itemView.findViewById(R.id.diff_ele_down); From 30c5fda90ab673fbf7d5540cc609e71138f0ed9f Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 29 Jan 2021 11:45:54 +0200 Subject: [PATCH 002/173] Fix UI --- .../res/layout/wikivoyage_travel_gpx_card.xml | 1 + .../explore/SavedArticlesRvAdapter.java | 26 ++++++++++++------- .../explore/travelcards/TravelGpxCard.java | 12 ++++++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml index 2e11585264..b3aaf7e849 100644 --- a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -184,6 +184,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/btn_border_bg" + android:visibility="gone" android:layout_marginLeft="@dimen/content_padding_half" android:layout_marginStart="@dimen/content_padding_half"> diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index a01de6e6cb..7d1531d5e0 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -18,12 +18,12 @@ import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator; -import net.osmand.AndroidUtils; import net.osmand.PicassoUtils; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.wikipedia.WikiArticleHelper; @@ -31,11 +31,13 @@ import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; -import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; +import net.osmand.util.Algorithms; import java.util.ArrayList; import java.util.List; +import static net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.*; + public class SavedArticlesRvAdapter extends RecyclerView.Adapter { private static final int HEADER_TYPE = 0; @@ -81,7 +83,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter Date: Fri, 29 Jan 2021 13:40:01 +0200 Subject: [PATCH 003/173] refactoring --- .../main/java/net/osmand/data/Amenity.java | 20 ------- .../main/java/net/osmand/osm/MapPoiTypes.java | 4 -- .../net/osmand/osm/edit/EntityParser.java | 56 +++++++++++++------ 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 48e15df815..861a7c9b93 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -179,26 +179,6 @@ public class Amenity extends MapObject { } } - public void addProfileTag(Entry e) { - if (getAdditionalInfo("profile") == null) { - if (e.getKey().startsWith("tag_")) { - switch (e.getValue().trim()) { - case "bicycle": - case "cycling": - case "mtb": - setAdditionalInfo("profile", "bicycle"); - break; - case "hiking": - case "hike": - case "walking": - case "walk": - setAdditionalInfo("profile", "pedestrian"); - break; - } - } - } - } - @Override public String toStringEn() { return super.toStringEn() + ": " + type.getKeyName() + ":" + subType; diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 70d35e24ae..77507de50c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -922,11 +922,7 @@ public class MapPoiTypes { } } pat = poiTypesByTag.get(otag); - if (pat == null && otag.startsWith("tag_")) { - a.addProfileTag(e); } - } - if (pat != null && pat.isAdditional()) { a.setAdditionalInfo(pat.getKeyName(), e.getValue()); } diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java index 9caa54b55c..9fb55fd64d 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java @@ -21,7 +21,7 @@ import net.osmand.osm.edit.Relation.RelationMember; import net.osmand.util.Algorithms; public class EntityParser { - + public static void parseMapObject(MapObject mo, Entity e, Map tags) { mo.setId(e.getId()); if(mo instanceof Amenity) { @@ -123,7 +123,7 @@ public class EntityParser { mo.setName(ref); } } - + private static void setNameFromBrand(MapObject mo, Map tags) { String ref = tags.get(OSMTagKey.BRAND.getValue()); if(ref != null){ @@ -140,7 +140,7 @@ public class EntityParser { op += " [" + ref + "]"; mo.setName(op); } - + private static String getWebSiteURL(Map tagValues, boolean checkWikipedia) { String siteUrl = null; @@ -170,14 +170,14 @@ public class EntityParser { } return siteUrl; } - - + + public static List parseAmenities(MapPoiTypes poiTypes, Entity entity, Map tags, List amenitiesList) { amenitiesList.clear(); // it could be collection of amenities boolean relation = entity instanceof Relation; - boolean purerelation = relation && + boolean purerelation = relation && !("multipolygon".equals(tags.get("type")) || "boundary".equals(tags.get("type"))); Collection> it = MapRenderingTypes.splitTagsIntoDifferentObjects(tags); for (Map ts : it) { @@ -193,6 +193,10 @@ public class EntityParser { if (wbs != null) { am.setAdditionalInfo("wikipedia", wbs); } + String tagCategory = getTagCategory(entity); + if (tagCategory != null) { + am.setAdditionalInfo("profile", tagCategory); + } if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) { amenitiesList.add(am); } @@ -201,9 +205,27 @@ public class EntityParser { } return amenitiesList; } - - - + + private static String getTagCategory(Entity e) { + Map tags = e.getTags(); + for (String key : tags.keySet()) { + if (key.startsWith("tag_")) { + switch (tags.get(key).trim()) { + case "bicycle": + case "cycling": + case "mtb": + return "bicycle"; + case "hiking": + case "hike": + case "walking": + case "walk": + return "pedestrian"; + } + } + } + return null; + } + private static boolean checkAmenitiesToAdd(Amenity a, List amenitiesList){ // check amenity for duplication for(Amenity b : amenitiesList){ @@ -212,9 +234,9 @@ public class EntityParser { } } return true; - + } - + public static Building parseBuilding(Entity e){ Building b = new Building(); parseMapObject(b, e, e.getTags()); @@ -228,7 +250,7 @@ public class EntityParser { List nodes = ((Way) e).getNodes(); for(int i = 0; i < nodes.size(); i++) { Node node = nodes.get(i); - if(node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) && + if(node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) && !Algorithms.isEmpty(node.getTag(OSMTagKey.REF))) { b.addEntrance(node.getTag(OSMTagKey.REF), node.getLatLon()); } @@ -236,11 +258,11 @@ public class EntityParser { } return b; } - + public static City parseCity(Node el) { return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE.getValue()))); } - + public static City parseCity(Entity el, CityType t) { if(t == null) { return null; @@ -252,15 +274,15 @@ public class EntityParser { c.setIsin(isin); return c; } - - + + public static TransportRoute parserRoute(Relation r, String ref){ TransportRoute rt = new TransportRoute(); parseMapObject(rt, r, r.getTags()); rt.setRef(ref); return rt; } - + public static TransportStop parseTransportStop(Entity e){ TransportStop st = new TransportStop(); parseMapObject(st, e, e.getTags()); From 2ae5bb6301d52328a1e4eb42a127ebaafbd083dd Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 29 Jan 2021 13:45:09 +0200 Subject: [PATCH 004/173] refactoring --- OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 77507de50c..e273fa4e7f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -915,14 +915,14 @@ public class MapPoiTypes { if (!otag.equals(tag) && !otag.equals("name")) { PoiType pat = poiTypesByTag.get(otag + "/" + e.getValue()); if (pat == null) { - for (String splValue : e.getValue().split(";")) { + for(String splValue : e.getValue().split(";")) { PoiType ps = poiTypesByTag.get(otag + "/" + splValue.trim()); - if (ps != null) { + if(ps != null) { a.setAdditionalInfo(ps.getKeyName(), splValue.trim()); } } pat = poiTypesByTag.get(otag); - } + } if (pat != null && pat.isAdditional()) { a.setAdditionalInfo(pat.getKeyName(), e.getValue()); } From e150d39c61fe9597c8ecac4dee2611b8ae76f353 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 29 Jan 2021 13:56:10 +0200 Subject: [PATCH 005/173] rename --- .../src/main/java/net/osmand/osm/edit/EntityParser.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java index 9fb55fd64d..e21927477a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java @@ -193,9 +193,9 @@ public class EntityParser { if (wbs != null) { am.setAdditionalInfo("wikipedia", wbs); } - String tagCategory = getTagCategory(entity); - if (tagCategory != null) { - am.setAdditionalInfo("profile", tagCategory); + String profileName = getProfileName(entity); + if (profileName != null) { + am.setAdditionalInfo("profile", profileName); } if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) { amenitiesList.add(am); @@ -206,7 +206,7 @@ public class EntityParser { return amenitiesList; } - private static String getTagCategory(Entity e) { + private static String getProfileName(Entity e) { Map tags = e.getTags(); for (String key : tags.keySet()) { if (key.startsWith("tag_")) { From d8ff9fb1e7e29becba9ce394feff12cb09bac0d5 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Sat, 30 Jan 2021 17:02:37 +0200 Subject: [PATCH 006/173] Add route activity type --- .../net/osmand/osm/edit/EntityParser.java | 24 ------------------- .../res/layout/wikivoyage_travel_gpx_card.xml | 6 ++--- .../plus/wikivoyage/data/TravelGpx.java | 4 ++-- .../plus/wikivoyage/data/TravelObfHelper.java | 4 ++-- .../explore/SavedArticlesRvAdapter.java | 10 ++++---- .../explore/travelcards/TravelGpxCard.java | 22 ++++++++--------- 6 files changed, 23 insertions(+), 47 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java index e21927477a..bd37de6ba0 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java @@ -193,10 +193,6 @@ public class EntityParser { if (wbs != null) { am.setAdditionalInfo("wikipedia", wbs); } - String profileName = getProfileName(entity); - if (profileName != null) { - am.setAdditionalInfo("profile", profileName); - } if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) { amenitiesList.add(am); } @@ -206,26 +202,6 @@ public class EntityParser { return amenitiesList; } - private static String getProfileName(Entity e) { - Map tags = e.getTags(); - for (String key : tags.keySet()) { - if (key.startsWith("tag_")) { - switch (tags.get(key).trim()) { - case "bicycle": - case "cycling": - case "mtb": - return "bicycle"; - case "hiking": - case "hike": - case "walking": - case "walk": - return "pedestrian"; - } - } - } - return null; - } - private static boolean checkAmenitiesToAdd(Amenity a, List amenitiesList){ // check amenity for duplication for(Amenity b : amenitiesList){ diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml index b3aaf7e849..963c27c9f3 100644 --- a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -180,7 +180,7 @@ Date: Tue, 2 Feb 2021 23:34:57 +0200 Subject: [PATCH 007/173] Add activity types --- .../net/osmand/osm/RouteActivityType.java | 50 +++++++++++++++---- OsmAnd/res/values/strings.xml | 13 +++++ .../explore/travelcards/TravelGpxCard.java | 21 +++++--- 3 files changed, 67 insertions(+), 17 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java index 28c9b11551..06471b933f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,29 +1,58 @@ package net.osmand.osm; public enum RouteActivityType { - WATER("Water", "yellow"), WINTER("Winter", "yellow"), SNOWMOBILE("Snowmobile", "yellow"), RIDING("Riding", "yellow"), RACING("Racing", "yellow"), - MOUNTAINBIKE("Mountainbike", "blue"), CYCLING("Cycling", "blue"), - HIKING("Hiking", "orange"), RUNNING("Running", "orange"), WALKING("Walking", "orange"), - OFFROAD("Off-road", "yellow"), - MOTORBIKE("Motorbike", "green"), CAR("Car", "green"); + WATER("Water", "yellow", "ic_action_motorboat", "activity_type_water"), + WINTER("Winter", "yellow", "ic_action_skiing", "activity_type_winter"), + SNOWMOBILE("Snowmobile", "yellow", "ic_action_snowmobile", "activity_type_snowmobile"), + RIDING("Riding", "yellow", "ic_action_horse", "activity_type_riding"), + RACING("Racing", "yellow", "ic_action_point_destination", "activity_type_racing"), + MOUNTAINBIKE("Mountainbike", "blue", "ic_action_bicycle_dark", "activity_type_mountainbike"), + CYCLING("Cycling", "blue", "ic_action_bicycle_dark", "activity_type_cycling"), + HIKING("Hiking", "orange", "ic_action_trekking_dark", "activity_type_hiking"), + RUNNING("Running", "orange", "ic_action_pedestrian_dark", "activity_type_running"), + WALKING("Walking", "orange", "ic_action_pedestrian_dark", "activity_type_walking"), + OFFROAD("Off-road", "yellow", "ic_action_offroad", "activity_type_offroad"), + MOTORBIKE("Motorbike", "green", "ic_action_motorcycle_dark", "activity_type_motorbike"), + CAR("Car", "green", "ic_action_car_dark", "activity_type_car"); // less specific bottom order String name; String color; + String icon; + String title; - private RouteActivityType(String nm, String clr) { + RouteActivityType(String nm, String clr, String icon, String title) { this.name = nm; this.color = clr; + this.icon = icon; + this.title = title; } - + public String getName() { return name; } - + public String getColor() { return color; } - + + public String getIcon() { + return icon; + } + + public String getTitle() { + return title; + } + + public static RouteActivityType getTypeFromName(String name) { + for (RouteActivityType rat : values()) { + if (rat.name().equalsIgnoreCase(name)) { + return rat; + } + } + return null; + } + public static RouteActivityType getTypeFromTags(String[] tags) { RouteActivityType activityType = null; for (String tg : tags) { @@ -36,7 +65,7 @@ public enum RouteActivityType { } return activityType; } - + public static RouteActivityType convertFromOsmGPXTag(String tg) { String t = tg.toLowerCase(); if ("mountain hiking".equalsIgnoreCase(t)) { @@ -214,5 +243,4 @@ public enum RouteActivityType { } return null; } - } \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 1d23e9db07..f17e06d46f 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,19 @@ --> + Car + Motorbike + Off-road + Walking + Running + Hiking + Cycling + Mountainbike + Racing + Riding + Snowmobile + Winter + Water Hillshade / Slope / Contour lines Select edits for upload Uploaded %1$d of %2$d diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 3677da0f41..c602f02a03 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -9,14 +9,13 @@ import androidx.annotation.NonNull; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.osm.RouteActivityType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.track.TrackMenuFragment; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; -import net.osmand.util.Algorithms; import java.io.File; @@ -44,10 +43,10 @@ public class TravelGpxCard extends BaseTravelCard { holder.title.setText(article.getTitle()); holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16)); holder.user.setText(article.user); - if (!Algorithms.isEmpty(article.activityType)) { - ProfileIcons profileRes = ProfileIcons.valueOf(article.activityType.toUpperCase()); - holder.activityTypeIcon.setImageDrawable(getActiveIcon(profileRes.getResId())); - holder.activityType.setText(profileRes.getTitleId()); + RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType); + if (activityType != null) { + holder.activityTypeIcon.setImageDrawable(getActivityTypeIcon(activityType)); + holder.activityType.setText(getActivityTypeName(activityType)); holder.activityTypeLabel.setVisibility(View.VISIBLE); } holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); @@ -72,6 +71,16 @@ public class TravelGpxCard extends BaseTravelCard { } } + private Drawable getActivityTypeIcon(RouteActivityType activityType) { + int iconId = app.getResources().getIdentifier(activityType.getIcon(), "drawable", app.getPackageName()); + return getActiveIcon(iconId > 0 ? iconId : R.drawable.ic_action_route_distance); + } + + private int getActivityTypeName(RouteActivityType activityType) { + int titleId = app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName()); + return titleId > 0 ? titleId : R.string.layer_route; + } + private void updateSaveButton(final TravelGpxVH holder) { if (article != null) { final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper(); From 0672f140aff60eb727954001436c345daaf6fa61 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 3 Feb 2021 11:24:22 +0200 Subject: [PATCH 008/173] Check resource --- .../explore/travelcards/TravelGpxCard.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index c602f02a03..69772bac1c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -5,7 +5,9 @@ import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; +import androidx.annotation.StringRes; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; @@ -45,9 +47,13 @@ public class TravelGpxCard extends BaseTravelCard { holder.user.setText(article.user); RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType); if (activityType != null) { - holder.activityTypeIcon.setImageDrawable(getActivityTypeIcon(activityType)); - holder.activityType.setText(getActivityTypeName(activityType)); - holder.activityTypeLabel.setVisibility(View.VISIBLE); + int iconId = getActivityTypeIcon(activityType); + int titleId = getActivityTypeTitle(activityType); + if (iconId > 0 && titleId > 0) { + holder.activityTypeIcon.setImageDrawable(getActiveIcon(iconId)); + holder.activityType.setText(titleId); + holder.activityTypeLabel.setVisibility(View.VISIBLE); + } } holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); @@ -71,14 +77,14 @@ public class TravelGpxCard extends BaseTravelCard { } } - private Drawable getActivityTypeIcon(RouteActivityType activityType) { - int iconId = app.getResources().getIdentifier(activityType.getIcon(), "drawable", app.getPackageName()); - return getActiveIcon(iconId > 0 ? iconId : R.drawable.ic_action_route_distance); + @DrawableRes + private int getActivityTypeIcon(RouteActivityType activityType) { + return app.getResources().getIdentifier(activityType.getIcon(), "drawable", app.getPackageName()); } - private int getActivityTypeName(RouteActivityType activityType) { - int titleId = app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName()); - return titleId > 0 ? titleId : R.string.layer_route; + @StringRes + private int getActivityTypeTitle(RouteActivityType activityType) { + return app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName()); } private void updateSaveButton(final TravelGpxVH holder) { From e9b02ae74bb32b9151740c595ab6dfa0f355c79a Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 3 Feb 2021 16:52:24 +0200 Subject: [PATCH 009/173] Renew activity icon --- .../net/osmand/osm/RouteActivityType.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java index 06471b933f..e7a7a0600a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,19 +1,19 @@ package net.osmand.osm; public enum RouteActivityType { - WATER("Water", "yellow", "ic_action_motorboat", "activity_type_water"), - WINTER("Winter", "yellow", "ic_action_skiing", "activity_type_winter"), - SNOWMOBILE("Snowmobile", "yellow", "ic_action_snowmobile", "activity_type_snowmobile"), - RIDING("Riding", "yellow", "ic_action_horse", "activity_type_riding"), - RACING("Racing", "yellow", "ic_action_point_destination", "activity_type_racing"), - MOUNTAINBIKE("Mountainbike", "blue", "ic_action_bicycle_dark", "activity_type_mountainbike"), - CYCLING("Cycling", "blue", "ic_action_bicycle_dark", "activity_type_cycling"), - HIKING("Hiking", "orange", "ic_action_trekking_dark", "activity_type_hiking"), - RUNNING("Running", "orange", "ic_action_pedestrian_dark", "activity_type_running"), - WALKING("Walking", "orange", "ic_action_pedestrian_dark", "activity_type_walking"), - OFFROAD("Off-road", "yellow", "ic_action_offroad", "activity_type_offroad"), - MOTORBIKE("Motorbike", "green", "ic_action_motorcycle_dark", "activity_type_motorbike"), - CAR("Car", "green", "ic_action_car_dark", "activity_type_car"); + WATER("Water", "yellow", "mx_special_kayak", "activity_type_water"), + WINTER("Winter", "yellow", "mx_special_skiing", "activity_type_winter"), + SNOWMOBILE("Snowmobile", "yellow", "mx_special_snowmobile", "activity_type_snowmobile"), + RIDING("Riding", "yellow", "mx_special_horse", "activity_type_riding"), + RACING("Racing", "yellow", "mx_raceway", "activity_type_racing"), + MOUNTAINBIKE("Mountainbike", "blue", "mx_sport_cycling", "activity_type_mountainbike"), + CYCLING("Cycling", "blue", "mx_special_bicycle", "activity_type_cycling"), + HIKING("Hiking", "orange", "mx_special_trekking", "activity_type_hiking"), + RUNNING("Running", "orange", "mx_running", "activity_type_running"), + WALKING("Walking", "orange", " mx_special_walking", "activity_type_walking"), + OFFROAD("Off-road", "yellow", "mx_special_offroad", "activity_type_offroad"), + MOTORBIKE("Motorbike", "green", "mx_special_motorcycle", "activity_type_motorbike"), + CAR("Car", "green", "mx_shop_car", "activity_type_car"); // less specific bottom order String name; From f55c64159e9b8a86e28a445cba5253b6164261e1 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 4 Feb 2021 11:43:53 +0200 Subject: [PATCH 010/173] Show all available obf travel files in the card to download --- .../layout/travel_download_update_card.xml | 198 -------------- OsmAnd/res/layout/travel_needed_maps_card.xml | 34 ++- .../wikivoyage/explore/ExploreRvAdapter.java | 7 +- .../explore/ExploreTabFragment.java | 167 ++++++------ .../travelcards/TravelDownloadUpdateCard.java | 250 ++---------------- .../travelcards/TravelNeededMapsCard.java | 32 ++- 6 files changed, 166 insertions(+), 522 deletions(-) delete mode 100644 OsmAnd/res/layout/travel_download_update_card.xml diff --git a/OsmAnd/res/layout/travel_download_update_card.xml b/OsmAnd/res/layout/travel_download_update_card.xml deleted file mode 100644 index 8ad3bb7779..0000000000 --- a/OsmAnd/res/layout/travel_download_update_card.xml +++ /dev/null @@ -1,198 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/res/layout/travel_needed_maps_card.xml b/OsmAnd/res/layout/travel_needed_maps_card.xml index c562b1fdd3..1a5aedcb7d 100644 --- a/OsmAnd/res/layout/travel_needed_maps_card.xml +++ b/OsmAnd/res/layout/travel_needed_maps_card.xml @@ -18,16 +18,34 @@ android:layout_margin="@dimen/content_padding" android:orientation="vertical"> - + android:layout_marginBottom="@dimen/bottom_sheet_content_padding_small"> + + + + + + mainIndexItems = new ArrayList<>(); private final List neededIndexItems = new ArrayList<>(); private boolean waitForIndexes; @@ -199,17 +196,24 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv } private void removeRedundantCards() { - if (mainIndexItem != null && mainIndexItem.isDownloaded() && !mainIndexItem.isOutdated()) { - removeDownloadUpdateCard(); - } - boolean allMapsDownloaded = true; - for (IndexItem item : neededIndexItems) { + boolean allTravelGuideDownloaded = true; + for (IndexItem item : mainIndexItems) { if (!item.isDownloaded()) { - allMapsDownloaded = false; + allTravelGuideDownloaded = false; break; } } - if (allMapsDownloaded) { + if (allTravelGuideDownloaded) { + removeDownloadUpdateCard(); + } + boolean neededMapsDownloaded = true; + for (IndexItem item : neededIndexItems) { + if (!item.isDownloaded()) { + neededMapsDownloaded = false; + break; + } + } + if (neededMapsDownloaded) { removeNeededMapsCard(); } } @@ -218,8 +222,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv new ProcessIndexItemsTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - private void addIndexItemCards(IndexItem mainIndexItem, List neededIndexItems) { - this.mainIndexItem = mainIndexItem; + private void addIndexItemCards(List mainIndexItem, List neededIndexItems) { + this.mainIndexItems.clear(); + this.mainIndexItems.addAll(mainIndexItem); this.neededIndexItems.clear(); this.neededIndexItems.addAll(neededIndexItems); addDownloadUpdateCard(); @@ -228,53 +233,58 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv private void addDownloadUpdateCard() { final OsmandApplication app = getMyApplication(); - if (app != null) { - final DownloadIndexesThread downloadThread = app.getDownloadThread(); - - boolean outdated = mainIndexItem != null && mainIndexItem.isOutdated(); - boolean needsDownloading = mainIndexItem != null && !mainIndexItem.isDownloaded(); - - if (!app.getTravelHelper().isAnyTravelBookPresent() || needsDownloading || (outdated && SHOW_TRAVEL_UPDATE_CARD)) { - boolean showOtherMaps = false; - if (needsDownloading) { - List items = downloadThread.getIndexes().getWikivoyageItems(); - showOtherMaps = items != null && items.size() > 1; + if (app != null && !mainIndexItems.isEmpty() && SHOW_TRAVEL_UPDATE_CARD) { + boolean outdated = isMapsOutdated(); + downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, mainIndexItems, !outdated); + downloadUpdateCard.setListener(new TravelDownloadUpdateCard.CardListener() { + @Override + public void onPrimaryButtonClick() { + if (downloadManager != null) { + downloadManager.startDownload(getMyActivity(), getAllItemsForDownload(mainIndexItems)); + adapter.updateDownloadUpdateCard(false); + } } - downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated); - downloadUpdateCard.setShowOtherMapsBtn(showOtherMaps); - downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() { - @Override - public void onPrimaryButtonClick() { - if (mainIndexItem != null && downloadManager != null) { - downloadManager.startDownload(getMyActivity(), mainIndexItem); - adapter.updateDownloadUpdateCard(false); - } + @Override + public void onSecondaryButtonClick() { + if (downloadUpdateCard.isDownloading()) { + app.getDownloadThread().cancelDownload(mainIndexItems); + adapter.updateDownloadUpdateCard(false); + } else { + SHOW_TRAVEL_UPDATE_CARD = false; + removeDownloadUpdateCard(); } + } - @Override - public void onSecondaryButtonClick() { - if (downloadUpdateCard.isLoading()) { - downloadThread.cancelDownload(mainIndexItem); - adapter.updateDownloadUpdateCard(false); - } else if (!downloadUpdateCard.isDownload()) { - SHOW_TRAVEL_UPDATE_CARD = false; - removeDownloadUpdateCard(); - } else if (downloadUpdateCard.isShowOtherMapsBtn()) { - Activity activity = getActivity(); - if (activity != null) { - Intent newIntent = new Intent(activity, - ((OsmandApplication) activity.getApplication()).getAppCustomization().getDownloadActivity()); - newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - activity.startActivity(newIntent); - } + @Override + public void onIndexItemClick(IndexItem item) { + if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE && !Version.isPaidVersion(app)) { + FragmentManager fm = getFragmentManager(); + if (fm != null) { + ChoosePlanDialogFragment.showWikipediaInstance(fm); } + } else { + DownloadIndexesThread downloadThread = app.getDownloadThread(); + if (downloadThread.isDownloading(item)) { + downloadThread.cancelDownload(item); + } else if (!item.isDownloaded() && downloadManager != null) { + downloadManager.startDownload(getMyActivity(), item); + } + adapter.updateDownloadUpdateCard(false); } - }); - downloadUpdateCard.setIndexItem(mainIndexItem); - adapter.addDownloadUpdateCard(downloadUpdateCard); + } + }); + adapter.addDownloadUpdateCard(downloadUpdateCard); + } + } + + private boolean isMapsOutdated() { + for (IndexItem indexItem : mainIndexItems) { + if (indexItem.isOutdated()) { + return true; } } + return false; } private void addNeededMapsCard() { @@ -285,7 +295,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv @Override public void onPrimaryButtonClick() { if (downloadManager != null) { - downloadManager.startDownload(getMyActivity(), getAllItemsForDownload()); + downloadManager.startDownload(getMyActivity(), getAllItemsForDownload(neededIndexItems)); adapter.updateNeededMapsCard(false); } } @@ -323,10 +333,10 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv } } - private IndexItem[] getAllItemsForDownload() { + private IndexItem[] getAllItemsForDownload(List indexItems) { boolean paidVersion = Version.isPaidVersion(getMyApplication()); ArrayList res = new ArrayList<>(); - for (IndexItem item : neededIndexItems) { + for (IndexItem item : indexItems) { if (!item.isDownloaded() && (paidVersion || item.getType() != DownloadActivityType.WIKIPEDIA_FILE)) { res.add(item); } @@ -344,7 +354,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv neededMapsCard = null; } - private static class ProcessIndexItemsTask extends AsyncTask>> { + private static class ProcessIndexItemsTask extends AsyncTask, List>> { private static final DownloadActivityType[] types = new DownloadActivityType[]{ DownloadActivityType.NORMAL_FILE, @@ -354,40 +364,41 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv private final OsmandApplication app; private final WeakReference weakFragment; - private final String fileName; - ProcessIndexItemsTask(ExploreTabFragment fragment) { app = fragment.getMyApplication(); weakFragment = new WeakReference<>(fragment); - fileName = app != null ? app.getTravelHelper().getWikivoyageFileName() : null; } @Override - protected Pair> doInBackground(Void... voids) { - if (fileName != null) { - IndexItem mainItem = app.getDownloadThread().getIndexes().getWikivoyageItem(fileName); - - List neededItems = new ArrayList<>(); - for (TravelArticle article : app.getTravelHelper().getBookmarksHelper().getSavedArticles()) { - LatLon latLon = new LatLon(article.getLat(), article.getLon()); - try { - for (DownloadActivityType type : types) { - IndexItem item = DownloadResources.findSmallestIndexItemAt(app, latLon, type); - if (item != null && !item.isDownloaded() && !neededItems.contains(item)) { - neededItems.add(item); - } - } - } catch (IOException e) { - // ignore + protected Pair, List> doInBackground(Void... voids) { + List mainItems = new ArrayList<>(); + List allWikivoyageItems = app.getDownloadThread().getIndexes().getWikivoyageItems(); + if (allWikivoyageItems != null) { + for (IndexItem item : allWikivoyageItems) { + if (!item.isDownloaded() && !mainItems.contains(item)) { + mainItems.add(item); } } - return new Pair<>(mainItem, neededItems); } - return null; + List neededItems = new ArrayList<>(); + for (TravelArticle article : app.getTravelHelper().getBookmarksHelper().getSavedArticles()) { + LatLon latLon = new LatLon(article.getLat(), article.getLon()); + try { + for (DownloadActivityType type : types) { + IndexItem item = DownloadResources.findSmallestIndexItemAt(app, latLon, type); + if (item != null && !item.isDownloaded() && !neededItems.contains(item)) { + neededItems.add(item); + } + } + } catch (IOException e) { + // ignore + } + } + return new Pair<>(mainItems, neededItems); } @Override - protected void onPostExecute(Pair> res) { + protected void onPostExecute(Pair, List> res) { ExploreTabFragment fragment = weakFragment.get(); if (res != null && fragment != null && fragment.isResumed()) { fragment.addIndexItemCards(res.first, res.second); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelDownloadUpdateCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelDownloadUpdateCard.java index d7aaa23bb7..f4a20a83f7 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelDownloadUpdateCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelDownloadUpdateCard.java @@ -1,257 +1,47 @@ package net.osmand.plus.wikivoyage.explore.travelcards; -import android.graphics.drawable.Drawable; -import android.view.View; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.TextView; - import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.recyclerview.widget.RecyclerView; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.download.IndexItem; -import java.lang.ref.WeakReference; -import java.text.DateFormat; +import java.util.List; -public class TravelDownloadUpdateCard extends BaseTravelCard { +public class TravelDownloadUpdateCard extends TravelNeededMapsCard { public static final int TYPE = 50; - private boolean download; - private boolean showOtherMapsBtn; - private WeakReference ref; + private final boolean download; - private ClickListener listener; - - @Nullable - private IndexItem indexItem; - - private DateFormat dateFormat; - - public boolean isDownload() { - return download; - } - - public boolean isShowOtherMapsBtn() { - return showOtherMapsBtn; - } - - public void setShowOtherMapsBtn(boolean showOtherMapsBtn) { - this.showOtherMapsBtn = showOtherMapsBtn; - } - - public void setListener(ClickListener listener) { - this.listener = listener; - } - - public void setIndexItem(@Nullable IndexItem indexItem) { - this.indexItem = indexItem; - } - - public TravelDownloadUpdateCard(OsmandApplication app, boolean nightMode, boolean download) { - super(app, nightMode); + public TravelDownloadUpdateCard(@NonNull OsmandApplication app, boolean nightMode, @NonNull List items, + boolean download) { + super(app, nightMode, items); this.download = download; - dateFormat = android.text.format.DateFormat.getMediumDateFormat(app); + } + + public int getTitle() { + if (isDownloading()) { + return R.string.shared_string_downloading; + } + return download ? R.string.download_file : R.string.update_is_available; } @Override - public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) { - if (viewHolder instanceof DownloadUpdateVH) { - boolean loading = isLoading(); - DownloadUpdateVH holder = (DownloadUpdateVH) viewHolder; - this.ref = new WeakReference(holder); - holder.title.setText(getTitle(loading)); - holder.icon.setImageResource(getIconRes()); - holder.description.setText(getDescription()); - if (indexItem == null) { - holder.fileDataContainer.setVisibility(View.GONE); - } else { - holder.fileDataContainer.setVisibility(View.VISIBLE); - holder.fileIcon.setImageDrawable(getFileIcon()); - holder.fileTitle.setText(getFileTitle()); - holder.fileDescription.setText(getFileDescription()); - holder.progressBar.setVisibility(loading ? View.VISIBLE : View.GONE); - updateProgressBar(holder); - } - boolean primaryBtnVisible = updatePrimaryButton(holder, loading); - boolean secondaryBtnVisible = updateSecondaryButton(holder, loading); - holder.buttonsDivider.setVisibility(primaryBtnVisible && secondaryBtnVisible ? View.VISIBLE : View.GONE); - } - } - - public void updateProgresBar() { - if(ref != null) { - DownloadUpdateVH holder = ref.get(); - if (holder != null && holder.itemView.isShown()) { - updateProgressBar(holder); - } + public int getDescription() { + if (!isInternetAvailable()) { + return R.string.no_index_file_to_download; } + return download ? R.string.travel_card_download_descr : R.string.travel_card_update_descr; } - private void updateProgressBar(DownloadUpdateVH holder) { - if (isLoadingInProgress()) { - int progress = app.getDownloadThread().getCurrentDownloadingItemProgress(); - holder.progressBar.setProgress(progress < 0 ? 0 : progress); - } else { - holder.progressBar.setProgress(0); - } + @Override + public int getIconRes() { + return download ? R.drawable.travel_card_download_icon : R.drawable.travel_card_update_icon; } @Override public int getCardType() { return TYPE; } - - @NonNull - private String getTitle(boolean loading) { - if (loading) { - return app.getString(R.string.shared_string_downloading); - } - return app.getString(download ? R.string.download_file : R.string.update_is_available); - } - - private int getIconRes() { - return download ? R.drawable.travel_card_download_icon : R.drawable.travel_card_update_icon; - } - - @NonNull - private String getDescription() { - if (!isInternetAvailable()) { - return app.getString(R.string.no_index_file_to_download); - } - return app.getString(download ? R.string.travel_card_download_descr : R.string.travel_card_update_descr); - } - - @NonNull - private String getFileTitle() { - return indexItem == null ? "" : indexItem.getVisibleName(app, app.getRegions(), false); - } - - @NonNull - private String getFileDescription() { - StringBuilder sb = new StringBuilder(); - if (indexItem != null) { - sb.append(app.getString(R.string.file_size_in_mb, indexItem.getArchiveSizeMB())); - sb.append(" • "); - sb.append(indexItem.getRemoteDate(dateFormat)); - } - return sb.toString(); - } - - private Drawable getFileIcon() { - return getActiveIcon(R.drawable.ic_action_read_article); - } - - /** - * @return true if button is visible, false otherwise. - */ - private boolean updateSecondaryButton(DownloadUpdateVH vh, boolean loading) { - if (loading || !download || showOtherMapsBtn) { - vh.secondaryBtnContainer.setVisibility(View.VISIBLE); - vh.secondaryBtn.setText(getSecondaryBtnTextId(loading)); - vh.secondaryBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - listener.onSecondaryButtonClick(); - } - } - }); - return true; - } - vh.secondaryBtnContainer.setVisibility(View.GONE); - return false; - } - - @StringRes - private int getSecondaryBtnTextId(boolean loading) { - if (loading) { - return R.string.shared_string_cancel; - } - if (!download) { - return R.string.later; - } - return R.string.download_select_map_types; - } - - /** - * @return true if button is visible, false otherwise. - */ - private boolean updatePrimaryButton(DownloadUpdateVH vh, boolean loading) { - if (!loading) { - boolean enabled = isInternetAvailable(); - vh.primaryBtnContainer.setVisibility(View.VISIBLE); - vh.primaryBtnContainer.setBackgroundResource(getPrimaryBtnBgRes(enabled)); - vh.primaryButton.setTextColor(getResolvedColor(getPrimaryBtnTextColorRes(enabled))); - vh.primaryButton.setEnabled(enabled); - vh.primaryButton.setText(download ? R.string.shared_string_download : R.string.shared_string_update); - vh.primaryButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - listener.onPrimaryButtonClick(); - } - } - }); - return true; - } - vh.primaryBtnContainer.setVisibility(View.GONE); - return false; - } - - public boolean isLoading() { - return indexItem != null && app.getDownloadThread().isDownloading(indexItem); - } - - private boolean isLoadingInProgress() { - IndexItem current = app.getDownloadThread().getCurrentDownloadingItem(); - return indexItem != null && current != null && indexItem == current; - } - - public interface ClickListener { - - void onPrimaryButtonClick(); - - void onSecondaryButtonClick(); - } - - public static class DownloadUpdateVH extends RecyclerView.ViewHolder { - - final TextView title; - final ImageView icon; - final TextView description; - final View fileDataContainer; - final ImageView fileIcon; - final TextView fileTitle; - final TextView fileDescription; - final ProgressBar progressBar; - final View secondaryBtnContainer; - final TextView secondaryBtn; - final View buttonsDivider; - final View primaryBtnContainer; - final TextView primaryButton; - - @SuppressWarnings("RedundantCast") - public DownloadUpdateVH(View itemView) { - super(itemView); - title = (TextView) itemView.findViewById(R.id.title); - icon = (ImageView) itemView.findViewById(R.id.icon); - description = (TextView) itemView.findViewById(R.id.description); - fileDataContainer = itemView.findViewById(R.id.file_data_container); - fileIcon = (ImageView) itemView.findViewById(R.id.file_icon); - fileTitle = (TextView) itemView.findViewById(R.id.file_title); - fileDescription = (TextView) itemView.findViewById(R.id.file_description); - progressBar = (ProgressBar) itemView.findViewById(R.id.progress_bar); - secondaryBtnContainer = itemView.findViewById(R.id.secondary_btn_container); - secondaryBtn = (TextView) itemView.findViewById(R.id.secondary_button); - buttonsDivider = itemView.findViewById(R.id.buttons_divider); - primaryBtnContainer = itemView.findViewById(R.id.primary_btn_container); - primaryButton = (TextView) itemView.findViewById(R.id.primary_button); - } - } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelNeededMapsCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelNeededMapsCard.java index 505a2095f6..900c80f1a2 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelNeededMapsCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelNeededMapsCard.java @@ -9,7 +9,9 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; +import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; +import androidx.annotation.StringRes; import androidx.recyclerview.widget.RecyclerView; import net.osmand.plus.OsmandApplication; @@ -60,8 +62,12 @@ public class TravelNeededMapsCard extends BaseTravelCard { if (viewHolder instanceof NeededMapsVH) { NeededMapsVH holder = (NeededMapsVH) viewHolder; ref = new WeakReference(holder); - holder.description.setText(isInternetAvailable() - ? R.string.maps_you_need_descr : R.string.no_index_file_to_download); + holder.title.setText(getTitle()); + holder.description.setText(getDescription()); + int iconRes = getIconRes(); + if (iconRes > 0) { + holder.icon.setImageResource(iconRes); + } adjustChildCount(holder.itemsContainer); updateView(holder); @@ -71,7 +77,23 @@ public class TravelNeededMapsCard extends BaseTravelCard { holder.buttonsDivider.setVisibility(primaryBtnVisible && secondaryBtnVisible ? View.VISIBLE : View.GONE); } } - + + @StringRes + public int getTitle() { + return R.string.maps_you_need; + } + + @StringRes + public int getDescription() { + return isInternetAvailable() + ? R.string.maps_you_need_descr : R.string.no_index_file_to_download; + } + + @DrawableRes + public int getIconRes() { + return 0; + } + public void updateView() { if (ref != null) { NeededMapsVH holder = ref.get(); @@ -227,7 +249,9 @@ public class TravelNeededMapsCard extends BaseTravelCard { public static class NeededMapsVH extends RecyclerView.ViewHolder { + final TextView title; final TextView description; + final ImageView icon; final LinearLayout itemsContainer; final View secondaryBtnContainer; final TextView secondaryBtn; @@ -238,7 +262,9 @@ public class TravelNeededMapsCard extends BaseTravelCard { @SuppressWarnings("RedundantCast") public NeededMapsVH(View itemView) { super(itemView); + title = (TextView) itemView.findViewById(R.id.title); description = (TextView) itemView.findViewById(R.id.description); + icon = (ImageView) itemView.findViewById(R.id.icon); itemsContainer = (LinearLayout) itemView.findViewById(R.id.items_container); secondaryBtnContainer = itemView.findViewById(R.id.secondary_btn_container); secondaryBtn = (TextView) itemView.findViewById(R.id.secondary_button); From 08b5e9fdf993e25a4f4c1ed2dfe94fc08fb472e7 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 5 Feb 2021 18:32:54 +0200 Subject: [PATCH 011/173] Add Show more button --- OsmAnd/res/layout/wikivoyage_button_card.xml | 26 +++++++ .../plus/wikivoyage/data/TravelDbHelper.java | 10 +-- .../plus/wikivoyage/data/TravelHelper.java | 6 +- .../plus/wikivoyage/data/TravelObfHelper.java | 76 +++++++++++-------- .../wikivoyage/explore/ExploreRvAdapter.java | 8 ++ .../explore/ExploreTabFragment.java | 27 ++++++- .../explore/WikivoyageExploreActivity.java | 16 ++-- .../explore/travelcards/TravelButtonCard.java | 56 ++++++++++++++ 8 files changed, 178 insertions(+), 47 deletions(-) create mode 100644 OsmAnd/res/layout/wikivoyage_button_card.xml create mode 100644 OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelButtonCard.java diff --git a/OsmAnd/res/layout/wikivoyage_button_card.xml b/OsmAnd/res/layout/wikivoyage_button_card.xml new file mode 100644 index 0000000000..412fd36f5d --- /dev/null +++ b/OsmAnd/res/layout/wikivoyage_button_card.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index b53605a0bb..90e6444cff 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -174,9 +174,9 @@ public class TravelDbHelper implements TravelHelper { } @Override - public void initializeDataToDisplay() { + public void initializeDataToDisplay(boolean showMore) { localDataHelper.refreshCachedData(); - loadPopularArticles(); + loadPopularArticles(showMore); } @@ -283,7 +283,7 @@ public class TravelDbHelper implements TravelHelper { } @NonNull - public List loadPopularArticles() { + public List loadPopularArticles(boolean showMore) { String language = application.getLanguage(); SQLiteConnection conn = openConnection(); if (conn == null) { @@ -292,7 +292,7 @@ public class TravelDbHelper implements TravelHelper { } String LANG_WHERE = " WHERE " + ARTICLES_COL_LANG + " = '" + language + "'"; SQLiteCursor cursor = conn.rawQuery(POP_ARTICLES_TABLE_SELECT + LANG_WHERE, null); - if(cursor == null) { + if (cursor == null) { return popularArticles; } // read popular articles @@ -549,7 +549,7 @@ public class TravelDbHelper implements TravelHelper { @Override @Nullable - public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, String lang, boolean readGpx, @Nullable GpxReadCallback callback) { TravelArticle res = null; SQLiteConnection conn = openConnection(); String routeId = articleId.routeId; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java index 967138b0bd..4688dd7ff0 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java @@ -3,7 +3,6 @@ package net.osmand.plus.wikivoyage.data; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; @@ -25,7 +24,7 @@ public interface TravelHelper { void initializeDataOnAppStartup(); - void initializeDataToDisplay(); + void initializeDataToDisplay(boolean showMore); boolean isAnyTravelBookPresent(); @@ -35,6 +34,9 @@ public interface TravelHelper { @NonNull List getPopularArticles(); + @NonNull + List loadPopularArticles(boolean showMore); + @NonNull Map> getNavigationMap(@NonNull TravelArticle article); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index f230929f1d..162616e063 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -68,9 +68,7 @@ public class TravelObfHelper implements TravelHelper { public static final String ROUTE_ARTICLE = "route_article"; public static final String ROUTE_ARTICLE_POINT = "route_article_point"; public static final String ROUTE_TRACK = "route_track"; - public static final int POPULAR_ARTICLES_SEARCH_RADIUS = 100000; public static final int ARTICLE_SEARCH_RADIUS = 50000; - public static final int GPX_TRACKS_SEARCH_RADIUS = 10000; public static final int MAX_POPULAR_ARTICLES_COUNT = 30; public static final String REF_TAG = "ref"; public static final String NAME_TAG = "name"; @@ -81,6 +79,10 @@ public class TravelObfHelper implements TravelHelper { private List popularArticles = new ArrayList<>(); private final Map> cachedArticles = new ConcurrentHashMap<>(); private final TravelLocalDataHelper localDataHelper; + private int searchRadius = ARTICLE_SEARCH_RADIUS; + private int count = 0; + private int page = 0; + final List> amenities = new ArrayList<>(); public TravelObfHelper(OsmandApplication app) { this.app = app; @@ -98,48 +100,54 @@ public class TravelObfHelper implements TravelHelper { } @Override - public void initializeDataToDisplay() { + public void initializeDataToDisplay(boolean showMore) { localDataHelper.refreshCachedData(); - loadPopularArticles(); + loadPopularArticles(showMore); } @NonNull - public synchronized List loadPopularArticles() { + public synchronized List loadPopularArticles(boolean showMore) { String lang = app.getLanguage(); List popularArticles = new ArrayList<>(); - final List> amenities = new ArrayList<>(); - final LatLon location = app.getMapViewTrackingUtilities().getMapLocation(); - for (final BinaryMapIndexReader reader : getReaders()) { - try { - searchAmenity(amenities, location, reader, POPULAR_ARTICLES_SEARCH_RADIUS, -1, ROUTE_ARTICLE); - searchAmenity(amenities, location, reader, GPX_TRACKS_SEARCH_RADIUS, 15, ROUTE_TRACK); - } catch (Exception e) { - LOG.error(e.getMessage(), e); + if (amenities.size() - count < MAX_POPULAR_ARTICLES_COUNT) { + final LatLon location = app.getMapViewTrackingUtilities().getMapLocation(); + for (final BinaryMapIndexReader reader : getReaders()) { + try { + searchAmenity(amenities, location, reader, searchRadius, -1, ROUTE_ARTICLE); + searchAmenity(amenities, location, reader, searchRadius / 5, 15, ROUTE_TRACK); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } } + if (amenities.size() > 0) { + Collections.sort(amenities, new Comparator>() { + @Override + public int compare(Pair article1, Pair article2) { + int d1 = (int) (MapUtils.getDistance(((Amenity) article1.second).getLocation(), location)); + int d2 = (int) (MapUtils.getDistance(((Amenity) article2.second).getLocation(), location)); + return d1 < d2 ? -1 : (d1 == d2 ? 0 : 1); + } + }); + } + searchRadius *= 2; } - if (amenities.size() > 0) { - Collections.sort(amenities, new Comparator>() { - @Override - public int compare(Pair article1, Pair article2) { - int d1 = (int) (MapUtils.getDistance(((Amenity) article1.second).getLocation(), location)); - int d2 = (int) (MapUtils.getDistance(((Amenity) article2.second).getLocation(), location)); - return d1 < d2 ? -1 : (d1 == d2 ? 0 : 1); - } - }); - for (Pair amenity : amenities) { - if (!Algorithms.isEmpty(amenity.second.getName(lang))) { - TravelArticle article = cacheTravelArticles(amenity.first, amenity.second, lang, false, null); - if (article != null) { - popularArticles.add(article); - if (popularArticles.size() >= MAX_POPULAR_ARTICLES_COUNT) { - break; - } + int lastIndex; + for (lastIndex = count; lastIndex < amenities.size() - 1; lastIndex++) { + Pair amenity = amenities.get(lastIndex); + if (!Algorithms.isEmpty(amenity.second.getName(lang))) { + TravelArticle article = cacheTravelArticles(amenity.first, amenity.second, lang, false, null); + if (article != null) { + popularArticles.add(article); + this.popularArticles.add(article); + if (this.popularArticles.size() >= (page + 1) * MAX_POPULAR_ARTICLES_COUNT) { + page++; + break; } } } } - this.popularArticles = popularArticles; + count = ++lastIndex; return popularArticles; } @@ -172,8 +180,10 @@ public class TravelObfHelper implements TravelHelper { } if (!Algorithms.isEmpty(articles)) { TravelArticleIdentifier newArticleId = articles.values().iterator().next().generateIdentifier(); - cachedArticles.put(newArticleId, articles); - article = getCachedArticle(newArticleId, lang, readPoints, callback); + if (!cachedArticles.containsKey(newArticleId)) { + cachedArticles.put(newArticleId, articles); + article = getCachedArticle(newArticleId, lang, readPoints, callback); + } } return article; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java index b18e04b7f4..923645b775 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java @@ -18,6 +18,8 @@ import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard.OpenBetaTravelVH; import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard.StartEditingTravelVH; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelButtonCard; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelButtonCard.TravelButtonVH; import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH; @@ -55,6 +57,9 @@ public class ExploreRvAdapter extends RecyclerView.Adapter 0; i--) { BaseTravelCard o = items.get(i); + if (o instanceof TravelButtonCard) { + return 0; + } if (o instanceof ArticleTravelCard || o instanceof TravelGpxCard) { return i; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index f3af57bc6d..2e0cacca65 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -36,6 +36,7 @@ import net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelButtonCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard; @@ -45,6 +46,8 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import static net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity.*; + public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents, TravelLocalDataHelper.Listener { private static boolean SHOW_TRAVEL_UPDATE_CARD = true; @@ -172,17 +175,37 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv if (!Version.isPaidVersion(app) && !OpenBetaTravelCard.isClosed()) { items.add(new OpenBetaTravelCard(activity, nightMode)); } - List popularArticles = app.getTravelHelper().getPopularArticles(); + final List popularArticles = app.getTravelHelper().getPopularArticles(); if (!popularArticles.isEmpty()) { items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations))); for (TravelArticle article : popularArticles) { if (article instanceof TravelGpx) { - items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, getActivity())); + items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, activity)); } else { items.add(new ArticleTravelCard(app, nightMode, article, activity.getSupportFragmentManager())); } } } + + TravelButtonCard travelButtonCard = new TravelButtonCard(app, nightMode); + travelButtonCard.setListener(new TravelNeededMapsCard.CardListener() { + @Override + public void onPrimaryButtonClick() { + new LoadWikivoyageData(ExploreTabFragment.this.getExploreActivity(), true).execute(); + } + + @Override + public void onSecondaryButtonClick() { + + } + + @Override + public void onIndexItemClick(IndexItem item) { + + } + }); + items.add(travelButtonCard); + items.add(new StartEditingTravelCard(activity, nightMode)); adapter.setItems(items); final DownloadIndexesThread downloadThread = app.getDownloadThread(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java index dae47525aa..fc28bc6213 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java @@ -314,6 +314,10 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv } public void populateData() { + populateData(false); + } + + public void populateData(final boolean showMore) { switchProgressBarVisibility(true); if (app.isApplicationInitializing()) { final WeakReference activityRef = new WeakReference<>(this); @@ -326,12 +330,12 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv public void onFinish(AppInitializer init) { WikivoyageExploreActivity activity = activityRef.get(); if (AndroidUtils.isActivityNotDestroyed(activity)) { - new LoadWikivoyageData(activity).execute(); + new LoadWikivoyageData(activity, showMore).execute(); } } }); } else { - new LoadWikivoyageData(this).execute(); + new LoadWikivoyageData(this, showMore).execute(); } } @@ -380,19 +384,21 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv updateFragments(); } - private static class LoadWikivoyageData extends AsyncTask { + public static class LoadWikivoyageData extends AsyncTask { private final WeakReference activityRef; private final TravelHelper travelHelper; + private final boolean showMore; - LoadWikivoyageData(WikivoyageExploreActivity activity) { + LoadWikivoyageData(WikivoyageExploreActivity activity, boolean showMore) { travelHelper = activity.getMyApplication().getTravelHelper(); activityRef = new WeakReference<>(activity); + this.showMore = showMore; } @Override protected Void doInBackground(Void... params) { - travelHelper.initializeDataToDisplay(); + travelHelper.initializeDataToDisplay(showMore); return null; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelButtonCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelButtonCard.java new file mode 100644 index 0000000000..fd0a48718d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelButtonCard.java @@ -0,0 +1,56 @@ +package net.osmand.plus.wikivoyage.explore.travelcards; + +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard.CardListener; + +public class TravelButtonCard extends BaseTravelCard { + + public static final int TYPE = 5; + private CardListener listener; + + public TravelButtonCard(OsmandApplication app, boolean nightMode) { + super(app, nightMode); + } + + public void setListener(CardListener listener) { + this.listener = listener; + } + + @Override + public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) { + if (viewHolder instanceof TravelButtonVH) { + final TravelButtonVH holder = (TravelButtonVH) viewHolder; + UiUtilities.setupDialogButton(nightMode, holder.button, UiUtilities.DialogButtonType.SECONDARY, R.string.show_more); + holder.button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onPrimaryButtonClick(); + } + } + }); + } + } + + public static class TravelButtonVH extends RecyclerView.ViewHolder { + + final View button; + + public TravelButtonVH(View itemView) { + super(itemView); + button = itemView.findViewById(R.id.button); + } + } + + @Override + public int getCardType() { + return TYPE; + } +} \ No newline at end of file From f20a8882bde3bdc16dac8f828c7a39635255fdeb Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Sat, 6 Feb 2021 13:11:49 +0200 Subject: [PATCH 012/173] Fix get activity type name and icon --- .../net/osmand/osm/RouteActivityType.java | 34 ++++++++----------- OsmAnd/res/values/strings.xml | 26 +++++++------- OsmAnd/src/net/osmand/AndroidUtils.java | 6 ++++ .../explore/travelcards/TravelGpxCard.java | 19 ++++++----- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java index e7a7a0600a..6f8a0b0e9a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,31 +1,29 @@ package net.osmand.osm; public enum RouteActivityType { - WATER("Water", "yellow", "mx_special_kayak", "activity_type_water"), - WINTER("Winter", "yellow", "mx_special_skiing", "activity_type_winter"), - SNOWMOBILE("Snowmobile", "yellow", "mx_special_snowmobile", "activity_type_snowmobile"), - RIDING("Riding", "yellow", "mx_special_horse", "activity_type_riding"), - RACING("Racing", "yellow", "mx_raceway", "activity_type_racing"), - MOUNTAINBIKE("Mountainbike", "blue", "mx_sport_cycling", "activity_type_mountainbike"), - CYCLING("Cycling", "blue", "mx_special_bicycle", "activity_type_cycling"), - HIKING("Hiking", "orange", "mx_special_trekking", "activity_type_hiking"), - RUNNING("Running", "orange", "mx_running", "activity_type_running"), - WALKING("Walking", "orange", " mx_special_walking", "activity_type_walking"), - OFFROAD("Off-road", "yellow", "mx_special_offroad", "activity_type_offroad"), - MOTORBIKE("Motorbike", "green", "mx_special_motorcycle", "activity_type_motorbike"), - CAR("Car", "green", "mx_shop_car", "activity_type_car"); + WATER("water", "yellow", "special_kayak"), + WINTER("winter", "yellow", "special_skiing"), + SNOWMOBILE("snowmobile", "yellow", "special_snowmobile"), + RIDING("riding", "yellow", "special_horse"), + RACING("racing", "yellow", "raceway"), + MOUNTAINBIKE("mountainbike", "blue", "sport_cycling"), + CYCLING("cycling", "blue", "special_bicycle"), + HIKING("hiking", "orange", "special_trekking"), + RUNNING("running", "orange", "running"), + WALKING("walking", "orange", "special_walking"), + OFFROAD("offroad", "yellow", "special_offroad"), + MOTORBIKE("motorbike", "green", "special_motorcycle"), + CAR("car", "green", "shop_car"); // less specific bottom order String name; String color; String icon; - String title; - RouteActivityType(String nm, String clr, String icon, String title) { + RouteActivityType(String nm, String clr, String icon) { this.name = nm; this.color = clr; this.icon = icon; - this.title = title; } public String getName() { @@ -40,10 +38,6 @@ public enum RouteActivityType { return icon; } - public String getTitle() { - return title; - } - public static RouteActivityType getTypeFromName(String name) { for (RouteActivityType rat : values()) { if (rat.name().equalsIgnoreCase(name)) { diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0c2feea060..8b1a73aa95 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,19 +12,19 @@ --> - Car - Motorbike - Off-road - Walking - Running - Hiking - Cycling - Mountainbike - Racing - Riding - Snowmobile - Winter - Water + Car + Motorbike + Off-road + Walking + Running + Hiking + Cycling + Mountainbike + Racing + Riding + Snowmobile + Winter + Water Login to OpenPlaceReviews Use test.openplacereviews.org OpenPlaceReviews diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 545e7b7391..ce7547a2c4 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -951,6 +951,12 @@ public class AndroidUtils { return value != null ? value : propertyValue; } + + public static String getActivityTypeStringPropertyName(Context ctx, String propertyName, String defValue) { + String value = getStringByProperty(ctx, "activity_type_" + propertyName + "_name"); + return value != null ? value : defValue; + } + private static String getStringByProperty(@NonNull Context ctx, @NonNull String property) { try { Field field = R.string.class.getField(property); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 69772bac1c..119df5a54a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -7,10 +7,10 @@ import android.widget.TextView; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; -import androidx.annotation.StringRes; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.AndroidUtils; import net.osmand.osm.RouteActivityType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; @@ -21,6 +21,8 @@ import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import java.io.File; +import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase; + public class TravelGpxCard extends BaseTravelCard { public static final int TYPE = 3; @@ -48,12 +50,11 @@ public class TravelGpxCard extends BaseTravelCard { RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType); if (activityType != null) { int iconId = getActivityTypeIcon(activityType); - int titleId = getActivityTypeTitle(activityType); - if (iconId > 0 && titleId > 0) { + if (iconId > 0) { holder.activityTypeIcon.setImageDrawable(getActiveIcon(iconId)); - holder.activityType.setText(titleId); - holder.activityTypeLabel.setVisibility(View.VISIBLE); } + holder.activityType.setText(getActivityTypeTitle(activityType)); + holder.activityTypeLabel.setVisibility(View.VISIBLE); } holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); @@ -79,12 +80,12 @@ public class TravelGpxCard extends BaseTravelCard { @DrawableRes private int getActivityTypeIcon(RouteActivityType activityType) { - return app.getResources().getIdentifier(activityType.getIcon(), "drawable", app.getPackageName()); + return app.getResources().getIdentifier("mx_" + activityType.getIcon(), "drawable", app.getPackageName()); } - @StringRes - private int getActivityTypeTitle(RouteActivityType activityType) { - return app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName()); + private String getActivityTypeTitle(RouteActivityType activityType) { + return AndroidUtils.getActivityTypeStringPropertyName(app, activityType.getName(), + capitalizeFirstLetterAndLowercase(activityType.getName())); } private void updateSaveButton(final TravelGpxVH holder) { From e261150279158cfe3d1e4afbf42391756f9d3a20 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 8 Feb 2021 16:41:10 +0200 Subject: [PATCH 013/173] Convert RouteActivityType to class --- .../net/osmand/osm/RouteActivityType.java | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java index 6f8a0b0e9a..01d5a5c98e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,29 +1,32 @@ package net.osmand.osm; -public enum RouteActivityType { - WATER("water", "yellow", "special_kayak"), - WINTER("winter", "yellow", "special_skiing"), - SNOWMOBILE("snowmobile", "yellow", "special_snowmobile"), - RIDING("riding", "yellow", "special_horse"), - RACING("racing", "yellow", "raceway"), - MOUNTAINBIKE("mountainbike", "blue", "sport_cycling"), - CYCLING("cycling", "blue", "special_bicycle"), - HIKING("hiking", "orange", "special_trekking"), - RUNNING("running", "orange", "running"), - WALKING("walking", "orange", "special_walking"), - OFFROAD("offroad", "yellow", "special_offroad"), - MOTORBIKE("motorbike", "green", "special_motorcycle"), - CAR("car", "green", "shop_car"); - // less specific bottom order +import java.util.ArrayList; +import java.util.List; +public class RouteActivityType { + private static final List values = new ArrayList<>(); + + public static final RouteActivityType WATER = createType("water", "yellow").icon("special_kayak").reg(); + public static final RouteActivityType WINTER = createType("winter", "yellow").icon("special_skiing").reg(); + public static final RouteActivityType SNOWMOBILE = createType("snowmobile", "yellow").icon("special_snowmobile").reg(); + public static final RouteActivityType RIDING = createType("riding", "yellow").icon("special_horse").reg(); + public static final RouteActivityType RACING = createType("racing", "yellow").icon("raceway").reg(); + public static final RouteActivityType MOUNTAINBIKE = createType("mountainbike", "blue").icon("sport_cycling").reg(); + public static final RouteActivityType CYCLING = createType("cycling", "blue").icon("special_bicycle").reg(); + public static final RouteActivityType HIKING = createType("hiking", "orange").icon("special_trekking").reg(); + public static final RouteActivityType RUNNING = createType("running", "orange").icon("running").reg(); + public static final RouteActivityType WALKING = createType("walking", "orange").icon("special_walking").reg(); + public static final RouteActivityType OFFROAD = createType("offroad", "yellow").icon("special_offroad").reg(); + public static final RouteActivityType MOTORBIKE = createType("motorbike", "green").icon("special_motorcycle").reg(); + public static final RouteActivityType CAR = createType("car", "green").icon("shop_car").reg(); + // less specific bottom order String name; String color; String icon; - RouteActivityType(String nm, String clr, String icon) { + RouteActivityType(String nm, String clr) { this.name = nm; this.color = clr; - this.icon = icon; } public String getName() { @@ -39,20 +42,26 @@ public enum RouteActivityType { } public static RouteActivityType getTypeFromName(String name) { - for (RouteActivityType rat : values()) { - if (rat.name().equalsIgnoreCase(name)) { + for (RouteActivityType rat : values) { + if (rat.name.equalsIgnoreCase(name)) { return rat; } } return null; } + private static RouteActivityTypeBuilder createType(String name, String color) { + RouteActivityTypeBuilder builder = new RouteActivityTypeBuilder(); + builder.routeActivityType = new RouteActivityType(name, color); + return builder; + } + public static RouteActivityType getTypeFromTags(String[] tags) { RouteActivityType activityType = null; for (String tg : tags) { RouteActivityType rat = RouteActivityType.convertFromOsmGPXTag(tg); if (rat != null) { - if (activityType == null || activityType.ordinal() > rat.ordinal()) { + if (activityType == null || values.indexOf(activityType) > values.indexOf(rat)) { activityType = rat; } } @@ -237,4 +246,19 @@ public enum RouteActivityType { } return null; } + + public static class RouteActivityTypeBuilder { + + private RouteActivityType routeActivityType; + + public RouteActivityTypeBuilder icon(String icon) { + routeActivityType.icon = icon; + return this; + } + + private RouteActivityType reg() { + values.add(routeActivityType); + return routeActivityType; + } + } } \ No newline at end of file From d01ff166d1e2d85cb9fbd75eb3553e42c161eb87 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 8 Feb 2021 17:38:21 +0200 Subject: [PATCH 014/173] Open wpt menu from TrackMenuFragment --- OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java | 4 +++- OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 6776ea8354..13b3188933 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -828,7 +828,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override protected void onHeaderClick() { - updateMenuState(); + if (getCurrentMenuState() == MenuState.HEADER_ONLY) { + updateMenuState(); + } } private void adjustMapPosition(int y) { diff --git a/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java b/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java index ec3bc0446e..d605f9ed43 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java @@ -26,6 +26,8 @@ import net.osmand.AndroidUtils; import net.osmand.Collator; import net.osmand.GPXUtilities.WptPt; import net.osmand.OsmAndCollator; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; @@ -173,6 +175,12 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { + GpxDisplayItem item = adapter.getChild(groupPosition, childPosition); + if (item != null && item.locationStart != null) { + LatLon location = new LatLon(item.locationStart.lat, item.locationStart.lon); + PointDescription description = new PointDescription(PointDescription.POINT_TYPE_WPT, item.name); + mapActivity.getContextMenu().show(location, description, item.locationStart); + } return true; } From 2efd0cad00b55700fe06d7faa55b7ce0fb2a37b9 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 8 Feb 2021 18:27:18 +0200 Subject: [PATCH 015/173] Add custom activity type --- .../src/main/java/net/osmand/osm/RouteActivityType.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java index 01d5a5c98e..65fa50bf68 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -5,6 +5,8 @@ import java.util.List; public class RouteActivityType { private static final List values = new ArrayList<>(); + public static final String DEFAULT_ICON = "special_marker"; + public static final String DEFAULT_COLOR = "orange"; public static final RouteActivityType WATER = createType("water", "yellow").icon("special_kayak").reg(); public static final RouteActivityType WINTER = createType("winter", "yellow").icon("special_skiing").reg(); @@ -47,7 +49,7 @@ public class RouteActivityType { return rat; } } - return null; + return createType(name.toLowerCase(), DEFAULT_COLOR).icon(DEFAULT_ICON).reg(); } private static RouteActivityTypeBuilder createType(String name, String color) { From 02117a8ffd79f8432d36f2c1acdac715a7a0d28c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 8 Feb 2021 18:34:08 +0200 Subject: [PATCH 016/173] Add description to overview card --- OsmAnd/res/layout/gpx_overview_fragment.xml | 16 +++++++++ .../osmand/plus/track/DescriptionCard.java | 18 +++------- .../GpxReadDescriptionDialogFragment.java | 18 +++++----- .../net/osmand/plus/track/OverviewCard.java | 33 +++++++++++++++++++ .../plus/wikipedia/WikiArticleHelper.java | 11 +++++++ 5 files changed, 73 insertions(+), 23 deletions(-) diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml index 426633eb83..3b205ae60e 100644 --- a/OsmAnd/res/layout/gpx_overview_fragment.xml +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -6,6 +6,22 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + \n" + content + "\n"; } - public static void showInstance(@NonNull FragmentActivity activity, @NonNull String title, @NonNull String imageUrl, @NonNull String description) { + public static void showInstance(@NonNull FragmentActivity activity, @NonNull String title, @Nullable String imageUrl, @NonNull String description) { FragmentManager fragmentManager = activity.getSupportFragmentManager(); if (!fragmentManager.isStateSaved()) { Bundle args = new Bundle(); diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index 5d46a69c25..d0a396499d 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -4,7 +4,9 @@ import android.annotation.SuppressLint; import android.graphics.drawable.Drawable; import android.view.MotionEvent; import android.view.View; +import android.view.View.OnClickListener; import android.widget.ImageView; +import android.widget.TextView; import androidx.annotation.ColorRes; import androidx.annotation.DrawableRes; @@ -13,18 +15,23 @@ import androidx.appcompat.widget.AppCompatImageView; import androidx.recyclerview.widget.RecyclerView; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.Metadata; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.util.Algorithms; +import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.getMetadataImageLink; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected; import static net.osmand.plus.track.OptionsCard.APPEARANCE_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.DIRECTIONS_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.EDIT_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX; +import static net.osmand.plus.wikipedia.WikiArticleHelper.getFirstParagraph; public class OverviewCard extends BaseCard { @@ -63,6 +70,7 @@ public class OverviewCard extends BaseCard { RecyclerView blocksView = view.findViewById(R.id.recycler_overview); blockStatisticsBuilder.setBlocksView(blocksView); + setupDescription(); initShowButton(iconColorDef, iconColorPres); initAppearanceButton(iconColorDef, iconColorPres); if (fileAvailable) { @@ -125,6 +133,31 @@ public class OverviewCard extends BaseCard { iv.setImageDrawable(icon); } + private void setupDescription() { + GPXFile gpxFile = getGPXFile(); + if (gpxFile.metadata == null) { + gpxFile.metadata = new Metadata(); + } + + TextView description = view.findViewById(R.id.description); + final String descriptionHtml = gpxFile.metadata.getDescription(); + if (Algorithms.isBlank(descriptionHtml)) { + AndroidUiHelper.updateVisibility(description, false); + } else { + description.setText(getFirstParagraph(descriptionHtml)); + description.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + GPXFile gpxFile = getGPXFile(); + String title = gpxFile.metadata.getArticleTitle(); + String imageUrl = getMetadataImageLink(gpxFile.metadata); + GpxReadDescriptionDialogFragment.showInstance(mapActivity, title, imageUrl, descriptionHtml); + } + }); + AndroidUiHelper.updateVisibility(description, true); + } + } + private void setOnTouchItem(View item, final ImageView image, final ImageView filled, @DrawableRes final Integer resId, @ColorRes final int colorDef, @ColorRes final int colorPres) { item.setOnTouchListener(new View.OnTouchListener() { @SuppressLint("ClickableViewAccessibility") diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java index 56137a780c..7b72024b12 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java @@ -333,6 +333,17 @@ public class WikiArticleHelper { return res.toString(); } + @Nullable + public static String getFirstParagraph(String descriptionHtml) { + if (descriptionHtml != null) { + String firstParagraph = WikiArticleHelper.getPartialContent(descriptionHtml); + if (!Algorithms.isEmpty(firstParagraph)) { + return firstParagraph; + } + } + return descriptionHtml; + } + public static String buildTravelUrl(String url, String lang) { String title = url.replace(" ", "_"); try { From 455518decc5632ff10cd5938f9e7ad17342b4fdf Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 8 Feb 2021 18:44:21 +0200 Subject: [PATCH 017/173] Add custom activity type --- .../wikivoyage/explore/travelcards/TravelGpxCard.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 119df5a54a..795980df32 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -48,14 +48,9 @@ public class TravelGpxCard extends BaseTravelCard { holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16)); holder.user.setText(article.user); RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType); - if (activityType != null) { - int iconId = getActivityTypeIcon(activityType); - if (iconId > 0) { - holder.activityTypeIcon.setImageDrawable(getActiveIcon(iconId)); - } - holder.activityType.setText(getActivityTypeTitle(activityType)); - holder.activityTypeLabel.setVisibility(View.VISIBLE); - } + holder.activityTypeIcon.setImageDrawable(getActiveIcon(getActivityTypeIcon(activityType))); + holder.activityType.setText(getActivityTypeTitle(activityType)); + holder.activityTypeLabel.setVisibility(View.VISIBLE); holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app)); From 095c22a03528bdd4cbac03ed9dd5beffc5e4eb50 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 8 Feb 2021 19:28:59 +0200 Subject: [PATCH 018/173] Add line on top of selected tab item --- .../drawable/bottom_navigation_item_bg_dark.xml | 8 ++++++++ .../drawable/bottom_navigation_item_bg_light.xml | 8 ++++++++ .../drawable/navigation_item_active_bg_dark.xml | 15 +++++++++++++++ .../drawable/navigation_item_active_bg_light.xml | 15 +++++++++++++++ OsmAnd/res/layout/track_menu.xml | 2 +- OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/styles.xml | 2 ++ 7 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 OsmAnd/res/drawable/bottom_navigation_item_bg_dark.xml create mode 100644 OsmAnd/res/drawable/bottom_navigation_item_bg_light.xml create mode 100644 OsmAnd/res/drawable/navigation_item_active_bg_dark.xml create mode 100644 OsmAnd/res/drawable/navigation_item_active_bg_light.xml diff --git a/OsmAnd/res/drawable/bottom_navigation_item_bg_dark.xml b/OsmAnd/res/drawable/bottom_navigation_item_bg_dark.xml new file mode 100644 index 0000000000..f0934052c1 --- /dev/null +++ b/OsmAnd/res/drawable/bottom_navigation_item_bg_dark.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/bottom_navigation_item_bg_light.xml b/OsmAnd/res/drawable/bottom_navigation_item_bg_light.xml new file mode 100644 index 0000000000..f410c7a1ff --- /dev/null +++ b/OsmAnd/res/drawable/bottom_navigation_item_bg_light.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/navigation_item_active_bg_dark.xml b/OsmAnd/res/drawable/navigation_item_active_bg_dark.xml new file mode 100644 index 0000000000..de8b54eb6e --- /dev/null +++ b/OsmAnd/res/drawable/navigation_item_active_bg_dark.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/navigation_item_active_bg_light.xml b/OsmAnd/res/drawable/navigation_item_active_bg_light.xml new file mode 100644 index 0000000000..31d31f1c40 --- /dev/null +++ b/OsmAnd/res/drawable/navigation_item_active_bg_light.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/track_menu.xml b/OsmAnd/res/layout/track_menu.xml index db0f8a47f9..e62361afc2 100644 --- a/OsmAnd/res/layout/track_menu.xml +++ b/OsmAnd/res/layout/track_menu.xml @@ -206,7 +206,7 @@ android:layout_height="@dimen/context_menu_action_buttons_height" android:layout_gravity="bottom" android:background="?attr/wikivoyage_card_bg_color" - osmand:itemBackground="?attr/wikivoyage_card_bg_color" + osmand:itemBackground="?attr/bottom_navigation_item_background" osmand:itemIconTint="@color/bottom_navigation_color_selector_light" osmand:itemTextColor="@color/bottom_navigation_color_selector_light" osmand:labelVisibilityMode="labeled" diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index c745589ef7..f75867c8e8 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -142,6 +142,7 @@ + diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 5c074185ef..4648cba1cc 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -249,6 +249,7 @@ @color/text_input_background_light @drawable/img_help_announcement_time_day @color/switch_button_active_light + @drawable/bottom_navigation_item_bg_light