Import voice
This commit is contained in:
parent
b5f06cf3c1
commit
e9a1bad5ab
6 changed files with 22 additions and 19 deletions
|
@ -21,8 +21,6 @@ import java.io.OutputStream;
|
||||||
|
|
||||||
public class FileSettingsItem extends StreamSettingsItem {
|
public class FileSettingsItem extends StreamSettingsItem {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public enum FileSubtype {
|
public enum FileSubtype {
|
||||||
UNKNOWN("", null),
|
UNKNOWN("", null),
|
||||||
OTHER("other", ""),
|
OTHER("other", ""),
|
||||||
|
@ -50,6 +48,10 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
return this == OBF_MAP || this == WIKI_MAP || this == SRTM_MAP;
|
return this == OBF_MAP || this == WIKI_MAP || this == SRTM_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDirectory() {
|
||||||
|
return this == TTS_VOICE || this == VOICE;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSubtypeName() {
|
public String getSubtypeName() {
|
||||||
return subtypeName;
|
return subtypeName;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +125,6 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
private final File appPath;
|
private final File appPath;
|
||||||
protected FileSubtype subtype;
|
protected FileSubtype subtype;
|
||||||
private long size;
|
private long size;
|
||||||
private boolean subFolders;
|
|
||||||
|
|
||||||
public FileSettingsItem(@NonNull OsmandApplication app, @NonNull File file) throws IllegalArgumentException {
|
public FileSettingsItem(@NonNull OsmandApplication app, @NonNull File file) throws IllegalArgumentException {
|
||||||
super(app, file.getPath().replace(app.getAppPath(null).getPath(), ""));
|
super(app, file.getPath().replace(app.getAppPath(null).getPath(), ""));
|
||||||
|
@ -210,14 +211,6 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSubFolders() {
|
|
||||||
return subFolders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubFolders(boolean subFolders) {
|
|
||||||
this.subFolders = subFolders;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public File getFile() {
|
public File getFile() {
|
||||||
return file;
|
return file;
|
||||||
|
@ -253,7 +246,7 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
@Override
|
@Override
|
||||||
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
|
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
|
||||||
OutputStream output;
|
OutputStream output;
|
||||||
File dest = FileSettingsItem.this.file;
|
File dest = getDestination();
|
||||||
if (dest.exists() && !shouldReplace) {
|
if (dest.exists() && !shouldReplace) {
|
||||||
dest = renameFile(dest);
|
dest = renameFile(dest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ class SettingsExporter {
|
||||||
if (Algorithms.isEmpty(fileName)) {
|
if (Algorithms.isEmpty(fileName)) {
|
||||||
fileName = item.getDefaultFileName();
|
fileName = item.getDefaultFileName();
|
||||||
}
|
}
|
||||||
if (item instanceof FileSettingsItem && ((FileSettingsItem) item).isSubFolders()) {
|
if (item instanceof FileSettingsItem && ((FileSettingsItem) item).getSubtype().isDirectory()) {
|
||||||
File file = ((FileSettingsItem) item).getFile();
|
File file = ((FileSettingsItem) item).getFile();
|
||||||
zipDirsWithFiles(file, writer, zos);
|
zipDirsWithFiles(file, writer, zos);
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,7 +97,7 @@ class SettingsExporter {
|
||||||
FileSettingsItem item = (FileSettingsItem) writer.getItem();
|
FileSettingsItem item = (FileSettingsItem) writer.getItem();
|
||||||
String zipEntryName = Algorithms.isEmpty(item.getSubtype().getSubtypeFolder())
|
String zipEntryName = Algorithms.isEmpty(item.getSubtype().getSubtypeFolder())
|
||||||
? f.getName()
|
? f.getName()
|
||||||
: f.getPath().substring(f.getPath().indexOf(item.getSubtype().getSubtypeFolder()));
|
: f.getPath().substring(f.getPath().indexOf(item.getSubtype().getSubtypeFolder()) - 1);
|
||||||
ZipEntry entry = new ZipEntry(zipEntryName);
|
ZipEntry entry = new ZipEntry(zipEntryName);
|
||||||
zos.putNextEntry(entry);
|
zos.putNextEntry(entry);
|
||||||
item.setInputStream(new FileInputStream(f));
|
item.setInputStream(new FileInputStream(f));
|
||||||
|
|
|
@ -610,9 +610,6 @@ public class SettingsHelper {
|
||||||
try {
|
try {
|
||||||
FileSettingsItem fileItem = new FileSettingsItem(app, (File) object);
|
FileSettingsItem fileItem = new FileSettingsItem(app, (File) object);
|
||||||
settingsItems.add(fileItem);
|
settingsItems.add(fileItem);
|
||||||
if (FileSubtype.getSubtypeByPath(app, ((File) object).getPath()) == FileSubtype.VOICE) {
|
|
||||||
fileItem.setSubFolders(true);
|
|
||||||
}
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
LOG.warn("Trying to export unsuported file type", e);
|
LOG.warn("Trying to export unsuported file type", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT;
|
||||||
|
|
||||||
class SettingsImporter {
|
class SettingsImporter {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private final OsmandApplication app;
|
||||||
|
|
||||||
SettingsImporter(@NonNull OsmandApplication app) {
|
SettingsImporter(@NonNull OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
@ -124,6 +124,7 @@ class SettingsImporter {
|
||||||
try {
|
try {
|
||||||
SettingsItemReader<? extends SettingsItem> reader = item.getReader();
|
SettingsItemReader<? extends SettingsItem> reader = item.getReader();
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
|
reader.setDestination(app.getAppPath(fileName));
|
||||||
reader.readFromStream(ois);
|
reader.readFromStream(ois);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
@ -88,7 +89,7 @@ public abstract class SettingsItem {
|
||||||
|
|
||||||
public boolean applyFileName(@NonNull String fileName) {
|
public boolean applyFileName(@NonNull String fileName) {
|
||||||
String n = getFileName();
|
String n = getFileName();
|
||||||
return n != null && (n.endsWith(fileName) || fileName.startsWith(n));
|
return n != null && (n.endsWith(fileName) || fileName.startsWith(n + File.separator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldReadOnCollecting() {
|
public boolean shouldReadOnCollecting() {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.settings.backend.backup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@ -9,9 +10,19 @@ public abstract class SettingsItemReader<T extends SettingsItem> {
|
||||||
|
|
||||||
private T item;
|
private T item;
|
||||||
|
|
||||||
|
File destination;
|
||||||
|
|
||||||
public SettingsItemReader(@NonNull T item) {
|
public SettingsItemReader(@NonNull T item) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDestination(File destination) {
|
||||||
|
this.destination = destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getDestination() {
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException;
|
public abstract void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue