Add MarkersSettingsItem initial commit

This commit is contained in:
Vitaliy 2020-11-03 18:11:38 +02:00
parent f9052e4c0b
commit 4923723ade
8 changed files with 209 additions and 7 deletions

View file

@ -16,5 +16,6 @@ public enum ExportSettingsType {
OFFLINE_MAPS, OFFLINE_MAPS,
FAVORITES, FAVORITES,
TTS_VOICE, TTS_VOICE,
VOICE VOICE,
MARKERS
} }

View file

@ -0,0 +1,152 @@
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.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static net.osmand.IndexConstants.GPX_FILE_EXT;
public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup> {
private MapMarkersHelper markersHelper;
public MarkersSettingsItem(@NonNull OsmandApplication app, @NonNull List<MapMarkersGroup> items) {
super(app, null, items);
}
public MarkersSettingsItem(@NonNull OsmandApplication app, @Nullable MarkersSettingsItem baseItem, @NonNull List<MapMarkersGroup> items) {
super(app, baseItem, items);
}
MarkersSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(app, json);
}
@Override
protected void init() {
super.init();
markersHelper = app.getMapMarkersHelper();
existingItems = new ArrayList<>(markersHelper.getMapMarkersGroups());
}
@NonNull
@Override
public SettingsItemType getType() {
return SettingsItemType.MARKERS;
}
@NonNull
@Override
public String getName() {
return "markers";
}
@NonNull
@Override
public String getPublicName(@NonNull Context ctx) {
return ctx.getString(R.string.map_markers);
}
@NonNull
public String getDefaultFileName() {
return getName() + getDefaultFileExtension();
}
@NonNull
public String getDefaultFileExtension() {
return GPX_FILE_EXT;
}
@Override
public void apply() {
List<MapMarkersGroup> newItems = getNewItems();
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
appliedItems = new ArrayList<>(newItems);
for (MapMarkersGroup duplicate : duplicateItems) {
if (shouldReplace) {
}
appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate));
}
}
}
@Override
public boolean isDuplicate(@NonNull MapMarkersGroup markersGroup) {
String name = markersGroup.getName();
for (MapMarkersGroup group : existingItems) {
if (group.getName().equals(name)) {
return true;
}
}
return false;
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@NonNull
@Override
public MapMarkersGroup renameItem(@NonNull MapMarkersGroup item) {
return item;
}
@Nullable
@Override
SettingsItemReader<MarkersSettingsItem> getReader() {
return new SettingsItemReader<MarkersSettingsItem>(this) {
@Override
public void readFromStream(@NonNull InputStream inputStream, File destination) throws IOException, 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, MapMarkersGroup> flatGroups = new LinkedHashMap<>();
}
}
};
}
@Nullable
@Override
SettingsItemWriter<MarkersSettingsItem> getWriter() {
return new SettingsItemWriter<MarkersSettingsItem>(this) {
@Override
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
// 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

@ -14,6 +14,7 @@ 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.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
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;
@ -552,6 +553,10 @@ public class SettingsHelper {
if (!files.isEmpty()) { if (!files.isEmpty()) {
dataList.put(ExportSettingsType.VOICE, files); dataList.put(ExportSettingsType.VOICE, files);
} }
List<MapMarkersGroup> markersGroups = app.getMapMarkersHelper().getMapMarkersGroups();
if (!markersGroups.isEmpty()) {
dataList.put(ExportSettingsType.MARKERS, markersGroups);
}
return dataList; return dataList;
} }
@ -591,6 +596,7 @@ public class SettingsHelper {
List<FavoriteGroup> favoriteGroups = 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<>();
List<MapMarkersGroup> markersGroups = new ArrayList<>();
for (Object object : data) { for (Object object : data) {
if (object instanceof QuickAction) { if (object instanceof QuickAction) {
@ -615,6 +621,8 @@ public class SettingsHelper {
osmEditsPointList.add((OpenstreetmapPoint) object); osmEditsPointList.add((OpenstreetmapPoint) object);
} else if (object instanceof FavoriteGroup) { } else if (object instanceof FavoriteGroup) {
favoriteGroups.add((FavoriteGroup) object); favoriteGroups.add((FavoriteGroup) object);
} else if (object instanceof MapMarkersGroup) {
markersGroups.add((MapMarkersGroup) object);
} }
} }
if (!quickActions.isEmpty()) { if (!quickActions.isEmpty()) {
@ -646,6 +654,9 @@ public class SettingsHelper {
if (!favoriteGroups.isEmpty()) { if (!favoriteGroups.isEmpty()) {
settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups)); settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups));
} }
if (!markersGroups.isEmpty()) {
settingsItems.add(new MarkersSettingsItem(app, markersGroups));
}
return settingsItems; return settingsItems;
} }
@ -667,6 +678,7 @@ public class SettingsHelper {
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<>(); List<FavoriteGroup> favoriteGroups = new ArrayList<>();
List<MapMarkersGroup> markersGroups = new ArrayList<>();
for (SettingsItem item : settingsItems) { for (SettingsItem item : settingsItems) {
switch (item.getType()) { switch (item.getType()) {
@ -746,6 +758,10 @@ public class SettingsHelper {
FavoritesSettingsItem favoritesSettingsItem = (FavoritesSettingsItem) item; FavoritesSettingsItem favoritesSettingsItem = (FavoritesSettingsItem) item;
favoriteGroups.addAll(favoritesSettingsItem.getItems()); favoriteGroups.addAll(favoritesSettingsItem.getItems());
break; break;
case MARKERS:
MarkersSettingsItem markersSettingsItem = (MarkersSettingsItem) item;
markersGroups.addAll(markersSettingsItem.getItems());
break;
default: default:
break; break;
} }
@ -799,6 +815,9 @@ public class SettingsHelper {
if (!voiceFilesList.isEmpty()) { if (!voiceFilesList.isEmpty()) {
settingsToOperate.put(ExportSettingsType.VOICE, voiceFilesList); settingsToOperate.put(ExportSettingsType.VOICE, voiceFilesList);
} }
if (!markersGroups.isEmpty()) {
settingsToOperate.put(ExportSettingsType.MARKERS, markersGroups);
}
return settingsToOperate; return settingsToOperate;
} }
} }

View file

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

View file

@ -134,6 +134,9 @@ class SettingsItemsFactory {
case FAVOURITES: case FAVOURITES:
item = new FavoritesSettingsItem(app, json); item = new FavoritesSettingsItem(app, json);
break; break;
case MARKERS:
item = new MarkersSettingsItem(app, json);
break;
} }
return item; return item;
} }

