Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-28 13:19:40 +02:00
commit 8c55b1b717
6 changed files with 48 additions and 78 deletions

View file

@ -1,5 +1,8 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapDataObject;
@ -39,7 +42,6 @@ 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 WORLD_WIKIVOYAGE_NAME = "world_wikivoyage";
private static final Log LOG = PlatformUtil.getLog(DownloadResources.class); private static final Log LOG = PlatformUtil.getLog(DownloadResources.class);
@ -71,7 +73,8 @@ public class DownloadResources extends DownloadResourceGroup {
return worldMap; return worldMap;
} }
public IndexItem getWorldWikivoyageItem() { @Nullable
public IndexItem getWikivoyageItem(@NonNull String fileName) {
String groupId = DownloadResourceGroupType.TRAVEL_GROUP.getDefaultId() + "#" + String groupId = DownloadResourceGroupType.TRAVEL_GROUP.getDefaultId() + "#" +
DownloadResourceGroupType.WIKIVOYAGE_MAPS.getDefaultId() + "#" + DownloadResourceGroupType.WIKIVOYAGE_MAPS.getDefaultId() + "#" +
DownloadResourceGroupType.WIKIVOYAGE_HEADER.getDefaultId(); DownloadResourceGroupType.WIKIVOYAGE_HEADER.getDefaultId();
@ -80,7 +83,7 @@ public class DownloadResources extends DownloadResourceGroup {
List<IndexItem> items = wikivoyageHeader.getIndividualResources(); List<IndexItem> items = wikivoyageHeader.getIndividualResources();
if (items != null) { if (items != null) {
for (IndexItem ii : items) { for (IndexItem ii : items) {
if (ii.getBasename().equalsIgnoreCase(DownloadResources.WORLD_WIKIVOYAGE_NAME)) { if (ii.getFileName().equals(fileName)) {
return ii; return ii;
} }
} }

View file

@ -220,7 +220,7 @@ public class FileNameTranslationHelper {
} else if (basename.equals(DownloadResources.WORLD_SEAMARKS_KEY) || } else if (basename.equals(DownloadResources.WORLD_SEAMARKS_KEY) ||
basename.equals(DownloadResources.WORLD_SEAMARKS_OLD_KEY)) { basename.equals(DownloadResources.WORLD_SEAMARKS_OLD_KEY)) {
return ctx.getString(R.string.index_item_world_seamarks); return ctx.getString(R.string.index_item_world_seamarks);
} else if (basename.equals(DownloadResources.WORLD_WIKIVOYAGE_NAME)) { } else if (basename.equals("world_wikivoyage")) {
return ctx.getString(R.string.index_item_world_wikivoyage); return ctx.getString(R.string.index_item_world_wikivoyage);
} else if (basename.equals("depth_contours_osmand_ext")) { } else if (basename.equals("depth_contours_osmand_ext")) {
return ctx.getString(R.string.index_item_depth_contours_osmand_ext); return ctx.getString(R.string.index_item_depth_contours_osmand_ext);

View file

@ -271,17 +271,17 @@ public class WikipediaDialogFragment extends DialogFragment {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
public static boolean showInstance(AppCompatActivity activity, Amenity amenity) { public static boolean showInstance(AppCompatActivity activity, Amenity amenity, String lang) {
try { try {
if (!amenity.getType().isWiki()) { if (!amenity.getType().isWiki()) {
return false; return false;
} }
OsmandApplication app = (OsmandApplication) activity.getApplication(); OsmandApplication app = (OsmandApplication) activity.getApplication();
String lang = app.getSettings().MAP_PREFERRED_LOCALE.get();
WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment(); WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment();
wikipediaDialogFragment.setAmenity(amenity); wikipediaDialogFragment.setAmenity(amenity);
wikipediaDialogFragment.setLanguage(lang); wikipediaDialogFragment.setLanguage(lang == null ?
app.getSettings().MAP_PREFERRED_LOCALE.get() : lang);
wikipediaDialogFragment.setRetainInstance(true); wikipediaDialogFragment.setRetainInstance(true);
wikipediaDialogFragment.show(activity.getSupportFragmentManager(), TAG); wikipediaDialogFragment.show(activity.getSupportFragmentManager(), TAG);
return true; return true;
@ -289,4 +289,8 @@ public class WikipediaDialogFragment extends DialogFragment {
return false; return false;
} }
} }
public static boolean showInstance(AppCompatActivity activity, Amenity amenity) {
return showInstance(activity, amenity, null);
}
} }

View file

@ -91,8 +91,9 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
} }
return true; return true;
} else if (url.contains(WIKI_DOMAIN)) { } else if (url.contains(WIKI_DOMAIN)) {
String articleName = getArticleNameFromUrl(url, getLang(url)); String lang = getLang(url);
getWikiArticle(articleName, url); String articleName = getArticleNameFromUrl(url, lang);
getWikiArticle(articleName, lang, url);
} else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) { } else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) {
warnAboutExternalLoad(url, context, nightMode); warnAboutExternalLoad(url, context, nightMode);
} else if (url.startsWith(PREFIX_GEO)) { } else if (url.startsWith(PREFIX_GEO)) {
@ -181,14 +182,14 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
} }
} }
private void getWikiArticle(String name, String url) { private void getWikiArticle(String name, String lang, String url) {
List<AmenityIndexRepositoryBinary> indexes = app.getResourceManager() List<AmenityIndexRepositoryBinary> indexes = app.getResourceManager()
.getWikiAmenityRepository(article.getLat(), article.getLon()); .getWikiAmenityRepository(article.getLat(), article.getLon());
if (indexes.isEmpty()) { if (indexes.isEmpty()) {
WikivoyageArticleWikiLinkFragment.showInstance(fragmentManager, regionName == null ? WikivoyageArticleWikiLinkFragment.showInstance(fragmentManager, regionName == null ?
"" : regionName, url); "" : regionName, url);
} else { } else {
articleSearchTask = new WikiArticleSearchTask(name, indexes, (MapActivity) context, nightMode, url); articleSearchTask = new WikiArticleSearchTask(name, lang, indexes, (MapActivity) context, nightMode, url);
articleSearchTask.execute(); articleSearchTask.execute();
} }
@ -274,10 +275,12 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
private WeakReference<MapActivity> weakContext; private WeakReference<MapActivity> weakContext;
private boolean isNightMode; private boolean isNightMode;
private String url; private String url;
private String lang;
WikiArticleSearchTask(String articleName, List<AmenityIndexRepositoryBinary> indexes, WikiArticleSearchTask(String articleName, String lang, List<AmenityIndexRepositoryBinary> indexes,
MapActivity context, boolean isNightMode, String url) { MapActivity context, boolean isNightMode, String url) {
name = articleName; name = articleName;
this.lang = lang;
this.indexes = indexes; this.indexes = indexes;
weakContext = new WeakReference<>(context); weakContext = new WeakReference<>(context);
dialog = createProgressDialog(); dialog = createProgressDialog();
@ -317,7 +320,7 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
if (activity != null && !activity.isActivityDestroyed() && dialog != null) { if (activity != null && !activity.isActivityDestroyed() && dialog != null) {
dialog.dismiss(); dialog.dismiss();
if (!found.isEmpty()) { if (!found.isEmpty()) {
WikipediaDialogFragment.showInstance(activity, found.get(0)); WikipediaDialogFragment.showInstance(activity, found.get(0), lang);
} else { } else {
warnAboutExternalLoad(url, weakContext.get(), isNightMode); warnAboutExternalLoad(url, weakContext.get(), isNightMode);
} }

View file

@ -45,7 +45,6 @@ public class WikivoyageWelcomeDialogFragment extends WikivoyageBaseDialogFragmen
public void onClick(View v) { public void onClick(View v) {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity != null) { if (activity != null) {
getMyApplication().getTravelDbHelper().initTravelBooks();
WikivoyageExploreDialogFragment.showInstance(activity.getSupportFragmentManager()); WikivoyageExploreDialogFragment.showInstance(activity.getSupportFragmentManager());
dismiss(); dismiss();
} }

View file

@ -14,15 +14,11 @@ import android.widget.Toast;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard;
@ -32,6 +28,7 @@ import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard;
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -47,7 +44,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
private IndexItem indexItem; private IndexItem indexItem;
private boolean worldWikivoyageDownloaded; private File selectedTravelBook;
private boolean downloadIndexesRequested; private boolean downloadIndexesRequested;
private boolean downloadUpdateCardAdded; private boolean downloadUpdateCardAdded;
@ -71,7 +68,10 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
public void newDownloadIndexes() { public void newDownloadIndexes() {
if (downloadIndexesRequested) { if (downloadIndexesRequested) {
downloadIndexesRequested = false; downloadIndexesRequested = false;
indexItem = getMyApplication().getDownloadThread().getIndexes().getWorldWikivoyageItem(); if (selectedTravelBook != null) {
indexItem = getMyApplication().getDownloadThread().getIndexes()
.getWikivoyageItem(selectedTravelBook.getName());
}
addDownloadUpdateCard(false); addDownloadUpdateCard(false);
} }
} }
@ -80,7 +80,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
public void downloadInProgress() { public void downloadInProgress() {
DownloadIndexesThread downloadThread = getMyApplication().getDownloadThread(); DownloadIndexesThread downloadThread = getMyApplication().getDownloadThread();
IndexItem current = downloadThread.getCurrentDownloadingItem(); IndexItem current = downloadThread.getCurrentDownloadingItem();
indexItem = downloadThread.getIndexes().getWorldWikivoyageItem(); if (selectedTravelBook != null) {
indexItem = downloadThread.getIndexes().getWikivoyageItem(selectedTravelBook.getName());
}
if (current != null if (current != null
&& indexItem != null && indexItem != null
&& current == indexItem && current == indexItem
@ -109,7 +111,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
boolean outdated = indexItem != null && indexItem.isOutdated(); boolean outdated = indexItem != null && indexItem.isOutdated();
if (!worldWikivoyageDownloaded || outdated) { if (selectedTravelBook == null || outdated) {
downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated); downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated);
downloadUpdateCard.setLoadingInProgress(loadingInProgress); downloadUpdateCard.setLoadingInProgress(loadingInProgress);
downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() { downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() {
@ -150,7 +152,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
final List<BaseTravelCard> items = new ArrayList<>(); final List<BaseTravelCard> items = new ArrayList<>();
final OsmandApplication app = getMyApplication(); final OsmandApplication app = getMyApplication();
runWorldWikivoyageFileCheck(); checkSelectedTravelBook();
startEditingTravelCard = new StartEditingTravelCard(app, nightMode); startEditingTravelCard = new StartEditingTravelCard(app, nightMode);
addOpenBetaTravelCard(items, nightMode); addOpenBetaTravelCard(items, nightMode);
items.add(startEditingTravelCard); items.add(startEditingTravelCard);
@ -163,24 +165,22 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
return items; return items;
} }
private void runWorldWikivoyageFileCheck() { private void checkSelectedTravelBook() {
final OsmandApplication app = getMyApplication(); final OsmandApplication app = getMyApplication();
new CheckWorldWikivoyageTask(app, new CheckWorldWikivoyageTask.Callback() { final DownloadIndexesThread downloadThread = app.getDownloadThread();
@Override selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook();
public void onCheckFinished(boolean worldWikivoyageDownloaded) {
ExploreTabFragment.this.worldWikivoyageDownloaded = worldWikivoyageDownloaded; if (!downloadThread.getIndexes().isDownloadedFromInternet) {
DownloadIndexesThread downloadThread = app.getDownloadThread(); downloadIndexesRequested = true;
if (!downloadThread.getIndexes().isDownloadedFromInternet) { downloadThread.runReloadIndexFilesSilent();
downloadIndexesRequested = true; } else {
app.getDownloadThread().runReloadIndexFilesSilent(); if (selectedTravelBook != null) {
} else { indexItem = downloadThread.getIndexes().getWikivoyageItem(selectedTravelBook.getName());
indexItem = downloadThread.getIndexes().getWorldWikivoyageItem();
IndexItem current = downloadThread.getCurrentDownloadingItem();
boolean loadingInProgress = current != null && indexItem != null && current == indexItem;
addDownloadUpdateCard(loadingInProgress);
}
} }
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); IndexItem current = downloadThread.getCurrentDownloadingItem();
boolean loadingInProgress = current != null && indexItem != null && current == indexItem;
addDownloadUpdateCard(loadingInProgress);
}
} }
private void addPopularDestinations(OsmandApplication app) { private void addPopularDestinations(OsmandApplication app) {
@ -196,45 +196,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
} }
} }
private static class CheckWorldWikivoyageTask extends AsyncTask<Void, Void, Boolean> {
private OsmandApplication app;
private Callback callback;
CheckWorldWikivoyageTask(OsmandApplication app, Callback callback) {
this.app = app;
this.callback = callback;
}
@Override
protected Boolean doInBackground(Void... voids) {
final boolean[] worldWikivoyageDownloaded = new boolean[1];
new LocalIndexHelper(app).getLocalTravelFiles(new AbstractLoadLocalIndexTask() {
@Override
public void loadFile(LocalIndexInfo... loaded) {
for (LocalIndexInfo lii : loaded) {
if (lii.getBaseName().toLowerCase().equals(DownloadResources.WORLD_WIKIVOYAGE_NAME)) {
worldWikivoyageDownloaded[0] = true;
}
}
}
});
return worldWikivoyageDownloaded[0];
}
@Override
protected void onPostExecute(Boolean worldWikivoyageDownloaded) {
if (callback != null) {
callback.onCheckFinished(worldWikivoyageDownloaded);
}
callback = null;
}
interface Callback {
void onCheckFinished(boolean worldWikivoyageDownloaded);
}
}
private static class PopularDestinationsSearchTask extends AsyncTask<Void, TravelDbHelper, List<TravelArticle>> { private static class PopularDestinationsSearchTask extends AsyncTask<Void, TravelDbHelper, List<TravelArticle>> {
private TravelDbHelper travelDbHelper; private TravelDbHelper travelDbHelper;