diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 4aaca14bb3..22beca7cbe 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -76,6 +76,22 @@ public class FavouritesDbHelper { private int color; private List points = new ArrayList<>(); + public FavoriteGroup() { + } + + public FavoriteGroup(String name, boolean visible, int color) { + this.name = name; + this.visible = visible; + this.color = color; + } + + public FavoriteGroup(String name, List points, int color, boolean visible) { + this.name = name; + this.color = color; + this.points = points; + this.visible = visible; + } + public boolean isPersonal() { return isPersonal(name); } @@ -640,7 +656,7 @@ public class FavouritesDbHelper { return asGpxFile(cachedFavoritePoints); } - private GPXFile asGpxFile(List favoritePoints) { + public GPXFile asGpxFile(List favoritePoints) { GPXFile gpx = new GPXFile(Version.getFullVersion(context)); for (FavouritePoint p : favoritePoints) { context.getSelectedGpxHelper().addPoint(p.toWpt(context), gpx); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index 541300a7ec..16fb083f13 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -650,8 +650,8 @@ public class ImportHelper { } } - protected static List asFavourites(OsmandApplication app, List wptPts, String fileName, boolean forceImportFavourites) { - final List favourites = new ArrayList<>(); + public static List asFavourites(OsmandApplication app, List wptPts, String fileName, boolean forceImportFavourites) { + List favourites = new ArrayList<>(); for (WptPt p : wptPts) { if (p.name != null) { final String fpCat; @@ -664,18 +664,18 @@ public class ImportHelper { } else { fpCat = p.category; } - final FavouritePoint fp = new FavouritePoint(p.lat, p.lon, p.name, fpCat); + FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat); if (p.desc != null) { - fp.setDescription(p.desc); + point.setDescription(p.desc); } - fp.setAddress(p.getExtensionsToRead().get("address")); - fp.setColor(p.getColor(0)); + point.setAddress(p.getExtensionsToRead().get("address")); + point.setColor(p.getColor(0)); String iconName = p.getIconName(); if (iconName != null) { - fp.setIconIdFromName(app, iconName); + point.setIconIdFromName(app, iconName); } - fp.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE)); - favourites.add(fp); + point.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE)); + favourites.add(point); } } return favourites; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 5b9b9eb7ce..285e323867 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -323,9 +323,9 @@ public class OsmEditingPlugin extends OsmandPlugin { @Override public void addMyPlacesTab(FavoritesActivity favoritesActivity, List mTabs, Intent intent) { - mTabs.add(favoritesActivity.getTabIndicator(R.string.osm_edits, OsmEditsFragment.class)); + mTabs.add(favoritesActivity.getTabIndicator(OSM_EDIT_TAB, OsmEditsFragment.class)); if (intent != null && "OSM".equals(intent.getStringExtra("TAB"))) { - app.getSettings().FAVORITES_TAB.set(R.string.osm_edits); + app.getSettings().FAVORITES_TAB.set(OSM_EDIT_TAB); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java index 17901458ec..591e5ae55b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java @@ -13,5 +13,6 @@ public enum ExportSettingsType { GLOBAL, OSM_NOTES, OSM_EDITS, - OFFLINE_MAPS + OFFLINE_MAPS, + FAVORITES } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java index 3088d9e86f..61b5f28541 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java @@ -174,6 +174,6 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem getWriter() { - return null; + return getJsonWriter(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/DownloadsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/DownloadsItem.java index 67b9d5812e..7c9318ad37 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/DownloadsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/DownloadsItem.java @@ -97,6 +97,6 @@ public class DownloadsItem extends SettingsItem { @Nullable @Override SettingsItemWriter getWriter() { - return null; + return getJsonWriter(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FavoritesSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FavoritesSettingsItem.java new file mode 100644 index 0000000000..8e8c4c6f36 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FavoritesSettingsItem.java @@ -0,0 +1,197 @@ +package net.osmand.plus.settings.backend.backup; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.data.FavouritePoint; +import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import static net.osmand.IndexConstants.GPX_FILE_EXT; +import static net.osmand.plus.importfiles.ImportHelper.asFavourites; + +public class FavoritesSettingsItem extends CollectionSettingsItem { + + private FavouritesDbHelper favoritesHelper; + + public FavoritesSettingsItem(@NonNull OsmandApplication app, @NonNull List items) { + super(app, null, items); + } + + public FavoritesSettingsItem(@NonNull OsmandApplication app, @Nullable FavoritesSettingsItem baseItem, @NonNull List items) { + super(app, baseItem, items); + } + + FavoritesSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { + super(app, json); + } + + @Override + protected void init() { + super.init(); + favoritesHelper = app.getFavorites(); + existingItems = new ArrayList<>(favoritesHelper.getFavoriteGroups()); + } + + @NonNull + @Override + public SettingsItemType getType() { + return SettingsItemType.FAVOURITES; + } + + @NonNull + @Override + public String getName() { + return "favourites"; + } + + @NonNull + @Override + public String getPublicName(@NonNull Context ctx) { + return ctx.getString(R.string.shared_string_favorites); + } + + @NonNull + public String getDefaultFileName() { + return getName() + getDefaultFileExtension(); + } + + @NonNull + public String getDefaultFileExtension() { + return GPX_FILE_EXT; + } + + @Override + public void apply() { + List newItems = getNewItems(); + if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { + appliedItems = new ArrayList<>(newItems); + + for (FavoriteGroup duplicate : duplicateItems) { + if (shouldReplace) { + FavoriteGroup existingGroup = favoritesHelper.getGroup(duplicate.getName()); + if (existingGroup != null) { + List favouritePoints = new ArrayList<>(existingGroup.getPoints()); + for (FavouritePoint favouritePoint : favouritePoints) { + favoritesHelper.deleteFavourite(favouritePoint, false); + } + } + } + appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate)); + } + List favourites = getPointsFromGroups(appliedItems); + for (FavouritePoint favourite : favourites) { + favoritesHelper.addFavourite(favourite, false); + } + favoritesHelper.sortAll(); + favoritesHelper.saveCurrentPointsIntoFile(); + } + } + + @Override + public boolean isDuplicate(@NonNull FavoriteGroup favoriteGroup) { + String name = favoriteGroup.getName(); + for (FavoriteGroup group : existingItems) { + if (group.getName().equals(name)) { + return true; + } + } + return false; + } + + @Override + public boolean shouldReadOnCollecting() { + return true; + } + + @NonNull + @Override + public FavoriteGroup renameItem(@NonNull FavoriteGroup item) { + int number = 0; + while (true) { + number++; + String name = item.getName() + " (" + number + ")"; + FavoriteGroup renamedItem = new FavoriteGroup(name, item.getPoints(), item.getColor(), item.isVisible()); + if (!isDuplicate(renamedItem)) { + for (FavouritePoint point : renamedItem.getPoints()) { + point.setCategory(renamedItem.getName()); + } + return renamedItem; + } + } + } + + @Nullable + @Override + SettingsItemReader getReader() { + return new SettingsItemReader(this) { + + @Override + public void readFromStream(@NonNull InputStream inputStream) throws IllegalArgumentException { + GPXFile gpxFile = GPXUtilities.loadGPXFile(inputStream); + if (gpxFile.error != null) { + warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType()))); + SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error); + } else { + Map flatGroups = new LinkedHashMap<>(); + List favourites = asFavourites(app, gpxFile.getPoints(), fileName, false); + for (FavouritePoint point : favourites) { + FavoriteGroup group = flatGroups.get(point.getCategory()); + if (group == null) { + group = new FavoriteGroup(point.getCategory(), point.isVisible(), point.getColor()); + flatGroups.put(group.getName(), group); + items.add(group); + } + group.getPoints().add(point); + } + } + } + }; + } + + private List getPointsFromGroups(List groups) { + List favouritePoints = new ArrayList<>(); + for (FavoriteGroup group : groups) { + favouritePoints.addAll(group.getPoints()); + } + return favouritePoints; + } + + @Nullable + @Override + SettingsItemWriter getWriter() { + return new SettingsItemWriter(this) { + + @Override + public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException { + List favourites = getPointsFromGroups(items); + GPXFile gpxFile = favoritesHelper.asGpxFile(favourites); + Exception error = GPXUtilities.writeGpx(new OutputStreamWriter(outputStream, "UTF-8"), gpxFile); + if (error != null) { + warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType()))); + SettingsHelper.LOG.error("Failed write to gpx file", error); + return false; + } + return true; + } + }; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/GlobalSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/GlobalSettingsItem.java index d30c4d94d8..bcf837de54 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/GlobalSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/GlobalSettingsItem.java @@ -19,6 +19,10 @@ public class GlobalSettingsItem extends OsmandSettingsItem { super(settings); } + public GlobalSettingsItem(@NonNull OsmandSettings settings, @NonNull JSONObject json) throws JSONException { + super(SettingsItemType.GLOBAL, settings, json); + } + @NonNull @Override public SettingsItemType getType() { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/MapSourcesSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/MapSourcesSettingsItem.java index 82cf840b94..4c38a07892 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/MapSourcesSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/MapSourcesSettingsItem.java @@ -236,6 +236,6 @@ public class MapSourcesSettingsItem extends CollectionSettingsItem @Nullable @Override SettingsItemWriter getWriter() { - return null; + return getJsonWriter(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java index 03e1e39ad5..287f6dc9de 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java @@ -194,6 +194,6 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem getWriter() { - return null; + return getJsonWriter(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java index afe23c2059..edcaa350e3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java @@ -167,6 +167,6 @@ public class OsmNotesSettingsItem extends CollectionSettingsItem @Nullable @Override SettingsItemWriter getWriter() { - return null; + return getJsonWriter(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/PoiUiFiltersSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/PoiUiFiltersSettingsItem.java index 8d1c464761..29e20679d9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/PoiUiFiltersSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/PoiUiFiltersSettingsItem.java @@ -173,6 +173,6 @@ public class PoiUiFiltersSettingsItem extends CollectionSettingsItem getWriter() { - return null; + return getJsonWriter(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/QuickActionsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/QuickActionsSettingsItem.java index b2e597ab60..499ac2a833 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/QuickActionsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/QuickActionsSettingsItem.java @@ -178,6 +178,6 @@ public class QuickActionsSettingsItem extends CollectionSettingsItem getWriter() { - return null; + return getJsonWriter(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 0cfa472ef0..7d79ef3481 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -13,6 +13,7 @@ import net.osmand.data.LatLon; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager.TileSourceTemplate; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.SQLiteTileSource; @@ -47,7 +48,7 @@ import java.util.Map; import java.util.Set; import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT; -import static net.osmand.plus.activities.LocalIndexHelper.*; +import static net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; /* Usage: @@ -535,6 +536,10 @@ public class SettingsHelper { if (!files.isEmpty()) { dataList.put(ExportSettingsType.OFFLINE_MAPS, files); } + List favoriteGroups = app.getFavorites().getFavoriteGroups(); + if (!favoriteGroups.isEmpty()) { + dataList.put(ExportSettingsType.FAVORITES, favoriteGroups); + } return dataList; } @@ -562,6 +567,7 @@ public class SettingsHelper { List tileSourceTemplates = new ArrayList<>(); List avoidRoads = new ArrayList<>(); List appModeBeans = new ArrayList<>(); + List favoriteGroups = new ArrayList<>(); List osmNotesPointList = new ArrayList<>(); List osmEditsPointList = new ArrayList<>(); @@ -586,6 +592,8 @@ public class SettingsHelper { osmNotesPointList.add((OsmNotesPoint) object); } else if (object instanceof OpenstreetmapPoint) { osmEditsPointList.add((OpenstreetmapPoint) object); + } else if (object instanceof FavoriteGroup) { + favoriteGroups.add((FavoriteGroup) object); } } if (!quickActions.isEmpty()) { @@ -614,6 +622,9 @@ public class SettingsHelper { if (!osmEditsPointList.isEmpty()) { settingsItems.add(new OsmEditsSettingsItem(app, osmEditsPointList)); } + if (!favoriteGroups.isEmpty()) { + settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups)); + } return settingsItems; } @@ -632,6 +643,8 @@ public class SettingsHelper { List globalSettingsItems = new ArrayList<>(); List notesPointList = new ArrayList<>(); List editsPointList = new ArrayList<>(); + List favoriteGroups = new ArrayList<>(); + for (SettingsItem item : settingsItems) { switch (item.getType()) { case PROFILE: @@ -705,6 +718,10 @@ public class SettingsHelper { editsPointList.addAll(osmEditsSettingsItem.getItems()); } break; + case FAVOURITES: + FavoritesSettingsItem favoritesSettingsItem = (FavoritesSettingsItem) item; + favoriteGroups.addAll(favoritesSettingsItem.getItems()); + break; default: break; } @@ -749,6 +766,9 @@ public class SettingsHelper { if (!mapFilesList.isEmpty()) { settingsToOperate.put(ExportSettingsType.OFFLINE_MAPS, mapFilesList); } + if (!favoriteGroups.isEmpty()) { + settingsToOperate.put(ExportSettingsType.FAVORITES, favoriteGroups); + } return settingsToOperate; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItem.java index caf2d57301..c80eb4cec2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItem.java @@ -142,7 +142,6 @@ public abstract class SettingsItem { } json.put("file", fileName); } - writeItemsToJson(json); } String toJson() throws JSONException { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java index a513dc748c..bb6b68b3ce 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java @@ -15,4 +15,5 @@ public enum SettingsItemType { DOWNLOADS, OSM_NOTES, OSM_EDITS, + FAVOURITES } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java index 8545b37503..9669099003 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java @@ -90,7 +90,7 @@ class SettingsItemsFactory { OsmandSettings settings = app.getSettings(); switch (type) { case GLOBAL: - item = new GlobalSettingsItem(settings); + item = new GlobalSettingsItem(settings, json); break; case PROFILE: item = new ProfileSettingsItem(app, json); @@ -131,6 +131,9 @@ class SettingsItemsFactory { case OSM_EDITS: item = new OsmEditsSettingsItem(app, json); break; + case FAVOURITES: + item = new FavoritesSettingsItem(app, json); + break; } return item; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SuggestedDownloadsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SuggestedDownloadsItem.java index d2dd9a8554..d6411fb89d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SuggestedDownloadsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SuggestedDownloadsItem.java @@ -123,6 +123,6 @@ public class SuggestedDownloadsItem extends SettingsItem { @Nullable @Override SettingsItemWriter getWriter() { - return null; + return getJsonWriter(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java index 8160e81e6e..d90f4b7429 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java @@ -13,6 +13,7 @@ import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.settings.backend.ApplicationMode; @@ -148,6 +149,10 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter multimediaFilesList = new ArrayList<>(); List trackFilesList = new ArrayList<>(); List avoidRoads = new ArrayList<>(); + List favoriteGroups = new ArrayList<>(); for (Object object : duplicatesList) { if (object instanceof ApplicationMode.ApplicationModeBean) { @@ -201,6 +203,8 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View } } else if (object instanceof AvoidRoadInfo) { avoidRoads.add((AvoidRoadInfo) object); + } else if (object instanceof FavoriteGroup) { + favoriteGroups.add((FavoriteGroup) object); } } if (!profiles.isEmpty()) { @@ -239,6 +243,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View duplicates.add(getString(R.string.avoid_road)); duplicates.addAll(avoidRoads); } + if (!favoriteGroups.isEmpty()) { + duplicates.add(getString(R.string.shared_string_favorites)); + duplicates.addAll(favoriteGroups); + } return duplicates; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 8250477d20..5cffbf5898 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -33,6 +33,7 @@ import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.AppInitializer; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.SQLiteTileSource; @@ -46,6 +47,8 @@ import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean; import net.osmand.plus.settings.backend.ExportSettingsType; +import net.osmand.plus.settings.backend.backup.FavoritesSettingsItem; +import net.osmand.plus.settings.backend.backup.GlobalSettingsItem; import net.osmand.plus.settings.backend.backup.OsmEditsSettingsItem; import net.osmand.plus.settings.backend.backup.OsmNotesSettingsItem; import net.osmand.plus.settings.backend.backup.SettingsHelper; @@ -437,6 +440,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment List avoidRoads = new ArrayList<>(); List osmNotesPointList = new ArrayList<>(); List osmEditsPointList = new ArrayList<>(); + List favoriteGroups = new ArrayList<>(); for (Object object : data) { if (object instanceof ApplicationModeBean) { appModeBeans.add((ApplicationModeBean) object); @@ -456,6 +460,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment osmNotesPointList.add((OsmNotesPoint) object); } else if (object instanceof OpenstreetmapPoint) { osmEditsPointList.add((OpenstreetmapPoint) object); + } else if (object instanceof FavoriteGroup) { + favoriteGroups.add((FavoriteGroup) object); + } else if (object instanceof GlobalSettingsItem) { + settingsItems.add((GlobalSettingsItem) object); } } if (!appModeBeans.isEmpty()) { @@ -483,6 +491,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class); settingsItems.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList)); } + if (!favoriteGroups.isEmpty()) { + FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class); + settingsItems.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups)); + } return settingsItems; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java index 7acd88ee4b..d50b00ae6f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java @@ -122,6 +122,18 @@ public class ImportedSettingsItemsAdapter extends holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_info_dark, activeColorRes)); holder.title.setText(R.string.osm_edit_modified_poi); break; + case FAVORITES: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_favorite, activeColorRes)); + holder.title.setText(R.string.shared_string_favorites); + break; + case OFFLINE_MAPS: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_map, activeColorRes)); + holder.title.setText(R.string.shared_string_local_maps); + break; + case GLOBAL: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_settings, activeColorRes)); + holder.title.setText(R.string.general_settings_2); + break; } }