Improved ability to download missing js tts files on option select and first start
This commit is contained in:
parent
7e05b41202
commit
0935f2b465
5 changed files with 25 additions and 24 deletions
|
@ -181,7 +181,7 @@ 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);
|
||||
app.getResourceManager().copyMissingJSAssets();
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit();
|
||||
}
|
||||
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
||||
|
|
|
@ -23,7 +23,6 @@ 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;
|
||||
|
@ -70,7 +69,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
|
|||
@Override
|
||||
public void stateChanged(Boolean change) {
|
||||
if (change) {
|
||||
DownloadOsmandIndexesHelper.copyMissingJSAssets(getMyApplication());
|
||||
getMyApplication().getResourceManager().copyMissingJSAssets();
|
||||
}
|
||||
getMyApplication().getDownloadThread().runReloadIndexFilesSilent();
|
||||
}
|
||||
|
|
|
@ -251,7 +251,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
|
|||
addButton(ll, "Roundabouts: prepareTurn, makeTurnIn, turn:", builder(p));
|
||||
addButton(ll, "\u25BA (5.1) After 1250m enter a roundabout", !isJS ? builder(p).prepareRoundAbout(1250, 3, street(p,"", "I 15", "Los Angeles")) :
|
||||
jsBuilder(p).prepareRoundAbout(1250, 3, jsStreet(p,"", "I 15", "Los Angeles")));
|
||||
addButton(ll, "\u25BA (5.2) In 450m enter the roundabout and take the 1st exit onto 'I 15' toward 'Los Angeles'", isJS ? builder(p).roundAbout(450, 0, 1, street(p,"", "I 15", "Los Angeles")) :
|
||||
addButton(ll, "\u25BA (5.2) In 450m enter the roundabout and take the 1st exit onto 'I 15' toward 'Los Angeles'", !isJS ? builder(p).roundAbout(450, 0, 1, street(p,"", "I 15", "Los Angeles")) :
|
||||
jsBuilder(p).roundAbout(450, 0, 1, jsStreet(p,"", "I 15", "Los Angeles")));
|
||||
addButton(ll, "\u25BA (5.3) Roundabout: Take the 2nd exit onto 'Highway 60'", !isJS ? builder(p).roundAbout(0, 2, street(p, "Highway 60")) :
|
||||
jsBuilder(p).roundAbout(0, 2, jsStreet(p, "Highway 60")));
|
||||
|
|
|
@ -124,27 +124,8 @@ public class DownloadOsmandIndexesHelper {
|
|||
listVoiceAssets(result, amanager, pm, app.getSettings());
|
||||
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 {
|
||||
public static Map<String, String> assetMapping(AssetManager assetManager) throws XmlPullParserException, IOException {
|
||||
XmlPullParser xmlParser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
InputStream isBundledAssetsXml = assetManager.open("bundled_assets.xml");
|
||||
xmlParser.setInput(isBundledAssetsXml, "UTF-8");
|
||||
|
|
|
@ -68,6 +68,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static net.osmand.plus.download.DownloadOsmandIndexesHelper.assetMapping;
|
||||
|
||||
/**
|
||||
* Resource manager is responsible to work with all resources
|
||||
* that could consume memory (especially with file resources).
|
||||
|
@ -418,6 +420,25 @@ public class ResourceManager {
|
|||
}
|
||||
return warnings;
|
||||
}
|
||||
|
||||
public void copyMissingJSAssets() {
|
||||
try {
|
||||
Map<String, String> mapping = assetMapping(context.getAssets());
|
||||
File appPath = context.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(context.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);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> checkAssets(IProgress progress, boolean forceUpdate) {
|
||||
String fv = Version.getFullVersion(context);
|
||||
|
|
Loading…
Reference in a new issue