From 1308d16e970dea283571cc50c52cc85e3b8a43fb Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 16 Oct 2020 00:13:30 +0300 Subject: [PATCH] Add multimedia notes to import/export --- .../AudioVideoNoteMenuController.java | 10 ++++---- .../audionotes/AudioVideoNotesPlugin.java | 21 ++++++++++++---- .../settings/backend/ExportSettingsType.java | 2 +- .../backend/backup/FileSettingsItem.java | 3 ++- .../backend/backup/SettingsHelper.java | 22 +++++++++++++++++ .../fragments/DuplicatesSettingsAdapter.java | 7 ++++++ .../ExportImportSettingsAdapter.java | 19 ++++++++++++--- .../fragments/ExportProfileBottomSheet.java | 1 - .../fragments/ImportDuplicatesFragment.java | 24 +++++++++++++------ .../ImportedSettingsItemsAdapter.java | 4 ++++ 10 files changed, 89 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java index f2f31e3a26..a0594ffc66 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java @@ -96,13 +96,11 @@ public class AudioVideoNoteMenuController extends MenuController { @Override public Drawable getRightIcon() { - if (mRecording.isPhoto()) { - return getIcon(R.drawable.ic_action_photo_dark, R.color.audio_video_icon_color); - } else if (mRecording.isAudio()) { - return getIcon(R.drawable.ic_action_micro_dark, R.color.audio_video_icon_color); - } else { - return getIcon(R.drawable.ic_action_video_dark, R.color.audio_video_icon_color); + int iconId = AudioVideoNotesPlugin.getIconIdForRecordingFile(mRecording.getFile()); + if (iconId == -1) { + iconId = R.drawable.ic_action_photo_dark; } + return getIcon(iconId, R.color.audio_video_icon_color); } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 0a99d15b03..f59b5869ea 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -47,14 +47,11 @@ import net.osmand.PlatformUtil; import net.osmand.data.DataTileManager; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.CommonPreference; -import net.osmand.plus.settings.backend.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -66,12 +63,15 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.quickaction.QuickActionType; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.CommonPreference; +import net.osmand.plus.settings.backend.OsmandPreference; import net.osmand.plus.settings.fragments.BaseSettingsFragment; -import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState; +import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget; +import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState; import net.osmand.util.Algorithms; import net.osmand.util.GeoPointParserUtil.GeoParsedPoint; import net.osmand.util.MapUtils; @@ -517,7 +517,18 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } return additional.toString(); } + } + public static int getIconIdForRecordingFile(@NonNull File file) { + String fileName = file.getName(); + if (fileName.endsWith(IMG_EXTENSION)) { + return R.drawable.ic_action_photo_dark; + } else if (fileName.endsWith(MPEG4_EXTENSION)) { + return R.drawable.ic_action_video_dark; + } else if (fileName.endsWith(THREEGP_EXTENSION)) { + return R.drawable.ic_action_micro_dark; + } + return -1; } // private static void initializeRemoteControlRegistrationMethods() { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java index 004887d8ee..79e35ffdf8 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java @@ -11,6 +11,6 @@ public enum ExportSettingsType { MARKERS, FAVORITES, TRACKS, - AUDIO_VIDEO_NOTES, + MULTIMEDIA_NOTES, OSM_CHANGES } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java index 7e64e7312a..c8d2838ae9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java @@ -30,7 +30,8 @@ public class FileSettingsItem extends StreamSettingsItem { TILES_MAP("tiles_map", IndexConstants.TILES_INDEX_DIR), GPX("gpx", IndexConstants.GPX_INDEX_DIR), VOICE("voice", IndexConstants.VOICE_INDEX_DIR), - TRAVEL("travel", IndexConstants.WIKIVOYAGE_INDEX_DIR); + TRAVEL("travel", IndexConstants.WIKIVOYAGE_INDEX_DIR), + MULTIMEDIA_NOTES("multimedia_notes", IndexConstants.AV_INDEX_DIR); private String subtypeName; private String subtypeFolder; 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 78d07e893c..9b6df2277d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -14,7 +14,10 @@ import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; import net.osmand.plus.SQLiteTileSource; +import net.osmand.plus.audionotes.AudioVideoNotesPlugin; +import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; @@ -473,6 +476,19 @@ public class SettingsHelper { if (!impassableRoads.isEmpty()) { dataList.put(ExportSettingsType.AVOID_ROADS, new ArrayList<>(impassableRoads.values())); } + AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class); + if (plugin != null) { + List files = new ArrayList<>(); + for (Recording rec : plugin.getAllRecordings()) { + File file = rec.getFile(); + if (file != null && file.exists()) { + files.add(file); + } + } + if (!files.isEmpty()) { + dataList.put(ExportSettingsType.MULTIMEDIA_NOTES, files); + } + } return dataList; } @@ -522,6 +538,7 @@ public class SettingsHelper { List tileSourceTemplates = new ArrayList<>(); List routingFilesList = new ArrayList<>(); List renderFilesList = new ArrayList<>(); + List multimediaFilesList = new ArrayList<>(); List avoidRoads = new ArrayList<>(); for (SettingsItem item : settingsItems) { switch (item.getType()) { @@ -534,6 +551,8 @@ public class SettingsHelper { renderFilesList.add(fileItem.getFile()); } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.ROUTING_CONFIG) { routingFilesList.add(fileItem.getFile()); + } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.MULTIMEDIA_NOTES) { + multimediaFilesList.add(fileItem.getFile()); } break; case QUICK_ACTIONS: @@ -594,6 +613,9 @@ public class SettingsHelper { if (!avoidRoads.isEmpty()) { settingsToOperate.put(ExportSettingsType.AVOID_ROADS, avoidRoads); } + if (!multimediaFilesList.isEmpty()) { + settingsToOperate.put(ExportSettingsType.MULTIMEDIA_NOTES, multimediaFilesList); + } return settingsToOperate; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java index dc78f5755c..c6ce3232b8 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.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean; import net.osmand.plus.OsmandApplication; @@ -131,6 +132,12 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter tileSources = new ArrayList<>(); List renderFilesList = new ArrayList<>(); List routingFilesList = new ArrayList<>(); + List multimediaFilesList = new ArrayList<>(); List avoidRoads = new ArrayList<>(); for (Object object : duplicatesList) { @@ -184,10 +188,12 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View tileSources.add((ITileSource) object); } else if (object instanceof File) { File file = (File) object; - if (file.getAbsolutePath().contains("files/rendering")) { + if (file.getAbsolutePath().contains(RENDERERS_DIR)) { renderFilesList.add(file); - } else if (file.getAbsolutePath().contains("files/routing")) { + } else if (file.getAbsolutePath().contains(ROUTING_PROFILES_DIR)) { routingFilesList.add(file); + } else if (file.getAbsolutePath().contains(AV_INDEX_DIR)) { + multimediaFilesList.add(file); } } else if (object instanceof AvoidRoadInfo) { avoidRoads.add((AvoidRoadInfo) object); @@ -217,6 +223,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View duplicates.add(getString(R.string.shared_string_rendering_style)); duplicates.addAll(renderFilesList); } + if (!multimediaFilesList.isEmpty()) { + duplicates.add(getString(R.string.audionotes_plugin_name)); + duplicates.addAll(multimediaFilesList); + } if (!avoidRoads.isEmpty()) { duplicates.add(getString(R.string.avoid_road)); duplicates.addAll(avoidRoads); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java index e663e6f189..ef98a624dd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java @@ -106,6 +106,10 @@ public class ImportedSettingsItemsAdapter extends holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_alert, activeColorRes)); holder.title.setText(R.string.avoid_road); break; + case MULTIMEDIA_NOTES: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_photo_dark, activeColorRes)); + holder.title.setText(R.string.audionotes_plugin_name); + break; } }