Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8c55b1b717
6 changed files with 48 additions and 78 deletions
|
@ -1,5 +1,8 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
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_OLD_KEY = "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);
|
||||
|
||||
|
||||
|
@ -71,7 +73,8 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
return worldMap;
|
||||
}
|
||||
|
||||
public IndexItem getWorldWikivoyageItem() {
|
||||
@Nullable
|
||||
public IndexItem getWikivoyageItem(@NonNull String fileName) {
|
||||
String groupId = DownloadResourceGroupType.TRAVEL_GROUP.getDefaultId() + "#" +
|
||||
DownloadResourceGroupType.WIKIVOYAGE_MAPS.getDefaultId() + "#" +
|
||||
DownloadResourceGroupType.WIKIVOYAGE_HEADER.getDefaultId();
|
||||
|
@ -80,7 +83,7 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
List<IndexItem> items = wikivoyageHeader.getIndividualResources();
|
||||
if (items != null) {
|
||||
for (IndexItem ii : items) {
|
||||
if (ii.getBasename().equalsIgnoreCase(DownloadResources.WORLD_WIKIVOYAGE_NAME)) {
|
||||
if (ii.getFileName().equals(fileName)) {
|
||||
return ii;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ public class FileNameTranslationHelper {
|
|||
} else if (basename.equals(DownloadResources.WORLD_SEAMARKS_KEY) ||
|
||||
basename.equals(DownloadResources.WORLD_SEAMARKS_OLD_KEY)) {
|
||||
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);
|
||||
} else if (basename.equals("depth_contours_osmand_ext")) {
|
||||
return ctx.getString(R.string.index_item_depth_contours_osmand_ext);
|
||||
|
|
|
@ -271,17 +271,17 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
public static boolean showInstance(AppCompatActivity activity, Amenity amenity) {
|
||||
public static boolean showInstance(AppCompatActivity activity, Amenity amenity, String lang) {
|
||||
try {
|
||||
if (!amenity.getType().isWiki()) {
|
||||
return false;
|
||||
}
|
||||
OsmandApplication app = (OsmandApplication) activity.getApplication();
|
||||
String lang = app.getSettings().MAP_PREFERRED_LOCALE.get();
|
||||
|
||||
WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment();
|
||||
wikipediaDialogFragment.setAmenity(amenity);
|
||||
wikipediaDialogFragment.setLanguage(lang);
|
||||
wikipediaDialogFragment.setLanguage(lang == null ?
|
||||
app.getSettings().MAP_PREFERRED_LOCALE.get() : lang);
|
||||
wikipediaDialogFragment.setRetainInstance(true);
|
||||
wikipediaDialogFragment.show(activity.getSupportFragmentManager(), TAG);
|
||||
return true;
|
||||
|
@ -289,4 +289,8 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean showInstance(AppCompatActivity activity, Amenity amenity) {
|
||||
return showInstance(activity, amenity, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,8 +91,9 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
}
|
||||
return true;
|
||||
} else if (url.contains(WIKI_DOMAIN)) {
|
||||
String articleName = getArticleNameFromUrl(url, getLang(url));
|
||||
getWikiArticle(articleName, url);
|
||||
String lang = getLang(url);
|
||||
String articleName = getArticleNameFromUrl(url, lang);
|
||||
getWikiArticle(articleName, lang, url);
|
||||
} else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) {
|
||||
warnAboutExternalLoad(url, context, nightMode);
|
||||
} 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()
|
||||
.getWikiAmenityRepository(article.getLat(), article.getLon());
|
||||
if (indexes.isEmpty()) {
|
||||
WikivoyageArticleWikiLinkFragment.showInstance(fragmentManager, regionName == null ?
|
||||
"" : regionName, url);
|
||||
} else {
|
||||
articleSearchTask = new WikiArticleSearchTask(name, indexes, (MapActivity) context, nightMode, url);
|
||||
articleSearchTask = new WikiArticleSearchTask(name, lang, indexes, (MapActivity) context, nightMode, url);
|
||||
articleSearchTask.execute();
|
||||
}
|
||||
|
||||
|
@ -274,10 +275,12 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
private WeakReference<MapActivity> weakContext;
|
||||
private boolean isNightMode;
|
||||
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) {
|
||||
name = articleName;
|
||||
this.lang = lang;
|
||||
this.indexes = indexes;
|
||||
weakContext = new WeakReference<>(context);
|
||||
dialog = createProgressDialog();
|
||||
|
@ -317,7 +320,7 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
if (activity != null && !activity.isActivityDestroyed() && dialog != null) {
|
||||
dialog.dismiss();
|
||||
if (!found.isEmpty()) {
|
||||
WikipediaDialogFragment.showInstance(activity, found.get(0));
|
||||
WikipediaDialogFragment.showInstance(activity, found.get(0), lang);
|
||||
} else {
|
||||
warnAboutExternalLoad(url, weakContext.get(), isNightMode);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ public class WikivoyageWelcomeDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
getMyApplication().getTravelDbHelper().initTravelBooks();
|
||||
WikivoyageExploreDialogFragment.showInstance(activity.getSupportFragmentManager());
|
||||
dismiss();
|
||||
}
|
||||
|
|
|
@ -14,15 +14,11 @@ import android.widget.Toast;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
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.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
import net.osmand.plus.download.DownloadValidationManager;
|
||||
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.TravelDbHelper;
|
||||
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.TravelDownloadUpdateCard;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -47,7 +44,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
|
||||
private IndexItem indexItem;
|
||||
|
||||
private boolean worldWikivoyageDownloaded;
|
||||
private File selectedTravelBook;
|
||||
private boolean downloadIndexesRequested;
|
||||
private boolean downloadUpdateCardAdded;
|
||||
|
||||
|
@ -71,7 +68,10 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
public void newDownloadIndexes() {
|
||||
if (downloadIndexesRequested) {
|
||||
downloadIndexesRequested = false;
|
||||
indexItem = getMyApplication().getDownloadThread().getIndexes().getWorldWikivoyageItem();
|
||||
if (selectedTravelBook != null) {
|
||||
indexItem = getMyApplication().getDownloadThread().getIndexes()
|
||||
.getWikivoyageItem(selectedTravelBook.getName());
|
||||
}
|
||||
addDownloadUpdateCard(false);
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
public void downloadInProgress() {
|
||||
DownloadIndexesThread downloadThread = getMyApplication().getDownloadThread();
|
||||
IndexItem current = downloadThread.getCurrentDownloadingItem();
|
||||
indexItem = downloadThread.getIndexes().getWorldWikivoyageItem();
|
||||
if (selectedTravelBook != null) {
|
||||
indexItem = downloadThread.getIndexes().getWikivoyageItem(selectedTravelBook.getName());
|
||||
}
|
||||
if (current != null
|
||||
&& indexItem != null
|
||||
&& current == indexItem
|
||||
|
@ -109,7 +111,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
|
||||
boolean outdated = indexItem != null && indexItem.isOutdated();
|
||||
|
||||
if (!worldWikivoyageDownloaded || outdated) {
|
||||
if (selectedTravelBook == null || outdated) {
|
||||
downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated);
|
||||
downloadUpdateCard.setLoadingInProgress(loadingInProgress);
|
||||
downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() {
|
||||
|
@ -150,7 +152,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
final List<BaseTravelCard> items = new ArrayList<>();
|
||||
final OsmandApplication app = getMyApplication();
|
||||
|
||||
runWorldWikivoyageFileCheck();
|
||||
checkSelectedTravelBook();
|
||||
startEditingTravelCard = new StartEditingTravelCard(app, nightMode);
|
||||
addOpenBetaTravelCard(items, nightMode);
|
||||
items.add(startEditingTravelCard);
|
||||
|
@ -163,25 +165,23 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
return items;
|
||||
}
|
||||
|
||||
private void runWorldWikivoyageFileCheck() {
|
||||
private void checkSelectedTravelBook() {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
new CheckWorldWikivoyageTask(app, new CheckWorldWikivoyageTask.Callback() {
|
||||
@Override
|
||||
public void onCheckFinished(boolean worldWikivoyageDownloaded) {
|
||||
ExploreTabFragment.this.worldWikivoyageDownloaded = worldWikivoyageDownloaded;
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook();
|
||||
|
||||
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
|
||||
downloadIndexesRequested = true;
|
||||
app.getDownloadThread().runReloadIndexFilesSilent();
|
||||
downloadThread.runReloadIndexFilesSilent();
|
||||
} else {
|
||||
indexItem = downloadThread.getIndexes().getWorldWikivoyageItem();
|
||||
if (selectedTravelBook != null) {
|
||||
indexItem = downloadThread.getIndexes().getWikivoyageItem(selectedTravelBook.getName());
|
||||
}
|
||||
IndexItem current = downloadThread.getCurrentDownloadingItem();
|
||||
boolean loadingInProgress = current != null && indexItem != null && current == indexItem;
|
||||
addDownloadUpdateCard(loadingInProgress);
|
||||
}
|
||||
}
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void addPopularDestinations(OsmandApplication app) {
|
||||
PopularDestinationsSearchTask popularDestinationsSearchTask = new PopularDestinationsSearchTask(
|
||||
|
@ -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 TravelDbHelper travelDbHelper;
|
||||
|
|
Loading…
Reference in a new issue