Add default wikivoyage, fix duplicates
This commit is contained in:
parent
8aed10e530
commit
fd9b7480c6
5 changed files with 91 additions and 16 deletions
BIN
OsmAnd/assets/Default_wikivoyage.travel.obf
Normal file
BIN
OsmAnd/assets/Default_wikivoyage.travel.obf
Normal file
Binary file not shown.
|
@ -109,4 +109,5 @@
|
||||||
<asset source="sounds/camera_click.ogg" destination="sounds/camera_click.ogg" mode="copyOnlyIfDoesNotExist" />
|
<asset source="sounds/camera_click.ogg" destination="sounds/camera_click.ogg" mode="copyOnlyIfDoesNotExist" />
|
||||||
|
|
||||||
<asset source="World_basemap_mini.obf" destination="World_basemap_mini.obf" mode="alwaysOverwriteOrCopy" />
|
<asset source="World_basemap_mini.obf" destination="World_basemap_mini.obf" mode="alwaysOverwriteOrCopy" />
|
||||||
|
<asset source="Default_wikivoyage.travel.obf" destination="travel/Default_wikivoyage.travel.obf" mode="copyOnlyIfDoesNotExist" />
|
||||||
</assets>
|
</assets>
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package net.osmand.plus.wikivoyage.data;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import net.osmand.data.Amenity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PopularArticleList {
|
||||||
|
|
||||||
|
public static final int POPULAR_ARTICLES_COUNT_PER_PAGE = 30;
|
||||||
|
|
||||||
|
private final List<TravelArticle> articles;
|
||||||
|
private int pageCount;
|
||||||
|
|
||||||
|
public PopularArticleList() {
|
||||||
|
this.articles = new ArrayList<>();
|
||||||
|
pageCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PopularArticleList(@NonNull PopularArticleList articles) {
|
||||||
|
this.articles = articles.articles;
|
||||||
|
this.pageCount = articles.pageCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
articles.clear();
|
||||||
|
pageCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public List<TravelArticle> getArticles() {
|
||||||
|
return articles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(@NonNull TravelArticle article) {
|
||||||
|
articles.add(article);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(@NonNull TravelArticle article) {
|
||||||
|
return articles.contains(article);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFullPage() {
|
||||||
|
return articles.size() >= pageCount * POPULAR_ARTICLES_COUNT_PER_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nextPage() {
|
||||||
|
pageCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsAmenity(@NonNull Amenity amenity) {
|
||||||
|
for (TravelArticle article : articles) {
|
||||||
|
if (article.getRouteId().equals(amenity.getAdditionalInfo(Amenity.ROUTE_ID))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,6 +55,7 @@ import static net.osmand.GPXUtilities.TrkSegment;
|
||||||
import static net.osmand.GPXUtilities.WptPt;
|
import static net.osmand.GPXUtilities.WptPt;
|
||||||
import static net.osmand.GPXUtilities.writeGpxFile;
|
import static net.osmand.GPXUtilities.writeGpxFile;
|
||||||
import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle;
|
import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle;
|
||||||
|
import static net.osmand.plus.wikivoyage.data.PopularArticleList.POPULAR_ARTICLES_COUNT_PER_PAGE;
|
||||||
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_DOWN;
|
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.DIFF_ELE_UP;
|
||||||
import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE;
|
import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE;
|
||||||
|
@ -69,16 +70,16 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
public static final String ROUTE_ARTICLE = "route_article";
|
public static final String ROUTE_ARTICLE = "route_article";
|
||||||
public static final String ROUTE_ARTICLE_POINT = "route_article_point";
|
public static final String ROUTE_ARTICLE_POINT = "route_article_point";
|
||||||
public static final String ROUTE_TRACK = "route_track";
|
public static final String ROUTE_TRACK = "route_track";
|
||||||
public static final int ARTICLE_SEARCH_RADIUS = 50000;
|
public static final int ARTICLE_SEARCH_RADIUS = 50 * 1000;
|
||||||
public static final int SAVED_ARTICLE_SEARCH_RADIUS = 30000;
|
public static final int SAVED_ARTICLE_SEARCH_RADIUS = 30 * 1000;
|
||||||
public static final int MAX_POPULAR_ARTICLES_COUNT = 30;
|
public static final int MAX_SEARCH_RADIUS = 10000 * 1000;
|
||||||
public static final String REF_TAG = "ref";
|
public static final String REF_TAG = "ref";
|
||||||
public static final String NAME_TAG = "name";
|
public static final String NAME_TAG = "name";
|
||||||
|
|
||||||
private final OsmandApplication app;
|
private final OsmandApplication app;
|
||||||
private final Collator collator;
|
private final Collator collator;
|
||||||
|
|
||||||
private List<TravelArticle> popularArticles = new ArrayList<>();
|
private PopularArticleList popularArticles = new PopularArticleList();
|
||||||
private final Map<TravelArticleIdentifier, Map<String, TravelArticle>> cachedArticles = new ConcurrentHashMap<>();
|
private final Map<TravelArticleIdentifier, Map<String, TravelArticle>> cachedArticles = new ConcurrentHashMap<>();
|
||||||
private final TravelLocalDataHelper localDataHelper;
|
private final TravelLocalDataHelper localDataHelper;
|
||||||
private int searchRadius = ARTICLE_SEARCH_RADIUS;
|
private int searchRadius = ARTICLE_SEARCH_RADIUS;
|
||||||
|
@ -113,13 +114,13 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public synchronized List<TravelArticle> loadPopularArticles() {
|
public synchronized PopularArticleList loadPopularArticles() {
|
||||||
String lang = app.getLanguage();
|
String lang = app.getLanguage();
|
||||||
List<TravelArticle> popularArticles = new ArrayList<>(this.popularArticles);
|
PopularArticleList popularArticles = new PopularArticleList(this.popularArticles);
|
||||||
int pagesCount;
|
popularArticles.nextPage();
|
||||||
if (isAnyTravelBookPresent()) {
|
if (isAnyTravelBookPresent()) {
|
||||||
do {
|
do {
|
||||||
if (foundAmenities.size() - foundAmenitiesIndex < MAX_POPULAR_ARTICLES_COUNT) {
|
if (foundAmenities.size() - foundAmenitiesIndex < POPULAR_ARTICLES_COUNT_PER_PAGE) {
|
||||||
final LatLon location = app.getMapViewTrackingUtilities().getMapLocation();
|
final LatLon location = app.getMapViewTrackingUtilities().getMapLocation();
|
||||||
for (final BinaryMapIndexReader reader : getReaders()) {
|
for (final BinaryMapIndexReader reader : getReaders()) {
|
||||||
try {
|
try {
|
||||||
|
@ -145,21 +146,20 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
}
|
}
|
||||||
searchRadius *= 2;
|
searchRadius *= 2;
|
||||||
}
|
}
|
||||||
pagesCount = popularArticles.size() / MAX_POPULAR_ARTICLES_COUNT;
|
|
||||||
while (foundAmenitiesIndex < foundAmenities.size() - 1) {
|
while (foundAmenitiesIndex < foundAmenities.size() - 1) {
|
||||||
Pair<File, Amenity> amenity = foundAmenities.get(foundAmenitiesIndex);
|
Pair<File, Amenity> amenity = foundAmenities.get(foundAmenitiesIndex);
|
||||||
if (!Algorithms.isEmpty(amenity.second.getName(lang))) {
|
if (!Algorithms.isEmpty(amenity.second.getName(lang)) && !popularArticles.containsAmenity(amenity.second)) {
|
||||||
TravelArticle article = cacheTravelArticles(amenity.first, amenity.second, lang, false, null);
|
TravelArticle article = cacheTravelArticles(amenity.first, amenity.second, lang, false, null);
|
||||||
if (article != null && !popularArticles.contains(article)) {
|
if (article != null && !popularArticles.contains(article)) {
|
||||||
popularArticles.add(article);
|
popularArticles.add(article);
|
||||||
if (popularArticles.size() >= (pagesCount + 1) * MAX_POPULAR_ARTICLES_COUNT) {
|
if (popularArticles.isFullPage()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foundAmenitiesIndex++;
|
foundAmenitiesIndex++;
|
||||||
}
|
}
|
||||||
} while (popularArticles.size() < (pagesCount + 1) * MAX_POPULAR_ARTICLES_COUNT);
|
} while (!popularArticles.isFullPage() && searchRadius < MAX_SEARCH_RADIUS);
|
||||||
}
|
}
|
||||||
this.popularArticles = popularArticles;
|
this.popularArticles = popularArticles;
|
||||||
return popularArticles;
|
return popularArticles;
|
||||||
|
@ -526,7 +526,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List<TravelArticle> getPopularArticles() {
|
public List<TravelArticle> getPopularArticles() {
|
||||||
return popularArticles;
|
return popularArticles.getArticles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -51,6 +52,7 @@ import static net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity.*;
|
||||||
|
|
||||||
public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents, TravelLocalDataHelper.Listener {
|
public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents, TravelLocalDataHelper.Listener {
|
||||||
|
|
||||||
|
public static final String DEFAULT_WIKIVOYAGE_TRAVEL_OBF = "Default_wikivoyage.travel.obf";
|
||||||
private static boolean SHOW_TRAVEL_UPDATE_CARD = true;
|
private static boolean SHOW_TRAVEL_UPDATE_CARD = true;
|
||||||
private static boolean SHOW_TRAVEL_NEEDED_MAPS_CARD = true;
|
private static boolean SHOW_TRAVEL_NEEDED_MAPS_CARD = true;
|
||||||
|
|
||||||
|
@ -187,7 +189,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (app.getTravelHelper().isAnyTravelBookPresent()) {
|
if (!isOnlyDefaultTravelBookPresent()) {
|
||||||
TravelButtonCard travelButtonCard = new TravelButtonCard(app, nightMode);
|
TravelButtonCard travelButtonCard = new TravelButtonCard(app, nightMode);
|
||||||
travelButtonCard.setListener(new TravelNeededMapsCard.CardListener() {
|
travelButtonCard.setListener(new TravelNeededMapsCard.CardListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -249,8 +251,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addIndexItemCards(List<IndexItem> mainIndexItem, List<IndexItem> neededIndexItems) {
|
private void addIndexItemCards(List<IndexItem> mainIndexItem, List<IndexItem> neededIndexItems) {
|
||||||
final OsmandApplication app = getMyApplication();
|
if (isOnlyDefaultTravelBookPresent()) {
|
||||||
if (app != null && !app.getTravelHelper().isAnyTravelBookPresent()) {
|
|
||||||
this.mainIndexItems.clear();
|
this.mainIndexItems.clear();
|
||||||
this.mainIndexItems.addAll(mainIndexItem);
|
this.mainIndexItems.addAll(mainIndexItem);
|
||||||
addDownloadUpdateCard();
|
addDownloadUpdateCard();
|
||||||
|
@ -260,6 +261,18 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
addNeededMapsCard();
|
addNeededMapsCard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isOnlyDefaultTravelBookPresent() {
|
||||||
|
OsmandApplication app = getMyApplication();
|
||||||
|
if (app != null && !app.isApplicationInitializing()) {
|
||||||
|
for (BinaryMapIndexReader reader : app.getResourceManager().getTravelRepositories()) {
|
||||||
|
if (!reader.getFile().getName().equals(DEFAULT_WIKIVOYAGE_TRAVEL_OBF)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void addDownloadUpdateCard() {
|
private void addDownloadUpdateCard() {
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
if (app != null && !mainIndexItems.isEmpty() && SHOW_TRAVEL_UPDATE_CARD) {
|
if (app != null && !mainIndexItems.isEmpty() && SHOW_TRAVEL_UPDATE_CARD) {
|
||||||
|
|
Loading…
Reference in a new issue