diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 8c84c0d85d..cf9adea3e5 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -28,6 +28,7 @@ import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.WaypointHelper; @@ -64,9 +65,12 @@ import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Random; +import java.util.Set; import btools.routingapp.BRouterServiceConnection; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent; @@ -84,6 +88,8 @@ public class AppInitializer implements IProgress { public static final int VERSION_2_2 = 22; // 23 - 2.3 public static final int VERSION_2_3 = 23; + // 32 - 3.2 + public static final int VERSION_3_2 = 32; public static final boolean TIPS_AND_TRICKS = false; @@ -175,6 +181,9 @@ public class AppInitializer implements IProgress { } if(prevAppVersion < VERSION_2_3) { startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit(); + } else if (prevAppVersion < VERSION_3_2) { + startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit(); + app.getDownloadThread().copyJSVoiceGuidanceFiles(); } startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); appVersionChanged = true; diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index 70665ad117..7f437cd040 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -67,6 +67,9 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { useJSVoiceGuidanceListener = new StateChangedListener() { @Override public void stateChanged(Boolean change) { + if (change) { + getMyApplication().getDownloadThread().copyJSVoiceGuidanceFiles(); + } getMyApplication().getDownloadThread().runReloadIndexFilesSilent(); } }; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 0add825ca8..f109a897c4 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -43,8 +43,10 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; @@ -98,6 +100,43 @@ public class DownloadIndexesThread { } } + public void copyJSVoiceGuidanceFiles() { + File extStorage = app.getAppPath(IndexConstants.VOICE_INDEX_DIR); + Map jsFiles = getJSTTSIndexes(); + if (extStorage.exists()) { + for (File f : extStorage.listFiles()) { + if (f.isDirectory()) { + if (jsFiles.containsKey(f.getName()) && !shouldSkip(f)) { + runDownloadFiles(jsFiles.get(f.getName())); + } + } + } + } + } + + private boolean shouldSkip(File voiceDir) { + for (File f : voiceDir.listFiles()) { + if (f.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) { + return true; + } + } + return false; + } + + private Map getJSTTSIndexes() { + Map items = new HashMap<>(); + DownloadOsmandIndexesHelper.IndexFileList indexFileList = new DownloadOsmandIndexesHelper.IndexFileList(); + DownloadOsmandIndexesHelper.listVoiceAssets(indexFileList, app.getAssets(), app.getPackageManager(), app.getSettings()); + for (IndexItem item : indexFileList.getIndexFiles()) { + if (item.getType() == DownloadActivityType.VOICE_FILE && !item.isDownloaded()) { + if (item.getFileName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) { + items.put(item.getBasename(), item); + } + } + } + return items; + } + @UiThread protected void downloadInProgress() { if (uiActivity != null) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index 2927a3f579..167d366397 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -141,7 +141,7 @@ public class DownloadOsmandIndexesHelper { return assets; } - private static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm, + public static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm, OsmandSettings settings) { try { String ext = DownloadActivityType.addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 80d7063e28..6230bc110f 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.text.ParseException; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List;