Added automatic js tts download for the exsisting tts voices

This commit is contained in:
PaulStets 2018-08-09 14:45:31 +03:00
parent cedb9d8982
commit d954be85e3
5 changed files with 53 additions and 1 deletions

View file

@ -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;

View file

@ -67,6 +67,9 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
useJSVoiceGuidanceListener = new StateChangedListener<Boolean>() {
@Override
public void stateChanged(Boolean change) {
if (change) {
getMyApplication().getDownloadThread().copyJSVoiceGuidanceFiles();
}
getMyApplication().getDownloadThread().runReloadIndexFilesSilent();
}
};

View file

@ -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<String, IndexItem> 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<String, IndexItem> getJSTTSIndexes() {
Map<String, IndexItem> 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) {

View file

@ -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);

View file

@ -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;