Merge pull request #9021 from osmandapp/import_fixes

Add check for render file extension
This commit is contained in:
vshcherb 2020-05-20 12:45:31 +02:00 committed by GitHub
commit e8c4ab139f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -90,9 +90,11 @@ public class Algorithms {
return def;
}
public static String getFileNameWithoutExtension(File f) {
String name = f.getName();
return getFileNameWithoutExtension(f.getName());
}
public static String getFileNameWithoutExtension(String name) {
int i = name.indexOf('.');
if (i >= 0) {
name = name.substring(0, i);

View file

@ -876,6 +876,10 @@ public class ImportHelper {
if (!destDir.exists()) {
destDir.mkdirs();
}
if (importType == ImportType.RENDERING && !destFileName.endsWith(RENDERER_INDEX_EXT)) {
String fileName = Algorithms.getFileNameWithoutExtension(destFileName);
destFileName = fileName + RENDERER_INDEX_EXT;
}
File destFile = new File(destDir, destFileName);
while (destFile.exists()) {
destFileName = AndroidUtils.createNewFileName(destFileName);
@ -1171,7 +1175,8 @@ public class ImportHelper {
return favourites;
}
private void executeImportTask(final AsyncTask<?, ?, ?> importTask) {
@SuppressWarnings("unchecked")
private <P> void executeImportTask(final AsyncTask<P, ?, ?> importTask, final P... requests) {
if (app.isApplicationInitializing()) {
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
@ -1180,11 +1185,11 @@ public class ImportHelper {
@Override
public void onFinish(AppInitializer init) {
importTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
importTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests);
}
});
} else {
importTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
importTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests);
}
}
}