Fix import duplicates

This commit is contained in:
Dima-1 2020-11-03 17:29:56 +02:00
parent f3900ffd4a
commit 7d9dbb09ff
13 changed files with 149 additions and 113 deletions

View file

@ -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)) {

View file

@ -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];

View file

@ -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())));

View file

@ -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,36 +24,34 @@ 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, -1),
OTHER("other", ""), OTHER("other", "", -1),
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), GPX("gpx", IndexConstants.GPX_INDEX_DIR, R.drawable.ic_action_route_distance),
TTS_VOICE("tts_voice", IndexConstants.VOICE_INDEX_DIR), TTS_VOICE("tts_voice", IndexConstants.VOICE_INDEX_DIR, R.drawable.ic_action_volume_up),
VOICE("voice", IndexConstants.VOICE_INDEX_DIR), VOICE("voice", IndexConstants.VOICE_INDEX_DIR, R.drawable.ic_action_volume_up),
TRAVEL("travel", IndexConstants.WIKIVOYAGE_INDEX_DIR), TRAVEL("travel", IndexConstants.WIKIVOYAGE_INDEX_DIR, R.drawable.ic_plugin_wikipedia),
MULTIMEDIA_NOTES("multimedia_notes", IndexConstants.AV_INDEX_DIR); 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;
} }
public boolean isDirectory() {
return this == TTS_VOICE || this == VOICE;
}
public String getSubtypeName() { public String getSubtypeName() {
return subtypeName; return subtypeName;
} }
@ -61,6 +60,10 @@ public class FileSettingsItem extends StreamSettingsItem {
return subtypeFolder; return subtypeFolder;
} }
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)) {
@ -227,15 +230,30 @@ public class FileSettingsItem extends StreamSettingsItem {
return file.exists(); return file.exists();
} }
private File renameFile(File file) { private File renameFile(File oldFile) {
int number = 0; int number = 0;
String path = file.getAbsolutePath(); String oldPath = oldFile.getAbsolutePath();
String suffix;
String prefix;
if (file.isDirectory()) {
prefix = file.getAbsolutePath();
suffix = oldPath.replace(file.getAbsolutePath(), "");
} else if (oldPath.endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
prefix = oldPath.substring(0, oldPath.lastIndexOf(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT));
suffix = 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));
suffix = IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
} else {
prefix = oldPath.substring(0, oldPath.lastIndexOf("."));
suffix = "." + Algorithms.getFileExtension(oldFile);
}
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,8 +263,12 @@ 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);
} }
@ -271,33 +293,28 @@ 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()) {
File file = getFile();
zipDirsWithFiles(file, zos); zipDirsWithFiles(file, zos);
} else {
super.writeEntry(fileName, zos);
}
} }
public void zipDirsWithFiles(File f, ZipOutputStream zos) public void zipDirsWithFiles(File file, ZipOutputStream zos) throws IOException {
throws IOException { if (file == null) {
if (f == null) {
return; return;
} }
if (f.isDirectory()) { if (file.isDirectory()) {
File[] fs = f.listFiles(); File[] fs = file.listFiles();
if (fs != null) { if (fs != null) {
for (File c : fs) { for (File c : fs) {
zipDirsWithFiles(c, zos); zipDirsWithFiles(c, zos);
@ -305,12 +322,13 @@ public class FileSettingsItem extends StreamSettingsItem {
} }
} else { } else {
String zipEntryName = Algorithms.isEmpty(getSubtype().getSubtypeFolder()) String zipEntryName = Algorithms.isEmpty(getSubtype().getSubtypeFolder())
? f.getName() ? file.getName()
: f.getPath().substring(f.getPath().indexOf(getSubtype().getSubtypeFolder()) - 1); : file.getPath().substring(file.getPath().indexOf(getSubtype().getSubtypeFolder()) - 1);
setInputStream(new FileInputStream(f)); setInputStream(new FileInputStream(file));
super.writeEntry(zipEntryName, zos); super.writeEntry(zipEntryName, zos);
} }
} }
}; };
} }
}
} }

View file

@ -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"));

View file

@ -72,7 +72,6 @@ class SettingsExporter {
} }
} }
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", SettingsHelper.VERSION);

View file

@ -542,9 +542,8 @@ 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()) {
sortData(files); sortData(files);
@ -561,7 +560,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) {

View file

@ -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()));

View file

@ -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"));

View file

@ -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;
} }

View file

@ -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;

View file

@ -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:

View file

@ -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;
} }