Merge pull request #10099 from osmandapp/favourites_backup

Add export and import favorites via osf file
This commit is contained in:
vshcherb 2020-10-30 14:48:34 +01:00 committed by GitHub
commit 3e362cd5cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 322 additions and 28 deletions

View file

@ -76,6 +76,22 @@ public class FavouritesDbHelper {
private int color; private int color;
private List<FavouritePoint> points = new ArrayList<>(); private List<FavouritePoint> 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<FavouritePoint> points, int color, boolean visible) {
this.name = name;
this.color = color;
this.points = points;
this.visible = visible;
}
public boolean isPersonal() { public boolean isPersonal() {
return isPersonal(name); return isPersonal(name);
} }
@ -640,7 +656,7 @@ public class FavouritesDbHelper {
return asGpxFile(cachedFavoritePoints); return asGpxFile(cachedFavoritePoints);
} }
private GPXFile asGpxFile(List<FavouritePoint> favoritePoints) { public GPXFile asGpxFile(List<FavouritePoint> favoritePoints) {
GPXFile gpx = new GPXFile(Version.getFullVersion(context)); GPXFile gpx = new GPXFile(Version.getFullVersion(context));
for (FavouritePoint p : favoritePoints) { for (FavouritePoint p : favoritePoints) {
context.getSelectedGpxHelper().addPoint(p.toWpt(context), gpx); context.getSelectedGpxHelper().addPoint(p.toWpt(context), gpx);

View file

@ -650,8 +650,8 @@ public class ImportHelper {
} }
} }
protected static List<FavouritePoint> asFavourites(OsmandApplication app, List<WptPt> wptPts, String fileName, boolean forceImportFavourites) { public static List<FavouritePoint> asFavourites(OsmandApplication app, List<WptPt> wptPts, String fileName, boolean forceImportFavourites) {
final List<FavouritePoint> favourites = new ArrayList<>(); List<FavouritePoint> favourites = new ArrayList<>();
for (WptPt p : wptPts) { for (WptPt p : wptPts) {
if (p.name != null) { if (p.name != null) {
final String fpCat; final String fpCat;
@ -664,18 +664,18 @@ public class ImportHelper {
} else { } else {
fpCat = p.category; 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) { if (p.desc != null) {
fp.setDescription(p.desc); point.setDescription(p.desc);
} }
fp.setAddress(p.getExtensionsToRead().get("address")); point.setAddress(p.getExtensionsToRead().get("address"));
fp.setColor(p.getColor(0)); point.setColor(p.getColor(0));
String iconName = p.getIconName(); String iconName = p.getIconName();
if (iconName != null) { if (iconName != null) {
fp.setIconIdFromName(app, iconName); point.setIconIdFromName(app, iconName);
} }
fp.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE)); point.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE));
favourites.add(fp); favourites.add(point);
} }
} }
return favourites; return favourites;

View file

@ -323,9 +323,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override @Override
public void addMyPlacesTab(FavoritesActivity favoritesActivity, List<TabActivity.TabItem> mTabs, Intent intent) { public void addMyPlacesTab(FavoritesActivity favoritesActivity, List<TabActivity.TabItem> 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"))) { 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);
} }
} }

View file

@ -13,5 +13,6 @@ public enum ExportSettingsType {
GLOBAL, GLOBAL,
OSM_NOTES, OSM_NOTES,
OSM_EDITS, OSM_EDITS,
OFFLINE_MAPS OFFLINE_MAPS,
FAVORITES
} }

View file

@ -174,6 +174,6 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
@Nullable @Nullable
@Override @Override
SettingsItemWriter<? extends SettingsItem> getWriter() { SettingsItemWriter<? extends SettingsItem> getWriter() {
return null; return getJsonWriter();
} }
} }

View file

@ -97,6 +97,6 @@ public class DownloadsItem extends SettingsItem {
@Nullable @Nullable
@Override @Override
SettingsItemWriter<? extends SettingsItem> getWriter() { SettingsItemWriter<? extends SettingsItem> getWriter() {
return null; return getJsonWriter();
} }
} }

