Merge pull request #10127 from osmandapp/imp_exp_voice
Fix maps sorting, import duplicates
This commit is contained in:
commit
59ecd6c89b
18 changed files with 320 additions and 138 deletions
|
@ -214,7 +214,7 @@ public class LocalIndexHelper {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadVoiceData(File voiceDir, List<LocalIndexInfo> result, boolean backup, AbstractLoadLocalIndexTask loadTask) {
|
private void loadVoiceData(File voiceDir, List<LocalIndexInfo> result, boolean backup, AbstractLoadLocalIndexTask loadTask) {
|
||||||
if (voiceDir.canRead()) {
|
if (voiceDir.canRead()) {
|
||||||
//First list TTS files, they are preferred
|
//First list TTS files, they are preferred
|
||||||
for (File voiceF : listFilesSorted(voiceDir)) {
|
for (File voiceF : listFilesSorted(voiceDir)) {
|
||||||
|
|
|
@ -342,7 +342,7 @@ public class DownloadActivityType {
|
||||||
return FileNameTranslationHelper.getFontName(ctx, getBasename(indexItem));
|
return FileNameTranslationHelper.getFontName(ctx, getBasename(indexItem));
|
||||||
}
|
}
|
||||||
final String basename = getBasename(indexItem);
|
final String basename = getBasename(indexItem);
|
||||||
if (basename.endsWith(FileNameTranslationHelper.WIKI_NAME)){
|
if (basename.endsWith(FileNameTranslationHelper.WIKI_NAME)) {
|
||||||
return FileNameTranslationHelper.getWikiName(ctx, basename);
|
return FileNameTranslationHelper.getWikiName(ctx, basename);
|
||||||
}
|
}
|
||||||
// if (this == HILLSHADE_FILE){
|
// if (this == HILLSHADE_FILE){
|
||||||
|
@ -357,7 +357,7 @@ public class DownloadActivityType {
|
||||||
final int ind = basename.indexOf("addresses-nationwide");
|
final int ind = basename.indexOf("addresses-nationwide");
|
||||||
String downloadName = basename.substring(0, ind - 1) + basename.substring(ind + "addresses-nationwide".length());
|
String downloadName = basename.substring(0, ind - 1) + basename.substring(ind + "addresses-nationwide".length());
|
||||||
return osmandRegions.getLocaleName(downloadName, includingParent) +
|
return osmandRegions.getLocaleName(downloadName, includingParent) +
|
||||||
" "+ ctx.getString(R.string.index_item_nation_addresses);
|
" " + ctx.getString(R.string.index_item_nation_addresses);
|
||||||
} else if (basename.startsWith("Depth_")) {
|
} else if (basename.startsWith("Depth_")) {
|
||||||
final int extInd = basename.indexOf("osmand_ext");
|
final int extInd = basename.indexOf("osmand_ext");
|
||||||
String downloadName = extInd == -1 ? basename.substring(6, basename.length()).replace('_', ' ')
|
String downloadName = extInd == -1 ? basename.substring(6, basename.length()).replace('_', ' ')
|
||||||
|
@ -438,11 +438,11 @@ public class DownloadActivityType {
|
||||||
}
|
}
|
||||||
if (this == HILLSHADE_FILE) {
|
if (this == HILLSHADE_FILE) {
|
||||||
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length())
|
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length())
|
||||||
.replace(FileNameTranslationHelper.HILL_SHADE, "");
|
.replace(FileNameTranslationHelper.HILL_SHADE + "_", "");
|
||||||
}
|
}
|
||||||
if (this == SLOPE_FILE) {
|
if (this == SLOPE_FILE) {
|
||||||
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length())
|
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length())
|
||||||
.replace(FileNameTranslationHelper.SLOPE, "");
|
.replace(FileNameTranslationHelper.SLOPE + "_", "");
|
||||||
}
|
}
|
||||||
if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||||
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length());
|
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length());
|
||||||
|
|
|
@ -143,9 +143,9 @@ public class IndexItem implements Comparable<IndexItem> {
|
||||||
|
|
||||||
public String getTranslatedBasename() {
|
public String getTranslatedBasename() {
|
||||||
if (type == DownloadActivityType.HILLSHADE_FILE) {
|
if (type == DownloadActivityType.HILLSHADE_FILE) {
|
||||||
return (FileNameTranslationHelper.HILL_SHADE + getBasename()).replace("_", " ");
|
return (FileNameTranslationHelper.HILL_SHADE + "_" + getBasename()).replace("_", " ");
|
||||||
} else if (type == DownloadActivityType.SLOPE_FILE) {
|
} else if (type == DownloadActivityType.SLOPE_FILE) {
|
||||||
return (FileNameTranslationHelper.SLOPE + getBasename()).replace('_', ' ');
|
return (FileNameTranslationHelper.SLOPE + "_" + getBasename()).replace('_', ' ');
|
||||||
} else {
|
} else {
|
||||||
return getBasename();
|
return getBasename();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.map.OsmandRegions;
|
import net.osmand.map.OsmandRegions;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.download.DownloadResources;
|
import net.osmand.plus.download.DownloadResources;
|
||||||
|
|
||||||
|
@ -18,10 +19,14 @@ import java.lang.reflect.Field;
|
||||||
public class FileNameTranslationHelper {
|
public class FileNameTranslationHelper {
|
||||||
private static final Log LOG = PlatformUtil.getLog(FileNameTranslationHelper.class);
|
private static final Log LOG = PlatformUtil.getLog(FileNameTranslationHelper.class);
|
||||||
public static final String WIKI_NAME = "_wiki";
|
public static final String WIKI_NAME = "_wiki";
|
||||||
public static final String HILL_SHADE = "Hillshade_";
|
public static final String HILL_SHADE = "Hillshade";
|
||||||
public static final String SLOPE = "Slope_";
|
public static final String SLOPE = "Slope";
|
||||||
public static final String SEA_DEPTH = "Depth_";
|
public static final String SEA_DEPTH = "Depth_";
|
||||||
|
|
||||||
|
public static String getFileNameWithRegion(OsmandApplication app, String fileName) {
|
||||||
|
return getFileName(app, app.getResourceManager().getOsmandRegions(), fileName);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getFileName(Context ctx, OsmandRegions regions, String fileName) {
|
public static String getFileName(Context ctx, OsmandRegions regions, String fileName) {
|
||||||
String basename = getBasename(fileName);
|
String basename = getBasename(fileName);
|
||||||
if (basename.endsWith(WIKI_NAME)) { //wiki files
|
if (basename.endsWith(WIKI_NAME)) { //wiki files
|
||||||
|
@ -30,13 +35,15 @@ public class FileNameTranslationHelper {
|
||||||
return getVoiceName(ctx, fileName);
|
return getVoiceName(ctx, fileName);
|
||||||
} else if (fileName.endsWith(IndexConstants.FONT_INDEX_EXT)) { //otf files
|
} else if (fileName.endsWith(IndexConstants.FONT_INDEX_EXT)) { //otf files
|
||||||
return getFontName(ctx, basename);
|
return getFontName(ctx, basename);
|
||||||
} else if (fileName.startsWith(HILL_SHADE)){
|
} else if (fileName.startsWith(HILL_SHADE)) {
|
||||||
|
basename = basename.replace(HILL_SHADE + " ", "");
|
||||||
return getTerrainName(ctx, regions, basename, R.string.download_hillshade_maps);
|
return getTerrainName(ctx, regions, basename, R.string.download_hillshade_maps);
|
||||||
} else if (fileName.startsWith(SLOPE)) {
|
} else if (fileName.startsWith(SLOPE)) {
|
||||||
|
basename = basename.replace(SLOPE + " ", "");
|
||||||
return getTerrainName(ctx, regions, basename, R.string.download_slope_maps);
|
return getTerrainName(ctx, regions, basename, R.string.download_slope_maps);
|
||||||
} else if (fileName.length() == 2) { //voice recorded files
|
} else if (fileName.length() == 2) { //voice recorded files
|
||||||
try {
|
try {
|
||||||
Field f = R.string.class.getField("lang_"+fileName);
|
Field f = R.string.class.getField("lang_" + fileName);
|
||||||
if (f != null) {
|
if (f != null) {
|
||||||
Integer in = (Integer) f.get(null);
|
Integer in = (Integer) f.get(null);
|
||||||
return ctx.getString(in);
|
return ctx.getString(in);
|
||||||
|
@ -62,9 +69,10 @@ public class FileNameTranslationHelper {
|
||||||
|
|
||||||
public static String getTerrainName(Context ctx, OsmandRegions regions, String basename,
|
public static String getTerrainName(Context ctx, OsmandRegions regions, String basename,
|
||||||
int terrainNameRes) {
|
int terrainNameRes) {
|
||||||
String terrain = ctx.getString(terrainNameRes) + " ";
|
basename = basename.replace(" ", "_");
|
||||||
|
String terrain = ctx.getString(terrainNameRes);
|
||||||
String locName = regions.getLocaleName(basename.trim(), true);
|
String locName = regions.getLocaleName(basename.trim(), true);
|
||||||
return terrain + locName;
|
return ctx.getString(R.string.ltr_or_rtl_combine_via_space, locName, "(" + terrain + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getWikiName(Context ctx, String basename){
|
public static String getWikiName(Context ctx, String basename){
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class DataSettingsItem extends StreamSettingsItem {
|
||||||
SettingsItemReader<? extends SettingsItem> getReader() {
|
SettingsItemReader<? extends SettingsItem> getReader() {
|
||||||
return new StreamSettingsItemReader(this) {
|
return new StreamSettingsItemReader(this) {
|
||||||
@Override
|
@Override
|
||||||
public void readFromStream(@NonNull InputStream inputStream, File destination) throws IOException, IllegalArgumentException {
|
public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IOException, IllegalArgumentException {
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
int nRead;
|
int nRead;
|
||||||
byte[] data = new byte[SettingsHelper.BUFFER];
|
byte[] data = new byte[SettingsHelper.BUFFER];
|
||||||
|
|
|
@ -16,7 +16,6 @@ import net.osmand.plus.R;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -146,7 +145,7 @@ public class FavoritesSettingsItem extends CollectionSettingsItem<FavoriteGroup>
|
||||||
return new SettingsItemReader<FavoritesSettingsItem>(this) {
|
return new SettingsItemReader<FavoritesSettingsItem>(this) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromStream(@NonNull InputStream inputStream, File destination) throws IllegalArgumentException {
|
public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IllegalArgumentException {
|
||||||
GPXFile gpxFile = GPXUtilities.loadGPXFile(inputStream);
|
GPXFile gpxFile = GPXUtilities.loadGPXFile(inputStream);
|
||||||
if (gpxFile.error != null) {
|
if (gpxFile.error != null) {
|
||||||
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
|
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.settings.backend.backup;
|
package net.osmand.plus.settings.backend.backup;
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -23,34 +24,33 @@ import java.util.zip.ZipOutputStream;
|
||||||
public class FileSettingsItem extends StreamSettingsItem {
|
public class FileSettingsItem extends StreamSettingsItem {
|
||||||
|
|
||||||
public enum FileSubtype {
|
public enum FileSubtype {
|
||||||
UNKNOWN("", null),
|
UNKNOWN("", null, R.drawable.ic_type_file),
|
||||||
OTHER("other", ""),
|
OTHER("other", "", R.drawable.ic_type_file),
|
||||||
ROUTING_CONFIG("routing_config", IndexConstants.ROUTING_PROFILES_DIR),
|
ROUTING_CONFIG("routing_config", IndexConstants.ROUTING_PROFILES_DIR, R.drawable.ic_action_route_distance),
|
||||||
RENDERING_STYLE("rendering_style", IndexConstants.RENDERERS_DIR),
|
RENDERING_STYLE("rendering_style", IndexConstants.RENDERERS_DIR, R.drawable.ic_action_map_style),
|
||||||
WIKI_MAP("wiki_map", IndexConstants.WIKI_INDEX_DIR),
|
WIKI_MAP("wiki_map", IndexConstants.WIKI_INDEX_DIR, R.drawable.ic_plugin_wikipedia),
|
||||||
SRTM_MAP("srtm_map", IndexConstants.SRTM_INDEX_DIR),
|
SRTM_MAP("srtm_map", IndexConstants.SRTM_INDEX_DIR, R.drawable.ic_plugin_srtm),
|
||||||
OBF_MAP("obf_map", IndexConstants.MAPS_PATH),
|
OBF_MAP("obf_map", IndexConstants.MAPS_PATH, R.drawable.ic_map),
|
||||||
TILES_MAP("tiles_map", IndexConstants.TILES_INDEX_DIR),
|
TILES_MAP("tiles_map", IndexConstants.TILES_INDEX_DIR, R.drawable.ic_map),
|
||||||
GPX("gpx", IndexConstants.GPX_INDEX_DIR),
|
ROAD_MAP("road_map", IndexConstants.ROADS_INDEX_DIR, R.drawable.ic_map),
|
||||||
TTS_VOICE("tts_voice", IndexConstants.VOICE_INDEX_DIR),
|
GPX("gpx", IndexConstants.GPX_INDEX_DIR, R.drawable.ic_action_route_distance),
|
||||||
VOICE("voice", IndexConstants.VOICE_INDEX_DIR),
|
TTS_VOICE("tts_voice", IndexConstants.VOICE_INDEX_DIR, R.drawable.ic_action_volume_up),
|
||||||
TRAVEL("travel", IndexConstants.WIKIVOYAGE_INDEX_DIR),
|
VOICE("voice", IndexConstants.VOICE_INDEX_DIR, R.drawable.ic_action_volume_up),
|
||||||
MULTIMEDIA_NOTES("multimedia_notes", IndexConstants.AV_INDEX_DIR);
|
TRAVEL("travel", IndexConstants.WIKIVOYAGE_INDEX_DIR, R.drawable.ic_plugin_wikipedia),
|
||||||
|
MULTIMEDIA_NOTES("multimedia_notes", IndexConstants.AV_INDEX_DIR, R.drawable.ic_action_photo_dark);
|
||||||
|
|
||||||
private String subtypeName;
|
private final String subtypeName;
|
||||||
private String subtypeFolder;
|
private final String subtypeFolder;
|
||||||
|
private final int iconId;
|
||||||
|
|
||||||
FileSubtype(String subtypeName, String subtypeFolder) {
|
FileSubtype(@NonNull String subtypeName, String subtypeFolder, @DrawableRes int iconId) {
|
||||||
this.subtypeName = subtypeName;
|
this.subtypeName = subtypeName;
|
||||||
this.subtypeFolder = subtypeFolder;
|
this.subtypeFolder = subtypeFolder;
|
||||||
|
this.iconId = iconId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMap() {
|
public boolean isMap() {
|
||||||
return this == OBF_MAP || this == WIKI_MAP || this == SRTM_MAP || this == TILES_MAP;
|
return this == OBF_MAP || this == WIKI_MAP || this == SRTM_MAP || this == TILES_MAP || this == ROAD_MAP;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDirectory() {
|
|
||||||
return this == TTS_VOICE || this == VOICE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubtypeName() {
|
public String getSubtypeName() {
|
||||||
|
@ -61,6 +61,11 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
return subtypeFolder;
|
return subtypeFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DrawableRes
|
||||||
|
public int getIconId() {
|
||||||
|
return iconId;
|
||||||
|
}
|
||||||
|
|
||||||
public static FileSubtype getSubtypeByName(@NonNull String name) {
|
public static FileSubtype getSubtypeByName(@NonNull String name) {
|
||||||
for (FileSubtype subtype : FileSubtype.values()) {
|
for (FileSubtype subtype : FileSubtype.values()) {
|
||||||
if (name.equals(subtype.subtypeName)) {
|
if (name.equals(subtype.subtypeName)) {
|
||||||
|
@ -205,7 +210,12 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getSize() {
|
public long getSize() {
|
||||||
|
if (size != 0) {
|
||||||
return size;
|
return size;
|
||||||
|
} else if (file != null && !file.isDirectory()) {
|
||||||
|
return file.length();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(long size) {
|
public void setSize(long size) {
|
||||||
|
@ -227,15 +237,28 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
return file.exists();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
private File renameFile(File file) {
|
private File renameFile(File oldFile) {
|
||||||
|
String oldPath = oldFile.getAbsolutePath();
|
||||||
|
String prefix;
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
prefix = file.getAbsolutePath();
|
||||||
|
} else if (oldPath.endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
|
||||||
|
prefix = oldPath.substring(0, oldPath.lastIndexOf(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT));
|
||||||
|
} else if (oldPath.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)) {
|
||||||
|
prefix = oldPath.substring(0, oldPath.lastIndexOf(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT));
|
||||||
|
} else if (oldPath.endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) {
|
||||||
|
prefix = oldPath.substring(0, oldPath.lastIndexOf(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT));
|
||||||
|
} else {
|
||||||
|
prefix = oldPath.substring(0, oldPath.lastIndexOf("."));
|
||||||
|
}
|
||||||
|
String suffix = oldPath.replace(prefix, "");
|
||||||
int number = 0;
|
int number = 0;
|
||||||
String path = file.getAbsolutePath();
|
|
||||||
while (true) {
|
while (true) {
|
||||||
number++;
|
number++;
|
||||||
String copyName = path.replaceAll(file.getName(), file.getName().replaceFirst("[.]", "_" + number + "."));
|
String newName = prefix + "_" + number + suffix;
|
||||||
File copyFile = new File(copyName);
|
File newFile = new File(newName);
|
||||||
if (!copyFile.exists()) {
|
if (!newFile.exists()) {
|
||||||
return copyFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,12 +268,17 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
SettingsItemReader<? extends SettingsItem> getReader() {
|
SettingsItemReader<? extends SettingsItem> getReader() {
|
||||||
return new StreamSettingsItemReader(this) {
|
return new StreamSettingsItemReader(this) {
|
||||||
@Override
|
@Override
|
||||||
public void readFromStream(@NonNull InputStream inputStream, File dest) throws IOException, IllegalArgumentException {
|
public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IOException, IllegalArgumentException {
|
||||||
OutputStream output;
|
OutputStream output;
|
||||||
|
File dest = FileSettingsItem.this.getFile();
|
||||||
|
if (dest.isDirectory()) {
|
||||||
|
dest = new File(dest, entryName.substring(fileName.length()));
|
||||||
|
}
|
||||||
if (dest.exists() && !shouldReplace) {
|
if (dest.exists() && !shouldReplace) {
|
||||||
dest = renameFile(dest);
|
dest = renameFile(dest);
|
||||||
}
|
}
|
||||||
if (dest.getParentFile() != null && !dest.getParentFile().exists()) {
|
if (dest.getParentFile() != null && !dest.getParentFile().exists()) {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
dest.getParentFile().mkdirs();
|
dest.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
output = new FileOutputStream(dest);
|
output = new FileOutputStream(dest);
|
||||||
|
@ -271,46 +299,42 @@ public class FileSettingsItem extends StreamSettingsItem {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public SettingsItemWriter<? extends SettingsItem> getWriter() {
|
public SettingsItemWriter<? extends SettingsItem> getWriter() {
|
||||||
try {
|
|
||||||
if (!file.isDirectory()) {
|
if (!file.isDirectory()) {
|
||||||
|
try {
|
||||||
setInputStream(new FileInputStream(file));
|
setInputStream(new FileInputStream(file));
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
warnings.add(app.getString(R.string.settings_item_read_error, file.getName()));
|
warnings.add(app.getString(R.string.settings_item_read_error, file.getName()));
|
||||||
SettingsHelper.LOG.error("Failed to set input stream from file: " + file.getName(), e);
|
SettingsHelper.LOG.error("Failed to set input stream from file: " + file.getName(), e);
|
||||||
}
|
}
|
||||||
|
return super.getWriter();
|
||||||
|
} else {
|
||||||
return new StreamSettingsItemWriter(this) {
|
return new StreamSettingsItemWriter(this) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeEntry(String fileName, @NonNull ZipOutputStream zos) throws IOException {
|
public void writeEntry(String fileName, @NonNull ZipOutputStream zos) throws IOException {
|
||||||
if (getSubtype().isDirectory()) {
|
writeDirWithFiles(file, zos);
|
||||||
File file = getFile();
|
|
||||||
zipDirsWithFiles(file, zos);
|
|
||||||
} else {
|
|
||||||
super.writeEntry(fileName, zos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zipDirsWithFiles(File f, ZipOutputStream zos)
|
public void writeDirWithFiles(File file, ZipOutputStream zos) throws IOException {
|
||||||
throws IOException {
|
if (file != null) {
|
||||||
if (f == null) {
|
if (file.isDirectory()) {
|
||||||
return;
|
File[] files = file.listFiles();
|
||||||
}
|
if (files != null) {
|
||||||
if (f.isDirectory()) {
|
for (File subfolderFile : files) {
|
||||||
File[] fs = f.listFiles();
|
writeDirWithFiles(subfolderFile, zos);
|
||||||
if (fs != null) {
|
|
||||||
for (File c : fs) {
|
|
||||||
zipDirsWithFiles(c, zos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String zipEntryName = Algorithms.isEmpty(getSubtype().getSubtypeFolder())
|
String subtypeFolder = getSubtype().getSubtypeFolder();
|
||||||
? f.getName()
|
String zipEntryName = Algorithms.isEmpty(subtypeFolder)
|
||||||
: f.getPath().substring(f.getPath().indexOf(getSubtype().getSubtypeFolder()) - 1);
|
? file.getName()
|
||||||
setInputStream(new FileInputStream(f));
|
: file.getPath().substring(file.getPath().indexOf(subtypeFolder) - 1);
|
||||||
|
setInputStream(new FileInputStream(file));
|
||||||
super.writeEntry(zipEntryName, zos);
|
super.writeEntry(zipEntryName, zos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ 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;
|
||||||
|
@ -30,7 +29,7 @@ public abstract class OsmandSettingsItemReader<T extends OsmandSettingsItem> ext
|
||||||
@NonNull JSONObject json) throws JSONException;
|
@NonNull JSONObject json) throws JSONException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromStream(@NonNull InputStream inputStream, File destination) throws IOException, IllegalArgumentException {
|
public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IOException, IllegalArgumentException {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||||
|
|
|
@ -16,13 +16,19 @@ import java.util.Map;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
import static net.osmand.plus.settings.backend.backup.SettingsHelper.*;
|
||||||
|
|
||||||
class SettingsExporter {
|
class SettingsExporter {
|
||||||
|
|
||||||
private Map<String, SettingsItem> items;
|
private Map<String, SettingsItem> items;
|
||||||
private Map<String, String> additionalParams;
|
private Map<String, String> additionalParams;
|
||||||
|
private ExportProgressListener progressListener;
|
||||||
|
|
||||||
|
private boolean cancelled;
|
||||||
private boolean exportItemsFiles;
|
private boolean exportItemsFiles;
|
||||||
|
|
||||||
SettingsExporter(boolean exportItemsFiles) {
|
SettingsExporter(ExportProgressListener progressListener, boolean exportItemsFiles) {
|
||||||
|
this.progressListener = progressListener;
|
||||||
this.exportItemsFiles = exportItemsFiles;
|
this.exportItemsFiles = exportItemsFiles;
|
||||||
items = new LinkedHashMap<>();
|
items = new LinkedHashMap<>();
|
||||||
additionalParams = new LinkedHashMap<>();
|
additionalParams = new LinkedHashMap<>();
|
||||||
|
@ -35,13 +41,17 @@ class SettingsExporter {
|
||||||
items.put(item.getName(), item);
|
items.put(item.getName(), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
void addAdditionalParam(String key, String value) {
|
void addAdditionalParam(String key, String value) {
|
||||||
additionalParams.put(key, value);
|
additionalParams.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void exportSettings(File file) throws JSONException, IOException {
|
void exportSettings(File file) throws JSONException, IOException {
|
||||||
JSONObject json = createItemsJson();
|
JSONObject json = createItemsJson();
|
||||||
OutputStream os = new BufferedOutputStream(new FileOutputStream(file), SettingsHelper.BUFFER);
|
OutputStream os = new BufferedOutputStream(new FileOutputStream(file), BUFFER);
|
||||||
ZipOutputStream zos = new ZipOutputStream(os);
|
ZipOutputStream zos = new ZipOutputStream(os);
|
||||||
try {
|
try {
|
||||||
ZipEntry entry = new ZipEntry("items.json");
|
ZipEntry entry = new ZipEntry("items.json");
|
||||||
|
@ -60,6 +70,7 @@ class SettingsExporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeItemFiles(ZipOutputStream zos) throws IOException {
|
private void writeItemFiles(ZipOutputStream zos) throws IOException {
|
||||||
|
int progress = 0;
|
||||||
for (SettingsItem item : items.values()) {
|
for (SettingsItem item : items.values()) {
|
||||||
SettingsItemWriter<? extends SettingsItem> writer = item.getWriter();
|
SettingsItemWriter<? extends SettingsItem> writer = item.getWriter();
|
||||||
if (writer != null) {
|
if (writer != null) {
|
||||||
|
@ -69,13 +80,22 @@ class SettingsExporter {
|
||||||
}
|
}
|
||||||
writer.writeEntry(fileName, zos);
|
writer.writeEntry(fileName, zos);
|
||||||
}
|
}
|
||||||
|
if (cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (item instanceof FileSettingsItem) {
|
||||||
|
int size = (int) ((FileSettingsItem) item).getSize() / (1 << 20);
|
||||||
|
progress += size;
|
||||||
|
if (progressListener != null) {
|
||||||
|
progressListener.updateProgress(progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JSONObject createItemsJson() throws JSONException {
|
private JSONObject createItemsJson() throws JSONException {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("version", SettingsHelper.VERSION);
|
json.put("version", VERSION);
|
||||||
for (Map.Entry<String, String> param : additionalParams.entrySet()) {
|
for (Map.Entry<String, String> param : additionalParams.entrySet()) {
|
||||||
json.put(param.getKey(), param.getValue());
|
json.put(param.getKey(), param.getValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.Collator;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
|
@ -23,6 +25,7 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
|
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
|
||||||
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
|
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
|
||||||
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||||
|
@ -34,6 +37,7 @@ import net.osmand.plus.quickaction.QuickActionRegistry;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
|
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
|
||||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -42,14 +46,16 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT;
|
import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT;
|
||||||
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.*;
|
|
||||||
import static net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
import static net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||||
|
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.FileSubtype;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Usage:
|
Usage:
|
||||||
|
@ -106,6 +112,8 @@ public class SettingsHelper {
|
||||||
|
|
||||||
public interface SettingsExportListener {
|
public interface SettingsExportListener {
|
||||||
void onSettingsExportFinished(@NonNull File file, boolean succeed);
|
void onSettingsExportFinished(@NonNull File file, boolean succeed);
|
||||||
|
|
||||||
|
void onSettingsExportProgressUpdate(int value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ImportType {
|
public enum ImportType {
|
||||||
|
@ -134,6 +142,14 @@ public class SettingsHelper {
|
||||||
return importTask == null || importTask.isImportDone();
|
return importTask == null || importTask.isImportDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean cancelExportForFile(File file) {
|
||||||
|
ExportAsyncTask exportTask = exportAsyncTasks.get(file);
|
||||||
|
if (exportTask != null && (exportTask.getStatus() == AsyncTask.Status.RUNNING)) {
|
||||||
|
return exportTask.cancel(true);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFileExporting(File file) {
|
public boolean isFileExporting(File file) {
|
||||||
return exportAsyncTasks.containsKey(file);
|
return exportAsyncTasks.containsKey(file);
|
||||||
}
|
}
|
||||||
|
@ -195,11 +211,15 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
public interface ExportProgressListener {
|
||||||
private class ExportAsyncTask extends AsyncTask<Void, Void, Boolean> {
|
void updateProgress(int value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
public class ExportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||||
|
|
||||||
private SettingsExporter exporter;
|
|
||||||
private File file;
|
private File file;
|
||||||
|
private SettingsExporter exporter;
|
||||||
private SettingsExportListener listener;
|
private SettingsExportListener listener;
|
||||||
|
|
||||||
ExportAsyncTask(@NonNull File settingsFile,
|
ExportAsyncTask(@NonNull File settingsFile,
|
||||||
|
@ -207,7 +227,7 @@ public class SettingsHelper {
|
||||||
@NonNull List<SettingsItem> items, boolean exportItemsFiles) {
|
@NonNull List<SettingsItem> items, boolean exportItemsFiles) {
|
||||||
this.file = settingsFile;
|
this.file = settingsFile;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.exporter = new SettingsExporter(exportItemsFiles);
|
this.exporter = new SettingsExporter(getProgressListener(), exportItemsFiles);
|
||||||
for (SettingsItem item : items) {
|
for (SettingsItem item : items) {
|
||||||
exporter.addSettingsItem(item);
|
exporter.addSettingsItem(item);
|
||||||
}
|
}
|
||||||
|
@ -226,6 +246,13 @@ public class SettingsHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Integer... values) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onSettingsExportProgressUpdate(values[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Boolean success) {
|
protected void onPostExecute(Boolean success) {
|
||||||
exportAsyncTasks.remove(file);
|
exportAsyncTasks.remove(file);
|
||||||
|
@ -233,6 +260,21 @@ public class SettingsHelper {
|
||||||
listener.onSettingsExportFinished(file, success);
|
listener.onSettingsExportFinished(file, success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCancelled() {
|
||||||
|
Algorithms.removeAllFiles(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExportProgressListener getProgressListener() {
|
||||||
|
return new ExportProgressListener() {
|
||||||
|
@Override
|
||||||
|
public void updateProgress(int value) {
|
||||||
|
exporter.setCancelled(isCancelled());
|
||||||
|
publishProgress(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
@ -537,11 +579,11 @@ public class SettingsHelper {
|
||||||
if (!favoriteGroups.isEmpty()) {
|
if (!favoriteGroups.isEmpty()) {
|
||||||
dataList.put(ExportSettingsType.FAVORITES, favoriteGroups);
|
dataList.put(ExportSettingsType.FAVORITES, favoriteGroups);
|
||||||
}
|
}
|
||||||
List<LocalIndexInfo> localIndexInfoList = getVoiceIndexInfo();
|
List<LocalIndexInfo> localIndexInfoList = getLocalIndexData();
|
||||||
List<File> files;
|
List<File> files = getFilesByType(localIndexInfoList, LocalIndexType.MAP_DATA, LocalIndexType.TILES_DATA,
|
||||||
files = getFilesByType(localIndexInfoList, LocalIndexType.MAP_DATA, LocalIndexType.TILES_DATA,
|
|
||||||
LocalIndexType.SRTM_DATA, LocalIndexType.WIKI_DATA);
|
LocalIndexType.SRTM_DATA, LocalIndexType.WIKI_DATA);
|
||||||
if (!files.isEmpty()) {
|
if (!files.isEmpty()) {
|
||||||
|
sortLocalFiles(files);
|
||||||
dataList.put(ExportSettingsType.OFFLINE_MAPS, files);
|
dataList.put(ExportSettingsType.OFFLINE_MAPS, files);
|
||||||
}
|
}
|
||||||
files = getFilesByType(localIndexInfoList, LocalIndexType.TTS_VOICE_DATA);
|
files = getFilesByType(localIndexInfoList, LocalIndexType.TTS_VOICE_DATA);
|
||||||
|
@ -555,7 +597,7 @@ public class SettingsHelper {
|
||||||
return dataList;
|
return dataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<LocalIndexInfo> getVoiceIndexInfo() {
|
private List<LocalIndexInfo> getLocalIndexData() {
|
||||||
return new LocalIndexHelper(app).getLocalIndexData(new AbstractLoadLocalIndexTask() {
|
return new LocalIndexHelper(app).getLocalIndexData(new AbstractLoadLocalIndexTask() {
|
||||||
@Override
|
@Override
|
||||||
public void loadFile(LocalIndexInfo... loaded) {
|
public void loadFile(LocalIndexInfo... loaded) {
|
||||||
|
@ -801,4 +843,18 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
return settingsToOperate;
|
return settingsToOperate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sortLocalFiles(List<File> files) {
|
||||||
|
final Collator collator = OsmAndCollator.primaryCollator();
|
||||||
|
Collections.sort(files, new Comparator<File>() {
|
||||||
|
@Override
|
||||||
|
public int compare(File lhs, File rhs) {
|
||||||
|
return collator.compare(getNameToDisplay(lhs), getNameToDisplay(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNameToDisplay(File item) {
|
||||||
|
return FileNameTranslationHelper.getFileNameWithRegion(app, item.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -124,7 +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.readFromStream(ois, app.getAppPath(fileName));
|
reader.readFromStream(ois, fileName);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
item.warnings.add(app.getString(R.string.settings_item_read_error, item.getName()));
|
item.warnings.add(app.getString(R.string.settings_item_read_error, item.getName()));
|
||||||
|
|
|
@ -169,7 +169,7 @@ public abstract class SettingsItem {
|
||||||
SettingsItemReader<? extends SettingsItem> getJsonReader() {
|
SettingsItemReader<? extends SettingsItem> getJsonReader() {
|
||||||
return new SettingsItemReader<SettingsItem>(this) {
|
return new SettingsItemReader<SettingsItem>(this) {
|
||||||
@Override
|
@Override
|
||||||
public void readFromStream(@NonNull InputStream inputStream, File destination) throws IOException, IllegalArgumentException {
|
public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IOException, IllegalArgumentException {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||||
|
|
|
@ -2,7 +2,6 @@ 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;
|
||||||
|
|
||||||
|
@ -14,5 +13,5 @@ public abstract class SettingsItemReader<T extends SettingsItem> {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void readFromStream(@NonNull InputStream inputStream, File destination) throws IOException, IllegalArgumentException;
|
public abstract void readFromStream(@NonNull InputStream inputStream, String entryName) throws IOException, IllegalArgumentException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.PlatformUtil;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||||
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
|
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
|
||||||
|
@ -34,6 +35,8 @@ import org.apache.commons.logging.Log;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.*;
|
||||||
|
|
||||||
public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private static final Log LOG = PlatformUtil.getLog(DuplicatesSettingsAdapter.class.getName());
|
private static final Log LOG = PlatformUtil.getLog(DuplicatesSettingsAdapter.class.getName());
|
||||||
|
@ -75,12 +78,11 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
if (holder instanceof HeaderViewHolder) {
|
if (holder instanceof HeaderViewHolder) {
|
||||||
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
|
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
|
||||||
headerHolder.title.setText((String) currentItem);
|
headerHolder.title.setText((String) currentItem);
|
||||||
headerHolder.subTitle.setText(String.format(
|
headerHolder.subTitle.setText(String.format(app.getString(R.string.listed_exist), currentItem));
|
||||||
app.getString(R.string.listed_exist),
|
|
||||||
(String) currentItem));
|
|
||||||
headerHolder.divider.setVisibility(View.VISIBLE);
|
headerHolder.divider.setVisibility(View.VISIBLE);
|
||||||
} else if (holder instanceof ItemViewHolder) {
|
} else if (holder instanceof ItemViewHolder) {
|
||||||
ItemViewHolder itemHolder = (ItemViewHolder) holder;
|
ItemViewHolder itemHolder = (ItemViewHolder) holder;
|
||||||
|
itemHolder.subTitle.setVisibility(View.GONE);
|
||||||
if (currentItem instanceof ApplicationModeBean) {
|
if (currentItem instanceof ApplicationModeBean) {
|
||||||
ApplicationModeBean modeBean = (ApplicationModeBean) currentItem;
|
ApplicationModeBean modeBean = (ApplicationModeBean) currentItem;
|
||||||
String profileName = modeBean.userProfileName;
|
String profileName = modeBean.userProfileName;
|
||||||
|
@ -116,19 +118,17 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
QuickAction action = (QuickAction) currentItem;
|
QuickAction action = (QuickAction) currentItem;
|
||||||
itemHolder.title.setText(action.getName(app));
|
itemHolder.title.setText(action.getName(app));
|
||||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(action.getIconRes(), activeColorRes));
|
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(action.getIconRes(), activeColorRes));
|
||||||
itemHolder.subTitle.setVisibility(View.GONE);
|
|
||||||
} else if (currentItem instanceof PoiUIFilter) {
|
} else if (currentItem instanceof PoiUIFilter) {
|
||||||
PoiUIFilter filter = (PoiUIFilter) currentItem;
|
PoiUIFilter filter = (PoiUIFilter) currentItem;
|
||||||
itemHolder.title.setText(filter.getName());
|
itemHolder.title.setText(filter.getName());
|
||||||
int iconRes = RenderingIcons.getBigIconResourceId(filter.getIconId());
|
int iconRes = RenderingIcons.getBigIconResourceId(filter.getIconId());
|
||||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_action_user, activeColorRes));
|
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_action_user, activeColorRes));
|
||||||
itemHolder.subTitle.setVisibility(View.GONE);
|
|
||||||
} else if (currentItem instanceof ITileSource) {
|
} else if (currentItem instanceof ITileSource) {
|
||||||
itemHolder.title.setText(((ITileSource) currentItem).getName());
|
itemHolder.title.setText(((ITileSource) currentItem).getName());
|
||||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_map, activeColorRes));
|
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_map, activeColorRes));
|
||||||
itemHolder.subTitle.setVisibility(View.GONE);
|
|
||||||
} else if (currentItem instanceof File) {
|
} else if (currentItem instanceof File) {
|
||||||
File file = (File) currentItem;
|
File file = (File) currentItem;
|
||||||
|
FileSubtype fileSubtype = FileSubtype.getSubtypeByPath(app, file.getPath());
|
||||||
itemHolder.title.setText(file.getName());
|
itemHolder.title.setText(file.getName());
|
||||||
if (file.getAbsolutePath().contains(IndexConstants.RENDERERS_DIR)) {
|
if (file.getAbsolutePath().contains(IndexConstants.RENDERERS_DIR)) {
|
||||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_map_style, activeColorRes));
|
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_map_style, activeColorRes));
|
||||||
|
@ -143,16 +143,18 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
iconId = R.drawable.ic_action_photo_dark;
|
iconId = R.drawable.ic_action_photo_dark;
|
||||||
}
|
}
|
||||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconId, activeColorRes));
|
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconId, activeColorRes));
|
||||||
|
} else if (fileSubtype.isMap()
|
||||||
|
|| fileSubtype == FileSubtype.TTS_VOICE
|
||||||
|
|| fileSubtype == FileSubtype.VOICE) {
|
||||||
|
itemHolder.title.setText(FileNameTranslationHelper.getFileNameWithRegion(app, file.getName()));
|
||||||
|
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(fileSubtype.getIconId(), activeColorRes));
|
||||||
}
|
}
|
||||||
itemHolder.subTitle.setVisibility(View.GONE);
|
|
||||||
} else if (currentItem instanceof AvoidRoadInfo) {
|
} else if (currentItem instanceof AvoidRoadInfo) {
|
||||||
itemHolder.title.setText(((AvoidRoadInfo) currentItem).name);
|
itemHolder.title.setText(((AvoidRoadInfo) currentItem).name);
|
||||||
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, activeColorRes));
|
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, activeColorRes));
|
||||||
itemHolder.subTitle.setVisibility(View.GONE);
|
|
||||||
} else if (currentItem instanceof FavoriteGroup) {
|
} else if (currentItem instanceof FavoriteGroup) {
|
||||||
itemHolder.title.setText(((FavoriteGroup) currentItem).getDisplayName(app));
|
itemHolder.title.setText(((FavoriteGroup) currentItem).getDisplayName(app));
|
||||||
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_favorite, activeColorRes));
|
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_favorite, activeColorRes));
|
||||||
itemHolder.subTitle.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
itemHolder.divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
|
itemHolder.divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -172,7 +174,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HeaderViewHolder extends RecyclerView.ViewHolder {
|
private static class HeaderViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView title;
|
TextView title;
|
||||||
TextView subTitle;
|
TextView subTitle;
|
||||||
View divider;
|
View divider;
|
||||||
|
@ -185,7 +187,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ItemViewHolder extends RecyclerView.ViewHolder {
|
private static class ItemViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView title;
|
TextView title;
|
||||||
TextView subTitle;
|
TextView subTitle;
|
||||||
ImageView icon;
|
ImageView icon;
|
||||||
|
|
|
@ -285,21 +285,9 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
file = (File) currentItem;
|
file = (File) currentItem;
|
||||||
size = file.length();
|
size = file.length();
|
||||||
}
|
}
|
||||||
title.setText(FileNameTranslationHelper.getFileName(app,
|
title.setText(FileNameTranslationHelper.getFileNameWithRegion(app, file.getName()));
|
||||||
app.getResourceManager().getOsmandRegions(),
|
|
||||||
file.getName()));
|
|
||||||
FileSubtype subtype = FileSubtype.getSubtypeByPath(app, file.getPath());
|
FileSubtype subtype = FileSubtype.getSubtypeByPath(app, file.getPath());
|
||||||
switch (subtype) {
|
setupIcon(icon, subtype.getIconId(), itemSelected);
|
||||||
case SRTM_MAP:
|
|
||||||
iconId = R.drawable.ic_plugin_srtm;
|
|
||||||
break;
|
|
||||||
case WIKI_MAP:
|
|
||||||
iconId = R.drawable.ic_plugin_wikipedia;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
iconId = R.drawable.ic_map;
|
|
||||||
}
|
|
||||||
setupIcon(icon, iconId, itemSelected);
|
|
||||||
subText.setText(AndroidUtils.formatSize(app, size));
|
subText.setText(AndroidUtils.formatSize(app, size));
|
||||||
subText.setVisibility(View.VISIBLE);
|
subText.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
|
@ -311,9 +299,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
case TTS_VOICE:
|
case TTS_VOICE:
|
||||||
case VOICE:
|
case VOICE:
|
||||||
file = (File) currentItem;
|
file = (File) currentItem;
|
||||||
title.setText(FileNameTranslationHelper.getFileName(app,
|
title.setText(FileNameTranslationHelper.getFileNameWithRegion(app, file.getName()));
|
||||||
app.getResourceManager().getOsmandRegions(),
|
|
||||||
file.getName()));
|
|
||||||
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
|
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.settings.fragments;
|
||||||
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
@ -33,6 +34,7 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||||
|
import net.osmand.plus.settings.backend.backup.FileSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.GlobalSettingsItem;
|
import net.osmand.plus.settings.backend.backup.GlobalSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
|
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsExportListener;
|
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsExportListener;
|
||||||
|
@ -47,6 +49,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
@ -60,8 +63,10 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
private static final String EXPORTING_PROFILE_KEY = "exporting_profile_key";
|
private static final String EXPORTING_PROFILE_KEY = "exporting_profile_key";
|
||||||
private static final String INCLUDE_ADDITIONAL_DATA_KEY = "include_additional_data_key";
|
private static final String INCLUDE_ADDITIONAL_DATA_KEY = "include_additional_data_key";
|
||||||
private static final String INCLUDE_GLOBAL_SETTINGS_KEY = "include_global_settings_key";
|
private static final String INCLUDE_GLOBAL_SETTINGS_KEY = "include_global_settings_key";
|
||||||
|
private static final String PROGRESS_MAX_KEY = "progress_max_key";
|
||||||
|
private static final String PROGRESS_VALUE_KEY = "progress_value_key";
|
||||||
|
|
||||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yy");
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yy", Locale.US);
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private Map<ExportSettingsType, List<?>> dataList = new HashMap<>();
|
private Map<ExportSettingsType, List<?>> dataList = new HashMap<>();
|
||||||
|
@ -69,6 +74,8 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
private SettingsExportListener exportListener;
|
private SettingsExportListener exportListener;
|
||||||
private ProgressDialog progress;
|
private ProgressDialog progress;
|
||||||
|
private int progressMax;
|
||||||
|
private int progressValue;
|
||||||
|
|
||||||
private long exportStartTime;
|
private long exportStartTime;
|
||||||
|
|
||||||
|
@ -87,6 +94,8 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
includeAdditionalData = savedInstanceState.getBoolean(INCLUDE_ADDITIONAL_DATA_KEY);
|
includeAdditionalData = savedInstanceState.getBoolean(INCLUDE_ADDITIONAL_DATA_KEY);
|
||||||
includeGlobalSettings = savedInstanceState.getBoolean(INCLUDE_GLOBAL_SETTINGS_KEY);
|
includeGlobalSettings = savedInstanceState.getBoolean(INCLUDE_GLOBAL_SETTINGS_KEY);
|
||||||
exportStartTime = savedInstanceState.getLong(EXPORT_START_TIME_KEY);
|
exportStartTime = savedInstanceState.getLong(EXPORT_START_TIME_KEY);
|
||||||
|
progressMax = savedInstanceState.getInt(PROGRESS_MAX_KEY);
|
||||||
|
progressValue = savedInstanceState.getInt(PROGRESS_VALUE_KEY);
|
||||||
}
|
}
|
||||||
dataList = app.getSettingsHelper().getAdditionalData(globalExport);
|
dataList = app.getSettingsHelper().getAdditionalData(globalExport);
|
||||||
}
|
}
|
||||||
|
@ -99,6 +108,8 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
outState.putBoolean(INCLUDE_ADDITIONAL_DATA_KEY, includeAdditionalData);
|
outState.putBoolean(INCLUDE_ADDITIONAL_DATA_KEY, includeAdditionalData);
|
||||||
outState.putBoolean(INCLUDE_GLOBAL_SETTINGS_KEY, includeGlobalSettings);
|
outState.putBoolean(INCLUDE_GLOBAL_SETTINGS_KEY, includeGlobalSettings);
|
||||||
outState.putLong(EXPORT_START_TIME_KEY, exportStartTime);
|
outState.putLong(EXPORT_START_TIME_KEY, exportStartTime);
|
||||||
|
outState.putInt(PROGRESS_MAX_KEY, progress.getMax());
|
||||||
|
outState.putInt(PROGRESS_VALUE_KEY, progress.getProgress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -271,10 +282,22 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
showExportProgressDialog();
|
showExportProgressDialog();
|
||||||
File tempDir = FileUtils.getTempDir(app);
|
File tempDir = FileUtils.getTempDir(app);
|
||||||
String fileName = getFileName();
|
String fileName = getFileName();
|
||||||
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), prepareSettingsItemsForExport(), true);
|
List<SettingsItem> items = prepareSettingsItemsForExport();
|
||||||
|
progress.setMax(getMaxProgress(items));
|
||||||
|
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getMaxProgress(List<SettingsItem> items) {
|
||||||
|
long maxProgress = 0;
|
||||||
|
for (SettingsItem item : items) {
|
||||||
|
if (item instanceof FileSettingsItem) {
|
||||||
|
maxProgress += ((FileSettingsItem) item).getSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (int) maxProgress / (1 << 20);
|
||||||
|
}
|
||||||
|
|
||||||
private String getFileName() {
|
private String getFileName() {
|
||||||
if (globalExport) {
|
if (globalExport) {
|
||||||
if (exportStartTime == 0) {
|
if (exportStartTime == 0) {
|
||||||
|
@ -295,12 +318,31 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
progress = new ProgressDialog(context);
|
progress = new ProgressDialog(context);
|
||||||
|
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
|
progress.setCancelable(true);
|
||||||
progress.setTitle(app.getString(R.string.shared_string_export));
|
progress.setTitle(app.getString(R.string.shared_string_export));
|
||||||
progress.setMessage(app.getString(R.string.shared_string_preparing));
|
progress.setMessage(app.getString(R.string.shared_string_preparing));
|
||||||
progress.setCancelable(false);
|
progress.setButton(DialogInterface.BUTTON_NEGATIVE, app.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
cancelExport();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
progress.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
cancelExport();
|
||||||
|
}
|
||||||
|
});
|
||||||
progress.show();
|
progress.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cancelExport() {
|
||||||
|
app.getSettingsHelper().cancelExportForFile(getExportFile());
|
||||||
|
progress.dismiss();
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
private SettingsExportListener getSettingsExportListener() {
|
private SettingsExportListener getSettingsExportListener() {
|
||||||
if (exportListener == null) {
|
if (exportListener == null) {
|
||||||
exportListener = new SettingsExportListener() {
|
exportListener = new SettingsExportListener() {
|
||||||
|
@ -315,6 +357,11 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
app.showToastMessage(R.string.export_profile_failed);
|
app.showToastMessage(R.string.export_profile_failed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSettingsExportProgressUpdate(int value) {
|
||||||
|
progress.setProgress(value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return exportListener;
|
return exportListener;
|
||||||
|
@ -326,6 +373,8 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
boolean fileExporting = app.getSettingsHelper().isFileExporting(file);
|
boolean fileExporting = app.getSettingsHelper().isFileExporting(file);
|
||||||
if (fileExporting) {
|
if (fileExporting) {
|
||||||
showExportProgressDialog();
|
showExportProgressDialog();
|
||||||
|
progress.setMax(progressMax);
|
||||||
|
progress.setProgress(progressValue);
|
||||||
app.getSettingsHelper().updateExportListener(file, getSettingsExportListener());
|
app.getSettingsHelper().updateExportListener(file, getSettingsExportListener());
|
||||||
} else if (file.exists()) {
|
} else if (file.exists()) {
|
||||||
dismissExportProgressDialog();
|
dismissExportProgressDialog();
|
||||||
|
|
|
@ -32,6 +32,8 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
|
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||||
|
import net.osmand.plus.osmedit.OsmNotesPoint;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.quickaction.QuickAction;
|
import net.osmand.plus.quickaction.QuickAction;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
@ -46,10 +48,7 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.osmand.IndexConstants.AV_INDEX_DIR;
|
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.*;
|
||||||
import static net.osmand.IndexConstants.GPX_INDEX_DIR;
|
|
||||||
import static net.osmand.IndexConstants.RENDERERS_DIR;
|
|
||||||
import static net.osmand.IndexConstants.ROUTING_PROFILES_DIR;
|
|
||||||
import static net.osmand.plus.settings.fragments.ImportSettingsFragment.IMPORT_SETTINGS_TAG;
|
import static net.osmand.plus.settings.fragments.ImportSettingsFragment.IMPORT_SETTINGS_TAG;
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,6 +195,11 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
|
||||||
List<File> trackFilesList = new ArrayList<>();
|
List<File> trackFilesList = new ArrayList<>();
|
||||||
List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
|
List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
|
||||||
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
|
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
|
||||||
|
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
|
||||||
|
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
|
||||||
|
List<File> ttsVoiceFilesList = new ArrayList<>();
|
||||||
|
List<File> voiceFilesList = new ArrayList<>();
|
||||||
|
List<File> mapFilesList = new ArrayList<>();
|
||||||
|
|
||||||
for (Object object : duplicatesList) {
|
for (Object object : duplicatesList) {
|
||||||
if (object instanceof ApplicationMode.ApplicationModeBean) {
|
if (object instanceof ApplicationMode.ApplicationModeBean) {
|
||||||
|
@ -208,19 +212,30 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
|
||||||
tileSources.add((ITileSource) object);
|
tileSources.add((ITileSource) object);
|
||||||
} else if (object instanceof File) {
|
} else if (object instanceof File) {
|
||||||
File file = (File) object;
|
File file = (File) object;
|
||||||
if (file.getAbsolutePath().contains(RENDERERS_DIR)) {
|
FileSubtype fileSubtype = FileSubtype.getSubtypeByPath(app, file.getPath());
|
||||||
|
if (fileSubtype == FileSubtype.RENDERING_STYLE) {
|
||||||
renderFilesList.add(file);
|
renderFilesList.add(file);
|
||||||
} else if (file.getAbsolutePath().contains(ROUTING_PROFILES_DIR)) {
|
} else if (fileSubtype == FileSubtype.ROUTING_CONFIG) {
|
||||||
routingFilesList.add(file);
|
routingFilesList.add(file);
|
||||||
} else if (file.getAbsolutePath().contains(AV_INDEX_DIR)) {
|
} else if (fileSubtype == FileSubtype.MULTIMEDIA_NOTES) {
|
||||||
multimediaFilesList.add(file);
|
multimediaFilesList.add(file);
|
||||||
} else if (file.getAbsolutePath().contains(GPX_INDEX_DIR)) {
|
} else if (fileSubtype == FileSubtype.GPX) {
|
||||||
trackFilesList.add(file);
|
trackFilesList.add(file);
|
||||||
|
} else if (fileSubtype.isMap()) {
|
||||||
|
mapFilesList.add(file);
|
||||||
|
} else if (fileSubtype == FileSubtype.TTS_VOICE) {
|
||||||
|
ttsVoiceFilesList.add(file);
|
||||||
|
} else if (fileSubtype == FileSubtype.VOICE) {
|
||||||
|
voiceFilesList.add(file);
|
||||||
}
|
}
|
||||||
} else if (object instanceof AvoidRoadInfo) {
|
} else if (object instanceof AvoidRoadInfo) {
|
||||||
avoidRoads.add((AvoidRoadInfo) object);
|
avoidRoads.add((AvoidRoadInfo) object);
|
||||||
} else if (object instanceof FavoriteGroup) {
|
} else if (object instanceof FavoriteGroup) {
|
||||||
favoriteGroups.add((FavoriteGroup) object);
|
favoriteGroups.add((FavoriteGroup) object);
|
||||||
|
} else if (object instanceof OsmNotesPoint) {
|
||||||
|
osmNotesPointList.add((OsmNotesPoint) object);
|
||||||
|
} else if (object instanceof OpenstreetmapPoint) {
|
||||||
|
osmEditsPointList.add((OpenstreetmapPoint) object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!profiles.isEmpty()) {
|
if (!profiles.isEmpty()) {
|
||||||
|
@ -263,6 +278,26 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
|
||||||
duplicates.add(getString(R.string.shared_string_favorites));
|
duplicates.add(getString(R.string.shared_string_favorites));
|
||||||
duplicates.addAll(favoriteGroups);
|
duplicates.addAll(favoriteGroups);
|
||||||
}
|
}
|
||||||
|
if (!osmNotesPointList.isEmpty()) {
|
||||||
|
duplicates.add(getString(R.string.osm_notes));
|
||||||
|
duplicates.addAll(osmNotesPointList);
|
||||||
|
}
|
||||||
|
if (!osmEditsPointList.isEmpty()) {
|
||||||
|
duplicates.add(getString(R.string.osm_edits));
|
||||||
|
duplicates.addAll(osmEditsPointList);
|
||||||
|
}
|
||||||
|
if (!mapFilesList.isEmpty()) {
|
||||||
|
duplicates.add(getString(R.string.shared_string_maps));
|
||||||
|
duplicates.addAll(mapFilesList);
|
||||||
|
}
|
||||||
|
if (!ttsVoiceFilesList.isEmpty()) {
|
||||||
|
duplicates.add(getString(R.string.local_indexes_cat_tts));
|
||||||
|
duplicates.addAll(ttsVoiceFilesList);
|
||||||
|
}
|
||||||
|
if (!voiceFilesList.isEmpty()) {
|
||||||
|
duplicates.add(getString(R.string.local_indexes_cat_voice));
|
||||||
|
duplicates.addAll(voiceFilesList);
|
||||||
|
}
|
||||||
return duplicates;
|
return duplicates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -735,6 +735,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
||||||
app.showToastMessage(R.string.profile_backup_failed);
|
app.showToastMessage(R.string.profile_backup_failed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSettingsExportProgressUpdate(int value) {
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return exportListener;
|
return exportListener;
|
||||||
|
|
Loading…
Reference in a new issue