From f1569fd5fb8c05939869df897fed5cae435389fb Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Sun, 24 Jan 2021 23:48:41 +0200 Subject: [PATCH 01/53] Travel GPX card --- .../main/java/net/osmand/data/Amenity.java | 4 + .../res/layout/wikivoyage_travel_gpx_card.xml | 242 ++++++++++++++++++ .../plus/wikivoyage/data/TravelGpx.java | 8 + .../wikivoyage/explore/ExploreRvAdapter.java | 13 +- .../explore/ExploreTabFragment.java | 8 +- .../explore/travelcards/TravelGpxCard.java | 120 +++++++++ 6 files changed, 392 insertions(+), 3 deletions(-) create mode 100644 OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml create mode 100644 OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java create mode 100644 OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java 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 3ef6a54652..959669a665 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -273,6 +273,10 @@ public class Amenity extends MapObject { return null; } + public String getTagContent(String tag) { + return getTagContent(tag, null); + } + public String getTagContent(String tag, String lang) { if (lang != null) { String translateName = getAdditionalInfo(tag + ":" + lang); diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml new file mode 100644 index 0000000000..eb97f02c0b --- /dev/null +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java new file mode 100644 index 0000000000..8393ec98a6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -0,0 +1,8 @@ +package net.osmand.plus.wikivoyage.data; + +public class TravelGpx extends TravelArticle { + public String user; + public float totalDistance = 0; + public double diffElevationUp = 0; + public double diffElevationDown = 0; +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java index a95614bdb8..5341edcb9d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java @@ -20,6 +20,8 @@ import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard.StartEditingTravelVH; import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard.DownloadUpdateVH; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH; import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard.NeededMapsVH; @@ -48,6 +50,9 @@ public class ExploreRvAdapter extends RecyclerView.Adapter 0; i--) { BaseTravelCard o = items.get(i); - if (o instanceof ArticleTravelCard) { + 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 c53027fb7a..ae6b0cace7 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -28,6 +28,7 @@ import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; import net.osmand.plus.wikivoyage.data.TravelArticle; +import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelHelper; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard; @@ -36,6 +37,7 @@ 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.TravelDownloadUpdateCard; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard; import java.io.IOException; @@ -183,7 +185,11 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv List popularArticles = app.getTravelHelper().getPopularArticles(); for (TravelArticle article : popularArticles) { - items.add(new ArticleTravelCard(app, nightMode, article, fm)); + if (article instanceof TravelGpx) { + items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, fm)); + } else { + items.add(new ArticleTravelCard(app, nightMode, article, fm)); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java new file mode 100644 index 0000000000..32790cc094 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -0,0 +1,120 @@ +package net.osmand.plus.wikivoyage.explore.travelcards; + +import android.graphics.drawable.Drawable; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.RecyclerView; + +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.wikipedia.WikiArticleHelper; +import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; +import net.osmand.plus.wikivoyage.data.TravelGpx; +import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; + +public class TravelGpxCard extends BaseTravelCard { + + public static final int TYPE = 3; + + private final TravelGpx article; + private final Drawable readIcon; + private final FragmentManager fragmentManager; + private boolean isLastItem; + + public TravelGpxCard(@NonNull OsmandApplication app, boolean nightMode, @NonNull TravelGpx article, + @NonNull FragmentManager fragmentManager) { + super(app, nightMode); + this.article = article; + readIcon = getActiveIcon(R.drawable.ic_action_read_article); + this.fragmentManager = fragmentManager; + } + + @Override + public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) { + if (viewHolder instanceof TravelGpxVH) { + final TravelGpxVH holder = (TravelGpxVH) viewHolder; + holder.title.setText(article.getTitle()); + holder.content.setText(WikiArticleHelper.getPartialContent(article.getContent())); + holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance,app)); + holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp,app)); + holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown,app)); + holder.leftButton.setText(app.getString(R.string.shared_string_view)); + View.OnClickListener readClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + if (fragmentManager != null) { + WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, + article.generateIdentifier(), article.getLang()); + } + } + }; + holder.leftButton.setOnClickListener(readClickListener); + holder.itemView.setOnClickListener(readClickListener); + holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null); + updateSaveButton(holder); + holder.divider.setVisibility(isLastItem ? View.GONE : View.VISIBLE); + holder.shadow.setVisibility(isLastItem ? View.VISIBLE : View.GONE); + } + } + + private void updateSaveButton(final TravelGpxVH holder) { + if (article != null) { + final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper(); + final boolean saved = helper.isArticleSaved(article); + Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later); + holder.rightButton.setText(saved ? R.string.shared_string_remove : R.string.shared_string_save); + holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null); + holder.rightButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (saved) { + helper.removeArticleFromSaved(article); + } else { + app.getTravelHelper().createGpxFile(article); + helper.addArticleToSaved(article); + } + updateSaveButton(holder); + } + }); + } + } + + public static class TravelGpxVH extends RecyclerView.ViewHolder { + + final TextView title; + final TextView content; + final TextView distance; + final TextView diffElevationUp; + final TextView diffElevationDown; + final TextView leftButton; + final TextView rightButton; + final View divider; + final View shadow; + + public TravelGpxVH(final View itemView) { + super(itemView); + title = itemView.findViewById(R.id.title); + content = itemView.findViewById(R.id.content); + distance = itemView.findViewById(R.id.distance); + diffElevationUp = itemView.findViewById(R.id.diff_ele_up); + diffElevationDown = itemView.findViewById(R.id.diff_ele_down); + leftButton = itemView.findViewById(R.id.left_button); + rightButton = itemView.findViewById(R.id.right_button); + divider = itemView.findViewById(R.id.divider); + shadow = itemView.findViewById(R.id.shadow); + } + } + + public void setLastItem(boolean lastItem) { + isLastItem = lastItem; + } + + @Override + public int getCardType() { + return TYPE; + } +} From a914efaa286353dbbfd9cb920de442773590de3f Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 25 Jan 2021 23:30:43 +0200 Subject: [PATCH 02/53] Sort travel GPX card and travel article, UI --- .../res/layout/wikivoyage_travel_gpx_card.xml | 78 +++++++--- .../plus/wikivoyage/data/TravelObfHelper.java | 143 ++++++++++++------ .../explore/ExploreTabFragment.java | 27 ++-- .../explore/travelcards/TravelGpxCard.java | 22 +-- 4 files changed, 184 insertions(+), 86 deletions(-) diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml index eb97f02c0b..44077a0dcd 100644 --- a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -10,17 +10,13 @@ android:id="@+id/background_view" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="@dimen/content_padding_small" - android:layout_marginStart="@dimen/content_padding" - android:layout_marginEnd="@dimen/content_padding" - android:background="?attr/wikivoyage_travel_card_bg"> + android:background="?attr/wikivoyage_card_bg_color"> + + + + - + android:orientation="vertical" + android:paddingTop="@dimen/content_padding_half" + android:paddingBottom="@dimen/content_padding_small"> + + + + + + android:layout_height="wrap_content" + android:paddingTop="@dimen/content_padding_small_half" + android:paddingBottom="@dimen/content_padding_small_half"> loadPopularArticles() { String lang = app.getLanguage(); List popularArticles = new ArrayList<>(); - for (BinaryMapIndexReader reader : getReaders()) { + final List> amenities = new ArrayList<>(); + final LatLon location = app.getMapViewTrackingUtilities().getMapLocation(); + for (final BinaryMapIndexReader reader : getReaders()) { try { - final LatLon location = app.getMapViewTrackingUtilities().getMapLocation(); - SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest( - location, POPULAR_ARTICLES_SEARCH_RADIUS, -1, getSearchFilter(false), null); - List amenities = reader.searchPoi(req); - if (amenities.size() > 0) { - for (Amenity amenity : amenities) { - if (!Algorithms.isEmpty(amenity.getName(lang))) { - TravelArticle article = cacheTravelArticles(reader.getFile(), amenity, lang, false); - if (article != null) { - popularArticles.add(article); - if (popularArticles.size() >= MAX_POPULAR_ARTICLES_COUNT) { - break; - } - } - } - } - Collections.sort(popularArticles, new Comparator() { - @Override - public int compare(TravelArticle article1, TravelArticle article2) { - int d1 = (int) (MapUtils.getDistance(article1.getLat(), article1.getLon(), - location.getLatitude(), location.getLongitude())); - int d2 = (int) (MapUtils.getDistance(article2.getLat(), article2.getLon(), - location.getLatitude(), location.getLongitude())); - return d1 < d2 ? -1 : (d1 == d2 ? 0 : 1); - } - }); - } + 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() > 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); + if (article != null) { + popularArticles.add(article); + if (popularArticles.size() >= MAX_POPULAR_ARTICLES_COUNT) { + break; + } + } + } + } + } this.popularArticles = popularArticles; return popularArticles; } + private void searchAmenity(final List> amenitiesList, LatLon location, + final BinaryMapIndexReader reader, int searchRadius, int zoom, + String searchFilter) throws IOException { + reader.searchPoi(BinaryMapIndexReader.buildSearchPoiRequest( + location, searchRadius, zoom, getSearchFilter(searchFilter), new ResultMatcher() { + @Override + public boolean publish(Amenity object) { + amenitiesList.add(new Pair<>(reader.getFile(), object)); + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + })); + } + @Nullable private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints) { TravelArticle article = null; - Map articles = readArticles(file, amenity, false); + Map articles; + if (amenity.getSubType().equals(ROUTE_TRACK)) { + articles = readRoutePoint(file, amenity); + } else { + articles = readArticles(file, amenity, false); + } if (!Algorithms.isEmpty(articles)) { TravelArticleIdentifier newArticleId = articles.values().iterator().next().generateIdentifier(); cachedArticles.put(newArticleId, articles); @@ -139,12 +165,38 @@ public class TravelObfHelper implements TravelHelper { return article; } - @NonNull - private SearchPoiTypeFilter getSearchFilter(final boolean articlePoints) { - return new SearchPoiTypeFilter() { + private Map readRoutePoint(File file, Amenity amenity) { + Map articles = new HashMap<>(); + TravelGpx res = new TravelGpx(); + String title = amenity.getName("en"); + res.title = capitalizeFirstLetter(getGpxTitle(Algorithms.isEmpty(title) ? amenity.getName() : title)); + res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)); + try { + res.totalDistance = Float.parseFloat(Algorithms.emptyIfNull(amenity.getTagContent("distance"))); + } catch (NumberFormatException e) { + LOG.debug(e.getMessage(), e); + } + try { + res.diffElevationUp = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent("diff_ele_up"))); + } catch (NumberFormatException e) { + LOG.debug(e.getMessage(), e); + } + try { + res.diffElevationDown = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent("diff_ele_down"))); + } catch (NumberFormatException e) { + LOG.debug(e.getMessage(), e); + } + res.user = Algorithms.emptyIfNull(amenity.getTagContent("user")); + articles.put("en", res); + return articles; + } + + + private BinaryMapIndexReader.SearchPoiTypeFilter getSearchFilter(final String filterSubcategory) { + return new BinaryMapIndexReader.SearchPoiTypeFilter() { @Override public boolean accept(PoiCategory type, String subcategory) { - return subcategory.equals(articlePoints ? ROUTE_ARTICLE_POINT : ROUTE_ARTICLE); + return subcategory.equals(filterSubcategory); } @Override @@ -175,9 +227,9 @@ public class TravelObfHelper implements TravelHelper { res.isParentOf = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IS_PARENT_OF, lang)); res.lat = amenity.getLocation().getLatitude(); res.lon = amenity.getLocation().getLongitude(); - res.imageTitle = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IMAGE_TITLE, null)); - res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID, null)); - res.routeSource = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_SOURCE, null)); + res.imageTitle = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IMAGE_TITLE)); + res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)); + res.routeSource = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_SOURCE)); res.originalId = 0; res.lang = lang; res.contentsJson = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.CONTENT_JSON, lang)); @@ -214,14 +266,14 @@ public class TravelObfHelper implements TravelHelper { } SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, Algorithms.emptyIfNull(article.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSearchFilter(true), new ResultMatcher() { + getSearchFilter(ROUTE_ARTICLE_POINT), new ResultMatcher() { @Override public boolean publish(Amenity amenity) { String amenityLang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); if (Algorithms.stringsEqual(lang, amenityLang) && Algorithms.stringsEqual(article.routeId, - Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID, null)))) { + Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)))) { pointList.add(amenity); } return false; @@ -263,7 +315,7 @@ public class TravelObfHelper implements TravelHelper { } String category = amenity.getTagSuffix("category_"); if (category != null) { - wptPt.category = Algorithms.capitalizeFirstLetter(category); + wptPt.category = capitalizeFirstLetter(category); } return wptPt; } @@ -283,7 +335,7 @@ public class TravelObfHelper implements TravelHelper { for (BinaryMapIndexReader reader : getReaders()) { try { SearchRequest searchRequest = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, searchQuery, - 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(false), new ResultMatcher() { + 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(ROUTE_ARTICLE), new ResultMatcher() { @Override public boolean publish(Amenity object) { List otherNames = object.getAllNames(false); @@ -458,7 +510,7 @@ public class TravelObfHelper implements TravelHelper { for (BinaryMapIndexReader reader : getReaders()) { try { SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest( - 0, 0, title, 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(false), + 0, 0, title, 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(ROUTE_ARTICLE), new ResultMatcher() { boolean done = false; @@ -531,12 +583,13 @@ public class TravelObfHelper implements TravelHelper { } SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSearchFilter(false), new ResultMatcher() { + getSearchFilter(ROUTE_ARTICLE), new ResultMatcher() { boolean done = false; @Override public boolean publish(Amenity amenity) { - if (Algorithms.stringsEqual(articleId.routeId, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID, null))) || isDbArticle) { + if (Algorithms.stringsEqual(articleId.routeId, + Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID))) || isDbArticle) { amenities.add(amenity); done = true; } @@ -604,7 +657,7 @@ public class TravelObfHelper implements TravelHelper { for (BinaryMapIndexReader reader : getReaders()) { try { SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest( - x, y, title, left, right, top, bottom, getSearchFilter(false), + x, y, title, left, right, top, bottom, getSearchFilter(ROUTE_ARTICLE), new ResultMatcher() { boolean done = false; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index e520487740..ce6f4475af 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -180,20 +180,21 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv List popularArticles = app.getTravelHelper().getPopularArticles(); for (TravelArticle article : popularArticles) { - if (article instanceof TravelGpx) { - items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, fm)); - } else { - items.add(new ArticleTravelCard(app, nightMode, article, activity.getSupportFragmentManager())); + if (article instanceof TravelGpx) { + items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, activity.getSupportFragmentManager())); + } else { + items.add(new ArticleTravelCard(app, nightMode, article, activity.getSupportFragmentManager())); + } + } + items.add(new StartEditingTravelCard(activity, nightMode)); + adapter.setItems(items); + final DownloadIndexesThread downloadThread = app.getDownloadThread(); + if (!downloadThread.getIndexes().isDownloadedFromInternet) { + waitForIndexes = true; + downloadThread.runReloadIndexFilesSilent(); + } else { + checkDownloadIndexes(); } - } - items.add(new StartEditingTravelCard(activity, nightMode)); - adapter.setItems(items); - final DownloadIndexesThread downloadThread = app.getDownloadThread(); - if (!downloadThread.getIndexes().isDownloadedFromInternet) { - waitForIndexes = true; - downloadThread.runReloadIndexFilesSilent(); - } else { - checkDownloadIndexes(); } } } 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 32790cc094..608b0b812f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -8,11 +8,11 @@ import androidx.annotation.NonNull; import androidx.fragment.app.FragmentManager; 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.wikipedia.WikiArticleHelper; -import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; @@ -38,17 +38,21 @@ public class TravelGpxCard extends BaseTravelCard { if (viewHolder instanceof TravelGpxVH) { final TravelGpxVH holder = (TravelGpxVH) viewHolder; holder.title.setText(article.getTitle()); - holder.content.setText(WikiArticleHelper.getPartialContent(article.getContent())); - holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance,app)); - holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp,app)); - holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown,app)); + Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16); + holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + holder.user.setText(WikiArticleHelper.getPartialContent(article.user)); + AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark); + holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); + holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); + holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app)); holder.leftButton.setText(app.getString(R.string.shared_string_view)); View.OnClickListener readClickListener = new View.OnClickListener() { @Override public void onClick(View v) { if (fragmentManager != null) { - WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, - article.generateIdentifier(), article.getLang()); +// WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, +// article.generateIdentifier(), article.getLang()); + app.getTravelHelper().createGpxFile(article); } } }; @@ -86,7 +90,7 @@ public class TravelGpxCard extends BaseTravelCard { public static class TravelGpxVH extends RecyclerView.ViewHolder { final TextView title; - final TextView content; + final TextView user; final TextView distance; final TextView diffElevationUp; final TextView diffElevationDown; @@ -98,7 +102,7 @@ public class TravelGpxCard extends BaseTravelCard { public TravelGpxVH(final View itemView) { super(itemView); title = itemView.findViewById(R.id.title); - content = itemView.findViewById(R.id.content); + user = itemView.findViewById(R.id.user_name); distance = itemView.findViewById(R.id.distance); diffElevationUp = itemView.findViewById(R.id.diff_ele_up); diffElevationDown = itemView.findViewById(R.id.diff_ele_down); From fea90fd37e6395feb960ff8e1c30c508ff7f20b4 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 26 Jan 2021 23:41:44 +0200 Subject: [PATCH 03/53] Add to bookmarks, build gpx track --- .../plus/wikivoyage/data/TravelGpx.java | 6 ++ .../data/TravelLocalDataHelper.java | 33 +++++-- .../plus/wikivoyage/data/TravelObfHelper.java | 82 +++++++++++++++- .../explore/SavedArticlesRvAdapter.java | 93 ++++++++++++++++--- .../explore/travelcards/TravelGpxCard.java | 18 ++-- 5 files changed, 198 insertions(+), 34 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index 8393ec98a6..185fdc922c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -1,6 +1,12 @@ package net.osmand.plus.wikivoyage.data; public class TravelGpx extends TravelArticle { + + public static final String DISTANCE = "distance"; + 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 String user; public float totalDistance = 0; public double diffElevationUp = 0; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index 2c59c16ed2..748800a611 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -143,6 +143,9 @@ public class TravelLocalDataHelper { @Nullable private TravelArticle getArticle(String title, String lang) { for (TravelArticle article : savedArticles) { + if (article.lang == null && lang == null && article.title != null && article.title.equals(title)) { + return article; + } if (article.title != null && article.title.equals(title) && article.lang != null && article.lang.equals(lang)) { return article; } @@ -477,12 +480,23 @@ public class TravelLocalDataHelper { SQLiteConnection conn = openConnection(false); if (conn != null) { try { - conn.execSQL("DELETE FROM " + BOOKMARKS_TABLE_NAME + - " WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" + - " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + - " AND " + BOOKMARKS_COL_LANG + " = ?" + - " AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?", - new Object[]{article.title, article.routeId, article.lang, travelBook}); + String query; + Object[] parameters; + if (article.lang == null) { + query = "DELETE FROM " + BOOKMARKS_TABLE_NAME + + " WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" + + " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + + " AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?"; + parameters = new Object[]{article.title, article.routeId, travelBook}; + } else { + query = "DELETE FROM " + BOOKMARKS_TABLE_NAME + + " WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" + + " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + + " AND " + BOOKMARKS_COL_LANG + " = ?" + + " AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?"; + parameters = new Object[]{article.title, article.routeId, article.lang, travelBook}; + } + conn.execSQL(query, parameters); } finally { conn.close(); } @@ -537,7 +551,12 @@ public class TravelLocalDataHelper { @NonNull private TravelArticle readSavedArticle(SQLiteCursor cursor) { - TravelArticle res = new TravelArticle(); + TravelArticle res; + if (cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_LANG)) == null) { + res = new TravelGpx(); + } else { + res = new TravelArticle(); + } res.title = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_ARTICLE_TITLE)); res.lang = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_LANG)); res.aggregatedPartOf = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_IS_PART_OF)); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 0f76eb775e..13c4fffa49 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -8,11 +8,13 @@ import androidx.annotation.Nullable; import net.osmand.Collator; import net.osmand.CollatorStringMatcher.StringMatcherMode; +import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; +import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.data.Amenity; @@ -48,6 +50,10 @@ import java.util.concurrent.ConcurrentHashMap; import static net.osmand.GPXUtilities.WptPt; import static net.osmand.GPXUtilities.writeGpxFile; 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.USER; import static net.osmand.util.Algorithms.capitalizeFirstLetter; public class TravelObfHelper implements TravelHelper { @@ -168,25 +174,26 @@ public class TravelObfHelper implements TravelHelper { private Map readRoutePoint(File file, Amenity amenity) { Map articles = new HashMap<>(); TravelGpx res = new TravelGpx(); + res.file = file; String title = amenity.getName("en"); res.title = capitalizeFirstLetter(getGpxTitle(Algorithms.isEmpty(title) ? amenity.getName() : title)); res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)); try { - res.totalDistance = Float.parseFloat(Algorithms.emptyIfNull(amenity.getTagContent("distance"))); + res.totalDistance = Float.parseFloat(Algorithms.emptyIfNull(amenity.getTagContent(DISTANCE))); } catch (NumberFormatException e) { LOG.debug(e.getMessage(), e); } try { - res.diffElevationUp = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent("diff_ele_up"))); + res.diffElevationUp = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(DIFF_ELE_UP))); } catch (NumberFormatException e) { LOG.debug(e.getMessage(), e); } try { - res.diffElevationDown = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent("diff_ele_down"))); + res.diffElevationDown = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(DIFF_ELE_DOWN))); } catch (NumberFormatException e) { LOG.debug(e.getMessage(), e); } - res.user = Algorithms.emptyIfNull(amenity.getTagContent("user")); + res.user = Algorithms.emptyIfNull(amenity.getTagContent(USER)); articles.put("en", res); return articles; } @@ -255,6 +262,66 @@ public class TravelObfHelper implements TravelHelper { return gpxFile; } + @Nullable + private GPXFile buildTravelGpxFile(@NonNull final TravelGpx article) { + String routeId = article.getRouteId(); + final String ref = routeId.substring(routeId.length() - 3); + final List segmentList = new ArrayList<>(); + + for (BinaryMapIndexReader reader : getReaders()) { + try { + if (article.file != null && !article.file.equals(reader.getFile())) { + continue; + } + BinaryMapIndexReader.SearchRequest sr = BinaryMapIndexReader.buildSearchRequest( + 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, 15, null, + new ResultMatcher() { + @Override + public boolean publish(BinaryMapDataObject object) { + if (object.getPointsLength() > 1) { + if (object.getObjectNames().get(2).equals(ref) + && capitalizeFirstLetter(getGpxTitle(object.getObjectNames().get(1))).equals(article.title)) { + segmentList.add(object); + } + } + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + }); + reader.searchMapIndex(sr); + if (!Algorithms.isEmpty(segmentList)) { + break; + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + GPXFile gpxFile = null; + if (!segmentList.isEmpty()) { + GPXUtilities.Track track = new GPXUtilities.Track(); + for (BinaryMapDataObject segment : segmentList) { + List pointList = new ArrayList<>(); + GPXUtilities.TrkSegment trkSegment = new GPXUtilities.TrkSegment(); + for (int i = 0; i < segment.getPointsLength(); i++) { + WptPt point = new WptPt(); + point.lat = MapUtils.get31LatitudeY(segment.getPoint31YTile(i)); + point.lon = MapUtils.get31LongitudeX(segment.getPoint31XTile(i)); + pointList.add(point); + } + trkSegment.points = pointList; + track.segments.add(trkSegment); + } + gpxFile = new GPXFile(article.getTitle(), article.getLang(), ""); + gpxFile.tracks = new ArrayList<>(); + gpxFile.tracks.add(track); + } + return gpxFile; + } + @NonNull private List getPointList(@NonNull final TravelArticle article) { final List pointList = new ArrayList<>(); @@ -744,7 +811,12 @@ public class TravelObfHelper implements TravelHelper { @NonNull @Override public File createGpxFile(@NonNull final TravelArticle article) { - final GPXFile gpx = article.getGpxFile(); + final GPXFile gpx; + if (article instanceof TravelGpx) { + gpx = buildTravelGpxFile((TravelGpx) article); + } else { + gpx = article.getGpxFile(); + } File file = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + getGPXName(article)); writeGpxFile(file, gpx); return file; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index 8996e4d375..89fc06ed37 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -7,6 +7,8 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.DrawableRes; +import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; @@ -16,16 +18,20 @@ 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.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.wikipedia.WikiArticleHelper; 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 java.util.ArrayList; import java.util.List; @@ -33,7 +39,8 @@ import java.util.List; public class SavedArticlesRvAdapter extends RecyclerView.Adapter { private static final int HEADER_TYPE = 0; - private static final int ITEM_TYPE = 1; + private static final int ARTICLE_TYPE = 1; + private static final int GPX_TYPE = 2; private final OsmandApplication app; private final OsmandSettings settings; @@ -45,6 +52,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter Date: Wed, 27 Jan 2021 10:20:55 +0200 Subject: [PATCH 04/53] Open mapActivity --- .../plus/wikivoyage/data/TravelObfHelper.java | 3 +++ .../explore/ExploreTabFragment.java | 2 +- .../explore/travelcards/TravelGpxCard.java | 21 ++++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 13c4fffa49..a44b131a66 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -177,6 +177,8 @@ public class TravelObfHelper implements TravelHelper { res.file = file; String title = amenity.getName("en"); res.title = capitalizeFirstLetter(getGpxTitle(Algorithms.isEmpty(title) ? amenity.getName() : title)); + res.lat = amenity.getLocation().getLatitude(); + res.lon = amenity.getLocation().getLongitude(); res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)); try { res.totalDistance = Float.parseFloat(Algorithms.emptyIfNull(amenity.getTagContent(DISTANCE))); @@ -319,6 +321,7 @@ public class TravelObfHelper implements TravelHelper { gpxFile.tracks = new ArrayList<>(); gpxFile.tracks.add(track); } + article.gpxFile = gpxFile; return gpxFile; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index ce6f4475af..9055acd4ed 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -181,7 +181,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv List popularArticles = app.getTravelHelper().getPopularArticles(); for (TravelArticle article : popularArticles) { if (article instanceof TravelGpx) { - items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, activity.getSupportFragmentManager())); + items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, getActivity())); } else { items.add(new ArticleTravelCard(app, nightMode, article, activity.getSupportFragmentManager())); } 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 ded096a260..3cfbc91c04 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -5,13 +5,15 @@ import android.view.View; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.fragment.app.FragmentManager; +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.activities.MapActivity; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; @@ -22,15 +24,15 @@ public class TravelGpxCard extends BaseTravelCard { private final TravelGpx article; private final Drawable readIcon; - private final FragmentManager fragmentManager; + private final FragmentActivity activity; private boolean isLastItem; public TravelGpxCard(@NonNull OsmandApplication app, boolean nightMode, @NonNull TravelGpx article, - @NonNull FragmentManager fragmentManager) { + @NonNull FragmentActivity activity) { super(app, nightMode); this.article = article; readIcon = getActiveIcon(R.drawable.ic_action_read_article); - this.fragmentManager = fragmentManager; + this.activity = activity; } @Override @@ -49,10 +51,15 @@ public class TravelGpxCard extends BaseTravelCard { View.OnClickListener readClickListener = new View.OnClickListener() { @Override public void onClick(View v) { - if (fragmentManager != null) { -// WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, -// article.generateIdentifier(), article.getLang()); + if (activity != null) { app.getTravelHelper().createGpxFile(article); + final OsmandSettings settings = app.getSettings(); + settings.setMapLocationToShow(article.getLat(), article.getLon(), + settings.getLastKnownMapZoom(), + null, + false, + article.getGpxFile()); + MapActivity.launchMapActivityMoveToTop(activity); } } }; From 048f6035cbf1a00ed8140c68f05f2250b883d547 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 27 Jan 2021 12:02:57 +0200 Subject: [PATCH 05/53] open TrackMenuFragment --- .../explore/SavedArticlesRvAdapter.java | 9 +++++++-- .../explore/SavedArticlesTabFragment.java | 20 +++++++++++++++---- .../explore/travelcards/TravelGpxCard.java | 15 +++++--------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index 89fc06ed37..bbc0cb6da7 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -11,6 +11,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.snackbar.Snackbar; @@ -25,6 +26,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.track.TrackMenuFragment; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.WikivoyageUtils; @@ -33,6 +35,7 @@ import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -58,7 +61,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter Date: Wed, 27 Jan 2021 16:33:49 +0200 Subject: [PATCH 06/53] Minor code cleanup --- .../data/TravelLocalDataHelper.java | 23 +++++-------------- .../plus/wikivoyage/data/TravelObfHelper.java | 23 +++++++++++-------- .../explore/SavedArticlesRvAdapter.java | 5 +--- .../explore/SavedArticlesTabFragment.java | 2 +- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index e27b3363b6..ae1c22b587 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -480,23 +480,12 @@ public class TravelLocalDataHelper { SQLiteConnection conn = openConnection(false); if (conn != null) { try { - String query; - Object[] parameters; - if (article.lang == null) { - query = "DELETE FROM " + BOOKMARKS_TABLE_NAME + - " WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" + - " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + - " AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?"; - parameters = new Object[]{article.title, article.routeId, travelBook}; - } else { - query = "DELETE FROM " + BOOKMARKS_TABLE_NAME + - " WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" + - " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + - " AND " + BOOKMARKS_COL_LANG + " = ?" + - " AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?"; - parameters = new Object[]{article.title, article.routeId, article.lang, travelBook}; - } - conn.execSQL(query, parameters); + String query = "DELETE FROM " + BOOKMARKS_TABLE_NAME + + " WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" + + " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + + " AND " + BOOKMARKS_COL_LANG + ((article.lang != null) ? " = '" + article.lang + "'" : " IS NULL") + + " AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?"; + conn.execSQL(query, new Object[]{article.title, article.routeId, travelBook}); } finally { conn.close(); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 17dd2c71c0..69c1506b9b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -9,7 +9,6 @@ import androidx.annotation.Nullable; import net.osmand.Collator; import net.osmand.CollatorStringMatcher.StringMatcherMode; -import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.OsmAndCollator; @@ -49,6 +48,8 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import static net.osmand.GPXUtilities.Track; +import static net.osmand.GPXUtilities.TrkSegment; import static net.osmand.GPXUtilities.WptPt; import static net.osmand.GPXUtilities.writeGpxFile; import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle; @@ -69,6 +70,8 @@ public class TravelObfHelper implements TravelHelper { 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 int REF_KEY = 2; + public static final int NAME_KEY = 1; private final OsmandApplication app; private final Collator collator; @@ -178,7 +181,7 @@ public class TravelObfHelper implements TravelHelper { TravelGpx res = new TravelGpx(); res.file = file; String title = amenity.getName("en"); - res.title = capitalizeFirstLetter(getGpxTitle(Algorithms.isEmpty(title) ? amenity.getName() : title)); + res.title = createTitle(Algorithms.isEmpty(title) ? amenity.getName() : title); res.lat = amenity.getLocation().getLatitude(); res.lon = amenity.getLocation().getLongitude(); res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)); @@ -265,8 +268,8 @@ public class TravelObfHelper implements TravelHelper { @Override public boolean publish(BinaryMapDataObject object) { if (object.getPointsLength() > 1) { - if (object.getObjectNames().get(2).equals(ref) - && capitalizeFirstLetter(getGpxTitle(object.getObjectNames().get(1))).equals(article.title)) { + if (object.getObjectNames().get(REF_KEY).equals(ref) + && createTitle(object.getObjectNames().get(NAME_KEY)).equals(article.title)) { segmentList.add(object); } } @@ -288,17 +291,15 @@ public class TravelObfHelper implements TravelHelper { } GPXFile gpxFile = null; if (!segmentList.isEmpty()) { - GPXUtilities.Track track = new GPXUtilities.Track(); + Track track = new Track(); for (BinaryMapDataObject segment : segmentList) { - List pointList = new ArrayList<>(); - GPXUtilities.TrkSegment trkSegment = new GPXUtilities.TrkSegment(); + TrkSegment trkSegment = new TrkSegment(); for (int i = 0; i < segment.getPointsLength(); i++) { WptPt point = new WptPt(); point.lat = MapUtils.get31LatitudeY(segment.getPoint31YTile(i)); point.lon = MapUtils.get31LongitudeX(segment.getPoint31XTile(i)); - pointList.add(point); + trkSegment.points.add(point); } - trkSegment.points = pointList; track.segments.add(trkSegment); } gpxFile = new GPXFile(article.getTitle(), article.getLang(), ""); @@ -309,6 +310,10 @@ public class TravelObfHelper implements TravelHelper { return gpxFile; } + private String createTitle(String name) { + return capitalizeFirstLetter(getGpxTitle(name)); + } + @NonNull private synchronized List getPointList(@NonNull final TravelArticle article) { final List pointList = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index bbc0cb6da7..a01de6e6cb 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -11,7 +11,6 @@ import androidx.annotation.DrawableRes; import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.snackbar.Snackbar; @@ -26,7 +25,6 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.track.TrackMenuFragment; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.WikivoyageUtils; @@ -35,7 +33,6 @@ import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; -import java.io.File; import java.util.ArrayList; import java.util.List; @@ -61,7 +58,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter Date: Wed, 27 Jan 2021 19:27:00 +0200 Subject: [PATCH 07/53] Add default height states for gpx menu tabs --- .../osmand/plus/base/ContextMenuFragment.java | 8 +++++ .../osmand/plus/track/TrackMenuFragment.java | 31 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java index 4cc90afd96..4b625e9515 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java @@ -946,6 +946,11 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment @TargetApi(Build.VERSION_CODES.JELLY_BEAN) protected void runLayoutListener() { + runLayoutListener(null); + } + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + protected void runLayoutListener(final Runnable runnable) { if (view != null) { ViewTreeObserver vto = view.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @@ -974,6 +979,9 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment int menuState = getCurrentMenuState(); listener.onContextMenuStateChanged(ContextMenuFragment.this, menuState, menuState); } + if (runnable != null) { + runnable.run(); + } } } }); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index a551ba2330..6c9857e11e 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -270,7 +270,18 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card setupToolbar(); updateHeader(); setupButtons(view); - runLayoutListener(); + runLayoutListener(new Runnable() { + @Override + public void run() { + if (menuType == TrackMenuType.OPTIONS) { + openMenuFullScreen(); + } else if (menuType == TrackMenuType.OVERVIEW) { + openMenuHeaderOnly(); + } else { + openMenuHalfScreen(); + } + } + }); } return view; } @@ -837,6 +848,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card menuType = type; setupCards(); updateHeader(); + updateMenuState(); break; } } @@ -845,6 +857,23 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card }); } + + private void updateMenuState() { + runLayoutListener(new Runnable() { + + @Override + public void run() { + if (menuType == TrackMenuType.OPTIONS) { + openMenuFullScreen(); + } else if (menuType == TrackMenuType.OVERVIEW) { + openMenuHeaderOnly(); + } else { + openMenuHalfScreen(); + } + } + }); + } + @Override public void updateContent() { if (segmentsCard != null) { From 0bc61f85c1d3d387df504e62fdb0f5f1c4f6341d Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 28 Jan 2021 01:48:44 +0200 Subject: [PATCH 08/53] fix saving correct icon and background type of waypoints after saving current recording track --- .../plus/activities/SavingTrackHelper.java | 137 ++++++++++-------- 1 file changed, 75 insertions(+), 62 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index ff7039702e..b06d3bb1a5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -38,10 +38,10 @@ import java.util.Locale; import java.util.Map; public class SavingTrackHelper extends SQLiteOpenHelper { - + public final static String DATABASE_NAME = "tracks"; //$NON-NLS-1$ - public final static int DATABASE_VERSION = 6; - + public final static int DATABASE_VERSION = 7; + public final static String TRACK_NAME = "track"; //$NON-NLS-1$ public final static String TRACK_COL_DATE = "date"; //$NON-NLS-1$ public final static String TRACK_COL_LAT = "lat"; //$NON-NLS-1$ @@ -50,7 +50,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { public final static String TRACK_COL_SPEED = "speed"; //$NON-NLS-1$ public final static String TRACK_COL_HDOP = "hdop"; //$NON-NLS-1$ public final static String TRACK_COL_HEADING = "heading"; //$NON-NLS-1$ - + public final static String POINT_NAME = "point"; //$NON-NLS-1$ public final static String POINT_COL_DATE = "date"; //$NON-NLS-1$ public final static String POINT_COL_LAT = "lat"; //$NON-NLS-1$ @@ -59,7 +59,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper { public final static String POINT_COL_CATEGORY = "category"; //$NON-NLS-1$ public final static String POINT_COL_DESCRIPTION = "description"; //$NON-NLS-1$ public final static String POINT_COL_COLOR = "color"; //$NON-NLS-1$ - + public final static String POINT_COL_ICON = "icon"; //$NON-NLS-1$ + public final static String POINT_COL_BACKGROUND = "background"; //$NON-NLS-1$ + public final static float NO_HEADING = -1.0f; public final static Log log = PlatformUtil.getLog(SavingTrackHelper.class); @@ -76,8 +78,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper { private SelectedGpxFile currentTrack; private int points; private int trkPoints = 0; - - public SavingTrackHelper(OsmandApplication ctx){ + + public SavingTrackHelper(OsmandApplication ctx) { super(ctx, DATABASE_NAME, null, DATABASE_VERSION); this.ctx = ctx; this.currentTrack = new SelectedGpxFile(); @@ -88,11 +90,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper { prepareCurrentTrackForRecording(); updateScript = "INSERT INTO " + TRACK_NAME + " (" + TRACK_COL_LAT + ", " + TRACK_COL_LON + ", " - + TRACK_COL_ALTITUDE + ", " + TRACK_COL_SPEED + ", " + TRACK_COL_HDOP + ", " - + TRACK_COL_DATE + ", " + TRACK_COL_HEADING + ")" + + TRACK_COL_ALTITUDE + ", " + TRACK_COL_SPEED + ", " + TRACK_COL_HDOP + ", " + + TRACK_COL_DATE + ", " + TRACK_COL_HEADING + ")" + " VALUES (?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$ - insertPointsScript = "INSERT INTO " + POINT_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$ + insertPointsScript = "INSERT INTO " + POINT_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$ } @Override @@ -100,19 +102,19 @@ public class SavingTrackHelper extends SQLiteOpenHelper { createTableForTrack(db); createTableForPoints(db); } - - private void createTableForTrack(SQLiteDatabase db){ + + private void createTableForTrack(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TRACK_NAME + " (" + TRACK_COL_LAT + " double, " + TRACK_COL_LON + " double, " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + TRACK_COL_ALTITUDE + " double, " + TRACK_COL_SPEED + " double, " //$NON-NLS-1$ //$NON-NLS-2$ + TRACK_COL_HDOP + " double, " + TRACK_COL_DATE + " long, " + TRACK_COL_HEADING + " float )"); //$NON-NLS-1$ //$NON-NLS-2$ } - - private void createTableForPoints(SQLiteDatabase db){ + + private void createTableForPoints(SQLiteDatabase db) { try { db.execSQL("CREATE TABLE " + POINT_NAME + " (" + POINT_COL_LAT + " double, " + POINT_COL_LON + " double, " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + POINT_COL_DATE + " long, " + POINT_COL_DESCRIPTION + " text, " + POINT_COL_NAME + " text, " - + POINT_COL_CATEGORY + " text, " + POINT_COL_COLOR + " long" + ")"); //$NON-NLS-1$ //$NON-NLS-2$ + + POINT_COL_CATEGORY + " text, " + POINT_COL_COLOR + " long, " + POINT_COL_ICON + " text, " + POINT_COL_BACKGROUND + " text )"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (RuntimeException e) { // ignore if already exists } @@ -120,25 +122,29 @@ public class SavingTrackHelper extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - if(oldVersion < 2){ + if (oldVersion < 2) { createTableForPoints(db); } - if(oldVersion < 3){ + if (oldVersion < 3) { db.execSQL("ALTER TABLE " + TRACK_NAME + " ADD " + TRACK_COL_HDOP + " double"); } - if(oldVersion < 4){ - db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_NAME + " text"); - db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_CATEGORY + " text"); + if (oldVersion < 4) { + db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_NAME + " text"); + db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_CATEGORY + " text"); } - if(oldVersion < 5){ - db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_COLOR + " long"); + if (oldVersion < 5) { + db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_COLOR + " long"); } - if(oldVersion < 6){ - db.execSQL("ALTER TABLE " + TRACK_NAME + " ADD " + TRACK_COL_HEADING + " float"); + if (oldVersion < 6) { + db.execSQL("ALTER TABLE " + TRACK_NAME + " ADD " + TRACK_COL_HEADING + " float"); + } + if (oldVersion < 7) { + db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_ICON + " text"); + db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_BACKGROUND + " text"); } } - - + + public long getLastTrackPointTime() { long res = 0; try { @@ -146,7 +152,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { if (db != null) { try { Cursor query = db.rawQuery("SELECT " + TRACK_COL_DATE + " FROM " + TRACK_NAME + " ORDER BY " + TRACK_COL_DATE + " DESC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if(query.moveToFirst()) { + if (query.moveToFirst()) { res = query.getLong(0); } query.close(); @@ -154,11 +160,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper { db.close(); } } - } catch(RuntimeException e) { + } catch (RuntimeException e) { } return res; } - + public synchronized boolean hasDataToSave() { try { SQLiteDatabase db = getWritableDatabase(); @@ -172,11 +178,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } q = db.query(false, POINT_NAME, new String[]{POINT_COL_LAT, POINT_COL_LON}, null, null, null, null, null, null); has = q.moveToFirst(); - while(has) { - if(q.getDouble(0) != 0 || q.getDouble(1) != 0) { + while (has) { + if (q.getDouble(0) != 0 || q.getDouble(1) != 0) { break; } - if(!q.moveToNext()) { + if (!q.moveToNext()) { has = false; break; } @@ -189,7 +195,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { db.close(); } } - } catch(RuntimeException e) { + } catch (RuntimeException e) { return false; } @@ -294,7 +300,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper { private void collectDBPoints(SQLiteDatabase db, Map dataTracks) { Cursor query = db.rawQuery("SELECT " + POINT_COL_LAT + "," + POINT_COL_LON + "," + POINT_COL_DATE + "," //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - + POINT_COL_DESCRIPTION + "," + POINT_COL_NAME + "," + POINT_COL_CATEGORY + "," + POINT_COL_COLOR + " FROM " + POINT_NAME+" ORDER BY " + POINT_COL_DATE +" ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + POINT_COL_DESCRIPTION + "," + POINT_COL_NAME + "," + POINT_COL_CATEGORY + "," + POINT_COL_COLOR + "," + + POINT_COL_ICON + "," + POINT_COL_BACKGROUND + " FROM " + POINT_NAME + " ORDER BY " + POINT_COL_DATE + " ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (query.moveToFirst()) { do { WptPt pt = new WptPt(); @@ -309,18 +316,20 @@ public class SavingTrackHelper extends SQLiteOpenHelper { if (color != 0) { pt.setColor(color); } + pt.setIconName(query.getString(7)); + pt.setBackgroundType(query.getString(8)); // check if name is extension (needed for audio/video plugin & josm integration) - if(pt.name != null && pt.name.length() > 4 && pt.name.charAt(pt.name.length() - 4) == '.') { + if (pt.name != null && pt.name.length() > 4 && pt.name.charAt(pt.name.length() - 4) == '.') { pt.link = pt.name; } - + String date = DateFormat.format("yyyy-MM-dd", time).toString(); //$NON-NLS-1$ GPXFile gpx; if (dataTracks.containsKey(date)) { gpx = dataTracks.get(date); } else { - gpx = new GPXFile(Version.getFullVersion(ctx)); + gpx = new GPXFile(Version.getFullVersion(ctx)); dataTracks.put(date, gpx); } ctx.getSelectedGpxHelper().addPoint(pt, gpx); @@ -329,10 +338,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } query.close(); } - + private void collectDBTracks(SQLiteDatabase db, Map dataTracks) { Cursor query = db.rawQuery("SELECT " + TRACK_COL_LAT + "," + TRACK_COL_LON + "," + TRACK_COL_ALTITUDE + "," //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - + TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + "," + TRACK_COL_HEADING + " FROM " + TRACK_NAME +" ORDER BY " + TRACK_COL_DATE +" ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + + TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + "," + TRACK_COL_HEADING + " FROM " + TRACK_NAME + " ORDER BY " + TRACK_COL_DATE + " ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ long previousTime = 0; long previousInterval = 0; TrkSegment segment = null; @@ -351,14 +360,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper { pt.heading = heading == NO_HEADING ? Float.NaN : heading; long currentInterval = Math.abs(time - previousTime); boolean newInterval = pt.lat == 0 && pt.lon == 0; - + if (track != null && !newInterval && (!ctx.getSettings().AUTO_SPLIT_RECORDING.get() || currentInterval < 6 * 60 * 1000 || currentInterval < 10 * previousInterval)) { // 6 minute - same segment segment.points.add(pt); } else if (track != null && (ctx.getSettings().AUTO_SPLIT_RECORDING.get() && currentInterval < 2 * 60 * 60 * 1000)) { // 2 hour - same track segment = new TrkSegment(); - if(!newInterval) { + if (!newInterval) { segment.points.add(pt); } track.segments.add(segment); @@ -367,10 +376,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper { track = new Track(); segment = new TrkSegment(); track.segments.add(segment); - if(!newInterval) { + if (!newInterval) { segment.points.add(pt); } - String date = new SimpleDateFormat("yyyy-MM-dd", Locale.US).format(new Date(time));; //$NON-NLS-1$ + String date = new SimpleDateFormat("yyyy-MM-dd", Locale.US).format(new Date(time)); //$NON-NLS-1$ if (dataTracks.containsKey(date)) { GPXFile gpx = dataTracks.get(date); gpx.tracks.add(track); @@ -411,14 +420,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper { dataTracks.remove(date); } } - + public void startNewSegment() { lastTimeUpdated = 0; lastPoint = null; - execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis(), NO_HEADING}); + execWithClose(updateScript, new Object[]{0, 0, 0, 0, 0, System.currentTimeMillis(), NO_HEADING}); addTrackPoint(null, true, System.currentTimeMillis()); } - + public void updateLocation(net.osmand.Location location, Float heading) { // use because there is a bug on some devices with location.getTime() long locationTime = System.currentTimeMillis(); @@ -459,12 +468,12 @@ public class SavingTrackHelper extends SQLiteOpenHelper { ctx.getNotificationHelper().refreshNotification(NotificationType.GPX); } } - + public void insertData(double lat, double lon, double alt, double speed, double hdop, long time, float heading, - OsmandSettings settings) { + OsmandSettings settings) { // * 1000 in next line seems to be wrong with new IntervalChooseDialog // if (time - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get() * 1000) { - execWithClose(updateScript, new Object[] { lat, lon, alt, speed, hdop, time, heading }); + execWithClose(updateScript, new Object[]{lat, lon, alt, speed, hdop, time, heading}); boolean newSegment = false; if (lastPoint == null || (time - lastTimeUpdated) > 180 * 1000) { lastPoint = new LatLon(lat, lon); @@ -485,7 +494,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { addTrackPoint(pt, newSegment, time); trkPoints++; } - + private void addTrackPoint(WptPt pt, boolean newSegment, long time) { List points = currentTrack.getModifiablePointsToDisplay(); Track track = currentTrack.getModifiableGpxFile().tracks.get(0); @@ -511,12 +520,12 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } public WptPt insertPointData(double lat, double lon, long time, String description, String name, String category, - int color) { + int color) { return insertPointData(lat, lon, time, description, name, category, color, null, null); } public WptPt insertPointData(double lat, double lon, long time, String description, String name, String category, - int color, String iconName, String backgroundName) { + int color, String iconName, String backgroundName) { final WptPt pt = new WptPt(lat, lon, time, Double.NaN, 0, Double.NaN); pt.name = name; pt.category = category; @@ -529,7 +538,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { ctx.getSelectedGpxHelper().addPoint(pt, currentTrack.getModifiableGpxFile()); currentTrack.getModifiableGpxFile().modifiedTime = time; points++; - execWithClose(insertPointsScript, new Object[] { lat, lon, time, description, name, category, color }); + execWithClose(insertPointsScript, new Object[]{lat, lon, time, description, name, category, color, iconName, backgroundName}); return pt; } @@ -538,7 +547,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } public void updatePointData(WptPt pt, double lat, double lon, long time, String description, String name, - String category, int color, String iconName, String iconBackground) { + String category, int color, String iconName, String iconBackground) { currentTrack.getModifiableGpxFile().modifiedTime = time; List params = new ArrayList<>(); @@ -549,6 +558,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper { params.add(name); params.add(category); params.add(color); + params.add(iconName); + params.add(iconBackground); params.add(pt.getLatitude()); params.add(pt.getLongitude()); @@ -563,7 +574,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper { + POINT_COL_DESCRIPTION + "=?, " + POINT_COL_NAME + "=?, " + POINT_COL_CATEGORY + "=?, " - + POINT_COL_COLOR + "=? " + + POINT_COL_COLOR + "=?, " + + POINT_COL_ICON + "=?, " + + POINT_COL_BACKGROUND + "=? " + "WHERE " + POINT_COL_LAT + "=? AND " + POINT_COL_LON + "=? AND " @@ -662,10 +675,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } } - public void loadGpxFromDatabase(){ + public void loadGpxFromDatabase() { Map files = collectRecordedData(); currentTrack.getModifiableGpxFile().tracks.clear(); - for (Map.Entry entry : files.entrySet()){ + for (Map.Entry entry : files.entrySet()) { ctx.getSelectedGpxHelper().addPoints(entry.getValue().getPoints(), currentTrack.getModifiableGpxFile()); currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks); } @@ -679,10 +692,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } private void prepareCurrentTrackForRecording() { - if(currentTrack.getModifiableGpxFile().tracks.size() == 0) { + if (currentTrack.getModifiableGpxFile().tracks.size() == 0) { currentTrack.getModifiableGpxFile().tracks.add(new Track()); } - while(currentTrack.getPointsToDisplay().size() < currentTrack.getModifiableGpxFile().tracks.size()) { + while (currentTrack.getPointsToDisplay().size() < currentTrack.getModifiableGpxFile().tracks.size()) { TrkSegment trkSegment = new TrkSegment(); currentTrack.getModifiablePointsToDisplay().add(trkSegment); } @@ -705,7 +718,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { public int getPoints() { return points; } - + public int getTrkPoints() { return trkPoints; } @@ -717,11 +730,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper { public GPXFile getCurrentGpx() { return currentTrack.getGpxFile(); } - + public SelectedGpxFile getCurrentTrack() { return currentTrack; } - + public class SaveGpxResult { public SaveGpxResult(List warnings, List filenames) { From 7508dea7cab8c93c53c74cf3aa1ec5f092926158 Mon Sep 17 00:00:00 2001 From: Hardy Date: Thu, 28 Jan 2021 08:18:59 +0100 Subject: [PATCH 09/53] string improvement --- OsmAnd/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7cd16f7f7e..2c3358dda4 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2444,7 +2444,7 @@ Average %1$d of %2$d Ascent/Descent - Moving time + Time in motion Max/Min Min/Max Tours From cc7ec8e0d9fc52ecd588ee0ba37ab116a390dd25 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 09:38:00 +0200 Subject: [PATCH 10/53] Add group to markers in gpx menu --- .../EditTrackGroupDialogFragment.java | 68 +++++++++++++++---- .../osmand/plus/track/TrackMenuFragment.java | 30 ++++---- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java index 19c398685c..fa7bff99ed 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java @@ -30,6 +30,7 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.FavouritePoint; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; @@ -70,19 +71,32 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment public static final String TAG = EditTrackGroupDialogFragment.class.getSimpleName(); private OsmandApplication app; + private GpxSelectionHelper selectedGpxHelper; + private MapMarkersHelper mapMarkersHelper; private GpxDisplayGroup group; @Override public void createMenuItems(Bundle savedInstanceState) { - app = requiredMyApplication(); if (group == null) { return; } + app = requiredMyApplication(); + selectedGpxHelper = app.getSelectedGpxHelper(); + mapMarkersHelper = app.getMapMarkersHelper(); items.add(new TitleItem(getCategoryName(app, group.getName()))); + GPXFile gpxFile = group.getGpx(); + + boolean currentTrack = group.getGpx().showCurrentTrack; + + SelectedGpxFile selectedGpxFile; + if (currentTrack) { + selectedGpxFile = selectedGpxHelper.getSelectedCurrentRecordingTrack(); + } else { + selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxFile.path); + } boolean trackPoints = group.getType() == GpxDisplayItemType.TRACK_POINTS; - SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getGpx().path); if (trackPoints && selectedGpxFile != null) { items.add(createShowOnMapItem(selectedGpxFile)); } @@ -92,7 +106,9 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment } items.add(new OptionsDividerItem(app)); -// items.add(createCopyToMarkersItem()); + if (!currentTrack) { + items.add(createCopyToMarkersItem(gpxFile)); + } items.add(createCopyToFavoritesItem()); items.add(new OptionsDividerItem(app)); @@ -175,27 +191,51 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment .create(); } - private BaseBottomSheetItem createCopyToMarkersItem() { + private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) { + final MapMarkersGroup markersGroup = getOrCreateMarkersGroup(gpxFile); + final Set categories = markersGroup.getWptCategories(); + final boolean synced = categories != null && categories.contains(group.getName()); + return new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_copy)) - .setTitle(getString(R.string.copy_to_map_markers)) - .setLayoutId(R.layout.bottom_sheet_item_simple) + .setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_copy)) + .setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.copy_to_map_markers)) .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { -// MapMarkersHelper markersHelper = app.getMapMarkersHelper(); -// MapMarkersGroup markersGroup = markersHelper.getMarkersGroup(group); -// if (markersGroup != null) { -// markersHelper.removeMarkersGroup(markersGroup); -// } else { -// markersHelper.addOrEnableGroup(group); -// } + updateGroupWptCategory(gpxFile, markersGroup, categories, synced); + dismiss(); } }) .create(); } + private void updateGroupWptCategory(GPXFile gpxFile, MapMarkersGroup markersGroup, Set categories, boolean synced) { + SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxFile.path); + if (selectedGpxFile == null) { + selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false); + } + Set selectedCategories = new HashSet<>(); + if (categories != null) { + selectedCategories.addAll(categories); + } + if (synced) { + selectedCategories.remove(group.getName()); + } else { + selectedCategories.add(group.getName()); + } + mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories); + mapMarkersHelper.runSynchronization(markersGroup); + } + + private MapMarkersGroup getOrCreateMarkersGroup(GPXFile gpxFile) { + MapMarkersGroup markersGroup = mapMarkersHelper.getMarkersGroup(gpxFile); + if (markersGroup == null) { + markersGroup = mapMarkersHelper.addOrEnableGroup(gpxFile); + } + return markersGroup; + } + private BaseBottomSheetItem createCopyToFavoritesItem() { return new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_copy)) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 6c9857e11e..dd2ca7f465 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -808,7 +808,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override protected void onHeaderClick() { - adjustMapPosition(getViewY()); + updateMenuState(); } private void adjustMapPosition(int y) { @@ -848,7 +848,12 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card menuType = type; setupCards(); updateHeader(); - updateMenuState(); + runLayoutListener(new Runnable() { + @Override + public void run() { + updateMenuState(); + } + }); break; } } @@ -857,21 +862,14 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card }); } - private void updateMenuState() { - runLayoutListener(new Runnable() { - - @Override - public void run() { - if (menuType == TrackMenuType.OPTIONS) { - openMenuFullScreen(); - } else if (menuType == TrackMenuType.OVERVIEW) { - openMenuHeaderOnly(); - } else { - openMenuHalfScreen(); - } - } - }); + if (menuType == TrackMenuType.OPTIONS) { + openMenuFullScreen(); + } else if (menuType == TrackMenuType.OVERVIEW) { + openMenuHeaderOnly(); + } else { + openMenuHalfScreen(); + } } @Override From e28246975000dbeb230209653e6a0e2282182ec9 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 10:49:44 +0200 Subject: [PATCH 11/53] Remove unnecessary code --- OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index dd2ca7f465..cfc6610b5b 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -273,13 +273,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card runLayoutListener(new Runnable() { @Override public void run() { - if (menuType == TrackMenuType.OPTIONS) { - openMenuFullScreen(); - } else if (menuType == TrackMenuType.OVERVIEW) { - openMenuHeaderOnly(); - } else { - openMenuHalfScreen(); - } + updateMenuState(); } }); } From 08621d17fdadcc19ce80aba303b637f66c5b6f53 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 11:35:23 +0200 Subject: [PATCH 12/53] Add new method for updating menu state after layout calculation --- .../osmand/plus/track/TrackMenuFragment.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index cfc6610b5b..7f3fef69ed 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -270,12 +270,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card setupToolbar(); updateHeader(); setupButtons(view); - runLayoutListener(new Runnable() { - @Override - public void run() { - updateMenuState(); - } - }); + calculateLayoutAndUpdateMenuState(); } return view; } @@ -842,12 +837,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card menuType = type; setupCards(); updateHeader(); - runLayoutListener(new Runnable() { - @Override - public void run() { - updateMenuState(); - } - }); + calculateLayoutAndUpdateMenuState(); break; } } @@ -856,6 +846,15 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card }); } + private void calculateLayoutAndUpdateMenuState() { + runLayoutListener(new Runnable() { + @Override + public void run() { + updateMenuState(); + } + }); + } + private void updateMenuState() { if (menuType == TrackMenuType.OPTIONS) { openMenuFullScreen(); From 1b1ed6e02f69a9b8d671ee46fa0f4257af4602a0 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 13:00:51 +0200 Subject: [PATCH 13/53] Show my location button and change header height for overview tab --- OsmAnd/res/layout/track_menu.xml | 7 +++++++ OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/track_menu.xml b/OsmAnd/res/layout/track_menu.xml index 671a9332f1..db0f8a47f9 100644 --- a/OsmAnd/res/layout/track_menu.xml +++ b/OsmAnd/res/layout/track_menu.xml @@ -91,6 +91,13 @@ + + Date: Thu, 28 Jan 2021 17:18:18 +0500 Subject: [PATCH 14/53] Test solution --- .../osmand/plus/activities/MapActivity.java | 4 +- .../plus/importfiles/SettingsImportTask.java | 2 +- .../backend/backup/SettingsHelper.java | 123 ++++++++++++++---- .../fragments/ExportSettingsFragment.java | 2 +- 4 files changed, 103 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index eb6dcbfbb7..7b81a13e0a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -652,7 +652,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven protected void onNewIntent(final Intent intent) { super.onNewIntent(intent); setIntent(intent); - intentHelper.parseLaunchIntents(); + if (!intentHelper.parseLaunchIntents()) { + intentHelper.parseContentIntent(); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java index 0a5e0370af..1f886a23bb 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java @@ -102,7 +102,7 @@ class SettingsImportTask extends BaseLoadAsyncTask { } } else { Map> allSettingsMap = getSettingsToOperate(pluginIndependentItems, false); - List settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes, false); + List settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes, pluginIndependentItems, false); settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace)); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 7008425f14..1fdfef081b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -480,19 +480,21 @@ public class SettingsHelper { typesMap.putAll(getMyPlacesItems()); typesMap.putAll(getResourcesItems()); - return getFilteredSettingsItems(typesMap, settingsTypes, export); + return getFilteredSettingsItems(typesMap, settingsTypes, null, export); } - public List getFilteredSettingsItems(Map> allSettingsMap, - List settingsTypes, boolean export) { - List settingsItems = new ArrayList<>(); + public List getFilteredSettingsItems( + Map> allSettingsMap, List settingsTypes, + List settingsItems, boolean export + ) { + List filteredSettingsItems = new ArrayList<>(); for (ExportSettingsType settingsType : settingsTypes) { List settingsDataObjects = allSettingsMap.get(settingsType); if (settingsDataObjects != null) { - settingsItems.addAll(prepareSettingsItems(settingsDataObjects, export)); + filteredSettingsItems.addAll(prepareSettingsItems(settingsDataObjects, settingsItems, export)); } } - return settingsItems; + return filteredSettingsItems; } public Map getSettingsByCategory(boolean addProfiles) { @@ -693,8 +695,8 @@ public class SettingsHelper { return files; } - public List prepareSettingsItems(List data, boolean export) { - List settingsItems = new ArrayList<>(); + public List prepareSettingsItems(List data, List settingsItems, boolean export) { + List result = new ArrayList<>(); List quickActions = new ArrayList<>(); List poiUIFilters = new ArrayList<>(); List tileSourceTemplates = new ArrayList<>(); @@ -719,9 +721,9 @@ public class SettingsHelper { try { File file = (File) object; if (file.getName().endsWith(IndexConstants.GPX_FILE_EXT)) { - settingsItems.add(new GpxSettingsItem(app, file)); + result.add(new GpxSettingsItem(app, file)); } else { - settingsItems.add(new FileSettingsItem(app, file)); + result.add(new FileSettingsItem(app, file)); } } catch (IllegalArgumentException e) { LOG.warn("Trying to export unsuported file type", e); @@ -746,65 +748,136 @@ public class SettingsHelper { } else if (object instanceof HistoryEntry) { historyEntries.add((HistoryEntry) object); } else if (object instanceof GlobalSettingsItem) { - settingsItems.add((GlobalSettingsItem) object); + result.add((GlobalSettingsItem) object); } else if (object instanceof OnlineRoutingEngine) { onlineRoutingEngines.add((OnlineRoutingEngine) object); } } if (!quickActions.isEmpty()) { - settingsItems.add(new QuickActionsSettingsItem(app, quickActions)); + result.add(new QuickActionsSettingsItem(app, getBaseQuickActionsSettingsItem(settingsItems), quickActions)); } if (!poiUIFilters.isEmpty()) { - settingsItems.add(new PoiUiFiltersSettingsItem(app, poiUIFilters)); + result.add(new PoiUiFiltersSettingsItem(app, getBasePoiUiFiltersSettingsItem(settingsItems), poiUIFilters)); } if (!tileSourceTemplates.isEmpty()) { - settingsItems.add(new MapSourcesSettingsItem(app, tileSourceTemplates)); + result.add(new MapSourcesSettingsItem(app, getBaseMapSourcesSettingsItem(settingsItems), tileSourceTemplates)); } if (!avoidRoads.isEmpty()) { - settingsItems.add(new AvoidRoadsSettingsItem(app, avoidRoads)); + result.add(new AvoidRoadsSettingsItem(app, getBaseAvoidRoadsSettingsItem(settingsItems), avoidRoads)); } if (!appModeBeans.isEmpty()) { for (ApplicationModeBean modeBean : appModeBeans) { if (export) { ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); if (mode != null) { - settingsItems.add(new ProfileSettingsItem(app, mode)); + result.add(new ProfileSettingsItem(app, mode)); } } else { - settingsItems.add(new ProfileSettingsItem(app, null, modeBean)); + result.add(new ProfileSettingsItem(app, getBaseProfileSettingsItem(modeBean, settingsItems), modeBean)); } } } if (!osmNotesPointList.isEmpty()) { - settingsItems.add(new OsmNotesSettingsItem(app, osmNotesPointList)); + OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class, settingsItems); + result.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList)); } if (!osmEditsPointList.isEmpty()) { - settingsItems.add(new OsmEditsSettingsItem(app, osmEditsPointList)); + OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class, settingsItems); + result.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList)); } if (!favoriteGroups.isEmpty()) { - settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups)); + FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class, settingsItems); + result.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups)); } if (!markersGroups.isEmpty()) { List mapMarkers = new ArrayList<>(); for (MapMarkersGroup group : markersGroups) { mapMarkers.addAll(group.getMarkers()); } - settingsItems.add(new MarkersSettingsItem(app, mapMarkers)); + MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems); + result.add(new MarkersSettingsItem(app, baseItem, mapMarkers)); } if (!markersHistoryGroups.isEmpty()) { List mapMarkers = new ArrayList<>(); for (MapMarkersGroup group : markersHistoryGroups) { mapMarkers.addAll(group.getMarkers()); } - settingsItems.add(new HistoryMarkersSettingsItem(app, mapMarkers)); + HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems); + result.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers)); } if (!historyEntries.isEmpty()) { - settingsItems.add(new SearchHistorySettingsItem(app, historyEntries)); + SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class, settingsItems); + result.add(new SearchHistorySettingsItem(app, baseItem, historyEntries)); } if (!onlineRoutingEngines.isEmpty()) { - settingsItems.add(new OnlineRoutingSettingsItem(app, onlineRoutingEngines)); + OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class, settingsItems); + result.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines)); } - return settingsItems; + return result; + } + + @Nullable + private ProfileSettingsItem getBaseProfileSettingsItem(ApplicationModeBean modeBean, List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.PROFILE) { + ProfileSettingsItem profileItem = (ProfileSettingsItem) settingsItem; + ApplicationModeBean bean = profileItem.getModeBean(); + if (Algorithms.objectEquals(bean.stringKey, modeBean.stringKey) && Algorithms.objectEquals(bean.userProfileName, modeBean.userProfileName)) { + return profileItem; + } + } + } + return null; + } + + @Nullable + private QuickActionsSettingsItem getBaseQuickActionsSettingsItem(List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.QUICK_ACTIONS) { + return (QuickActionsSettingsItem) settingsItem; + } + } + return null; + } + + @Nullable + private PoiUiFiltersSettingsItem getBasePoiUiFiltersSettingsItem(List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.POI_UI_FILTERS) { + return (PoiUiFiltersSettingsItem) settingsItem; + } + } + return null; + } + + @Nullable + private MapSourcesSettingsItem getBaseMapSourcesSettingsItem(List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.MAP_SOURCES) { + return (MapSourcesSettingsItem) settingsItem; + } + } + return null; + } + + @Nullable + private AvoidRoadsSettingsItem getBaseAvoidRoadsSettingsItem(List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.AVOID_ROADS) { + return (AvoidRoadsSettingsItem) settingsItem; + } + } + return null; + } + + @Nullable + private T getBaseItem(SettingsItemType settingsItemType, Class clazz, List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == settingsItemType && clazz.isInstance(settingsItem)) { + return clazz.cast(settingsItem); + } + } + return null; } public static Map getSettingsToOperateByCategory(List items, boolean importComplete) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java index 586b6f0db3..f38a0ba77a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java @@ -150,7 +150,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment { showExportProgressDialog(); File tempDir = FileUtils.getTempDir(app); String fileName = getFileName(); - List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), true); + List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), null, true); progress.setMax(getMaxProgress(items)); app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true); } From d2aa6c331e786519f093d56111991160840cac9c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 14:33:31 +0200 Subject: [PATCH 15/53] Fix back to context menu from gpx menu --- .../controllers/SelectedGpxMenuController.java | 4 +--- .../src/net/osmand/plus/track/TrackMenuFragment.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java index 427e0cce35..acdce38b90 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java @@ -42,9 +42,7 @@ public class SelectedGpxMenuController extends MenuController { leftTitleButtonController = new TitleButtonController() { @Override public void buttonPressed() { - SelectedGpxFile selectedGpxFile = selectedGpxPoint.getSelectedGpxFile(); - mapActivity.getContextMenu().hide(false); - TrackMenuFragment.showInstance(mapActivity, selectedGpxFile.getGpxFile().path, selectedGpxFile.isShowCurrentTrack()); + TrackMenuFragment.showInstance(mapActivity, selectedGpxPoint.getSelectedGpxFile()); } }; leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_open_track); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 533268fd62..b145fc903d 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -227,11 +227,15 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card FragmentActivity activity = requireMyActivity(); activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { public void handleOnBackPressed() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.launchPrevActivityIntent(); + if (getCurrentMenuState() != MenuState.HEADER_ONLY && isPortrait()) { + openMenuHeaderOnly(); + } else { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null && mapActivity.getSupportFragmentManager().getBackStackEntryCount() == 1) { + mapActivity.launchPrevActivityIntent(); + } + dismiss(); } - dismiss(); } }); } From c0727f658fc2eeff3e5a37acded82e4bbc27cc7f Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 15:04:41 +0200 Subject: [PATCH 16/53] Fix back from track appearance screen to trip recording dialog --- .../osmand/plus/activities/MapActivity.java | 2 +- .../monitoring/TripRecordingBottomSheet.java | 2 +- .../plus/track/TrackAppearanceFragment.java | 26 ++++++++++--------- .../osmand/plus/track/TrackMenuFragment.java | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 0de562fa2b..12f66f8c49 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1200,7 +1200,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path); } - TrackAppearanceFragment.showInstance(this, selectedGpxFile); + TrackAppearanceFragment.showInstance(this, selectedGpxFile, null); } else if (toShow instanceof QuadRect) { QuadRect qr = (QuadRect) toShow; mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0); diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java index 789fc0aeb0..178e662176 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java @@ -90,7 +90,7 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment { if (mapActivity != null) { hide(); SelectedGpxFile selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack(); - TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile); + TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile, TripRecordingBottomSheet.this); } } }); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index ddc102adc9..522103ac02 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -19,6 +19,7 @@ import androidx.activity.OnBackPressedCallback; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -37,6 +38,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.base.ContextMenuScrollFragment; import net.osmand.plus.dialogs.GpxAppearanceAdapter; import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem; @@ -165,16 +167,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement } requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { public void handleOnBackPressed() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - TripRecordingBottomSheet fragment = mapActivity.getTripRecordingBottomSheet(); - if (fragment != null) { - fragment.show(); - } else { - mapActivity.launchPrevActivityIntent(); - } - dismissImmediate(); - } + dismiss(); } }); } @@ -385,6 +378,14 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement return y; } + @Override + public void onContextMenuDismiss(@NonNull ContextMenuFragment fragment) { + Fragment target = getTargetFragment(); + if (target instanceof TripRecordingBottomSheet) { + ((TripRecordingBottomSheet) target).show(); + } + } + private void updateAppearanceIcon() { Drawable icon = getTrackIcon(app, trackDrawInfo.getWidth(), trackDrawInfo.isShowArrows(), trackDrawInfo.getColor()); trackIcon.setImageDrawable(icon); @@ -725,11 +726,12 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement return totalScreenHeight - frameTotalHeight; } - public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull SelectedGpxFile selectedGpxFile) { + public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull SelectedGpxFile selectedGpxFile, Fragment target) { try { TrackAppearanceFragment fragment = new TrackAppearanceFragment(); - fragment.setSelectedGpxFile(selectedGpxFile); fragment.setRetainInstance(true); + fragment.setSelectedGpxFile(selectedGpxFile); + fragment.setTargetFragment(target, 0); mapActivity.getSupportFragmentManager() .beginTransaction() diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index b145fc903d..597dc4c485 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -663,7 +663,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card app.getSelectedGpxHelper().selectGpxFile(gpxFile, gpxFileSelected, false); mapActivity.refreshMap(); } else if (buttonIndex == APPEARANCE_BUTTON_INDEX) { - TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile); + TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile, this); } else if (buttonIndex == DIRECTIONS_BUTTON_INDEX) { MapActivityActions mapActions = mapActivity.getMapActions(); if (app.getRoutingHelper().isFollowingMode()) { From 65facb4af39b7e41a9e37ed720cc2896ed6e1878 Mon Sep 17 00:00:00 2001 From: cepprice Date: Thu, 28 Jan 2021 18:11:24 +0500 Subject: [PATCH 17/53] Add silent setting --- .../customization/ProfileSettingsParams.java | 13 +++++++++++-- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 4 ++-- OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java index 00c68851e7..afca79aa0e 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java @@ -15,16 +15,18 @@ public class ProfileSettingsParams extends AidlParams { public static final String VERSION_KEY = "version"; public static final String REPLACE_KEY = "replace"; + public static final String SILENT_IMPORT_KEY = "silent_import"; public static final String LATEST_CHANGES_KEY = "latestChanges"; public static final String PROFILE_SETTINGS_URI_KEY = "profileSettingsUri"; private Uri profileSettingsUri; private String latestChanges; private int version; private ArrayList settingsTypeKeyList = new ArrayList<>(); - boolean replace; + private boolean silent; + private boolean replace; public ProfileSettingsParams(Uri profileSettingsUri, ArrayList settingsTypeList, boolean replace, - String latestChanges, int version) { + boolean silent, String latestChanges, int version) { this.profileSettingsUri = profileSettingsUri; for (AExportSettingsType settingsType : settingsTypeList) { settingsTypeKeyList.add(settingsType.name()); @@ -32,6 +34,7 @@ public class ProfileSettingsParams extends AidlParams { this.replace = replace; this.latestChanges = latestChanges; this.version = version; + this.silent = silent; } public ProfileSettingsParams(Parcel in) { @@ -70,6 +73,10 @@ public class ProfileSettingsParams extends AidlParams { return replace; } + public boolean isSilent() { + return silent; + } + @Override public void writeToBundle(Bundle bundle) { bundle.putInt(VERSION_KEY, version); @@ -77,6 +84,7 @@ public class ProfileSettingsParams extends AidlParams { bundle.putParcelable(PROFILE_SETTINGS_URI_KEY, profileSettingsUri); bundle.putStringArrayList(SETTINGS_TYPE_KEY, settingsTypeKeyList); bundle.putBoolean(REPLACE_KEY, replace); + bundle.putBoolean(SILENT_IMPORT_KEY, silent); } @Override @@ -86,5 +94,6 @@ public class ProfileSettingsParams extends AidlParams { profileSettingsUri = bundle.getParcelable(PROFILE_SETTINGS_URI_KEY); settingsTypeKeyList = bundle.getStringArrayList(SETTINGS_TYPE_KEY); replace = bundle.getBoolean(REPLACE_KEY); + silent = bundle.getBoolean(SILENT_IMPORT_KEY); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 1dc3e00d98..033fceff1a 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -2297,12 +2297,12 @@ public class OsmandAidlApi { } public boolean importProfileV2(final Uri profileUri, ArrayList settingsTypeKeys, boolean replace, - String latestChanges, int version) { + boolean silent, String latestChanges, int version) { if (profileUri != null) { Bundle bundle = new Bundle(); bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, settingsTypeKeys); bundle.putBoolean(REPLACE_KEY, replace); - bundle.putBoolean(SILENT_IMPORT_KEY, true); + bundle.putBoolean(SILENT_IMPORT_KEY, silent); bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges); bundle.putInt(SettingsHelper.SETTINGS_VERSION_KEY, version); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index ed7ab614f3..fcd5d5159e 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -1270,7 +1270,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener try { OsmandAidlApi api = getApi("importProfile"); return api != null && api.importProfileV2(params.getProfileSettingsUri(), params.getSettingsTypeKeys(), - params.isReplace(), params.getLatestChanges(), params.getVersion()); + params.isReplace(), params.isSilent(), params.getLatestChanges(), params.getVersion()); } catch (Exception e) { handleException(e); return false; From 1f345d0dfd0a714b65fbaa8b9b53e833a3a33560 Mon Sep 17 00:00:00 2001 From: cepprice Date: Thu, 28 Jan 2021 18:19:30 +0500 Subject: [PATCH 18/53] Small edit --- .../osmand/plus/settings/backend/backup/SettingsHelper.java | 4 ++-- .../plus/settings/fragments/ExportSettingsFragment.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 1fdfef081b..9a50851a56 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -480,12 +480,12 @@ public class SettingsHelper { typesMap.putAll(getMyPlacesItems()); typesMap.putAll(getResourcesItems()); - return getFilteredSettingsItems(typesMap, settingsTypes, null, export); + return getFilteredSettingsItems(typesMap, settingsTypes, Collections.emptyList(), export); } public List getFilteredSettingsItems( Map> allSettingsMap, List settingsTypes, - List settingsItems, boolean export + @NonNull List settingsItems, boolean export ) { List filteredSettingsItems = new ArrayList<>(); for (ExportSettingsType settingsType : settingsTypes) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java index f38a0ba77a..6fef4d4e03 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java @@ -36,6 +36,7 @@ import org.apache.commons.logging.Log; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; @@ -150,7 +151,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment { showExportProgressDialog(); File tempDir = FileUtils.getTempDir(app); String fileName = getFileName(); - List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), null, true); + List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), Collections.emptyList(), true); progress.setMax(getMaxProgress(items)); app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true); } From 2bd2839f495cde38c94748553dad521a4e9c5d05 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 15:32:21 +0200 Subject: [PATCH 19/53] Fix context menu visibility --- .../controllers/SelectedGpxMenuController.java | 1 + .../net/osmand/plus/track/TrackMenuFragment.java | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java index acdce38b90..5ea0766469 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java @@ -42,6 +42,7 @@ public class SelectedGpxMenuController extends MenuController { leftTitleButtonController = new TitleButtonController() { @Override public void buttonPressed() { + mapContextMenu.hide(false); TrackMenuFragment.showInstance(mapActivity, selectedGpxPoint.getSelectedGpxFile()); } }; diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 597dc4c485..0c7c88b7a3 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -230,11 +230,18 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (getCurrentMenuState() != MenuState.HEADER_ONLY && isPortrait()) { openMenuHeaderOnly(); } else { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null && mapActivity.getSupportFragmentManager().getBackStackEntryCount() == 1) { - mapActivity.launchPrevActivityIntent(); - } dismiss(); + + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + MapContextMenu contextMenu = mapActivity.getContextMenu(); + if (contextMenu.isActive() && contextMenu.getPointDescription() != null + && contextMenu.getPointDescription().isGpxPoint()) { + contextMenu.show(); + } else { + mapActivity.launchPrevActivityIntent(); + } + } } } }); From 593657475a93ac040d97a6454edfebd8d2e240c1 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 16:06:10 +0200 Subject: [PATCH 20/53] Fix menu drag under toolbar --- OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 0c7c88b7a3..492ac2ff3d 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -193,6 +193,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card return 0.5f; } + public int getMinY() { + return getFullScreenTopPosY(); + } + @Override public int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; From a9761c1a39fa36b34b313e487aed7ed7aeaf9dca Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 16:30:29 +0200 Subject: [PATCH 21/53] UI improvements --- .../net/osmand/plus/track/TrackMenuFragment.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 492ac2ff3d..9147de6de9 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -186,7 +186,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override public int getToolbarHeight() { - return toolbarHeightPx; + return isPortrait() ? toolbarHeightPx : 0; } public float getMiddleStateKoef() { @@ -286,6 +286,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card setupToolbar(); updateHeader(); setupButtons(view); + updateCardsLayout(); calculateLayoutAndUpdateMenuState(); } return view; @@ -443,6 +444,17 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } + private void updateCardsLayout() { + FrameLayout bottomContainer = getBottomContainer(); + if (menuType == TrackMenuType.OPTIONS) { + AndroidUtils.setBackground(app, bottomContainer, isNightMode(), + R.color.list_background_color_light, R.color.list_background_color_dark); + } else { + AndroidUtils.setBackground(app, bottomContainer, isNightMode(), + R.color.activity_background_color_light, R.color.activity_background_color_dark); + } + } + @Override protected void calculateLayout(View view, boolean initLayout) { menuTitleHeight = routeMenuTopShadowAll.getHeight() @@ -852,6 +864,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card menuType = type; setupCards(); updateHeader(); + updateCardsLayout(); calculateLayoutAndUpdateMenuState(); break; } From cbebccb12374ee1ac61ec5a24954e901425da97f Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 28 Jan 2021 16:42:08 +0200 Subject: [PATCH 22/53] Small refactoring --- .../data/TravelLocalDataHelper.java | 6 ++--- .../plus/wikivoyage/data/TravelObfHelper.java | 25 +++++++++++++++---- .../explore/travelcards/TravelGpxCard.java | 3 +-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index ae1c22b587..a95438a77e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -143,10 +143,8 @@ public class TravelLocalDataHelper { @Nullable private TravelArticle getArticle(String title, String lang) { for (TravelArticle article : savedArticles) { - if (article.lang == null && lang == null && article.title != null && article.title.equals(title)) { - return article; - } - if (article.title != null && article.title.equals(title) && article.lang != null && article.lang.equals(lang)) { + if (article.title != null && article.title.equals(title) + && (article.lang != null && article.lang.equals(lang) || article.lang == null && lang == null)) { return article; } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 69c1506b9b..ab9e926c10 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -48,6 +48,8 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import gnu.trove.iterator.TIntObjectIterator; + import static net.osmand.GPXUtilities.Track; import static net.osmand.GPXUtilities.TrkSegment; import static net.osmand.GPXUtilities.WptPt; @@ -70,8 +72,8 @@ public class TravelObfHelper implements TravelHelper { 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 int REF_KEY = 2; - public static final int NAME_KEY = 1; + public static final String REF_TAG = "ref"; + public static final String NAME_TAG = "name"; private final OsmandApplication app; private final Collator collator; @@ -163,7 +165,7 @@ public class TravelObfHelper implements TravelHelper { private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints, @Nullable GpxReadCallback callback) { TravelArticle article = null; Map articles; - if (amenity.getSubType().equals(ROUTE_TRACK)) { + if (Algorithms.objectEquals(amenity.getSubType(), ROUTE_TRACK)) { articles = readRoutePoint(file, amenity); } else { articles = readArticles(file, amenity); @@ -268,8 +270,8 @@ public class TravelObfHelper implements TravelHelper { @Override public boolean publish(BinaryMapDataObject object) { if (object.getPointsLength() > 1) { - if (object.getObjectNames().get(REF_KEY).equals(ref) - && createTitle(object.getObjectNames().get(NAME_KEY)).equals(article.title)) { + if (getTagValue(object, REF_TAG).equals(ref) + && createTitle(getTagValue(object, NAME_TAG)).equals(article.title)) { segmentList.add(object); } } @@ -310,6 +312,19 @@ public class TravelObfHelper implements TravelHelper { return gpxFile; } + private String getTagValue(BinaryMapDataObject object, String tag) { + BinaryMapIndexReader.MapIndex mi = object.getMapIndex(); + TIntObjectIterator it = object.getObjectNames().iterator(); + while (it.hasNext()) { + it.advance(); + BinaryMapIndexReader.TagValuePair tp = mi.decodeType(it.key()); + if (tp.tag.equals(tag)) { + return it.value(); + } + } + return ""; + } + private String createTitle(String name) { return capitalizeFirstLetter(getGpxTitle(name)); } 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 515a5f5b06..1bc2409621 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -13,7 +13,6 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.track.TrackMenuFragment; -import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; @@ -43,7 +42,7 @@ public class TravelGpxCard extends BaseTravelCard { holder.title.setText(article.getTitle()); Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16); holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); - holder.user.setText(WikiArticleHelper.getPartialContent(article.user)); + holder.user.setText(article.user); AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark); holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); From 25f7a2a8b309a0bfdbfa1c44a2a90613027ce14a Mon Sep 17 00:00:00 2001 From: vshcherb Date: Thu, 28 Jan 2021 16:00:47 +0100 Subject: [PATCH 23/53] Moved to docs --- GPX.md | 157 --------------------------------------------------------- 1 file changed, 157 deletions(-) delete mode 100644 GPX.md diff --git a/GPX.md b/GPX.md deleted file mode 100644 index b3f1e441e4..0000000000 --- a/GPX.md +++ /dev/null @@ -1,157 +0,0 @@ -The OsmAnd's GPX file format conforms to the GPX 1.1 specification with additional data written as extensions. There are several sections of such data: - -## Track appearance -The following parameters are used to customize the appearance of a track on the map. They are used inside the "gpx" tag and apply to all tracks contained in the gpx. -#### Parameters -* **show_arrows** [*true, false*] - show / hide arrows along the path line. -* **width** [*thin, medium, bold, 1-24*] - width of the track line on the map. The thin, medium, and bold are style depended values (should be defined as currentTrackWidth attribute). -* **color** [*#AARRGGBB, #RRGGBB*] - color of a track line on the map. Hex value. -* **split_type** [*no_split, distance, time*] - split type for a track. -* **split_interval** [*double*] - split interval for a track. Distance (meters), time (seconds). - -#### Example: -```xml - -... - - true - #4e4eff - distance - 2000.0 - bold - - -``` -## Details of a track point (trkpt) -Written to a gpx file while recording a track. -* **speed** (meters per second) -* **heading** (0-359 degrees) - -#### Example: -```xml - - 203 - - 3 - - 273 - 5.02 - - -``` - -## Calculated route(s) -This data contains all details of a route built with **OsmAnd** (route segments, turns, road names, road types, restrictions, etc.). The route can be completely restored as if just built, even in the absence of the respective offline maps. - -A gpx file may contain several routes. Each of them is contained in a specific segment under **trkseg** / **extensions**. A gpx file is saved in this form when exporting a constructed route or when saving a track that consists of several separate segments via the **Plan a route** functionality. -**Plan a route** also adds one (or several, in accordance with the number of contained separate segments / tracks) **rte** blocks to the gpx file, containing route key points (**rtept**). -#### Gpx structure: -```xml - - - - - - - - - - - - - - - - - - - - - - - - - - ... - - ... - - - -``` - -#### Example: -```xml - - - Fri 06 Nov 2020 - - - Fri 06 Nov 2020 - - - 0.801 - - - 0.998 - - - 1 - - - 0.963 - - - 0.899 - - - .... - - - - - - - - ... - - - - - - - - ... - - - - - - - - - pedestrian - 0 - - - - - pedestrian - 24 - - - - - pedestrian - 89 - - - - - pedestrian - 121 - - - - -``` From f4c5685ff5ce15d51ee0ecf0086a9d06a49494e2 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Thu, 28 Jan 2021 16:03:32 +0100 Subject: [PATCH 24/53] Update no_translate.xml --- OsmAnd/no_translate.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/no_translate.xml b/OsmAnd/no_translate.xml index 92d3a4034f..d5ecc7c149 100644 --- a/OsmAnd/no_translate.xml +++ b/OsmAnd/no_translate.xml @@ -40,7 +40,7 @@ items modified OsmAnd Unlimited Markers - https://test.openplacereviews.org/ + https://openplacereviews.org/ https://test.openplacereviews.org/ v8G8r9NLJZGMV4he5lwbQlz620FNVARKjI9Bm5UJ jDvM95Ne1Bq2BDTmIfB6b3ZMxvdK87WGfp6DC07J From 0f994e2da6133d79a12cf8ae43b34e2c0df05421 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 28 Jan 2021 17:21:32 +0200 Subject: [PATCH 25/53] Small refactoring --- .../osmand/plus/wikivoyage/data/TravelLocalDataHelper.java | 4 ++-- .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index a95438a77e..c2ccc442c3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -143,8 +143,8 @@ public class TravelLocalDataHelper { @Nullable private TravelArticle getArticle(String title, String lang) { for (TravelArticle article : savedArticles) { - if (article.title != null && article.title.equals(title) - && (article.lang != null && article.lang.equals(lang) || article.lang == null && lang == null)) { + if (Algorithms.stringsEqual(article.title, title) + && Algorithms.stringsEqual(article.lang, lang)) { return article; } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index ab9e926c10..294cf2cd13 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -165,7 +165,7 @@ public class TravelObfHelper implements TravelHelper { private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints, @Nullable GpxReadCallback callback) { TravelArticle article = null; Map articles; - if (Algorithms.objectEquals(amenity.getSubType(), ROUTE_TRACK)) { + if (ROUTE_TRACK.equals(amenity.getSubType())) { articles = readRoutePoint(file, amenity); } else { articles = readArticles(file, amenity); From 111e2791090ada3346ad0af9c6a208a606e341da Mon Sep 17 00:00:00 2001 From: Damjan Gerl Date: Wed, 27 Jan 2021 16:58:34 +0000 Subject: [PATCH 26/53] Translated using Weblate (Slovenian) Currently translated at 72.9% (2663 of 3651 strings) --- OsmAnd/res/values-sl/strings.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OsmAnd/res/values-sl/strings.xml b/OsmAnd/res/values-sl/strings.xml index 89091ce1d4..0cb17c35f4 100644 --- a/OsmAnd/res/values-sl/strings.xml +++ b/OsmAnd/res/values-sl/strings.xml @@ -3305,4 +3305,8 @@ MTB Napaka strežnika: %1$s To ime že obstaja + Preberi v celoti + Uredi opis + Brisanje točk + Kopiraj na oznake na zemljevidu \ No newline at end of file From fe2e610b0577de8f624be798402dc8eb1978b504 Mon Sep 17 00:00:00 2001 From: solokot Date: Wed, 27 Jan 2021 15:45:19 +0000 Subject: [PATCH 27/53] Translated using Weblate (Russian) Currently translated at 99.5% (3633 of 3651 strings) --- OsmAnd/res/values-ru/strings.xml | 57 +++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 33236ca153..a0a8f5fdea 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1185,7 +1185,7 @@ Нет маршрута Включите GPS в настройках Показывать направление к пункту назначения - Включите плагин «Запись поездки» для использования сервисов мониторинга (запись GPX, сопровождение в реальном времени) + Включите плагин «Запись поездки» для использования служб мониторинга (запись GPX, сопровождение в реальном времени) Выберите цветовую схему дорог: Цветовая схема дорог Ш %1$.3f Д %2$.3f @@ -1731,7 +1731,7 @@ выбранные Нет Отменить выбор - Отменить выбор всех + Отменить выбор Поделиться Мои места Избранные @@ -3225,7 +3225,7 @@ \n Контурные линии и затенение рельефа Предпочитать грунтовые дороги - Предпочитать грунтовые дороги. + Предпочитать грунтовые дороги Вы уверены, что хотите обновить все карты (%1$d)\? Вы можете применить это ко всем или только к выбранному профилю. Общий @@ -3713,7 +3713,7 @@ Удалить ближайший пункт Задайте название точки Следующая точка маршрута будет удалена. Если это конечный пункт, навигация завершится. - Информация о достопримечательностях из Википедии. Ваш карманный офлайн-путеводитель — просто включите плагин Википедии и читайте об объектах вокруг вас. + Информация о достопримечательностях из Википедии, карманного автономного путеводителя со статьями о местах и направлениях. Скачать карты Википедии Эндуро мотоцикл Мотороллер @@ -3937,4 +3937,53 @@ Папки Выбор папки Выберите папку или добавьте новую + Время голосовых подсказок + Можно использовать данные о высотах для учёта подъёма/спуска поездки + Предпочитать пешеходные маршруты + Подтип + Введите параметр + Пешеход + Самокат + Анализ по интервалам (по отдельности) + Заблаговременно + Заранее + При прохождении + При приближении + Инвалидная коляска + Пеший туризм + Малый грузовик + Грузовик + Копировать в маркеры + Копировать в избранное + Удалить онлайн-маршрутизатор\? + Предпочитать пешеходные маршруты + Добавить онлайн-маршрутизатор + Редактировать онлайн-маршрутизатор + Ключ API + URL-адрес сервера + Оставить пустым, если не + URL со всеми параметрами будет выглядеть так: + Тест расчёта маршрута + Автомобиль + Онлайн-маршрутизатор + Онлайн-маршрутизаторы + Пусто + Отправить в OpenStreetMap + Редактировать трек + Переименовать трек + Изменить папку + сек. + Вне маршрута + Прибытие в пункт назначения + Поворот + Интервалы времени и расстояния + Время объявления + Время объявления различных голосовых подсказок зависит от типа подсказки, текущей скорости навигации и скорости навигации по умолчанию. + Начать запись + Показать трек на карте + Ошибка сервера: %1$s + Имя уже существует + Читать полностью + Редактировать описание + Удалить путевые точки \ No newline at end of file From 624c2419f4af2e97362a5ffb5a4ee6c3212672ab Mon Sep 17 00:00:00 2001 From: ace shadow Date: Wed, 27 Jan 2021 23:39:53 +0000 Subject: [PATCH 28/53] Translated using Weblate (Slovak) Currently translated at 100.0% (3651 of 3651 strings) --- OsmAnd/res/values-sk/strings.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OsmAnd/res/values-sk/strings.xml b/OsmAnd/res/values-sk/strings.xml index 95f34a3db1..2da9b2324b 100644 --- a/OsmAnd/res/values-sk/strings.xml +++ b/OsmAnd/res/values-sk/strings.xml @@ -3995,4 +3995,10 @@ Chyba servera: %1$s Názov už existuje Odbočiť + Odstrániť túto online navigačnú službu\? + Prečítať celé + Upraviť popis + Odstrániť body trasy + Skopírovať do mapových značiek + Skopírovať do obľúbených \ No newline at end of file From 45357c21397989fa550424d3cf20d0a38c363049 Mon Sep 17 00:00:00 2001 From: Ahmad Alfrhood Date: Wed, 27 Jan 2021 12:59:17 +0000 Subject: [PATCH 29/53] Translated using Weblate (Arabic) Currently translated at 100.0% (3651 of 3651 strings) --- OsmAnd/res/values-ar/strings.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index 8929bd6f4d..699c82cd8e 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -4063,4 +4063,10 @@ MTB خطأ في الخادم: %1$s الاسم موجود بالفعل + هل تريد حذف محرك التوجيه عبر الإنترنت؟ + قراءة كاملة + تحرير الوصف + حذف نقاط الطريق + نسخ لعلامات الخريطة + نسخ للمفضلة \ No newline at end of file From 092f990229c4e19cd7fd84a0c8a4ec63661fa53f Mon Sep 17 00:00:00 2001 From: nasr pen Date: Wed, 27 Jan 2021 09:10:59 +0000 Subject: [PATCH 30/53] Translated using Weblate (Arabic) Currently translated at 100.0% (3651 of 3651 strings) --- OsmAnd/res/values-ar/strings.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index 699c82cd8e..4b91263f2d 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -3513,7 +3513,7 @@ أنواع نقاط الاهتمام لا شيء محدد زر الإجراء السريع - ملفات التعريف + الأوضاع سيتم استبدال العناصر الحالية بالعناصر التي في الملف استبدل الكل احصل على %1$d %2$s عند %3$s مقابل. @@ -3965,7 +3965,7 @@ مساحة جهازك %1$s الخالية فقط. يرجى تحرير بعض المساحة أو إلغاء تحديد بعض العناصر للتصدير. المصادر حجم الملف التقريبي - حدد البيانات التي سيتم تصديرها إلى الملف. + حدد البيانات التي سيتم تصديرها إلى ملف. مطلوب للاستيراد لا يوجد مساحة كافية أضف إلى مابيلاي @@ -3997,10 +3997,10 @@ \n • دعم ألوان مخصصة للمفضلة ونقاط لمسار الطريق \n \n - ملف تعريف أوسماند + وضع الاستعراض ملف تعريف المستخدم عكس جميع النقاط - حدد ملف التعريف، الذي سيتم استخدامه في بدء التطبيق. + حدد الوضع الذي سيتم استخدامه في بدء التطبيق. آخر استخدام تفضيل طرق التنزه تفضيل طرق التنزه From c53b863bd21a5bfe5b8d5354d4880581584aa53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allan=20Nordh=C3=B8y?= Date: Wed, 27 Jan 2021 04:05:25 +0000 Subject: [PATCH 31/53] =?UTF-8?q?Translated=20using=20Weblate=20(Norwegian?= =?UTF-8?q?=20Bokm=C3=A5l)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently translated at 59.2% (2163 of 3651 strings) --- OsmAnd/res/values-nb/strings.xml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/values-nb/strings.xml b/OsmAnd/res/values-nb/strings.xml index bff5af5293..7c3e0695ce 100644 --- a/OsmAnd/res/values-nb/strings.xml +++ b/OsmAnd/res/values-nb/strings.xml @@ -1526,7 +1526,7 @@ Taledataversjon som ikke støttes Sporer posisjonen din mens skjermen er slått av. Favoritter delt via OsmAnd - Lagre data som GPX-fil eller importere rutepunkter til Favoritter\? + Lagre data som GPX-fil eller importere rutepunkter til favoritter\? Format for geografiske koordinater. Koordinatformat Søk @@ -3919,4 +3919,18 @@ Vanlig sykling Tjenerfeil: %1$s Navnet finnes allerede + Analyser ved intervaller (delt intervall) + Ruteavvik + Stor lastebil + Slett denne nettbaserte rutingsmotoren\? + Les hele + Slett rutepunkt + Luke + Logg inn på OpenStreetMap + Logg inn + Tidsforbruk + Ankomst + Rediger beskrivelse + Kopier til kartmarkører + Kopier til favoritter \ No newline at end of file From 8694faaba66c3e4d06a9b0611007d8cd78314ab4 Mon Sep 17 00:00:00 2001 From: Franco Date: Wed, 27 Jan 2021 22:34:54 +0000 Subject: [PATCH 32/53] Translated using Weblate (Spanish (Argentina)) Currently translated at 99.8% (3646 of 3651 strings) --- OsmAnd/res/values-es-rAR/strings.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/values-es-rAR/strings.xml b/OsmAnd/res/values-es-rAR/strings.xml index 1a037e42ff..56f6940aae 100644 --- a/OsmAnd/res/values-es-rAR/strings.xml +++ b/OsmAnd/res/values-es-rAR/strings.xml @@ -3982,7 +3982,7 @@ Preparar Fuera de la ruta Has llegado al destino - Giro + Girar Intervalos de tiempo y distancia El tiempo de anuncio de las diferentes indicaciones por voz depende del tipo de mensaje, la velocidad de navegación actual y la velocidad de navegación predefinida. Tiempo de anuncio @@ -4003,4 +4003,10 @@ Bicicleta de montaña Error de servidor: %1$s El nombre ya existe + ¿Borrar este motor de navegación en línea\? + Leer completo + Editar descripción + Borrar puntos de referencia + Copiar a «Marcadores del mapa» + Copiar a favoritos \ No newline at end of file From c96276556325757ebb18b5d1468b8efa863d6b7a Mon Sep 17 00:00:00 2001 From: Oymate Date: Thu, 28 Jan 2021 08:21:59 +0000 Subject: [PATCH 33/53] Translated using Weblate (Bengali) Currently translated at 0.4% (17 of 3651 strings) --- OsmAnd/res/values-bn/strings.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OsmAnd/res/values-bn/strings.xml b/OsmAnd/res/values-bn/strings.xml index 1dd3435fca..09ae3e8f32 100644 --- a/OsmAnd/res/values-bn/strings.xml +++ b/OsmAnd/res/values-bn/strings.xml @@ -24,4 +24,8 @@ ওএসএমও কেনাকাটা একটি মানচিত্রের প্রতীকের জন্য গাইড ন্যাভিগেশন প্রোফাইল + অবস্থানগুলো + দিক নির্ণয় + মি/সে + নটিকাল মাইল \ No newline at end of file From a591cb14c6cf65a42b57d9e619f56471d26672c9 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Wed, 27 Jan 2021 01:46:38 +0000 Subject: [PATCH 34/53] Translated using Weblate (Chinese (Traditional)) Currently translated at 100.0% (3651 of 3651 strings) --- OsmAnd/res/values-zh-rTW/strings.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OsmAnd/res/values-zh-rTW/strings.xml b/OsmAnd/res/values-zh-rTW/strings.xml index 2c86df4178..c092cb961b 100644 --- a/OsmAnd/res/values-zh-rTW/strings.xml +++ b/OsmAnd/res/values-zh-rTW/strings.xml @@ -3993,4 +3993,10 @@ 登山車 伺服器錯誤:%1$s 名稱已存在 + 刪除此線上路線引擎? + 讀取全部 + 編輯描述 + 刪除航點 + 複製到地圖標記 + 複製到收藏 \ No newline at end of file From eabd5037fd802d31fa6db7bc59e2ebf005d9741e Mon Sep 17 00:00:00 2001 From: CJTmmr Date: Wed, 27 Jan 2021 16:29:50 +0000 Subject: [PATCH 35/53] Translated using Weblate (Dutch) Currently translated at 96.1% (3510 of 3651 strings) --- OsmAnd/res/values-nl/strings.xml | 87 +++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/OsmAnd/res/values-nl/strings.xml b/OsmAnd/res/values-nl/strings.xml index 012850fd00..c9d8e87306 100644 --- a/OsmAnd/res/values-nl/strings.xml +++ b/OsmAnd/res/values-nl/strings.xml @@ -2178,8 +2178,8 @@ Tijdsduur Tijd in beweging Rijstijl - Gebruik hoogtegegevens - Factor in hoogtegegevens (van SRTM, ASTER en EU-DEM data). + Hoogtegegevens gebruiken + Gebruik hoogtegegevens (van SRTM, ASTER en EU-DEM data) bij bepalen route. Track Rechts rijdend Automatisch @@ -3320,9 +3320,9 @@ Route herberekening Meld Gebruikersnaam en wachtwoord - Deze instellingen hebben betrekking op alle profielen + Deze plugin-instellingen hebben betrekking op alle profielen OSM Bewerking - U kan al uw niet geüploade bewerkingen of OSM fouten zien in %1$s. Geüploade punten ziet u niet meer. + U kunt alle niet-geüploade bewerkingen of OSM-opmerkingen zien in %1$s. Geüploade wijzigingen ziet u niet meer. OSM Tijdens navigatie of beweging getoond icoon. Bij rust getoond icoon. @@ -3667,8 +3667,8 @@ Volgende segment Alle volgende segmenten Alle volgende segmenten worden opnieuw berekend met het geselecteerde profiel. - De ganse track - De ganse track wordt herberekend volgens het geselecteerde profiel. + De gehele route + De gehele route wordt herberekend volgens het geselecteerde profiel. Punt van de track om te navigeren Bewaar als nieuw trackbestand Bewaar als nieuwe track @@ -3730,8 +3730,8 @@ \nDe grafiek is beschikbaar na herberekening. %1$s — %2$s Kies een trackbestand om te volgen of importeer het, vanaf uw apparaat. - Kloof - Op maat + Onderbreking + Aangepast Voer een OAuth-login uit om osm edit functies te gebruiken "• Bijgewerkte app- en profielinstellingen: instellingen zijn nu gerangschikt op type. Elk profiel kan afzonderlijk worden aangepast. \n @@ -3843,41 +3843,41 @@ Onderhoud Symbolen Sport - Noodtoestand + Noodgevallen Reizen Trackbestanden importeren of opnemen Track waypoint toevoegen Opslaan als trackbestand Rec U moet minimaal twee punten toevoegen - Login op OpenStreetMap - Login op OpenStreetMap.org - Login met OpenStreetMap - U moet inloggen om nieuwe of gewijzigde wijzigingen te uploaden. + Inloggen bij OpenStreetMap + Inloggen bij OpenStreetMap.org + Aanmelden via OpenStreetMap (OAuth) + U moet inloggen om wijzigingen te uploaden. \n -\nU kunt inloggen met de veilige OAuth-methode of uw login en wachtwoord gebruiken. - Gebruik uw login gegevens +\nU kunt inloggen met de veilige OAuth-methode of uw loginnaam en wachtwoord gebruiken. + Inloggen met gebruikersnaam en wachtwoord. Account - Inloggen + Gebruikersnaam Abonnement beheren Er is een probleem met uw abonnement. Klik op de knop om naar de Google Play-abonnementsinstellingen te gaan om uw betalingsmethode te corrigeren. OsmAnd Live-abonnement is verlopen OsmAnd Live-abonnement is gepauzeerd - Het OsmAnd Live-abonnement is op wacht gezet - Markeervlaggen geschiedenis + Het OsmAnd Live-abonnement is opgeschort + Markeervlaggetjes-geschiedenis Stuur het GPX-bestand naar OpenStreetMap Voer tags in, gescheiden door komma\'s. - Openbaar betekent dat de trace openbaar zal worden getoond in Uw GPS-sporen en in openbare GPS-traceerlijsten. Gegevens die via de API worden geleverd, verwijzen niet naar uw traceerpagina. Tijdaanduidingen van de traceerpunten zijn niet beschikbaar via de openbare GPS-API en de punten zijn niet chronologisch gerangschikt. Andere gebruikers kunnen de onbewerkte tracering echter nog steeds downloaden van de openbare traceringslijst en eventuele tijdaanduiding erin. - Privé betekent dat de trace niet in openbare vermeldingen zal verschijnen, maar trackpoints ervan zullen nog steeds beschikbaar zijn via de openbare GPS API zonder tijdaanduiding, maar zullen niet chronologisch worden gerangschikt. - Identificeerbaar betekent dat de trace openbaar wordt getoond in uw GPS-sporen en in openbare GPS-trace-lijsten, dat wil zeggen dat andere gebruikers de onbewerkte trace kunnen downloaden en deze aan uw gebruikersnaam kunnen koppelen. Gegevens die via de trackpoints-API worden aangeboden, verwijzen naar uw oorspronkelijke tracepagina. Tijdaanduidingen van de traceerpunten zijn beschikbaar via de openbare GPS-API. - Trackbaar betekent dat de trace niet in openbare vermeldingen zal verschijnen, maar trackpoints ervan zullen nog steeds beschikbaar zijn via de openbare GPS API met tijdaanduiding. Andere gebruikers kunnen alleen verwerkte trackpoints downloaden van uw trace die niet rechtstreeks aan u kunnen worden gekoppeld. + \"Publiek\" betekent dat de track openbaar wordt getoond in \"Jouw GPS-tracks\" en in openbare GPS-track-lijsten. Trackpoints die d.m.v. de API worden gedownload zullen niet aan je oorspronkelijke trackpagina refereren. Tijden in de tracks zijn niet beschikbaar in de publieke GPS API, maar de punten zullen wel chronologisch geordend zijn. Echter, andere gebruikers kunnen de track van de openbare GPS-track-lijsten downloaden met alle tijdinformatie. + \"Persoonlijk\" betekent dat de track niet wordt getoond in openbare GPS-track-lijsten, maar de trackpunten zijn wel beschikbaar in volgorde van tijd door de publieke GPS API, maar zonder tijdinformatie. + \"Identificeerbaar\" betekent dat de trace openbaar wordt getoond in uw GPS-sporen en in openbare GPS-trace-lijsten. Dat wil zeggen dat andere gebruikers de onbewerkte trace kunnen downloaden en deze aan uw gebruikersnaam kunnen koppelen. Gegevens die via de trackpoints-API worden aangeboden, verwijzen naar uw oorspronkelijke tracepagina. Tijdaanduidingen van de traceerpunten zijn beschikbaar via de openbare GPS-API. + \"Traceerbaar\" betekent dat de track niet wordt getoond in openbare GPS-track-lijsten maar de trackpunten zijn wel beschikbaar door de publieke GPS API met tijdinformatie. Andere gebruikers kunnen alleen bewerkte trackpunten downloaden die niet aan jou herleid kunnen worden. Sluit OSM Note Opmerking maken bij OSM-nota - U kunt inloggen met de veilige OAuth-methode of uw login en wachtwoord gebruiken. + U kunt inloggen met de veilige OAuth-methode, of uw loginnaam en wachtwoord gebruiken. Een foto toevoegen Registreer u op \nOpenPlaceReviews.org - Foto\'s zijn afkomstig van het open data-project OpenPlaceReviews.org. Om uw foto\'s te uploaden, moet u zich aanmelden op deze website. + Foto\'s zijn afkomstig van het open data-project OpenPlaceReviews.org. Om uw foto\'s te uploaden, moet u zich aanmelden op hun website. Maak een nieuw account aan Ik heb al een account %1$s * %2$s @@ -3954,4 +3954,43 @@ Laat regelmatig droogvallende waterwegen toe Geef een parameter Laat leeg indien niet + Analyseren met intervallen + Uploaden naar OpenStreetMap + GPX-track bewerken + GPX-track hernoemen + Map wijzigen + sec + Bij nadering + Bij passeren + Ruime vooraankondiging + Vooraankondiging + Afwijking van de route + Aankomst op bestemming + Bocht + Tijd- en afstandsintervallen + De aankondigingstijd van verschillende aankondigen hangt af van type en huidige snelheid. + Aankondigingstijd + Start opname + Toon GPX-track op de kaart + Rolstoel + Hiken + Wandelen + Elektische Fiets + Mountainbiken + Fietsen + Normaal Fietsen + Vrachtwagen + Kleine Vrachtwagen + Vrachtwagen + Scooter + Racefiets + Mountainbike + Server fout: %1$s + Deze naam bestaat al + Deze Online-routeservice verwijderen\? + Helemaal inlezen + Beschrijving bewerken + Waypoints verwijderen + Kopiëren naar Markeervlaggetjes + Kopiëren naar Favorieten \ No newline at end of file From f87592c4adf0ff4acc883c700cebf7950026edf6 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Thu, 28 Jan 2021 19:04:14 +0300 Subject: [PATCH 36/53] Travel fixes --- .../net/osmand/plus/OsmandApplication.java | 13 ++++++++++ .../plus/activities/MapActivityActions.java | 2 +- .../data/TravelLocalDataHelper.java | 26 +++++++++++++++++++ .../plus/wikivoyage/data/TravelObfHelper.java | 14 +++++----- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 842a36237e..6b9aa4d0a4 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -210,6 +210,8 @@ public class OsmandApplication extends MultiDexApplication { File mapillaryVectorTilesPath = new File(tilesPath, TileSourceManager.getMapillaryVectorSource().getName()); Algorithms.removeAllFiles(mapillaryRasterTilesPath); Algorithms.removeAllFiles(mapillaryVectorTilesPath); + // Remove travel sqlite db files + removeSqliteDbTravelFiles(); } checkPreferredLocale(); @@ -234,6 +236,17 @@ public class OsmandApplication extends MultiDexApplication { return externalStorageDirectoryReadOnly; } + private void removeSqliteDbTravelFiles() { + File[] files = getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles(); + if (files != null) { + for (File file : files) { + if (file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) { + file.delete(); + } + } + } + } + @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index b5dd0dc3ea..258ed7be38 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -928,7 +928,7 @@ public class MapActivityActions implements DialogProvider { MapActivity.clearPrevActivityIntent(); TravelHelper travelHelper = getMyApplication().getTravelHelper(); travelHelper.initializeDataOnAppStartup(); - if (!travelHelper.isAnyTravelBookPresent()) { + if (!travelHelper.isAnyTravelBookPresent() && !travelHelper.getBookmarksHelper().hasSavedArticles()) { WikivoyageWelcomeDialogFragment.showInstance(mapActivity.getSupportFragmentManager()); } else { Intent intent = new Intent(mapActivity, WikivoyageExploreActivity.class); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index 02ee5a32c8..151a0ef424 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -1,6 +1,9 @@ package net.osmand.plus.wikivoyage.data; +import android.database.DatabaseUtils; +import android.database.sqlite.SQLiteDatabase; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -100,6 +103,10 @@ public class TravelLocalDataHelper { } } + public boolean hasSavedArticles() { + return !savedArticles.isEmpty() || dbHelper.hasSavedArticles(); + } + @NonNull public List getSavedArticles() { return new ArrayList<>(savedArticles); @@ -438,6 +445,25 @@ public class TravelLocalDataHelper { return res; } + boolean hasSavedArticles() { + int count = 0; + SQLiteConnection conn = openConnection(true); + if (conn != null) { + try { + SQLiteCursor cursor = conn.rawQuery("SELECT COUNT(*) FROM " + BOOKMARKS_TABLE_NAME, null); + if (cursor != null) { + if (cursor.moveToFirst()) { + count = cursor.getInt(0); + } + cursor.close(); + } + } finally { + conn.close(); + } + } + return count > 0; + } + void addSavedArticle(@NonNull TravelArticle article) { String travelBook = article.getTravelBook(context); if (travelBook == null) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 0f14896a94..1336dcc2f6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -485,7 +485,7 @@ public class TravelObfHelper implements TravelHelper { @Nullable private TravelArticle getCachedArticle(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, - boolean forceReadPoints, @Nullable GpxReadCallback callback) { + boolean readGpx, @Nullable GpxReadCallback callback) { TravelArticle article = null; Map articles = cachedArticles.get(articleId); if (articles != null) { @@ -502,9 +502,9 @@ public class TravelObfHelper implements TravelHelper { } } if (article == null && articles == null) { - article = findArticleById(articleId, lang, callback); + article = findArticleById(articleId, lang, readGpx, callback); } - if (article != null && forceReadPoints && !Algorithms.isEmpty(lang)) { + if (article != null && readGpx && !Algorithms.isEmpty(lang)) { readGpxFile(article, callback); } return article; @@ -518,8 +518,8 @@ public class TravelObfHelper implements TravelHelper { } } - private TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, - final String lang, @Nullable GpxReadCallback callback) { + private synchronized TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, + final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { TravelArticle article = null; final boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT); final List amenities = new ArrayList<>(); @@ -562,7 +562,7 @@ public class TravelObfHelper implements TravelHelper { LOG.error(e.getMessage()); } if (!Algorithms.isEmpty(amenities)) { - article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, true, callback); + article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, readGpx, callback); } } return article; @@ -585,7 +585,7 @@ public class TravelObfHelper implements TravelHelper { @Nullable @Override - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull QuadRect rect, + public synchronized TravelArticle getArticleByTitle(@NonNull final String title, @NonNull QuadRect rect, @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { TravelArticle article = null; final List amenities = new ArrayList<>(); From 8098f5d92c32c4bfcc6f85bdc8304a5bd0fee348 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Thu, 28 Jan 2021 19:17:25 +0300 Subject: [PATCH 37/53] Fix npe --- .../WikivoyageArticleDialogFragment.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 4ee8099c26..cced9d45ad 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -1,6 +1,7 @@ package net.osmand.plus.wikivoyage.article; import android.annotation.SuppressLint; +import android.content.Context; import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; @@ -339,17 +340,20 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme } private void updateTrackButton(boolean processing, @Nullable GPXFile gpxFile) { - if (processing) { - trackButton.setVisibility(View.GONE); - gpxProgress.setVisibility(View.VISIBLE); - } else { - if (gpxFile != null && gpxFile.getPointsSize() > 0) { - trackButton.setVisibility(View.VISIBLE); - trackButton.setText(getString(R.string.shared_string_gpx_points) + " (" + gpxFile.getPointsSize() + ")"); - } else { + Context ctx = getContext(); + if (ctx != null) { + if (processing) { trackButton.setVisibility(View.GONE); + gpxProgress.setVisibility(View.VISIBLE); + } else { + if (gpxFile != null && gpxFile.getPointsSize() > 0) { + trackButton.setVisibility(View.VISIBLE); + trackButton.setText(ctx.getString(R.string.shared_string_gpx_points) + " (" + gpxFile.getPointsSize() + ")"); + } else { + trackButton.setVisibility(View.GONE); + } + gpxProgress.setVisibility(View.GONE); } - gpxProgress.setVisibility(View.GONE); } } From 1b30f1f428b3fbc7ea54693b389e41f5cc02d040 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Thu, 28 Jan 2021 19:53:34 +0300 Subject: [PATCH 38/53] Fix travel cards when no book --- .../explore/ExploreTabFragment.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index 9055acd4ed..c13c7fb22f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -175,10 +175,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv if (!Version.isPaidVersion(app) && !OpenBetaTravelCard.isClosed()) { items.add(new OpenBetaTravelCard(activity, nightMode)); } - if (app.getTravelHelper().isAnyTravelBookPresent()) { + List popularArticles = app.getTravelHelper().getPopularArticles(); + if (!popularArticles.isEmpty()) { items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations))); - - List popularArticles = app.getTravelHelper().getPopularArticles(); for (TravelArticle article : popularArticles) { if (article instanceof TravelGpx) { items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, getActivity())); @@ -186,15 +185,15 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv items.add(new ArticleTravelCard(app, nightMode, article, activity.getSupportFragmentManager())); } } - items.add(new StartEditingTravelCard(activity, nightMode)); - adapter.setItems(items); - final DownloadIndexesThread downloadThread = app.getDownloadThread(); - if (!downloadThread.getIndexes().isDownloadedFromInternet) { - waitForIndexes = true; - downloadThread.runReloadIndexFilesSilent(); - } else { - checkDownloadIndexes(); - } + } + items.add(new StartEditingTravelCard(activity, nightMode)); + adapter.setItems(items); + final DownloadIndexesThread downloadThread = app.getDownloadThread(); + if (!downloadThread.getIndexes().isDownloadedFromInternet) { + waitForIndexes = true; + downloadThread.runReloadIndexFilesSilent(); + } else { + checkDownloadIndexes(); } } } From 44bcf483759a72aa40a36761b46e1b166acf53ba Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 18:54:45 +0200 Subject: [PATCH 39/53] Add opr blockchain name --- .../plus/mapcontextmenu/MenuBuilder.java | 2 +- .../mapcontextmenu/UploadPhotosAsyncTask.java | 6 ++-- .../osmand/plus/osmedit/opr/OpenDBAPI.java | 32 ++++++++++++++++--- .../plus/settings/backend/OsmandSettings.java | 3 ++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 183e41a84f..93f2bdf6b5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -421,7 +421,7 @@ public class MenuBuilder { new Thread(new Runnable() { @Override public void run() { - if (openDBAPI.checkPrivateKeyValid(baseUrl, name, privateKey)) { + if (openDBAPI.checkPrivateKeyValid(app, baseUrl, name, privateKey)) { app.runInUIThread(new Runnable() { @Override public void run() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java index 30932e8b42..1bb48ff1f0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java @@ -131,12 +131,12 @@ public class UploadPhotosAsyncTask extends AsyncTask { try { StringBuilder error = new StringBuilder(); String privateKey = app.getSettings().OPR_ACCESS_TOKEN.get(); - String username = app.getSettings().OPR_USERNAME.get(); + String name = app.getSettings().OPR_BLOCKCHAIN_NAME.get(); res = openDBAPI.uploadImage( placeId, baseUrl, privateKey, - username, + name, response, error); if (res != 200) { app.showToastMessage(error.toString()); @@ -170,7 +170,7 @@ public class UploadPhotosAsyncTask extends AsyncTask { String baseUrl = OPRConstants.getBaseUrl(app); String name = app.getSettings().OPR_USERNAME.get(); String privateKey = app.getSettings().OPR_ACCESS_TOKEN.get(); - if (openDBAPI.checkPrivateKeyValid(baseUrl, name, privateKey)) { + if (openDBAPI.checkPrivateKeyValid(app, baseUrl, name, privateKey)) { app.showToastMessage(R.string.cannot_upload_image); } else { app.runInUIThread(new Runnable() { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java index a16361c8bd..14c0e97672 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java @@ -3,10 +3,15 @@ package net.osmand.plus.osmedit.opr; import android.net.TrafficStats; import android.os.Build; +import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonSyntaxException; +import com.google.gson.reflect.TypeToken; import net.osmand.PlatformUtil; import net.osmand.osm.io.NetworkUtils; +import net.osmand.plus.OsmandApplication; +import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import org.bouncycastle.jce.provider.BouncyCastleProvider; @@ -27,6 +32,7 @@ import java.security.KeyPair; import java.security.Security; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -40,7 +46,7 @@ public class OpenDBAPI { public static final String PURPOSE = "osmand-android"; private static final Log log = PlatformUtil.getLog(SecUtils.class); private static final String checkLoginEndpoint = "api/auth/user-check-loginkey?"; - private static final String LOGIN_SUCCESS_MESSAGE = "{\"result\":\"OK\"}"; + private static final String LOGIN_SUCCESS_MESSAGE = "\"result\":\"OK\""; private static final int THREAD_ID = 11200; /* @@ -51,7 +57,7 @@ public class OpenDBAPI { * Need to encode key * Do not call on mainThread */ - public boolean checkPrivateKeyValid(String baseUrl, String username, String privateKey) { + public boolean checkPrivateKeyValid(OsmandApplication app, String baseUrl, String username, String privateKey) { String url = null; try { String purposeParam = "purpose=" + PURPOSE; @@ -65,9 +71,27 @@ public class OpenDBAPI { } catch (UnsupportedEncodingException e) { return false; } + StringBuilder response = new StringBuilder(); - return (NetworkUtils.sendGetRequest(url,null,response) == null) && - response.toString().contains(LOGIN_SUCCESS_MESSAGE); + String error = NetworkUtils.sendGetRequest(url, null, response); + if (error == null) { + String responseStr = response.toString(); + try { + Map tagMap = new Gson().fromJson( + responseStr, new TypeToken>() { + }.getType() + ); + if (Algorithms.isEmpty(tagMap) && tagMap.containsKey("blockchain-name")) { + String blockchainName = tagMap.get("blockchain-name"); + app.getSettings().OPR_BLOCKCHAIN_NAME.set(blockchainName); + } + } catch (JsonSyntaxException e) { + return false; + } + return responseStr.contains(LOGIN_SUCCESS_MESSAGE); + } else { + return false; + } } public int uploadImage(String[] placeId, String baseUrl, String privateKey, String username, String image, StringBuilder sb) throws FailedVerificationException { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index dfaaea9468..0d3cddb136 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -1171,6 +1171,9 @@ public class OsmandSettings { public final OsmandPreference OPR_USERNAME = new StringPreference(this, "opr_username_secret", "").makeGlobal(); + public final OsmandPreference OPR_BLOCKCHAIN_NAME = + new StringPreference(this, "opr_blockchain_name", "").makeGlobal(); + // this value boolean is synchronized with settings_pref.xml preference offline POI/Bugs edition public final OsmandPreference OFFLINE_EDITION = new BooleanPreference(this, "offline_osm_editing", true).makeGlobal().makeShared(); public final OsmandPreference USE_DEV_URL = new BooleanPreference(this, "use_dev_url", false).makeGlobal().makeShared(); From ef899fad821229ecefb27c317d6ac907d90520ec Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 18:58:49 +0200 Subject: [PATCH 40/53] Small fix --- OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java index 14c0e97672..62612f2ffe 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java @@ -77,13 +77,15 @@ public class OpenDBAPI { if (error == null) { String responseStr = response.toString(); try { - Map tagMap = new Gson().fromJson( + Map map = new Gson().fromJson( responseStr, new TypeToken>() { }.getType() ); - if (Algorithms.isEmpty(tagMap) && tagMap.containsKey("blockchain-name")) { - String blockchainName = tagMap.get("blockchain-name"); + if (Algorithms.isEmpty(map) && map.containsKey("blockchain-name")) { + String blockchainName = map.get("blockchain-name"); app.getSettings().OPR_BLOCKCHAIN_NAME.set(blockchainName); + } else { + return false; } } catch (JsonSyntaxException e) { return false; From b43a4e46f370b1ba4549f538352a5435303c5b93 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Thu, 28 Jan 2021 18:00:25 +0100 Subject: [PATCH 41/53] Update no_translate.xml --- OsmAnd/no_translate.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/no_translate.xml b/OsmAnd/no_translate.xml index d5ecc7c149..92d3a4034f 100644 --- a/OsmAnd/no_translate.xml +++ b/OsmAnd/no_translate.xml @@ -40,7 +40,7 @@ items modified OsmAnd Unlimited Markers - https://openplacereviews.org/ + https://test.openplacereviews.org/ https://test.openplacereviews.org/ v8G8r9NLJZGMV4he5lwbQlz620FNVARKjI9Bm5UJ jDvM95Ne1Bq2BDTmIfB6b3ZMxvdK87WGfp6DC07J From 31dc53203d727fb00be67b5b0654833bdd8d5c7d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 Jan 2021 19:04:23 +0200 Subject: [PATCH 42/53] Fix typo --- OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java index 62612f2ffe..1fdeba64f0 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/opr/OpenDBAPI.java @@ -81,7 +81,7 @@ public class OpenDBAPI { responseStr, new TypeToken>() { }.getType() ); - if (Algorithms.isEmpty(map) && map.containsKey("blockchain-name")) { + if (!Algorithms.isEmpty(map) && map.containsKey("blockchain-name")) { String blockchainName = map.get("blockchain-name"); app.getSettings().OPR_BLOCKCHAIN_NAME.set(blockchainName); } else { From 70c7e8a3676111ed088a0ab2d830d4139bbb11b8 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Thu, 28 Jan 2021 20:44:22 +0100 Subject: [PATCH 43/53] Update no_translate.xml --- OsmAnd/no_translate.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/no_translate.xml b/OsmAnd/no_translate.xml index 92d3a4034f..d5ecc7c149 100644 --- a/OsmAnd/no_translate.xml +++ b/OsmAnd/no_translate.xml @@ -40,7 +40,7 @@ items modified OsmAnd Unlimited Markers - https://test.openplacereviews.org/ + https://openplacereviews.org/ https://test.openplacereviews.org/ v8G8r9NLJZGMV4he5lwbQlz620FNVARKjI9Bm5UJ jDvM95Ne1Bq2BDTmIfB6b3ZMxvdK87WGfp6DC07J From e188034530bc0ec591fe944fed8febbd4c1153c7 Mon Sep 17 00:00:00 2001 From: Jurijus Date: Thu, 28 Jan 2021 16:19:56 +0000 Subject: [PATCH 44/53] Translated using Weblate (Lithuanian) Currently translated at 59.1% (2163 of 3656 strings) --- OsmAnd/res/values-lt/strings.xml | 44 +++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/OsmAnd/res/values-lt/strings.xml b/OsmAnd/res/values-lt/strings.xml index 09ee2a83fd..3c683d41cf 100644 --- a/OsmAnd/res/values-lt/strings.xml +++ b/OsmAnd/res/values-lt/strings.xml @@ -18,9 +18,8 @@ po piet ryto Statymo vieta - Šis įskiepis leidžia įsiminti vietą, kurioje palikote savo automobilį ir kiek laiko liko iki parkavimo pabaigos (jei ribojamas laikas). - -Tiek vieta, tiek laikas yra matomi OsmAnd valdymo skydelyje bei skydelyje žemėlapyje rodinyje. Šis įskiepis taip pat gali įrašyti priminimą į kalendorių. + Šis įskiepis leidžia įsiminti vietą, kurioje palikote savo automobilį ir kiek laiko liko iki parkavimo pabaigos . +\nTiek vieta, tiek laikas yra matomi OsmAnd valdymo skydelyje bei skydelyje žemėlapyje rodinyje. Šis įskiepis taip pat gali įrašyti priminimą į Android kalendorių. Statymo vieta Žymėti statymo vietą Naikinti statymo žymę @@ -200,9 +199,8 @@ Tiek vieta, tiek laikas yra matomi OsmAnd valdymo skydelyje bei skydelyje žemė Foninis režimas Reikalinga, jei norite naudoti OsmAnd kai ekranas yra išjungtas. Neužtenka vietos parsiųsti %1$s MB (laisva: %2$s). - Atsiųsti {0} failą(-us)? -Tam prireiks {1} MB pastoviam saugojimui. -(Dabar laisvos vietos yra {2} MB.) + Atsiųsti {0} failą(-us)\? +\nTam prireiks {1} MB pastoviam saugojimui. (Dabar laisvos vietos yra {2} MB.) Permatoma tema Aparatinė biblioteka šiame įrenginyje nepalaikoma. Inicializuojama aparatinė biblioteka… @@ -778,8 +776,28 @@ Tam prireiks {1} MB pastoviam saugojimui. Vengti greitkelių Poziciją rodyti ant kelių kai naviguojama. Rodyti ant kelio - OsmAnd (OSM Automated Navigation Directions) -\nOsmAnd yra atviro kodo programa naudojanti įvairius OpenStreetMap (OSM) duomenis. Visi žemėlapių duomenys (vektoriniai ar lakštiniai) gali būti išsaugoti telefone ir naudojami be interneto prieigos. OsmAnd taip pat gali pasiūlyti maršruto skaičiavimo paslaugas internete ar įrenginyje, bei balso nurodymus kelionei apskaičiuotu maršrutu. Dalis pagrindinių savybių: - Veikia be interneto (išsaugokite parsiųstus žemėlapius ar jų lakštus įrenginyje) - Kompaktiški vektoriniai viso pasaulio žemėlapiai - Parsisųskite šalies ar regiono žemėlapius tiesiai iš pačios propgramos - Galima sulieti kelis žemėlapop sluoksnius, tokius kaip GPX ar judėjimo istoriją, Lankytinas Vietas, mėgiamas vietas, kontūrų linijas, viešojo transporto stoteles, papildomus žemėlapius su pasirinktinai nustatomu permatomumo lygiu - Adresų ir LV paieška nenaudojant interneto - Vidutinio ilgio maršruto apskaičiavimas be interneto paslaugų - Automobilio, dviračio ir pėsčiojo režimai su: - pasirinktiniu dineos/nakties rodinio perjungimu - pasirinktiniu pagal judėjimo greitį automatiškai nustatomu mąsteliu - pasirinktine žemėlapio orientacija pagal kompaso arba judėjimo kryptį - pasirinktinis eismo juostų nurodymas, greičio ribojimų rodymas, įrašyti ar generuojami balsai Šios nemokamos OsmAnd versijos apribojimai: - Ribojamas žemėlapių parsiuntimų skaičius - Nėra prieigos prie iš Wikipedia parsiunčiamų LV OsmAnd yra aktyviai tobulinama ir mūsų projektas bei jo tolesnis progresas priklauso nuo finansinės paramos, kuri įgalina tolesnį vystymą ir naujų funkcijų kūrimą. Norime paskatinti jus nusipirkti OsmAnd+ programą arba finansiškai prisidėti prie specifinių funkcijų kūrimo arba šiaip paremti programą osmand.net svetainėje. + OsmAnd (OSM Automated Navigation Directions) +\n +\nOsmAnd yra atviro kodo programa naudojanti įvairius OpenStreetMap (OSM) duomenis. Visi žemėlapių duomenys (vektoriniai ar lakštiniai) gali būti išsaugoti telefone ir naudojami be interneto prieigos. OsmAnd taip pat gali pasiūlyti maršruto skaičiavimo paslaugas internete ar įrenginyje, bei balso nurodymus kelionei apskaičiuotu maršrutu. +\n +\nDalis pagrindinių savybių: +\n- Veikia be interneto (išsaugokite parsiųstus žemėlapius ar jų lakštus įrenginyje) +\n- Kompaktiški vektoriniai viso pasaulio žemėlapiai +\n- Parsisųskite šalies ar regiono žemėlapius tiesiai iš pačios propgramos +\n- Galima sulieti kelis žemėlapop sluoksnius, tokius kaip GPX ar judėjimo istoriją, Lankytinas Vietas, mėgiamas vietas, kontūrų linijas, viešojo transporto stoteles, papildomus žemėlapius su pasirinktinai nustatomu permatomumo lygiu +\n - Adresų ir LV paieška nenaudojant interneto +\n- Vidutinio ilgio maršruto apskaičiavimas be interneto prieigos +\n- Automobilio, dviračio ir pėsčiojo režimai su: +\n- pasirinktiniu dineos/nakties rodinio perjungimu +\n- pasirinktiniu pagal judėjimo greitį automatiškai nustatomu mąsteliu +\n- pasirinktine žemėlapio orientacija pagal kompaso arba judėjimo kryptį +\n- pasirinktinis eismo juostų nurodymas, greičio ribojimų rodymas, įrašyti ar generuojami balsai +\n +\nNemokamos OsmAnd versijos apribojimai: +\n- Ribojamas žemėlapių parsiuntimų skaičius +\n- Nėra prieigos prie iš Wikipedia parsiunčiamų LV +\n +\n OsmAnd yra aktyviai tobulinama ir mūsų projektas bei jo tolesnis progresas priklauso nuo finansinės paramos, kuri įgalina tolesnį vystymą ir naujų funkcijų kūrimą. Norime paskatinti jus nusipirkti OsmAnd+ programą arba finansiškai prisidėti prie specifinių funkcijų kūrimo arba šiaip paremti programą https://osmand.net svetainėje. OsmAnd - atviro kodo navigacijos programa su žemėlapiais OsmAnd+ (OSM Automated Navigation Directions) \n @@ -1872,9 +1890,9 @@ Failams reikalinga {3} MB laikinam ir {1} MB pastoviam saugojimui. Prenumerata leidžia kas valandą gauti visų pasaulio žemėlapių atnaujinimus. Dalis pajamų grįžta OSM bendruomenei ir apmokamas kiekvienas indėlis į OSM kūrimą. Tai yra puikus būdas paremti OsmAnd ir OSM, jei jie jums patinka. - Ar siųsti {0} failų? - Failams reikalinga {3} MB laikinam ir {1} MB pastoviam saugojimui. - (Šiuo metu prieinama tik {2} MB vietos.) + Ar siųsti {0} failų\? +\nFailams reikalinga {3} MB laikinam ir {1} MB pastoviam saugojimui. +\n(Šiuo metu prieinama tik {2} MB vietos.) Ispanų (Amerikos) Anglų (Junginė Karalystė) Belarusų (Lotynų) @@ -2419,7 +2437,9 @@ Tai yra puikus būdas paremti OsmAnd ir OSM, jei jie jums patinka. Paskutinį kartą naudota: %1$s Taisymų %1$s, suma %2$s mBTC Laosiečių - OsmAnd (OSM Automated Navigation Directions) yra žemėlapio ir navigacijos programa su prieiga prie nemokamų, pasaulinių ir aukštos kokybės OpenStreetMap (OSM) duomenų. Naudokitės balso ir vaizdo navigatoriumi, peržiūrėkite LV (lankytinas vietas), kurkite ir valdytkite GPX kelius, naudojkite kontūro linijos vizualizaciją ir aukščio info (įskiepių pagalba), pasirinkite vairavimo, dviračių, pėsčiųjų režimus, redaguokite OSM duomenis ir daug daugiau. + OsmAnd (OSM Automated Navigation Directions) yra žemėlapio ir navigacijos programa su prieiga prie nemokamų, pasaulinių ir aukštos kokybės OpenStreetMap (OSM) duomenų. +\n +\nNaudokitės balso ir vaizdo navigatoriumi, peržiūrėkite LV (lankytinas vietas), kurkite ir valdytkite GPX kelius, naudojkite kontūro linijos vizualizaciją ir aukščio info (įskiepių pagalba), pasirinkite vairavimo, dviračių, pėsčiųjų režimus, redaguokite OSM duomenis ir daug daugiau. Nuostatos pavadinimas Bakstelėję veiksmo mygtuką pridėsite žemėlapio žymeklį ekrano centre. Bakstelėję veiksmo mygtuką pridėsite garso įrašą ekrano centre. From b5f01a1c7f117a5756b2f6f65c7678ac601c048b Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 29 Jan 2021 04:04:33 +0200 Subject: [PATCH 45/53] add the ability to save the global settings of Wikipedia Languages --- .../SelectWikiLanguagesBottomSheet.java | 52 +++++++++++++++++-- .../plus/wikipedia/WikipediaPlugin.java | 31 +++++++++-- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java index 873feba53c..da3b6f106d 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java @@ -1,8 +1,12 @@ package net.osmand.plus.wikipedia; +import android.app.Activity; import android.content.res.Resources; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.text.SpannableString; +import android.text.style.StyleSpan; import android.view.View; import android.widget.CompoundButton; @@ -12,6 +16,8 @@ import androidx.core.content.ContextCompat; import androidx.core.os.ConfigurationCompat; import androidx.core.os.LocaleListCompat; +import com.google.android.material.snackbar.Snackbar; + import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -124,6 +130,12 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen } } + @Nullable + public MapActivity getMapActivity() { + Activity activity = getActivity(); + return (MapActivity) activity; + } + private void initLanguagesData() { languages = new ArrayList<>(); @@ -188,12 +200,44 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen localesForSaving.add(language.getLocale()); } } - wikiPlugin.setLanguagesToShow(localesForSaving); - wikiPlugin.setShowAllLanguages(isGlobalWikiPoiEnabled); - wikiPlugin.updateWikipediaState(); + applyPreferenceWithSnackBar(localesForSaving, isGlobalWikiPoiEnabled); dismiss(); } + protected final void applyPreference(boolean applyToAllProfiles, List localesForSaving, boolean global) { + if (applyToAllProfiles) { + for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { + wikiPlugin.setLanguagesToShow(mode, localesForSaving); + wikiPlugin.setShowAllLanguages(mode, global); + } + } else { + wikiPlugin.setLanguagesToShow(localesForSaving); + wikiPlugin.setShowAllLanguages(isGlobalWikiPoiEnabled); + } + + wikiPlugin.updateWikipediaState(); + } + + protected void applyPreferenceWithSnackBar(final List localesForSaving, final boolean global) { + applyPreference(false, localesForSaving, global); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + String modeName = appMode.toHumanString(); + String text = app.getString(R.string.changes_applied_to_profile, modeName); + SpannableString message = UiUtilities.createSpannableString(text, new StyleSpan(Typeface.BOLD), modeName); + Snackbar snackbar = Snackbar.make(mapActivity.getLayout(), message, Snackbar.LENGTH_LONG) + .setAction(R.string.apply_to_all_profiles, new View.OnClickListener() { + @Override + public void onClick(View view) { + applyPreference(true, localesForSaving, global); + } + }); + UiUtilities.setupSnackbarVerticalLayout(snackbar); + UiUtilities.setupSnackbar(snackbar, nightMode); + snackbar.show(); + } + } + private View getCustomButtonView() { OsmandApplication app = getMyApplication(); if (app == null) { @@ -265,7 +309,7 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen } public static void showInstance(@NonNull MapActivity mapActivity, - boolean usedOnMap) { + boolean usedOnMap) { SelectWikiLanguagesBottomSheet fragment = new SelectWikiLanguagesBottomSheet(); fragment.setUsedOnMap(usedOnMap); fragment.show(mapActivity.getSupportFragmentManager(), SelectWikiLanguagesBottomSheet.TAG); diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java index 16684fbe25..88b7618185 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java @@ -30,6 +30,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.search.QuickSearchListAdapter; import net.osmand.plus.search.listitems.QuickSearchBannerListItem; import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem; +import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.layers.DownloadedRegionsLayer; import net.osmand.plus.views.OsmandMapTileView; @@ -97,8 +98,8 @@ public class WikipediaPlugin extends OsmandPlugin { @Override protected void registerLayerContextMenuActions(OsmandMapTileView mapView, - ContextMenuAdapter adapter, - final MapActivity mapActivity) { + ContextMenuAdapter adapter, + final MapActivity mapActivity) { ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() { @Override @@ -113,7 +114,7 @@ public class WikipediaPlugin extends OsmandPlugin { @Override public boolean onContextMenuClick(final ArrayAdapter adapter, int itemId, - final int pos, boolean isChecked, int[] viewCoordinates) { + final int pos, boolean isChecked, int[] viewCoordinates) { if (itemId == R.string.shared_string_wikipedia) { toggleWikipediaPoi(isChecked, new CallbackWithObject() { @Override @@ -189,26 +190,50 @@ public class WikipediaPlugin extends OsmandPlugin { return !isShowAllLanguages() && getLanguagesToShow() != null; } + public boolean hasCustomSettings(ApplicationMode profile) { + return !isShowAllLanguages(profile) && getLanguagesToShow(profile) != null; + } + public boolean hasLanguagesFilter() { return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.get() != null; } + public boolean hasLanguagesFilter(ApplicationMode profile) { + return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getModeValue(profile) != null; + } + public boolean isShowAllLanguages() { return settings.GLOBAL_WIKIPEDIA_POI_ENABLED.get(); } + public boolean isShowAllLanguages(ApplicationMode mode) { + return settings.GLOBAL_WIKIPEDIA_POI_ENABLED.getModeValue(mode); + } + public void setShowAllLanguages(boolean showAllLanguages) { settings.GLOBAL_WIKIPEDIA_POI_ENABLED.set(showAllLanguages); } + public void setShowAllLanguages(ApplicationMode mode, boolean showAllLanguages) { + settings.GLOBAL_WIKIPEDIA_POI_ENABLED.setModeValue(mode, showAllLanguages); + } + public List getLanguagesToShow() { return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getStringsList(); } + public List getLanguagesToShow(ApplicationMode mode) { + return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getStringsListForProfile(mode); + } + public void setLanguagesToShow(List languagesToShow) { settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsList(languagesToShow); } + public void setLanguagesToShow(ApplicationMode mode, List languagesToShow) { + settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsListForProfile(mode, languagesToShow); + } + public void toggleWikipediaPoi(boolean enable, CallbackWithObject callback) { if (enable) { showWikiOnMap(); From 54763fc22d1b73dd3e6f360d53d6ceb5e586e190 Mon Sep 17 00:00:00 2001 From: cepprice Date: Fri, 29 Jan 2021 18:51:28 +0500 Subject: [PATCH 46/53] Small edit --- .../aidlapi/customization/ProfileSettingsParams.java | 9 +++++---- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java index afca79aa0e..eee80329f7 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java @@ -8,6 +8,7 @@ import net.osmand.aidlapi.AidlParams; import net.osmand.aidlapi.profile.AExportSettingsType; import java.util.ArrayList; +import java.util.List; import static net.osmand.aidlapi.profile.ExportProfileParams.SETTINGS_TYPE_KEY; @@ -21,11 +22,11 @@ public class ProfileSettingsParams extends AidlParams { private Uri profileSettingsUri; private String latestChanges; private int version; - private ArrayList settingsTypeKeyList = new ArrayList<>(); + private List settingsTypeKeyList = new ArrayList<>(); private boolean silent; private boolean replace; - public ProfileSettingsParams(Uri profileSettingsUri, ArrayList settingsTypeList, boolean replace, + public ProfileSettingsParams(Uri profileSettingsUri, List settingsTypeList, boolean replace, boolean silent, String latestChanges, int version) { this.profileSettingsUri = profileSettingsUri; for (AExportSettingsType settingsType : settingsTypeList) { @@ -65,7 +66,7 @@ public class ProfileSettingsParams extends AidlParams { return profileSettingsUri; } - public ArrayList getSettingsTypeKeys() { + public List getSettingsTypeKeys() { return settingsTypeKeyList; } @@ -82,7 +83,7 @@ public class ProfileSettingsParams extends AidlParams { bundle.putInt(VERSION_KEY, version); bundle.putString(LATEST_CHANGES_KEY, latestChanges); bundle.putParcelable(PROFILE_SETTINGS_URI_KEY, profileSettingsUri); - bundle.putStringArrayList(SETTINGS_TYPE_KEY, settingsTypeKeyList); + bundle.putStringArrayList(SETTINGS_TYPE_KEY, new ArrayList<>(settingsTypeKeyList)); bundle.putBoolean(REPLACE_KEY, replace); bundle.putBoolean(SILENT_IMPORT_KEY, silent); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 033fceff1a..3687602716 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -2296,11 +2296,11 @@ public class OsmandAidlApi { return false; } - public boolean importProfileV2(final Uri profileUri, ArrayList settingsTypeKeys, boolean replace, + public boolean importProfileV2(final Uri profileUri, List settingsTypeKeys, boolean replace, boolean silent, String latestChanges, int version) { if (profileUri != null) { Bundle bundle = new Bundle(); - bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, settingsTypeKeys); + bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, new ArrayList<>(settingsTypeKeys)); bundle.putBoolean(REPLACE_KEY, replace); bundle.putBoolean(SILENT_IMPORT_KEY, silent); bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges); From f04a181524d781955366d3b3aa8418f33d67a96f Mon Sep 17 00:00:00 2001 From: max-klaus Date: Fri, 29 Jan 2021 18:46:27 +0300 Subject: [PATCH 47/53] Fix travel in free version --- OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index aaac5e6f9e..298e3fc287 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -292,10 +292,6 @@ public class DownloadActivityType { public IndexItem parseIndexItem(OsmandApplication ctx, XmlPullParser parser) { - if (TRAVEL_FILE == this && !Version.isDeveloperVersion(ctx)) { - //todo remove "if" when .travel.obf will be used in production - return null; - } String name = parser.getAttributeValue(null, "name"); //$NON-NLS-1$ if (!isAccepted(name)) { return null; From 55a1669afbfcd6d4d68aaf11f75702626c390da3 Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 29 Jan 2021 18:12:20 +0200 Subject: [PATCH 48/53] fix max-width in stats block; fix align icon to the right in stats block --- OsmAnd/res/layout/item_gpx_stat_block.xml | 44 +++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/OsmAnd/res/layout/item_gpx_stat_block.xml b/OsmAnd/res/layout/item_gpx_stat_block.xml index 18dfa5cdde..dd0ed2a571 100644 --- a/OsmAnd/res/layout/item_gpx_stat_block.xml +++ b/OsmAnd/res/layout/item_gpx_stat_block.xml @@ -10,43 +10,59 @@ android:orientation="horizontal"> + android:gravity="center_vertical" + android:orientation="horizontal" + android:weightSum="2"> - + + + + + From 9d5bd47f4a62f80bdeb17d165cf6bad7a9fde36e Mon Sep 17 00:00:00 2001 From: Skalii Date: Sun, 31 Jan 2021 02:59:28 +0200 Subject: [PATCH 49/53] fix display of distance and direction --- .../SelectedGpxMenuController.java | 4 +++- .../osmand/plus/track/TrackMenuFragment.java | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java index 5ea0766469..6e062829a6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java @@ -43,7 +43,9 @@ public class SelectedGpxMenuController extends MenuController { @Override public void buttonPressed() { mapContextMenu.hide(false); - TrackMenuFragment.showInstance(mapActivity, selectedGpxPoint.getSelectedGpxFile()); + WptPt wptPt = selectedGpxPoint.selectedPoint; + LatLon latLon = new LatLon(wptPt.lat, wptPt.lon); + TrackMenuFragment.showInstance(mapActivity, selectedGpxPoint.getSelectedGpxFile(), latLon); } }; leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_open_track); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 9147de6de9..4b58c0b9dc 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -149,6 +149,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private Location lastLocation; private UpdateLocationViewCache updateLocationViewCache; private boolean locationUpdateStarted; + private LatLon latLon; private int menuTitleHeight; private int toolbarHeightPx; @@ -259,6 +260,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card this.selectedGpxFile = selectedGpxFile; } + public void setLatLon(LatLon latLon) { + this.latLon = latLon; + } + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); @@ -556,10 +561,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card MapActivity mapActivity = getMapActivity(); View view = overviewCard.getView(); if (mapActivity != null && view != null) { - MapContextMenu menu = mapActivity.getContextMenu(); TextView distanceText = (TextView) view.findViewById(R.id.distance); ImageView direction = (ImageView) view.findViewById(R.id.direction); - app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); + app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, latLon); } } @@ -1113,7 +1117,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(path); } if (selectedGpxFile != null) { - showInstance(mapActivity, selectedGpxFile); + showInstance(mapActivity, selectedGpxFile, null); } else if (!Algorithms.isEmpty(path)) { String title = app.getString(R.string.loading_smth, ""); final ProgressDialog progress = ProgressDialog.show(mapActivity, title, app.getString(R.string.loading_data)); @@ -1126,7 +1130,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null) { OsmandApplication app = mapActivity.getMyApplication(); SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(result, true, false); - showInstance(mapActivity, selectedGpxFile); + showInstance(mapActivity, selectedGpxFile, null); } if (progress != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) { progress.dismiss(); @@ -1138,7 +1142,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } - public static boolean showInstance(@NonNull MapActivity mapActivity, SelectedGpxFile selectedGpxFile) { + public static boolean showInstance(@NonNull MapActivity mapActivity, SelectedGpxFile selectedGpxFile, @Nullable LatLon latLon) { try { Bundle args = new Bundle(); args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY); @@ -1148,6 +1152,14 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card fragment.setRetainInstance(true); fragment.setSelectedGpxFile(selectedGpxFile); + if (latLon != null) { + fragment.setLatLon(latLon); + } else { + QuadRect rect = selectedGpxFile.getGpxFile().getRect(); + LatLon latLonRect = new LatLon(rect.centerY(), rect.centerX()); + fragment.setLatLon(latLonRect); + } + mapActivity.getSupportFragmentManager() .beginTransaction() .replace(R.id.fragmentContainer, fragment, TAG) From bbf341cde2dc6bdc375eb81870bd9cf1e167bf07 Mon Sep 17 00:00:00 2001 From: Skalii Date: Sun, 31 Jan 2021 12:43:14 +0200 Subject: [PATCH 50/53] add column names to the insert script for clarity in which order to insert data --- OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index b06d3bb1a5..e173a49ad1 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -94,7 +94,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper { + TRACK_COL_DATE + ", " + TRACK_COL_HEADING + ")" + " VALUES (?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$ - insertPointsScript = "INSERT INTO " + POINT_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$ + insertPointsScript = "INSERT INTO " + POINT_NAME + " (" + POINT_COL_LAT + ", " + POINT_COL_LON + ", " + + POINT_COL_DATE + ", " + POINT_COL_DESCRIPTION + ", " + POINT_COL_NAME + ", " + + POINT_COL_CATEGORY + ", " + POINT_COL_COLOR + ", " + POINT_COL_ICON + ", " + + POINT_COL_BACKGROUND + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$ } @Override From 29b9d038758e9e537f8b404b7570e1a4904594be Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sun, 31 Jan 2021 15:34:00 +0200 Subject: [PATCH 51/53] Small fix --- .../osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java index da3b6f106d..2fdf57b9be 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java @@ -212,7 +212,7 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen } } else { wikiPlugin.setLanguagesToShow(localesForSaving); - wikiPlugin.setShowAllLanguages(isGlobalWikiPoiEnabled); + wikiPlugin.setShowAllLanguages(global); } wikiPlugin.updateWikipediaState(); From 46559fc3280a4bbb4dd25a4c0e1a4841afdbf5db Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 1 Feb 2021 01:19:40 +0200 Subject: [PATCH 52/53] Small fix --- .../net/osmand/aidlapi/customization/ProfileSettingsParams.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java index eee80329f7..a22d4e3c91 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java @@ -16,7 +16,7 @@ public class ProfileSettingsParams extends AidlParams { public static final String VERSION_KEY = "version"; public static final String REPLACE_KEY = "replace"; - public static final String SILENT_IMPORT_KEY = "silent_import"; + public static final String SILENT_IMPORT_KEY = "silentImport"; public static final String LATEST_CHANGES_KEY = "latestChanges"; public static final String PROFILE_SETTINGS_URI_KEY = "profileSettingsUri"; private Uri profileSettingsUri; From 8f8ddbf9b457362e28d8b873ed208c00b871c116 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 1 Feb 2021 01:59:58 +0200 Subject: [PATCH 53/53] Try to remove duplicate code --- .../backend/backup/SettingsHelper.java | 54 +---- .../fragments/ImportSettingsFragment.java | 210 +----------------- 2 files changed, 11 insertions(+), 253 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 9a50851a56..11fe377040 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -728,6 +728,8 @@ public class SettingsHelper { } catch (IllegalArgumentException e) { LOG.warn("Trying to export unsuported file type", e); } + } else if (object instanceof FileSettingsItem) { + result.add((FileSettingsItem) object); } else if (object instanceof AvoidRoadInfo) { avoidRoads.add((AvoidRoadInfo) object); } else if (object instanceof ApplicationModeBean) { @@ -754,16 +756,20 @@ public class SettingsHelper { } } if (!quickActions.isEmpty()) { - result.add(new QuickActionsSettingsItem(app, getBaseQuickActionsSettingsItem(settingsItems), quickActions)); + QuickActionsSettingsItem baseItem = getBaseItem(SettingsItemType.QUICK_ACTIONS, QuickActionsSettingsItem.class, settingsItems); + result.add(new QuickActionsSettingsItem(app, baseItem, quickActions)); } if (!poiUIFilters.isEmpty()) { - result.add(new PoiUiFiltersSettingsItem(app, getBasePoiUiFiltersSettingsItem(settingsItems), poiUIFilters)); + PoiUiFiltersSettingsItem baseItem = getBaseItem(SettingsItemType.POI_UI_FILTERS, PoiUiFiltersSettingsItem.class, settingsItems); + result.add(new PoiUiFiltersSettingsItem(app, baseItem, poiUIFilters)); } if (!tileSourceTemplates.isEmpty()) { - result.add(new MapSourcesSettingsItem(app, getBaseMapSourcesSettingsItem(settingsItems), tileSourceTemplates)); + MapSourcesSettingsItem baseItem = getBaseItem(SettingsItemType.MAP_SOURCES, MapSourcesSettingsItem.class, settingsItems); + result.add(new MapSourcesSettingsItem(app, baseItem, tileSourceTemplates)); } if (!avoidRoads.isEmpty()) { - result.add(new AvoidRoadsSettingsItem(app, getBaseAvoidRoadsSettingsItem(settingsItems), avoidRoads)); + AvoidRoadsSettingsItem baseItem = getBaseItem(SettingsItemType.AVOID_ROADS, AvoidRoadsSettingsItem.class, settingsItems); + result.add(new AvoidRoadsSettingsItem(app, baseItem, avoidRoads)); } if (!appModeBeans.isEmpty()) { for (ApplicationModeBean modeBean : appModeBeans) { @@ -830,46 +836,6 @@ public class SettingsHelper { return null; } - @Nullable - private QuickActionsSettingsItem getBaseQuickActionsSettingsItem(List settingsItems) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.QUICK_ACTIONS) { - return (QuickActionsSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private PoiUiFiltersSettingsItem getBasePoiUiFiltersSettingsItem(List settingsItems) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.POI_UI_FILTERS) { - return (PoiUiFiltersSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private MapSourcesSettingsItem getBaseMapSourcesSettingsItem(List settingsItems) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.MAP_SOURCES) { - return (MapSourcesSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private AvoidRoadsSettingsItem getBaseAvoidRoadsSettingsItem(List settingsItems) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.AVOID_ROADS) { - return (AvoidRoadsSettingsItem) settingsItem; - } - } - return null; - } - @Nullable private T getBaseItem(SettingsItemType settingsItemType, Class clazz, List settingsItems) { for (SettingsItem settingsItem : settingsItems) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 83a271b059..b614bc57dd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -18,57 +18,24 @@ import androidx.fragment.app.FragmentManager; import com.google.android.material.appbar.CollapsingToolbarLayout; -import net.osmand.IndexConstants; import net.osmand.PlatformUtil; -import net.osmand.map.ITileSource; -import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.AppInitializer; -import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; -import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.download.ReloadIndexesTask; import net.osmand.plus.download.ReloadIndexesTask.ReloadIndexesListener; -import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; -import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; -import net.osmand.plus.mapmarkers.MapMarker; -import net.osmand.plus.mapmarkers.MapMarkersGroup; -import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; -import net.osmand.plus.osmedit.OpenstreetmapPoint; -import net.osmand.plus.osmedit.OsmNotesPoint; -import net.osmand.plus.poi.PoiUIFilter; -import net.osmand.plus.quickaction.QuickAction; -import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean; -import net.osmand.plus.settings.backend.ExportSettingsType; -import net.osmand.plus.settings.backend.backup.AvoidRoadsSettingsItem; -import net.osmand.plus.settings.backend.backup.FavoritesSettingsItem; import net.osmand.plus.settings.backend.backup.FileSettingsItem; -import net.osmand.plus.settings.backend.backup.GlobalSettingsItem; -import net.osmand.plus.settings.backend.backup.GpxSettingsItem; -import net.osmand.plus.settings.backend.backup.HistoryMarkersSettingsItem; -import net.osmand.plus.settings.backend.backup.MapSourcesSettingsItem; -import net.osmand.plus.settings.backend.backup.MarkersSettingsItem; -import net.osmand.plus.settings.backend.backup.OnlineRoutingSettingsItem; -import net.osmand.plus.settings.backend.backup.OsmEditsSettingsItem; -import net.osmand.plus.settings.backend.backup.OsmNotesSettingsItem; -import net.osmand.plus.settings.backend.backup.PoiUiFiltersSettingsItem; -import net.osmand.plus.settings.backend.backup.ProfileSettingsItem; -import net.osmand.plus.settings.backend.backup.QuickActionsSettingsItem; -import net.osmand.plus.settings.backend.backup.SearchHistorySettingsItem; import net.osmand.plus.settings.backend.backup.SettingsHelper; import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportAsyncTask; import net.osmand.plus.settings.backend.backup.SettingsItem; -import net.osmand.plus.settings.backend.backup.SettingsItemType; -import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import java.io.File; import java.lang.ref.WeakReference; -import java.util.ArrayList; import java.util.List; public class ImportSettingsFragment extends BaseSettingsListFragment { @@ -177,7 +144,7 @@ public class ImportSettingsFragment extends BaseSettingsListFragment { } private void importItems() { - List selectedItems = getSettingsItemsFromData(adapter.getData()); + List selectedItems = settingsHelper.prepareSettingsItems(adapter.getData(), settingsItems, false); if (file != null && settingsItems != null) { duplicateStartTime = System.currentTimeMillis(); settingsHelper.checkDuplicates(file, settingsItems, selectedItems, getDuplicatesListener()); @@ -272,181 +239,6 @@ public class ImportSettingsFragment extends BaseSettingsListFragment { this.settingsItems = settingsItems; } - @Nullable - private ProfileSettingsItem getBaseProfileSettingsItem(ApplicationModeBean modeBean) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.PROFILE) { - ProfileSettingsItem profileItem = (ProfileSettingsItem) settingsItem; - ApplicationModeBean bean = profileItem.getModeBean(); - if (Algorithms.objectEquals(bean.stringKey, modeBean.stringKey) && Algorithms.objectEquals(bean.userProfileName, modeBean.userProfileName)) { - return profileItem; - } - } - } - return null; - } - - @Nullable - private QuickActionsSettingsItem getBaseQuickActionsSettingsItem() { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.QUICK_ACTIONS) { - return (QuickActionsSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private PoiUiFiltersSettingsItem getBasePoiUiFiltersSettingsItem() { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.POI_UI_FILTERS) { - return (PoiUiFiltersSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private MapSourcesSettingsItem getBaseMapSourcesSettingsItem() { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.MAP_SOURCES) { - return (MapSourcesSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private AvoidRoadsSettingsItem getBaseAvoidRoadsSettingsItem() { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.AVOID_ROADS) { - return (AvoidRoadsSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private T getBaseItem(SettingsItemType settingsItemType, Class clazz) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == settingsItemType && clazz.isInstance(settingsItem)) { - return clazz.cast(settingsItem); - } - } - return null; - } - - private List getSettingsItemsFromData(List data) { - List settingsItems = new ArrayList<>(); - List appModeBeans = new ArrayList<>(); - List quickActions = new ArrayList<>(); - List poiUIFilters = new ArrayList<>(); - List tileSourceTemplates = new ArrayList<>(); - List avoidRoads = new ArrayList<>(); - List osmNotesPointList = new ArrayList<>(); - List osmEditsPointList = new ArrayList<>(); - List favoriteGroups = new ArrayList<>(); - List markersGroups = new ArrayList<>(); - List markersHistoryGroups = new ArrayList<>(); - List historyEntries = new ArrayList<>(); - List onlineRoutingEngines = new ArrayList<>(); - for (Object object : data) { - if (object instanceof ApplicationModeBean) { - appModeBeans.add((ApplicationModeBean) object); - } else if (object instanceof QuickAction) { - quickActions.add((QuickAction) object); - } else if (object instanceof PoiUIFilter) { - poiUIFilters.add((PoiUIFilter) object); - } else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) { - tileSourceTemplates.add((ITileSource) object); - } else if (object instanceof File) { - File file = (File) object; - if (file.getName().endsWith(IndexConstants.GPX_FILE_EXT)) { - settingsItems.add(new GpxSettingsItem(app, file)); - } else { - settingsItems.add(new FileSettingsItem(app, file)); - } - } else if (object instanceof FileSettingsItem) { - settingsItems.add((FileSettingsItem) object); - } else if (object instanceof AvoidRoadInfo) { - avoidRoads.add((AvoidRoadInfo) object); - } else if (object instanceof OsmNotesPoint) { - osmNotesPointList.add((OsmNotesPoint) object); - } else if (object instanceof OpenstreetmapPoint) { - osmEditsPointList.add((OpenstreetmapPoint) object); - } else if (object instanceof FavoriteGroup) { - favoriteGroups.add((FavoriteGroup) object); - } else if (object instanceof GlobalSettingsItem) { - settingsItems.add((GlobalSettingsItem) object); - } else if (object instanceof MapMarkersGroup) { - MapMarkersGroup markersGroup = (MapMarkersGroup) object; - if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) { - markersGroups.add((MapMarkersGroup) object); - } else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) { - markersHistoryGroups.add((MapMarkersGroup) object); - } - } else if (object instanceof HistoryEntry) { - historyEntries.add((HistoryEntry) object); - } else if (object instanceof OnlineRoutingEngine) { - onlineRoutingEngines.add((OnlineRoutingEngine) object); - } - } - if (!appModeBeans.isEmpty()) { - for (ApplicationModeBean modeBean : appModeBeans) { - settingsItems.add(new ProfileSettingsItem(app, getBaseProfileSettingsItem(modeBean), modeBean)); - } - } - if (!quickActions.isEmpty()) { - settingsItems.add(new QuickActionsSettingsItem(app, getBaseQuickActionsSettingsItem(), quickActions)); - } - if (!poiUIFilters.isEmpty()) { - settingsItems.add(new PoiUiFiltersSettingsItem(app, getBasePoiUiFiltersSettingsItem(), poiUIFilters)); - } - if (!tileSourceTemplates.isEmpty()) { - settingsItems.add(new MapSourcesSettingsItem(app, getBaseMapSourcesSettingsItem(), tileSourceTemplates)); - } - if (!avoidRoads.isEmpty()) { - settingsItems.add(new AvoidRoadsSettingsItem(app, getBaseAvoidRoadsSettingsItem(), avoidRoads)); - } - if (!osmNotesPointList.isEmpty()) { - OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class); - settingsItems.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList)); - } - if (!osmEditsPointList.isEmpty()) { - OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class); - settingsItems.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList)); - } - if (!favoriteGroups.isEmpty()) { - FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class); - settingsItems.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups)); - } - if (!markersGroups.isEmpty()) { - List mapMarkers = new ArrayList<>(); - for (MapMarkersGroup group : markersGroups) { - mapMarkers.addAll(group.getMarkers()); - } - MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class); - settingsItems.add(new MarkersSettingsItem(app, baseItem, mapMarkers)); - } - if (!markersHistoryGroups.isEmpty()) { - List mapMarkers = new ArrayList<>(); - for (MapMarkersGroup group : markersHistoryGroups) { - mapMarkers.addAll(group.getMarkers()); - } - HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class); - settingsItems.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers)); - } - if (!historyEntries.isEmpty()) { - SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class); - settingsItems.add(new SearchHistorySettingsItem(app, baseItem, historyEntries)); - } - if (!onlineRoutingEngines.isEmpty()) { - OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class); - settingsItems.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines)); - } - return settingsItems; - } - public void setFile(File file) { this.file = file; }