From 4335926c8b1b381e65687a9d67f9ed1d21d68c61 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 19 Jun 2015 01:09:10 +0200 Subject: [PATCH] Fix wiki issues --- OsmAnd/src/net/osmand/plus/AppInitializer.java | 4 +--- .../src/net/osmand/plus/OsmandApplication.java | 11 +++++++++-- .../plus/download/DownloadIndexesThread.java | 17 ++++++++++------- .../src/net/osmand/plus/views/POIMapLayer.java | 8 +++++--- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index a68ae9bccc..68692a9ff3 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -267,9 +267,7 @@ public class AppInitializer implements IProgress { app.favorites = startupInit(new FavouritesDbHelper(app), FavouritesDbHelper.class); app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class); app.regions = startupInit(new OsmandRegions(), OsmandRegions.class); - String lang = osmandSettings.PREFERRED_LOCALE.get(); - String clang = "".equals(lang) ? new Locale(lang).getLanguage() : lang; - app.regions.setLocale(clang); + app.regions.setLocale(app.getLanguage()); app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class); app.rendererRegistry = startupInit(new RendererRegistry(app), RendererRegistry.class); app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class); diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 9142f5e1bc..4e652a54c9 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -78,7 +78,6 @@ public class OsmandApplication extends Application { Handler uiHandler; NavigationService navigationService; - private Locale preferredLocale = null; // start variables ResourceManager resourceManager; @@ -101,6 +100,7 @@ public class OsmandApplication extends Application { RoutingConfiguration.Builder defaultRoutingConfig; + private Locale preferredLocale = null; private Locale defaultLocale; private File externalStorageDirectory; @@ -131,11 +131,11 @@ public class OsmandApplication extends Application { osmandSettings = appCustomization.getOsmandSettings(); externalStorageDirectory = osmandSettings.getExternalStorageDirectory(); + checkPreferredLocale(); appInitializer.onCreateApplication(); // if(!osmandSettings.FOLLOW_THE_ROUTE.get()) { // targetPointsHelper.clearPointToNavigate(false); // } - checkPreferredLocale(); startApplication(); System.out.println("Time to start application " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms"); timeToStart = System.currentTimeMillis(); @@ -623,6 +623,13 @@ public class OsmandApplication extends Application { } } + public String getLanguage() { + if(preferredLocale != null) { + return preferredLocale.getLanguage(); + } + return Locale.getDefault().getLanguage(); + } + public RoutingConfiguration.Builder getDefaultRoutingConfig() { if(defaultRoutingConfig == null) { defaultRoutingConfig = appInitializer.getLazyDefaultRoutingConfig(); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 1c446503b1..a95a604719 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -598,14 +598,17 @@ public class DownloadIndexesThread { File file = new File(((AssetIndexItem) item).getDestFile()); oldItemSize = file.length(); } else { - oldItemSize = new File(item.getType().getDownloadFolder(app, item), sfName +"/_config.p").length(); - try { - InputStream is = ctx.getAssets(). open("voice/" + sfName + "/config.p"); - if(is != null) { - oldItemSize = is.available(); - is.close(); + File fl = new File(item.getType().getDownloadFolder(app, item), sfName +"/_config.p"); + if (fl.exists()) { + oldItemSize = fl.length(); + try { + InputStream is = ctx.getAssets().open("voice/" + sfName + "/config.p"); + if (is != null) { + itemSize = is.available(); + is.close(); + } + } catch (IOException e) { } - } catch (IOException e) { } } } diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 6302283dc6..0b5860e5ac 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -337,9 +337,11 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon public static void showDescriptionDialog(Context ctx, OsmandApplication app, Amenity a) { String lang = app.getSettings().MAP_PREFERRED_LOCALE.get(); if (a.getType().isWiki()) { - // First choice to display wiki article in should be the selected OsmAnd locale (not the map display language) - //showWiki(ctx, app, a, lang); - showWiki(ctx, app, a, app.getSettings().MAP_PREFERRED_LOCALE.get()); + String preferredLang = lang; + if(Algorithms.isEmpty(preferredLang)) { + preferredLang = app.getLanguage(); + } + showWiki(ctx, app, a, preferredLang); } else { String d = OsmAndFormatter.getAmenityDescriptionContent(app, a, false); SpannableString spannable = new SpannableString(d);