View file

@ -14,19 +14,20 @@ 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.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
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;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.ProfileIconColors; import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources; import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -153,6 +154,15 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
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.subTitle.setVisibility(View.GONE);
} else if (currentItem instanceof MapMarkersGroup) {
MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
String groupName = markersGroup.getName();
if (Algorithms.isEmpty(groupName)) {
groupName = app.getString(R.string.map_markers);
}
itemHolder.title.setText(groupName);
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_flag, 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

@ -17,6 +17,7 @@ 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.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
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;
@ -316,6 +317,15 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
file.getName())); file.getName()));
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected); setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
break; break;
case MARKERS:
MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
String groupName = markersGroup.getName();
if (Algorithms.isEmpty(groupName)) {
groupName = app.getString(R.string.map_markers);
}
title.setText(groupName);
setupIcon(icon, R.drawable.ic_action_flag, itemSelected);
break;
default: default:
return child; return child;
} }
@ -416,6 +426,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
return R.string.local_indexes_cat_tts; return R.string.local_indexes_cat_tts;
case VOICE: case VOICE:
return R.string.local_indexes_cat_voice; return R.string.local_indexes_cat_voice;
case MARKERS:
return R.string.map_markers;
default: default:
return R.string.access_empty_list; return R.string.access_empty_list;
} }

View file

@ -142,6 +142,10 @@ public class ImportedSettingsItemsAdapter extends
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_settings, activeColorRes)); holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_settings, activeColorRes));
holder.title.setText(R.string.general_settings_2); holder.title.setText(R.string.general_settings_2);
break; break;
case MARKERS:
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_flag, activeColorRes));
holder.title.setText(R.string.map_markers);
break;
} }
} }