View file

@ -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<FavoriteGroup> {
private FavouritesDbHelper favoritesHelper;
public FavoritesSettingsItem(@NonNull OsmandApplication app, @NonNull List<FavoriteGroup> items) {
super(app, null, items);
}
public FavoritesSettingsItem(@NonNull OsmandApplication app, @Nullable FavoritesSettingsItem baseItem, @NonNull List<FavoriteGroup> 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<FavoriteGroup> 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<FavouritePoint> favouritePoints = new ArrayList<>(existingGroup.getPoints());
for (FavouritePoint favouritePoint : favouritePoints) {
favoritesHelper.deleteFavourite(favouritePoint, false);
}
}
}
appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate));
}
List<FavouritePoint> 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<FavoritesSettingsItem> getReader() {
return new SettingsItemReader<FavoritesSettingsItem>(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<String, FavoriteGroup> flatGroups = new LinkedHashMap<>();
List<FavouritePoint> 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<FavouritePoint> getPointsFromGroups(List<FavoriteGroup> groups) {
List<FavouritePoint> favouritePoints = new ArrayList<>();
for (FavoriteGroup group : groups) {
favouritePoints.addAll(group.getPoints());
}
return favouritePoints;
}
@Nullable
@Override
SettingsItemWriter<FavoritesSettingsItem> getWriter() {
return new SettingsItemWriter<FavoritesSettingsItem>(this) {
@Override
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
List<FavouritePoint> 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;
}
};
}
}

View file

@ -19,6 +19,10 @@ public class GlobalSettingsItem extends OsmandSettingsItem {
super(settings); super(settings);
} }
public GlobalSettingsItem(@NonNull OsmandSettings settings, @NonNull JSONObject json) throws JSONException {
super(SettingsItemType.GLOBAL, settings, json);
}
@NonNull @NonNull
@Override @Override
public SettingsItemType getType() { public SettingsItemType getType() {

View file

@ -236,6 +236,6 @@ public class MapSourcesSettingsItem extends CollectionSettingsItem<ITileSource>
@Nullable @Nullable
@Override @Override
SettingsItemWriter<? extends SettingsItem> getWriter() { SettingsItemWriter<? extends SettingsItem> getWriter() {
return null; return getJsonWriter();
} }
} }

View file

@ -194,6 +194,6 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem<OpenstreetmapPo
@Nullable @Nullable
@Override @Override
SettingsItemWriter<? extends SettingsItem> getWriter() { SettingsItemWriter<? extends SettingsItem> getWriter() {
return null; return getJsonWriter();
} }
} }

View file

@ -167,6 +167,6 @@ public class OsmNotesSettingsItem extends CollectionSettingsItem<OsmNotesPoint>
@Nullable @Nullable
@Override @Override
SettingsItemWriter<? extends SettingsItem> getWriter() { SettingsItemWriter<? extends SettingsItem> getWriter() {
return null; return getJsonWriter();
} }
} }

View file

@ -173,6 +173,6 @@ public class PoiUiFiltersSettingsItem extends CollectionSettingsItem<PoiUIFilter
@Nullable @Nullable
@Override @Override
SettingsItemWriter<? extends SettingsItem> getWriter() { SettingsItemWriter<? extends SettingsItem> getWriter() {
return null; return getJsonWriter();
} }
} }

View file

@ -178,6 +178,6 @@ public class QuickActionsSettingsItem extends CollectionSettingsItem<QuickAction
@Nullable @Nullable
@Override @Override
SettingsItemWriter<? extends SettingsItem> getWriter() { SettingsItemWriter<? extends SettingsItem> getWriter() {
return null; return getJsonWriter();
} }
} }

View file

