Small fixes
This commit is contained in:
parent
f119539679
commit
f7dcf50f4b
5 changed files with 52 additions and 45 deletions
|
@ -11,7 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="file_does_not_contains_routing_rules">\'%1$s\' file doesn\'t contain routing rules, please choose another file.</string>
|
||||
<string name="file_does_not_contain_routing_rules">\'%1$s\' file doesn\'t contain routing rules, please choose another file.</string>
|
||||
<string name="not_support_file_type_with_ext">Not supported file type. You need to select a file with %1$s extension.</string>
|
||||
<string name="import_from_file">Import from file</string>
|
||||
<string name="import_routing_file">Import routing file</string>
|
||||
|
|
|
@ -690,7 +690,7 @@ public class AndroidUtils {
|
|||
return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||
}
|
||||
|
||||
public static String createFileNameWithIncreasedNumber(String oldName) {
|
||||
public static String createNewFileName(String oldName) {
|
||||
int firstDotIndex = oldName.indexOf('.');
|
||||
String nameWithoutExt = oldName.substring(0, firstDotIndex);
|
||||
String ext = oldName.substring(firstDotIndex);
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
|
@ -31,7 +32,6 @@ import net.osmand.plus.base.MapViewTrackingUtilities;
|
|||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
|
||||
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||
import net.osmand.plus.helpers.ImportHelper;
|
||||
import net.osmand.plus.helpers.LockHelper;
|
||||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
|
@ -57,11 +57,16 @@ import net.osmand.plus.voice.MediaCommandPlayerImpl;
|
|||
import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
||||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -135,6 +140,10 @@ public class AppInitializer implements IProgress {
|
|||
|
||||
void onFinish(AppInitializer init);
|
||||
}
|
||||
|
||||
public interface LoadRoutingFilesCallback {
|
||||
void onRoutingFilesLoaded();
|
||||
}
|
||||
|
||||
|
||||
public AppInitializer(OsmandApplication app) {
|
||||
|
@ -573,7 +582,7 @@ public class AppInitializer implements IProgress {
|
|||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private void getLazyRoutingConfig() {
|
||||
ImportHelper.loadRoutingFiles(app, new ImportHelper.LoadRoutingFilesCallback() {
|
||||
loadRoutingFiles(app, new LoadRoutingFilesCallback() {
|
||||
@Override
|
||||
public void onRoutingFilesLoaded() {
|
||||
notifyEvent(InitEvents.ROUTING_CONFIG_INITIALIZED);
|
||||
|
@ -581,6 +590,39 @@ public class AppInitializer implements IProgress {
|
|||
});
|
||||
}
|
||||
|
||||
public static void loadRoutingFiles(final OsmandApplication app, final LoadRoutingFilesCallback callback) {
|
||||
new AsyncTask<Void, Void, RoutingConfiguration.Builder>() {
|
||||
|
||||
@Override
|
||||
protected RoutingConfiguration.Builder doInBackground(Void... voids) {
|
||||
File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
|
||||
RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault();
|
||||
if (routingFolder.isDirectory()) {
|
||||
File[] fl = routingFolder.listFiles();
|
||||
if (fl != null && fl.length > 0) {
|
||||
for (File f : fl) {
|
||||
if (f.isFile() && f.getName().endsWith(".xml") && f.canRead()) {
|
||||
try {
|
||||
RoutingConfiguration.parseFromInputStream(new FileInputStream(f), f.getName(), builder);
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(RoutingConfiguration.Builder builder) {
|
||||
super.onPostExecute(builder);
|
||||
app.updateRoutingConfig(builder);
|
||||
callback.onRoutingFilesLoaded();
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
|
||||
public synchronized void initVoiceDataInDifferentThread(final Activity uiContext,
|
||||
final ApplicationMode applicationMode,
|
||||
|
|
|
@ -83,7 +83,7 @@ public class SettingsHelper {
|
|||
private ImportAsyncTask importTask;
|
||||
|
||||
public interface SettingsImportListener {
|
||||
void onSettingsImportFinished(boolean succeed, boolean empty, List<SettingsItem> items);
|
||||
void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items);
|
||||
}
|
||||
|
||||
public interface SettingsExportListener {
|
||||
|
|
|
@ -76,6 +76,7 @@ import java.util.zip.ZipInputStream;
|
|||
import static android.app.Activity.RESULT_OK;
|
||||
import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT;
|
||||
import static net.osmand.IndexConstants.ROUTING_FILE_EXT;
|
||||
import static net.osmand.plus.AppInitializer.loadRoutingFiles;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
|
||||
|
@ -113,10 +114,6 @@ public class ImportHelper {
|
|||
public interface OnGpxImportCompleteListener {
|
||||
void onComplete(boolean success);
|
||||
}
|
||||
|
||||
public interface LoadRoutingFilesCallback {
|
||||
void onRoutingFilesLoaded();
|
||||
}
|
||||
|
||||
public ImportHelper(final AppCompatActivity activity, final OsmandApplication app, final OsmandMapTileView mapView) {
|
||||
this.activity = activity;
|
||||
|
@ -609,38 +606,6 @@ public class ImportHelper {
|
|||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public static void loadRoutingFiles(final OsmandApplication app, final LoadRoutingFilesCallback callback) {
|
||||
new AsyncTask<Void, Void, RoutingConfiguration.Builder>() {
|
||||
@Override
|
||||
protected RoutingConfiguration.Builder doInBackground(Void... voids) {
|
||||
File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
|
||||
RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault();
|
||||
if (routingFolder.isDirectory()) {
|
||||
File[] fl = routingFolder.listFiles();
|
||||
if (fl != null && fl.length > 0) {
|
||||
for (File f : fl) {
|
||||
if (f.isFile() && f.getName().endsWith(".xml") && f.canRead()) {
|
||||
try {
|
||||
RoutingConfiguration.parseFromInputStream(new FileInputStream(f), f.getName(), builder);
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(RoutingConfiguration.Builder builder) {
|
||||
super.onPostExecute(builder);
|
||||
app.updateRoutingConfig(builder);
|
||||
callback.onRoutingFilesLoaded();
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public void chooseFileToImport(final ImportType importType, final CallbackWithObject callback) {
|
||||
final MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity == null) {
|
||||
|
@ -716,7 +681,7 @@ public class ImportHelper {
|
|||
}
|
||||
File dest = new File(routingDir, mFileName);
|
||||
while (dest.exists()) {
|
||||
mFileName = AndroidUtils.createFileNameWithIncreasedNumber(mFileName);
|
||||
mFileName = AndroidUtils.createNewFileName(mFileName);
|
||||
dest = new File(routingDir, mFileName);
|
||||
}
|
||||
return copyFile(app, dest, uri, true);
|
||||
|
@ -727,7 +692,7 @@ public class ImportHelper {
|
|||
File routingDir = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
|
||||
final File file = new File(routingDir, mFileName);
|
||||
if (error == null && file.exists()) {
|
||||
loadRoutingFiles(app, new LoadRoutingFilesCallback() {
|
||||
loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
||||
@Override
|
||||
public void onRoutingFilesLoaded() {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
|
@ -740,7 +705,7 @@ public class ImportHelper {
|
|||
callback.processResult(profileKey);
|
||||
}
|
||||
} else {
|
||||
app.showToastMessage(app.getString(R.string.file_does_not_contains_routing_rules, mFileName));
|
||||
app.showToastMessage(app.getString(R.string.file_does_not_contain_routing_rules, mFileName));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -808,7 +773,7 @@ public class ImportHelper {
|
|||
if (error == null && file.exists()) {
|
||||
app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, List<SettingsHelper.SettingsItem> items) {
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue