Download missing js files
This commit is contained in:
parent
a8b28ccb9e
commit
5bcb0a55fd
4 changed files with 26 additions and 40 deletions
|
@ -29,6 +29,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.DownloadOsmandIndexesHelper;
|
||||
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
|
||||
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
|
@ -180,8 +181,8 @@ 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) {
|
||||
DownloadOsmandIndexesHelper.copyMissingJSAssets(app);
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit();
|
||||
app.getDownloadThread().copyJSVoiceGuidanceFiles();
|
||||
}
|
||||
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
||||
appVersionChanged = true;
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.preference.PreferenceScreen;
|
|||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndLocationSimulation;
|
||||
|
@ -22,6 +23,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.SettingsBaseActivity;
|
||||
import net.osmand.plus.activities.actions.AppModeDialog;
|
||||
import net.osmand.plus.download.DownloadOsmandIndexesHelper;
|
||||
import net.osmand.util.SunriseSunset;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -68,7 +70,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
|
|||
@Override
|
||||
public void stateChanged(Boolean change) {
|
||||
if (change) {
|
||||
getMyApplication().getDownloadThread().copyJSVoiceGuidanceFiles();
|
||||
DownloadOsmandIndexesHelper.copyMissingJSAssets(getMyApplication());
|
||||
}
|
||||
getMyApplication().getDownloadThread().runReloadIndexFilesSilent();
|
||||
}
|
||||
|
|
|
@ -100,43 +100,6 @@ 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) {
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.PlatformUtil;
|
|||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -124,6 +125,25 @@ public class DownloadOsmandIndexesHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void copyMissingJSAssets(OsmandApplication app) {
|
||||
try {
|
||||
Map<String, String> mapping = assetMapping(app.getAssets());
|
||||
File appPath = app.getAppPath(null);
|
||||
if (appPath.canWrite()) {
|
||||
for (Map.Entry<String,String> entry : mapping.entrySet()) {
|
||||
File jsFile = new File(appPath, entry.getValue());
|
||||
if (jsFile.getParentFile().exists() && !jsFile.exists()) {
|
||||
ResourceManager.copyAssets(app.getAssets(), entry.getKey(), jsFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (XmlPullParserException e) {
|
||||
log.error("Error while loading tts files from assets", e);
|
||||
} catch (IOException e) {
|
||||
log.error("Error while loading tts files from assets", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> assetMapping(AssetManager assetManager) throws XmlPullParserException, IOException {
|
||||
XmlPullParser xmlParser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
InputStream isBundledAssetsXml = assetManager.open("bundled_assets.xml");
|
||||
|
@ -141,7 +161,7 @@ public class DownloadOsmandIndexesHelper {
|
|||
return assets;
|
||||
}
|
||||
|
||||
public static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm,
|
||||
private static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm,
|
||||
OsmandSettings settings) {
|
||||
try {
|
||||
String ext = DownloadActivityType.addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION);
|
||||
|
|
Loading…
Reference in a new issue