diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java index 1b4231b873..d6718d9579 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 { TRACKS, MULTIMEDIA_NOTES, OSM_NOTES, - OSM_EDITS + OSM_EDITS, + OFFLINE_MAPS } 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 7bcb692058..e7d30ce30f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -16,8 +16,11 @@ 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.activities.LocalIndexHelper; +import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; +import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; @@ -519,9 +522,30 @@ public class SettingsHelper { dataList.put(ExportSettingsType.OSM_EDITS, editsPointList); } } + List files = getLocalMapFiles(); + if (!files.isEmpty()) { + dataList.put(ExportSettingsType.OFFLINE_MAPS, files); + } return dataList; } + private List getLocalMapFiles() { + List files = new ArrayList<>(); + LocalIndexHelper helper = new LocalIndexHelper(app); + List localMapFileList = helper.getLocalFullMaps(new AbstractLoadLocalIndexTask() { + @Override + public void loadFile(LocalIndexInfo... loaded) { + } + }); + for (LocalIndexInfo map : localMapFileList) { + File file = new File(map.getPathToData()); + if (file != null && file.exists()) { + files.add(file); + } + } + return files; + } + public List prepareAdditionalSettingsItems(List data) { List settingsItems = new ArrayList<>(); List quickActions = new ArrayList<>(); @@ -583,6 +607,7 @@ public class SettingsHelper { List renderFilesList = new ArrayList<>(); List multimediaFilesList = new ArrayList<>(); List tracksFilesList = new ArrayList<>(); + List mapFilesList = new ArrayList<>(); List avoidRoads = new ArrayList<>(); List notesPointList = new ArrayList<>(); List editsPointList = new ArrayList<>(); @@ -601,6 +626,8 @@ public class SettingsHelper { multimediaFilesList.add(fileItem.getFile()); } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.GPX) { tracksFilesList.add(fileItem.getFile()); + } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.OBF_MAP) { + mapFilesList.add(fileItem.getFile()); } break; case QUICK_ACTIONS: @@ -689,6 +716,9 @@ public class SettingsHelper { if (!editsPointList.isEmpty()) { settingsToOperate.put(ExportSettingsType.OSM_EDITS, editsPointList); } + if (!mapFilesList.isEmpty()) { + settingsToOperate.put(ExportSettingsType.OFFLINE_MAPS, mapFilesList); + } return settingsToOperate; } } \ No newline at end of file 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 051f122c2e..d931e5a5c4 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java @@ -18,5 +18,6 @@ public enum SettingsItemType { TRACKS, AUDIO_VIDEO_NOTES, OSM_NOTES, - OSM_EDITS + OSM_EDITS, + OFFLINE_MAPS } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java index c1ca0fb590..8fa7c93a14 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java @@ -264,6 +264,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { title.setText(OsmEditingPlugin.getTitle((OpenstreetmapPoint) currentItem, app)); setupIcon(icon, R.drawable.ic_action_info_dark, itemSelected); break; + case OFFLINE_MAPS: + file = (File) currentItem; + title.setText(file.getName()); + setupIcon(icon, R.drawable.ic_map, itemSelected); + break; default: return child; } @@ -344,6 +349,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { return R.string.osm_notes; case OSM_EDITS: return R.string.osm_edit_modified_poi; + case OFFLINE_MAPS: + return R.string.download_regular_maps; default: return R.string.access_empty_list; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index b564f733cf..52a85fee11 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.graphics.Typeface; +import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.text.style.StyleSpan; @@ -27,6 +28,7 @@ import androidx.fragment.app.FragmentManager; import com.google.android.material.appbar.CollapsingToolbarLayout; import net.osmand.AndroidUtils; +import net.osmand.IProgress; import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager.TileSourceTemplate; @@ -63,11 +65,14 @@ import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import java.io.File; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static net.osmand.plus.settings.backend.backup.FileSettingsItem.FileSubtype.*; + public class ImportSettingsFragment extends BaseOsmAndFragment implements View.OnClickListener { @@ -271,6 +276,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment if (succeed) { app.getRendererRegistry().updateExternalRenderers(); AppInitializer.loadRoutingFiles(app, null); + reloadIndexes(items); if (fm != null && file != null) { ImportCompleteFragment.showInstance(fm, items, file.getName()); } @@ -279,6 +285,43 @@ public class ImportSettingsFragment extends BaseOsmAndFragment }; } + private void reloadIndexes(@NonNull List items) { + for (SettingsItem item : items) { + if (item instanceof FileSettingsItem && ((FileSettingsItem) item).getSubtype() == OBF_MAP) { + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + new ReloadIndexesTack((MapActivity) activity).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + break; + } + } + } + + private static class ReloadIndexesTack extends AsyncTask { + + private final WeakReference mapActivityRef; + private final OsmandApplication app; + + ReloadIndexesTack(@NonNull MapActivity mapActivity) { + this.mapActivityRef = new WeakReference<>(mapActivity); + this.app = mapActivity.getMyApplication(); + } + + @Override + protected Void doInBackground(Void[] params) { + app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList()); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + MapActivity mapActivity = mapActivityRef.get(); + if (mapActivity != null) { + mapActivity.refreshMap(); + } + } + } + private SettingsHelper.CheckDuplicatesListener getDuplicatesListener() { return new SettingsHelper.CheckDuplicatesListener() { @Override