Merge branch 'imp_exp_local_maps_offline' into imp_exp_osm_note
This commit is contained in:
commit
ada0a8d300
5 changed files with 84 additions and 2 deletions
|
@ -13,5 +13,6 @@ public enum ExportSettingsType {
|
||||||
TRACKS,
|
TRACKS,
|
||||||
MULTIMEDIA_NOTES,
|
MULTIMEDIA_NOTES,
|
||||||
OSM_NOTES,
|
OSM_NOTES,
|
||||||
OSM_EDITS
|
OSM_EDITS,
|
||||||
|
OFFLINE_MAPS
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,11 @@ import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||||
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;
|
||||||
|
import net.osmand.plus.activities.LocalIndexHelper;
|
||||||
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
|
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.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||||
|
@ -519,9 +522,30 @@ public class SettingsHelper {
|
||||||
dataList.put(ExportSettingsType.OSM_EDITS, editsPointList);
|
dataList.put(ExportSettingsType.OSM_EDITS, editsPointList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<File> files = getLocalMapFiles();
|
||||||
|
if (!files.isEmpty()) {
|
||||||
|
dataList.put(ExportSettingsType.OFFLINE_MAPS, files);
|
||||||
|
}
|
||||||
return dataList;
|
return dataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<File> getLocalMapFiles() {
|
||||||
|
List<File> files = new ArrayList<>();
|
||||||
|
LocalIndexHelper helper = new LocalIndexHelper(app);
|
||||||
|
List<LocalIndexInfo> 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<SettingsItem> prepareAdditionalSettingsItems(List<? super Object> data) {
|
public List<SettingsItem> prepareAdditionalSettingsItems(List<? super Object> data) {
|
||||||
List<SettingsItem> settingsItems = new ArrayList<>();
|
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||||
List<QuickAction> quickActions = new ArrayList<>();
|
List<QuickAction> quickActions = new ArrayList<>();
|
||||||
|
@ -583,6 +607,7 @@ public class SettingsHelper {
|
||||||
List<File> renderFilesList = new ArrayList<>();
|
List<File> renderFilesList = new ArrayList<>();
|
||||||
List<File> multimediaFilesList = new ArrayList<>();
|
List<File> multimediaFilesList = new ArrayList<>();
|
||||||
List<File> tracksFilesList = new ArrayList<>();
|
List<File> tracksFilesList = new ArrayList<>();
|
||||||
|
List<File> mapFilesList = new ArrayList<>();
|
||||||
List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
|
List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
|
||||||
List<OsmNotesPoint> notesPointList = new ArrayList<>();
|
List<OsmNotesPoint> notesPointList = new ArrayList<>();
|
||||||
List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
|
List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
|
||||||
|
@ -601,6 +626,8 @@ public class SettingsHelper {
|
||||||
multimediaFilesList.add(fileItem.getFile());
|
multimediaFilesList.add(fileItem.getFile());
|
||||||
} else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.GPX) {
|
} else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.GPX) {
|
||||||
tracksFilesList.add(fileItem.getFile());
|
tracksFilesList.add(fileItem.getFile());
|
||||||
|
} else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.OBF_MAP) {
|
||||||
|
mapFilesList.add(fileItem.getFile());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QUICK_ACTIONS:
|
case QUICK_ACTIONS:
|
||||||
|
@ -689,6 +716,9 @@ public class SettingsHelper {
|
||||||
if (!editsPointList.isEmpty()) {
|
if (!editsPointList.isEmpty()) {
|
||||||
settingsToOperate.put(ExportSettingsType.OSM_EDITS, editsPointList);
|
settingsToOperate.put(ExportSettingsType.OSM_EDITS, editsPointList);
|
||||||
}
|
}
|
||||||
|
if (!mapFilesList.isEmpty()) {
|
||||||
|
settingsToOperate.put(ExportSettingsType.OFFLINE_MAPS, mapFilesList);
|
||||||
|
}
|
||||||
return settingsToOperate;
|
return settingsToOperate;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,5 +18,6 @@ public enum SettingsItemType {
|
||||||
TRACKS,
|
TRACKS,
|
||||||
AUDIO_VIDEO_NOTES,
|
AUDIO_VIDEO_NOTES,
|
||||||
OSM_NOTES,
|
OSM_NOTES,
|
||||||
OSM_EDITS
|
OSM_EDITS,
|
||||||
|
OFFLINE_MAPS
|
||||||
}
|
}
|
|
@ -264,6 +264,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
title.setText(OsmEditingPlugin.getTitle((OpenstreetmapPoint) currentItem, app));
|
title.setText(OsmEditingPlugin.getTitle((OpenstreetmapPoint) currentItem, app));
|
||||||
setupIcon(icon, R.drawable.ic_action_info_dark, itemSelected);
|
setupIcon(icon, R.drawable.ic_action_info_dark, itemSelected);
|
||||||
break;
|
break;
|
||||||
|
case OFFLINE_MAPS:
|
||||||
|
file = (File) currentItem;
|
||||||
|
title.setText(file.getName());
|
||||||
|
setupIcon(icon, R.drawable.ic_map, itemSelected);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
@ -344,6 +349,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
return R.string.osm_notes;
|
return R.string.osm_notes;
|
||||||
case OSM_EDITS:
|
case OSM_EDITS:
|
||||||
return R.string.osm_edit_modified_poi;
|
return R.string.osm_edit_modified_poi;
|
||||||
|
case OFFLINE_MAPS:
|
||||||
|
return R.string.download_regular_maps;
|
||||||
default:
|
default:
|
||||||
return R.string.access_empty_list;
|
return R.string.access_empty_list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
|
@ -27,6 +28,7 @@ import androidx.fragment.app.FragmentManager;
|
||||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.IProgress;
|
||||||
import net.osmand.PlatformUtil;
|
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;
|
||||||
|
@ -63,11 +65,14 @@ import net.osmand.util.Algorithms;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
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.backup.FileSettingsItem.FileSubtype.*;
|
||||||
|
|
||||||
|
|
||||||
public class ImportSettingsFragment extends BaseOsmAndFragment
|
public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
implements View.OnClickListener {
|
implements View.OnClickListener {
|
||||||
|
@ -271,6 +276,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
if (succeed) {
|
if (succeed) {
|
||||||
app.getRendererRegistry().updateExternalRenderers();
|
app.getRendererRegistry().updateExternalRenderers();
|
||||||
AppInitializer.loadRoutingFiles(app, null);
|
AppInitializer.loadRoutingFiles(app, null);
|
||||||
|
reloadIndexes(items);
|
||||||
if (fm != null && file != null) {
|
if (fm != null && file != null) {
|
||||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||||
}
|
}
|
||||||
|
@ -279,6 +285,43 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reloadIndexes(@NonNull List<SettingsItem> 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<Void, Void, Void> {
|
||||||
|
|
||||||
|
private final WeakReference<MapActivity> 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<String>());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
MapActivity mapActivity = mapActivityRef.get();
|
||||||
|
if (mapActivity != null) {
|
||||||
|
mapActivity.refreshMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SettingsHelper.CheckDuplicatesListener getDuplicatesListener() {
|
private SettingsHelper.CheckDuplicatesListener getDuplicatesListener() {
|
||||||
return new SettingsHelper.CheckDuplicatesListener() {
|
return new SettingsHelper.CheckDuplicatesListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue