Merge pull request #10936 from osmandapp/finish_wikivoyage_#475
Finish wikivoyage
This commit is contained in:
commit
58f2378472
14 changed files with 173 additions and 64 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>
|
||||||
|
|
|
@ -78,20 +78,20 @@
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button_action"
|
android:id="@+id/button_action"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="33dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginLeft="@dimen/content_padding"
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
android:layout_marginStart="@dimen/content_padding"
|
android:layout_marginStart="@dimen/content_padding"
|
||||||
android:background="@drawable/buy_btn_background_light"
|
android:minWidth="@dimen/list_header_height"
|
||||||
android:minWidth="40dp"
|
android:minHeight="@dimen/list_content_padding_large"
|
||||||
android:paddingLeft="18dp"
|
android:paddingLeft="@dimen/bottom_sheet_exit_button_margin"
|
||||||
android:paddingRight="18dp"
|
android:paddingRight="@dimen/bottom_sheet_exit_button_margin"
|
||||||
android:text="@string/get_plugin"
|
android:text="@string/get_plugin"
|
||||||
android:textColor="@color/buy_button_color"
|
android:textColor="@color/text_color_tab_active_light"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:visibility="visible"
|
tools:visibility="visible"
|
||||||
android:paddingEnd="18dp"
|
android:paddingEnd="@dimen/bottom_sheet_exit_button_margin"
|
||||||
android:paddingStart="18dp" />
|
android:paddingStart="@dimen/bottom_sheet_exit_button_margin" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -94,13 +94,13 @@
|
||||||
android:layout_marginRight="@dimen/list_header_padding"
|
android:layout_marginRight="@dimen/list_header_padding"
|
||||||
android:minWidth="@dimen/list_header_height"
|
android:minWidth="@dimen/list_header_height"
|
||||||
android:minHeight="@dimen/list_content_padding_large"
|
android:minHeight="@dimen/list_content_padding_large"
|
||||||
android:paddingStart="@dimen/context_menu_progress_padding_left"
|
android:paddingStart="@dimen/bottom_sheet_exit_button_margin"
|
||||||
android:paddingLeft="@dimen/context_menu_progress_padding_left"
|
android:paddingLeft="@dimen/bottom_sheet_exit_button_margin"
|
||||||
android:paddingEnd="@dimen/context_menu_progress_padding_left"
|
android:paddingEnd="@dimen/bottom_sheet_exit_button_margin"
|
||||||
android:paddingRight="@dimen/context_menu_progress_padding_left"
|
android:paddingRight="@dimen/bottom_sheet_exit_button_margin"
|
||||||
android:text="@string/buy"
|
android:text="@string/buy"
|
||||||
android:textColor="@color/text_color_tab_active_light"
|
android:textColor="@color/text_color_tab_active_light"
|
||||||
android:visibility="gone" />
|
android:visibility="visible" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,12 @@
|
||||||
android:icon="@drawable/ic_map"
|
android:icon="@drawable/ic_map"
|
||||||
android:title="@string/shared_string_maps"/>
|
android:title="@string/shared_string_maps"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="travel_memory_used"
|
||||||
|
android:layout="@layout/data_storage_memory_used_item"
|
||||||
|
android:icon="@drawable/ic_action_wikipedia"
|
||||||
|
android:title="@string/wikivoyage_travel_guide"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="terrain_memory_used"
|
android:key="terrain_memory_used"
|
||||||
android:layout="@layout/data_storage_memory_used_item"
|
android:layout="@layout/data_storage_memory_used_item"
|
||||||
|
|
|
@ -50,10 +50,10 @@ public class DownloadResources extends DownloadResourceGroup {
|
||||||
public static final String WORLD_SEAMARKS_NAME = "World_seamarks";
|
public static final String WORLD_SEAMARKS_NAME = "World_seamarks";
|
||||||
public static final String WORLD_SEAMARKS_OLD_KEY = "world_seamarks_basemap";
|
public static final String WORLD_SEAMARKS_OLD_KEY = "world_seamarks_basemap";
|
||||||
public static final String WORLD_SEAMARKS_OLD_NAME = "World_seamarks_basemap";
|
public static final String WORLD_SEAMARKS_OLD_NAME = "World_seamarks_basemap";
|
||||||
|
public static final String WIKIVOYAGE_FILE_FILTER = "wikivoyage";
|
||||||
private static final Log LOG = PlatformUtil.getLog(DownloadResources.class);
|
private static final Log LOG = PlatformUtil.getLog(DownloadResources.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public DownloadResources(OsmandApplication app) {
|
public DownloadResources(OsmandApplication app) {
|
||||||
super(null, DownloadResourceGroupType.WORLD, "");
|
super(null, DownloadResourceGroupType.WORLD, "");
|
||||||
this.region = app.getRegions().getWorldRegion();
|
this.region = app.getRegions().getWorldRegion();
|
||||||
|
@ -369,7 +369,9 @@ public class DownloadResources extends DownloadResourceGroup {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ii.getType() == DownloadActivityType.TRAVEL_FILE) {
|
if (ii.getType() == DownloadActivityType.TRAVEL_FILE) {
|
||||||
|
if (ii.getFileName().contains(WIKIVOYAGE_FILE_FILTER)) {
|
||||||
wikivoyageMaps.addItem(ii);
|
wikivoyageMaps.addItem(ii);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String basename = ii.getBasename().toLowerCase();
|
String basename = ii.getBasename().toLowerCase();
|
||||||
|
|
|
@ -335,7 +335,8 @@ public class ItemViewHolder {
|
||||||
clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE;
|
clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE
|
} else if ((item.getType() == DownloadActivityType.WIKIPEDIA_FILE
|
||||||
|
|| item.getType() == DownloadActivityType.TRAVEL_FILE)
|
||||||
&& !Version.isPaidVersion(context.getMyApplication())) {
|
&& !Version.isPaidVersion(context.getMyApplication())) {
|
||||||
clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
|
clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
|
||||||
} else if (item.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) {
|
} else if (item.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) {
|
||||||
|
|
|
@ -88,6 +88,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
public static final String VECTOR_MAP = "#vector_map"; //$NON-NLS-1$
|
public static final String VECTOR_MAP = "#vector_map"; //$NON-NLS-1$
|
||||||
private static final String INDEXES_CACHE = "ind.cache";
|
private static final String INDEXES_CACHE = "ind.cache";
|
||||||
|
public static final String DEFAULT_WIKIVOYAGE_TRAVEL_OBF = "Default_wikivoyage.travel.obf";
|
||||||
|
|
||||||
private static final Log log = PlatformUtil.getLog(ResourceManager.class);
|
private static final Log log = PlatformUtil.getLog(ResourceManager.class);
|
||||||
|
|
||||||
|
@ -638,6 +639,8 @@ public class ResourceManager {
|
||||||
if (Version.isPaidVersion(context)) {
|
if (Version.isPaidVersion(context)) {
|
||||||
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT, files);
|
collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT, files);
|
||||||
|
} else {
|
||||||
|
collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), DEFAULT_WIKIVOYAGE_TRAVEL_OBF, files);
|
||||||
}
|
}
|
||||||
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isContourLinesPurchased(context)) {
|
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isContourLinesPurchased(context)) {
|
||||||
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
|
@ -701,7 +704,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT));
|
boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT));
|
||||||
boolean srtmMap = f.getName().contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT);
|
boolean srtmMap = f.getName().contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT);
|
||||||
if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap)) {
|
if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap && !f.getName().equals(DEFAULT_WIKIVOYAGE_TRAVEL_OBF))) {
|
||||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
if (mapReader.isBasemap()) {
|
if (mapReader.isBasemap()) {
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class DataStorageHelper {
|
||||||
public final static String MANUALLY_SPECIFIED = "manually_specified";
|
public final static String MANUALLY_SPECIFIED = "manually_specified";
|
||||||
|
|
||||||
public final static String MAPS_MEMORY = "maps_memory_used";
|
public final static String MAPS_MEMORY = "maps_memory_used";
|
||||||
|
public final static String TRAVEL_MEMORY = "travel_memory_used";
|
||||||
public final static String TERRAIN_MEMORY = "terrain_memory_used";
|
public final static String TERRAIN_MEMORY = "terrain_memory_used";
|
||||||
public final static String TRACKS_MEMORY = "tracks_memory_used";
|
public final static String TRACKS_MEMORY = "tracks_memory_used";
|
||||||
public final static String NOTES_MEMORY = "notes_memory_used";
|
public final static String NOTES_MEMORY = "notes_memory_used";
|
||||||
|
@ -52,6 +53,7 @@ public class DataStorageHelper {
|
||||||
|
|
||||||
private ArrayList<MemoryItem> memoryItems = new ArrayList<>();
|
private ArrayList<MemoryItem> memoryItems = new ArrayList<>();
|
||||||
private MemoryItem mapsMemory;
|
private MemoryItem mapsMemory;
|
||||||
|
private MemoryItem travelMemory;
|
||||||
private MemoryItem terrainMemory;
|
private MemoryItem terrainMemory;
|
||||||
private MemoryItem tracksMemory;
|
private MemoryItem tracksMemory;
|
||||||
private MemoryItem notesMemory;
|
private MemoryItem notesMemory;
|
||||||
|
@ -184,11 +186,18 @@ public class DataStorageHelper {
|
||||||
createDirectory(MAPS_PATH, false, EXTENSIONS, true),
|
createDirectory(MAPS_PATH, false, EXTENSIONS, true),
|
||||||
createDirectory(ROADS_INDEX_DIR, true, EXTENSIONS, true),
|
createDirectory(ROADS_INDEX_DIR, true, EXTENSIONS, true),
|
||||||
createDirectory(WIKI_INDEX_DIR, true, EXTENSIONS, true),
|
createDirectory(WIKI_INDEX_DIR, true, EXTENSIONS, true),
|
||||||
createDirectory(WIKIVOYAGE_INDEX_DIR, true, EXTENSIONS, true),
|
|
||||||
createDirectory(BACKUP_INDEX_DIR, true, EXTENSIONS, true))
|
createDirectory(BACKUP_INDEX_DIR, true, EXTENSIONS, true))
|
||||||
.createItem();
|
.createItem();
|
||||||
memoryItems.add(mapsMemory);
|
memoryItems.add(mapsMemory);
|
||||||
|
|
||||||
|
travelMemory = MemoryItem.builder()
|
||||||
|
.setKey(TRAVEL_MEMORY)
|
||||||
|
.setExtensions(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT)
|
||||||
|
.setDirectories(
|
||||||
|
createDirectory(WIKIVOYAGE_INDEX_DIR, true, EXTENSIONS, true))
|
||||||
|
.createItem();
|
||||||
|
memoryItems.add(travelMemory);
|
||||||
|
|
||||||
terrainMemory = MemoryItem.builder()
|
terrainMemory = MemoryItem.builder()
|
||||||
.setKey(TERRAIN_MEMORY)
|
.setKey(TERRAIN_MEMORY)
|
||||||
.setExtensions(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|
.setExtensions(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|
||||||
|
@ -270,7 +279,7 @@ public class DataStorageHelper {
|
||||||
public RefreshUsedMemoryTask calculateMemoryUsedInfo(UpdateMemoryInfoUIAdapter uiAdapter) {
|
public RefreshUsedMemoryTask calculateMemoryUsedInfo(UpdateMemoryInfoUIAdapter uiAdapter) {
|
||||||
File rootDir = new File(currentStoragePath);
|
File rootDir = new File(currentStoragePath);
|
||||||
RefreshUsedMemoryTask task = new RefreshUsedMemoryTask(uiAdapter, otherMemory, rootDir, null, null, OTHER_MEMORY);
|
RefreshUsedMemoryTask task = new RefreshUsedMemoryTask(uiAdapter, otherMemory, rootDir, null, null, OTHER_MEMORY);
|
||||||
task.execute(mapsMemory, terrainMemory, tracksMemory, notesMemory);
|
task.execute(mapsMemory, travelMemory, terrainMemory, tracksMemory, notesMemory);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
|
|
||||||
public void addNeededMapsCard(TravelNeededMapsCard card) {
|
public void addNeededMapsCard(TravelNeededMapsCard card) {
|
||||||
this.neededMapsCard = card;
|
this.neededMapsCard = card;
|
||||||
if (neededMapsCardExists(getNeededMapsCardPosition())) {
|
if (isCardExists(getNeededMapsCardPosition(), TravelNeededMapsCard.TYPE)) {
|
||||||
updateNeededMapsCard(false);
|
updateNeededMapsCard(false);
|
||||||
} else if (addItem(getNeededMapsCardPosition(), card)) {
|
} else if (addItem(getNeededMapsCardPosition(), card)) {
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
@ -172,7 +172,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = getNeededMapsCardPosition();
|
int pos = getNeededMapsCardPosition();
|
||||||
if (neededMapsCardExists(pos)) {
|
if (isCardExists(pos, TravelNeededMapsCard.TYPE)) {
|
||||||
notifyItemChanged(pos);
|
notifyItemChanged(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,28 +180,25 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
public void removeNeededMapsCard() {
|
public void removeNeededMapsCard() {
|
||||||
this.neededMapsCard = null;
|
this.neededMapsCard = null;
|
||||||
int pos = getNeededMapsCardPosition();
|
int pos = getNeededMapsCardPosition();
|
||||||
if (neededMapsCardExists(pos)) {
|
if (isCardExists(pos, TravelNeededMapsCard.TYPE)) {
|
||||||
removeItem(pos);
|
removeItem(pos);
|
||||||
notifyItemRemoved(pos);
|
notifyItemRemoved(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNeededMapsCardPosition() {
|
private int getNeededMapsCardPosition() {
|
||||||
if (downloadUpdateCardExists(FIRST_POSITION)) {
|
if (isCardExists(FIRST_POSITION, TravelDownloadUpdateCard.TYPE)) {
|
||||||
return SECOND_POSITION;
|
return SECOND_POSITION;
|
||||||
}
|
}
|
||||||
return FIRST_POSITION;
|
return FIRST_POSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean neededMapsCardExists(int position) {
|
|
||||||
return items.size() > position && items.get(position).getCardType() == TravelNeededMapsCard.TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDownloadUpdateCard(TravelDownloadUpdateCard card) {
|
public void addDownloadUpdateCard(TravelDownloadUpdateCard card) {
|
||||||
this.downloadCard = card;
|
this.downloadCard = card;
|
||||||
if (downloadUpdateCardExists(getDownloadUpdateCardPosition())) {
|
int pos = getDownloadUpdateCardPosition();
|
||||||
|
if (isCardExists(pos, TravelDownloadUpdateCard.TYPE)) {
|
||||||
updateDownloadUpdateCard(false);
|
updateDownloadUpdateCard(false);
|
||||||
} else if (addItem(getDownloadUpdateCardPosition(), card)) {
|
} else if (addItem(pos, card)) {
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +212,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = getDownloadUpdateCardPosition();
|
int pos = getDownloadUpdateCardPosition();
|
||||||
if (downloadUpdateCardExists(pos)) {
|
if (isCardExists(pos, TravelDownloadUpdateCard.TYPE)) {
|
||||||
notifyItemChanged(pos);
|
notifyItemChanged(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,7 +220,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
public void removeDownloadUpdateCard() {
|
public void removeDownloadUpdateCard() {
|
||||||
this.downloadCard = null;
|
this.downloadCard = null;
|
||||||
int pos = getDownloadUpdateCardPosition();
|
int pos = getDownloadUpdateCardPosition();
|
||||||
if (downloadUpdateCardExists(pos)) {
|
if (isCardExists(pos, TravelDownloadUpdateCard.TYPE)) {
|
||||||
removeItem(pos);
|
removeItem(pos);
|
||||||
notifyItemRemoved(pos);
|
notifyItemRemoved(pos);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +230,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
return FIRST_POSITION;
|
return FIRST_POSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean downloadUpdateCardExists(int position) {
|
private boolean isCardExists(int position, int cardType) {
|
||||||
return items.size() > position && items.get(position).getCardType() == TravelDownloadUpdateCard.TYPE;
|
return items.size() > position && items.get(position).getCardType() == cardType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -46,6 +47,8 @@ import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.osmand.plus.download.DownloadResources.WIKIVOYAGE_FILE_FILTER;
|
||||||
|
import static net.osmand.plus.resources.ResourceManager.DEFAULT_WIKIVOYAGE_TRAVEL_OBF;
|
||||||
import static net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity.*;
|
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 {
|
||||||
|
@ -186,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
|
||||||
|
@ -248,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();
|
||||||
|
@ -259,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) {
|
||||||
|
@ -286,7 +300,8 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onIndexItemClick(IndexItem item) {
|
public void onIndexItemClick(IndexItem item) {
|
||||||
if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE && !Version.isPaidVersion(app)) {
|
if ((item.getType() == DownloadActivityType.WIKIPEDIA_FILE
|
||||||
|
|| item.getType() == DownloadActivityType.TRAVEL_FILE) && !Version.isPaidVersion(app)) {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
if (fm != null) {
|
if (fm != null) {
|
||||||
ChoosePlanDialogFragment.showWikipediaInstance(fm);
|
ChoosePlanDialogFragment.showWikipediaInstance(fm);
|
||||||
|
@ -341,7 +356,8 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onIndexItemClick(IndexItem item) {
|
public void onIndexItemClick(IndexItem item) {
|
||||||
if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE && !Version.isPaidVersion(app)) {
|
if ((item.getType() == DownloadActivityType.WIKIPEDIA_FILE
|
||||||
|
|| item.getType() == DownloadActivityType.TRAVEL_FILE) && !Version.isPaidVersion(app)) {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
if (fm != null) {
|
if (fm != null) {
|
||||||
ChoosePlanDialogFragment.showWikipediaInstance(fm);
|
ChoosePlanDialogFragment.showWikipediaInstance(fm);
|
||||||
|
@ -403,7 +419,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
List<IndexItem> allWikivoyageItems = app.getDownloadThread().getIndexes().getWikivoyageItems();
|
List<IndexItem> allWikivoyageItems = app.getDownloadThread().getIndexes().getWikivoyageItems();
|
||||||
if (allWikivoyageItems != null) {
|
if (allWikivoyageItems != null) {
|
||||||
for (IndexItem item : allWikivoyageItems) {
|
for (IndexItem item : allWikivoyageItems) {
|
||||||
if (!item.isDownloaded() && !mainItems.contains(item)) {
|
if (!item.isDownloaded()
|
||||||
|
&& !mainItems.contains(item)
|
||||||
|
&& item.getFileName().contains(WIKIVOYAGE_FILE_FILTER)) {
|
||||||
mainItems.add(item);
|
mainItems.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
||||||
boolean downloading = downloadThread.isDownloading(item);
|
boolean downloading = downloadThread.isDownloading(item);
|
||||||
boolean currentDownloading = downloading && downloadThread.getCurrentDownloadingItem() == item;
|
boolean currentDownloading = downloading && downloadThread.getCurrentDownloadingItem() == item;
|
||||||
boolean lastItem = i == items.size() - 1;
|
boolean lastItem = i == items.size() - 1;
|
||||||
View view = holder.itemsContainer.getChildAt(i);
|
final View view = holder.itemsContainer.getChildAt(i);
|
||||||
|
|
||||||
if (item.isDownloaded()) {
|
if (item.isDownloaded()) {
|
||||||
view.setOnClickListener(null);
|
view.setOnClickListener(null);
|
||||||
|
@ -131,12 +131,23 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
||||||
if (item.isDownloaded()) {
|
if (item.isDownloaded()) {
|
||||||
iconAction.setVisibility(View.GONE);
|
iconAction.setVisibility(View.GONE);
|
||||||
buttonAction.setVisibility(View.GONE);
|
buttonAction.setVisibility(View.GONE);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
boolean showBtn = !paidVersion && item.getType() == DownloadActivityType.WIKIPEDIA_FILE;
|
boolean showBtn = !paidVersion
|
||||||
|
&& (item.getType() == DownloadActivityType.WIKIPEDIA_FILE
|
||||||
|
|| item.getType() == DownloadActivityType.TRAVEL_FILE);
|
||||||
iconAction.setVisibility(showBtn ? View.GONE : View.VISIBLE);
|
iconAction.setVisibility(showBtn ? View.GONE : View.VISIBLE);
|
||||||
buttonAction.setVisibility(showBtn ? View.VISIBLE : View.GONE);
|
buttonAction.setVisibility(showBtn ? View.VISIBLE : View.GONE);
|
||||||
if (!showBtn) {
|
if (showBtn) {
|
||||||
|
buttonAction.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
view.callOnClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
iconAction.setImageDrawable(downloading ? cancelIcon : downloadIcon);
|
iconAction.setImageDrawable(downloading ? cancelIcon : downloadIcon);
|
||||||
|
buttonAction.setOnClickListener(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +206,7 @@ public class TravelNeededMapsCard extends BaseTravelCard {
|
||||||
* @return true if button is visible, false otherwise.
|
* @return true if button is visible, false otherwise.
|
||||||
*/
|
*/
|
||||||
private boolean updatePrimaryButton(NeededMapsVH vh) {
|
private boolean updatePrimaryButton(NeededMapsVH vh) {
|
||||||
if (showPrimaryButton()) {
|
if (showPrimaryButton() && Version.isPaidVersion(app)) {
|
||||||
boolean enabled = isInternetAvailable();
|
boolean enabled = isInternetAvailable();
|
||||||
vh.primaryBtnContainer.setVisibility(View.VISIBLE);
|
vh.primaryBtnContainer.setVisibility(View.VISIBLE);
|
||||||
vh.primaryBtnContainer.setBackgroundResource(getPrimaryBtnBgRes(enabled));
|
vh.primaryBtnContainer.setBackgroundResource(getPrimaryBtnBgRes(enabled));
|
||||||
|
|
Loading…
Reference in a new issue