@ -13,6 +13,7 @@ import net.osmand.data.LatLon;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager;
import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.SQLiteTileSource;
@ -47,7 +48,7 @@ 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.activities.LocalIndexHelper.*; import static net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
/* /*
Usage: Usage:
@ -535,6 +536,10 @@ public class SettingsHelper {
if (!files.isEmpty()) { if (!files.isEmpty()) {
dataList.put(ExportSettingsType.OFFLINE_MAPS, files); dataList.put(ExportSettingsType.OFFLINE_MAPS, files);
} }
List<FavoriteGroup> favoriteGroups = app.getFavorites().getFavoriteGroups();
if (!favoriteGroups.isEmpty()) {
dataList.put(ExportSettingsType.FAVORITES, favoriteGroups);
}
return dataList; return dataList;
} }
@ -562,6 +567,7 @@ public class SettingsHelper {
List<ITileSource> tileSourceTemplates = new ArrayList<>(); List<ITileSource> tileSourceTemplates = new ArrayList<>();
List<AvoidRoadInfo> avoidRoads = new ArrayList<>(); List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
List<ApplicationModeBean> appModeBeans = new ArrayList<>(); List<ApplicationModeBean> appModeBeans = new ArrayList<>();
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>(); List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>(); List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
@ -586,6 +592,8 @@ public class SettingsHelper {
osmNotesPointList.add((OsmNotesPoint) object); osmNotesPointList.add((OsmNotesPoint) object);
} else if (object instanceof OpenstreetmapPoint) { } else if (object instanceof OpenstreetmapPoint) {
osmEditsPointList.add((OpenstreetmapPoint) object); osmEditsPointList.add((OpenstreetmapPoint) object);
} else if (object instanceof FavoriteGroup) {
favoriteGroups.add((FavoriteGroup) object);
} }
} }
if (!quickActions.isEmpty()) { if (!quickActions.isEmpty()) {
@ -614,6 +622,9 @@ public class SettingsHelper {
if (!osmEditsPointList.isEmpty()) { if (!osmEditsPointList.isEmpty()) {
settingsItems.add(new OsmEditsSettingsItem(app, osmEditsPointList)); settingsItems.add(new OsmEditsSettingsItem(app, osmEditsPointList));
} }
if (!favoriteGroups.isEmpty()) {
settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups));
}
return settingsItems; return settingsItems;
} }
@ -632,6 +643,8 @@ public class SettingsHelper {
List<GlobalSettingsItem> globalSettingsItems = new ArrayList<>(); List<GlobalSettingsItem> globalSettingsItems = new ArrayList<>();
List<OsmNotesPoint> notesPointList = new ArrayList<>(); List<OsmNotesPoint> notesPointList = new ArrayList<>();
List<OpenstreetmapPoint> editsPointList = new ArrayList<>(); List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
for (SettingsItem item : settingsItems) { for (SettingsItem item : settingsItems) {
switch (item.getType()) { switch (item.getType()) {
case PROFILE: case PROFILE:
@ -705,6 +718,10 @@ public class SettingsHelper {
editsPointList.addAll(osmEditsSettingsItem.getItems()); editsPointList.addAll(osmEditsSettingsItem.getItems());
} }
break; break;
case FAVOURITES:
FavoritesSettingsItem favoritesSettingsItem = (FavoritesSettingsItem) item;
favoriteGroups.addAll(favoritesSettingsItem.getItems());
break;
default: default:
break; break;
} }
@ -749,6 +766,9 @@ public class SettingsHelper {
if (!mapFilesList.isEmpty()) { if (!mapFilesList.isEmpty()) {
settingsToOperate.put(ExportSettingsType.OFFLINE_MAPS, mapFilesList); settingsToOperate.put(ExportSettingsType.OFFLINE_MAPS, mapFilesList);
} }
if (!favoriteGroups.isEmpty()) {
settingsToOperate.put(ExportSettingsType.FAVORITES, favoriteGroups);
}
return settingsToOperate; return settingsToOperate;
} }
} }

View file

@ -142,7 +142,6 @@ public abstract class SettingsItem {
} }
json.put("file", fileName); json.put("file", fileName);
} }
writeItemsToJson(json);
} }
String toJson() throws JSONException { String toJson() throws JSONException {

View file

@ -15,4 +15,5 @@ public enum SettingsItemType {
DOWNLOADS, DOWNLOADS,
OSM_NOTES, OSM_NOTES,
OSM_EDITS, OSM_EDITS,
FAVOURITES
} }

View file

@ -90,7 +90,7 @@ class SettingsItemsFactory {
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
switch (type) { switch (type) {
case GLOBAL: case GLOBAL:
item = new GlobalSettingsItem(settings); item = new GlobalSettingsItem(settings, json);
break; break;
case PROFILE: case PROFILE:
item = new ProfileSettingsItem(app, json); item = new ProfileSettingsItem(app, json);
@ -131,6 +131,9 @@ class SettingsItemsFactory {
case OSM_EDITS: case OSM_EDITS:
item = new OsmEditsSettingsItem(app, json); item = new OsmEditsSettingsItem(app, json);
break; break;
case FAVOURITES:
item = new FavoritesSettingsItem(app, json);
break;
} }
return item; return item;
} }

View file

@ -123,6 +123,6 @@ public class SuggestedDownloadsItem extends SettingsItem {
@Nullable @Nullable
@Override @Override
SettingsItemWriter<? extends SettingsItem> getWriter() { SettingsItemWriter<? extends SettingsItem> getWriter() {
return null; return getJsonWriter();
} }
} }

View file

@ -13,6 +13,7 @@ import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
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;
@ -148,6 +149,10 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
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); itemHolder.subTitle.setVisibility(View.GONE);
} else if (currentItem instanceof FavoriteGroup) {
itemHolder.title.setText(((FavoriteGroup) currentItem).getDisplayName(app));
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);
} }

View file

@ -16,6 +16,7 @@ import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
@ -35,8 +36,8 @@ import net.osmand.plus.render.RenderingIcons;
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.plus.settings.backend.backup.GlobalSettingsItem;
import net.osmand.plus.settings.backend.backup.FileSettingsItem; import net.osmand.plus.settings.backend.backup.FileSettingsItem;
import net.osmand.plus.settings.backend.backup.GlobalSettingsItem;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.view.ThreeStateCheckbox; import net.osmand.view.ThreeStateCheckbox;
@ -49,8 +50,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static net.osmand.plus.settings.backend.ExportSettingsType.*; import static net.osmand.plus.settings.backend.ExportSettingsType.OFFLINE_MAPS;
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.*; import static net.osmand.plus.settings.backend.backup.FileSettingsItem.FileSubtype;
import static net.osmand.view.ThreeStateCheckbox.State.CHECKED; import static net.osmand.view.ThreeStateCheckbox.State.CHECKED;
import static net.osmand.view.ThreeStateCheckbox.State.MISC; import static net.osmand.view.ThreeStateCheckbox.State.MISC;
import static net.osmand.view.ThreeStateCheckbox.State.UNCHECKED; import static net.osmand.view.ThreeStateCheckbox.State.UNCHECKED;
@ -303,6 +304,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
subText.setText(AndroidUtils.formatSize(app, size)); subText.setText(AndroidUtils.formatSize(app, size));
subText.setVisibility(View.VISIBLE); subText.setVisibility(View.VISIBLE);
break; break;
case FAVORITES:
FavoriteGroup favoriteGroup = (FavoriteGroup) currentItem;
title.setText(favoriteGroup.getDisplayName(app));
setupIcon(icon, R.drawable.ic_action_favorite, itemSelected);
break;
default: default:
return child; return child;
} }
@ -393,6 +399,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
return R.string.osm_edit_modified_poi; return R.string.osm_edit_modified_poi;
case OFFLINE_MAPS: case OFFLINE_MAPS:
return R.string.shared_string_local_maps; return R.string.shared_string_local_maps;
case FAVORITES:
return R.string.shared_string_favorites;
default: default:
return R.string.access_empty_list; return R.string.access_empty_list;
} }

View file

@ -28,6 +28,8 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment; import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.quickaction.QuickActionListFragment; import net.osmand.plus.quickaction.QuickActionListFragment;
import net.osmand.plus.routepreparationmenu.AvoidRoadsBottomSheetDialogFragment; import net.osmand.plus.routepreparationmenu.AvoidRoadsBottomSheetDialogFragment;
import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment;
@ -194,9 +196,15 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
OsmAndAppCustomization appCustomization = app.getAppCustomization(); OsmAndAppCustomization appCustomization = app.getAppCustomization();
final Intent favorites = new Intent(activity, appCustomization.getFavoritesActivity()); final Intent favorites = new Intent(activity, appCustomization.getFavoritesActivity());
favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
app.getSettings().FAVORITES_TAB.set(R.string.osm_edits); app.getSettings().FAVORITES_TAB.set(OsmEditingPlugin.OSM_EDIT_TAB);
startActivity(favorites); startActivity(favorites);
break; break;
case FAVORITES:
Intent favoritesActivity = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
favoritesActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
app.getSettings().FAVORITES_TAB.set(FavoritesActivity.FAV_TAB);
startActivity(favoritesActivity);
break;
default: default:
break; break;
} }

View file

@ -26,6 +26,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
@ -178,6 +179,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
List<File> multimediaFilesList = new ArrayList<>(); List<File> multimediaFilesList = new ArrayList<>();
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<>();
for (Object object : duplicatesList) { for (Object object : duplicatesList) {
if (object instanceof ApplicationMode.ApplicationModeBean) { if (object instanceof ApplicationMode.ApplicationModeBean) {
@ -201,6 +203,8 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
} }
} else if (object instanceof AvoidRoadInfo) { } else if (object instanceof AvoidRoadInfo) {
avoidRoads.add((AvoidRoadInfo) object); avoidRoads.add((AvoidRoadInfo) object);
} else if (object instanceof FavoriteGroup) {
favoriteGroups.add((FavoriteGroup) object);
} }
} }
if (!profiles.isEmpty()) { if (!profiles.isEmpty()) {
@ -239,6 +243,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
duplicates.add(getString(R.string.avoid_road)); duplicates.add(getString(R.string.avoid_road));
duplicates.addAll(avoidRoads); duplicates.addAll(avoidRoads);
} }
if (!favoriteGroups.isEmpty()) {
duplicates.add(getString(R.string.shared_string_favorites));
duplicates.addAll(favoriteGroups);
}
return duplicates; return duplicates;
} }

View file

@ -33,6 +33,7 @@ import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource; 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.quickaction.QuickAction;
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.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.OsmEditsSettingsItem;
import net.osmand.plus.settings.backend.backup.OsmNotesSettingsItem; import net.osmand.plus.settings.backend.backup.OsmNotesSettingsItem;
import net.osmand.plus.settings.backend.backup.SettingsHelper; import net.osmand.plus.settings.backend.backup.SettingsHelper;
@ -437,6 +440,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
List<AvoidRoadInfo> avoidRoads = new ArrayList<>(); List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>(); List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>(); List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
for (Object object : data) { for (Object object : data) {
if (object instanceof ApplicationModeBean) { if (object instanceof ApplicationModeBean) {
appModeBeans.add((ApplicationModeBean) object); appModeBeans.add((ApplicationModeBean) object);
@ -456,6 +460,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
osmNotesPointList.add((OsmNotesPoint) object); osmNotesPointList.add((OsmNotesPoint) object);
} else if (object instanceof OpenstreetmapPoint) { } else if (object instanceof OpenstreetmapPoint) {
osmEditsPointList.add((OpenstreetmapPoint) object); 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()) { if (!appModeBeans.isEmpty()) {
@ -483,6 +491,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class); OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class);
settingsItems.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList)); 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; return settingsItems;
} }

View file

@ -122,6 +122,18 @@ public class ImportedSettingsItemsAdapter extends
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_info_dark, activeColorRes)); holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_info_dark, activeColorRes));
holder.title.setText(R.string.osm_edit_modified_poi); holder.title.setText(R.string.osm_edit_modified_poi);
break; 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;
} }
} }