Search in sources :

Example 1 with GpxSettingsItem

use of net.osmand.plus.settings.backend.backup.items.GpxSettingsItem in project Osmand by osmandapp.

the class SettingsItemsFactory method createItem.

@Nullable
private SettingsItem createItem(@NonNull JSONObject json) throws IllegalArgumentException, JSONException {
    SettingsItem item = null;
    SettingsItemType type = SettingsItem.parseItemType(json);
    if (type == null) {
        return null;
    }
    OsmandSettings settings = app.getSettings();
    switch(type) {
        case GLOBAL:
            item = new GlobalSettingsItem(settings, json);
            break;
        case PROFILE:
            item = new ProfileSettingsItem(app, json);
            break;
        case PLUGIN:
            item = new PluginSettingsItem(app, json);
            break;
        case DATA:
            item = new DataSettingsItem(app, json);
            break;
        case FILE:
            item = new FileSettingsItem(app, json);
            break;
        case RESOURCES:
            item = new ResourcesSettingsItem(app, json);
            break;
        case QUICK_ACTIONS:
            item = new QuickActionsSettingsItem(app, json);
            break;
        case POI_UI_FILTERS:
            item = new PoiUiFiltersSettingsItem(app, json);
            break;
        case MAP_SOURCES:
            item = new MapSourcesSettingsItem(app, json);
            break;
        case AVOID_ROADS:
            item = new AvoidRoadsSettingsItem(app, json);
            break;
        case SUGGESTED_DOWNLOADS:
            item = new SuggestedDownloadsItem(app, json);
            break;
        case DOWNLOADS:
            item = new DownloadsItem(app, json);
            break;
        case OSM_NOTES:
            item = new OsmNotesSettingsItem(app, json);
            break;
        case OSM_EDITS:
            item = new OsmEditsSettingsItem(app, json);
            break;
        case FAVOURITES:
            item = new FavoritesSettingsItem(app, json);
            break;
        case ACTIVE_MARKERS:
            item = new MarkersSettingsItem(app, json);
            break;
        case HISTORY_MARKERS:
            item = new HistoryMarkersSettingsItem(app, json);
            break;
        case SEARCH_HISTORY:
            item = new SearchHistorySettingsItem(app, json);
            break;
        case GPX:
            item = new GpxSettingsItem(app, json);
            break;
        case ONLINE_ROUTING_ENGINES:
            item = new OnlineRoutingSettingsItem(app, json);
            break;
        case ITINERARY_GROUPS:
            item = new ItinerarySettingsItem(app, json);
            break;
    }
    return item;
}
Also used : SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) DataSettingsItem(net.osmand.plus.settings.backend.backup.items.DataSettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) ResourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.ResourcesSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) DownloadsItem(net.osmand.plus.settings.backend.backup.items.DownloadsItem) SuggestedDownloadsItem(net.osmand.plus.settings.backend.backup.items.SuggestedDownloadsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) DataSettingsItem(net.osmand.plus.settings.backend.backup.items.DataSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) ResourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.ResourcesSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) SuggestedDownloadsItem(net.osmand.plus.settings.backend.backup.items.SuggestedDownloadsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) Nullable(androidx.annotation.Nullable)

Example 2 with GpxSettingsItem

use of net.osmand.plus.settings.backend.backup.items.GpxSettingsItem in project Osmand by osmandapp.

the class ExportItemsBottomSheet method setupBottomSheetItem.

private void setupBottomSheetItem(BottomSheetItemWithCompoundButton item, Object object) {
    if (object instanceof ApplicationModeBean) {
        ApplicationModeBean modeBean = (ApplicationModeBean) object;
        String profileName = modeBean.userProfileName;
        if (Algorithms.isEmpty(profileName)) {
            ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
            if (appMode != null) {
                profileName = appMode.toHumanString();
            } else {
                profileName = Algorithms.capitalizeFirstLetter(modeBean.stringKey);
            }
        }
        item.setTitle(profileName);
        String routingProfile = "";
        String routingProfileValue = modeBean.routingProfile;
        if (!routingProfileValue.isEmpty()) {
            try {
                routingProfile = getString(RoutingProfilesResources.valueOf(routingProfileValue.toUpperCase()).getStringRes());
                routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfile);
            } catch (IllegalArgumentException e) {
                routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfileValue);
                LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e);
            }
        }
        if (!Algorithms.isEmpty(routingProfile)) {
            item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.nav_type_hint), routingProfile));
        } else {
            item.setDescription(getString(R.string.profile_type_osmand_string));
        }
        int profileIconRes = AndroidUtils.getDrawableId(app, modeBean.iconName);
        ProfileIconColors iconColor = modeBean.iconColor;
        Integer customIconColor = modeBean.customIconColor;
        int actualIconColor;
        if (selectedItems.contains(object)) {
            actualIconColor = customIconColor != null ? customIconColor : ContextCompat.getColor(app, iconColor.getColor(nightMode));
        } else {
            actualIconColor = ContextCompat.getColor(app, secondaryColorRes);
        }
        int iconRes = profileIconRes != 0 ? profileIconRes : R.drawable.ic_world_globe_dark;
        item.setIcon(uiUtilities.getPaintedIcon(iconRes, actualIconColor));
    } else if (object instanceof QuickAction) {
        QuickAction quickAction = (QuickAction) object;
        item.setTitle(quickAction.getName(app));
        item.setIcon(uiUtilities.getIcon(quickAction.getIconRes(), getItemIconColor(object)));
    } else if (object instanceof PoiUIFilter) {
        PoiUIFilter poiUIFilter = (PoiUIFilter) object;
        item.setTitle(poiUIFilter.getName());
        int iconRes = RenderingIcons.getBigIconResourceId(poiUIFilter.getIconId());
        item.setIcon(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_action_user, activeColorRes));
    } else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) {
        ITileSource tileSource = (ITileSource) object;
        item.setTitle(tileSource.getName());
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_map, getItemIconColor(object)));
    } else if (object instanceof File) {
        setupBottomSheetItemForFile(item, (File) object);
    } else if (object instanceof GpxSettingsItem) {
        GpxSettingsItem settingsItem = (GpxSettingsItem) object;
        setupBottomSheetItemForGpx(item, settingsItem.getFile(), settingsItem.getAppearanceInfo());
    } else if (object instanceof FileSettingsItem) {
        FileSettingsItem settingsItem = (FileSettingsItem) object;
        setupBottomSheetItemForFile(item, settingsItem.getFile());
    } else if (object instanceof AvoidRoadInfo) {
        AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) object;
        item.setTitle(avoidRoadInfo.name);
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_alert, getItemIconColor(object)));
    } else if (object instanceof OsmNotesPoint) {
        OsmNotesPoint osmNotesPoint = (OsmNotesPoint) object;
        item.setTitle(osmNotesPoint.getText());
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_osm_note_add, getItemIconColor(object)));
    } else if (object instanceof OpenstreetmapPoint) {
        OpenstreetmapPoint openstreetmapPoint = (OpenstreetmapPoint) object;
        item.setTitle(OsmEditingPlugin.getTitle(openstreetmapPoint, app));
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_info_dark, getItemIconColor(object)));
    } else if (object instanceof FavoriteGroup) {
        FavoriteGroup group = (FavoriteGroup) object;
        item.setTitle(group.getDisplayName(app));
        int color;
        if (selectedItems.contains(object)) {
            color = group.getColor() == 0 ? ContextCompat.getColor(app, R.color.color_favorite) : group.getColor();
        } else {
            color = ContextCompat.getColor(app, secondaryColorRes);
        }
        item.setIcon(uiUtilities.getPaintedIcon(R.drawable.ic_action_folder, color));
        int points = group.getPoints().size();
        String itemsDescr = getString(R.string.shared_string_gpx_points);
        item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, points));
    } else if (object instanceof GlobalSettingsItem) {
        GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object;
        item.setTitle(globalSettingsItem.getPublicName(app));
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, getItemIconColor(object)));
    } else if (object instanceof MapMarkersGroup) {
        MapMarkersGroup markersGroup = (MapMarkersGroup) object;
        if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
            item.setTitle(getString(R.string.map_markers));
            item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
        } else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
            item.setTitle(getString(R.string.markers_history));
            item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_history, getItemIconColor(object)));
        } else {
            String groupName = markersGroup.getName();
            if (Algorithms.isEmpty(groupName)) {
                if (markersGroup.getType() == ItineraryType.FAVOURITES) {
                    groupName = app.getString(R.string.shared_string_favorites);
                } else if (markersGroup.getType() == ItineraryType.MARKERS) {
                    groupName = app.getString(R.string.map_markers);
                }
            }
            item.setTitle(groupName);
            item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
        }
        int selectedMarkers = markersGroup.getMarkers().size();
        String itemsDescr = getString(R.string.shared_string_items);
        item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers));
    } else if (object instanceof HistoryEntry) {
        HistoryEntry historyEntry = (HistoryEntry) object;
        item.setTitle(historyEntry.getName().getName());
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_history, getItemIconColor(object)));
    } else if (object instanceof OnlineRoutingEngine) {
        OnlineRoutingEngine onlineRoutingEngine = (OnlineRoutingEngine) object;
        item.setTitle(onlineRoutingEngine.getName(app));
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_world_globe_dark, getItemIconColor(object)));
    }
}
Also used : QuickAction(net.osmand.plus.quickaction.QuickAction) ProfileIconColors(net.osmand.plus.profiles.ProfileIconColors) TileSourceTemplate(net.osmand.map.TileSourceManager.TileSourceTemplate) ApplicationModeBean(net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) AvoidRoadInfo(net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) SQLiteTileSource(net.osmand.plus.resources.SQLiteTileSource) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) ITileSource(net.osmand.map.ITileSource) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) File(java.io.File)

Example 3 with GpxSettingsItem

use of net.osmand.plus.settings.backend.backup.items.GpxSettingsItem in project Osmand by osmandapp.

the class BackupHelper method collectLocalFiles.

@SuppressLint("StaticFieldLeak")
void collectLocalFiles(@Nullable final OnCollectLocalFilesListener listener) {
    OperationLog operationLog = new OperationLog("collectLocalFiles", DEBUG);
    operationLog.startOperation();
    AsyncTask<Void, LocalFile, List<LocalFile>> task = new AsyncTask<Void, LocalFile, List<LocalFile>>() {

        BackupDbHelper dbHelper;

        SQLiteConnection db;

        Map<String, UploadedFileInfo> infos;

        @Override
        protected void onPreExecute() {
            dbHelper = app.getBackupHelper().getDbHelper();
            db = dbHelper.openConnection(true);
        }

        @Override
        protected List<LocalFile> doInBackground(Void... voids) {
            List<LocalFile> result = new ArrayList<>();
            infos = dbHelper.getUploadedFileInfoMap();
            List<SettingsItem> localItems = getLocalItems();
            operationLog.log("getLocalItems");
            for (SettingsItem item : localItems) {
                String fileName = BackupHelper.getItemFileName(item);
                if (item instanceof FileSettingsItem) {
                    FileSettingsItem fileItem = (FileSettingsItem) item;
                    File file = fileItem.getFile();
                    if (file.isDirectory()) {
                        if (item instanceof GpxSettingsItem) {
                            continue;
                        } else if (fileItem.getSubtype() == FileSubtype.VOICE) {
                            File jsFile = new File(file, file.getName() + "_" + IndexConstants.TTSVOICE_INDEX_EXT_JS);
                            if (jsFile.exists()) {
                                fileName = jsFile.getPath().replace(app.getAppPath(null).getPath() + "/", "");
                                createLocalFile(result, item, fileName, jsFile, jsFile.lastModified());
                                continue;
                            }
                        } else if (fileItem.getSubtype() == FileSubtype.TTS_VOICE) {
                            String langName = file.getName().replace(IndexConstants.VOICE_PROVIDER_SUFFIX, "");
                            File jsFile = new File(file, langName + "_" + IndexConstants.TTSVOICE_INDEX_EXT_JS);
                            if (jsFile.exists()) {
                                fileName = jsFile.getPath().replace(app.getAppPath(null).getPath() + "/", "");
                                createLocalFile(result, item, fileName, jsFile, jsFile.lastModified());
                                continue;
                            }
                        } else if (fileItem.getSubtype() == FileSubtype.TILES_MAP) {
                            continue;
                        }
                        List<File> dirs = new ArrayList<>();
                        dirs.add(file);
                        Algorithms.collectDirs(file, dirs);
                        operationLog.log("collectDirs " + file.getName() + " BEGIN");
                        for (File dir : dirs) {
                            File[] files = dir.listFiles();
                            if (files != null && files.length > 0) {
                                for (File f : files) {
                                    if (!f.isDirectory()) {
                                        fileName = f.getPath().replace(app.getAppPath(null).getPath() + "/", "");
                                        createLocalFile(result, item, fileName, f, f.lastModified());
                                    }
                                }
                            }
                        }
                        operationLog.log("collectDirs " + file.getName() + " END");
                    } else if (fileItem.getSubtype() == FileSubtype.TILES_MAP) {
                        if (file.getName().endsWith(SQLiteTileSource.EXT)) {
                            createLocalFile(result, item, fileName, file, file.lastModified());
                        }
                    } else {
                        createLocalFile(result, item, fileName, file, file.lastModified());
                    }
                } else {
                    createLocalFile(result, item, fileName, null, item.getLastModifiedTime());
                }
            }
            return result;
        }

        private void createLocalFile(@NonNull List<LocalFile> result, @NonNull SettingsItem item, @NonNull String fileName, @Nullable File file, long lastModifiedTime) {
            LocalFile localFile = new LocalFile();
            localFile.file = file;
            localFile.item = item;
            localFile.fileName = fileName;
            localFile.localModifiedTime = lastModifiedTime;
            if (infos != null) {
                UploadedFileInfo fileInfo = infos.get(item.getType().name() + "___" + fileName);
                if (fileInfo != null) {
                    localFile.uploadTime = fileInfo.getUploadTime();
                    String lastMd5 = fileInfo.getMd5Digest();
                    boolean needM5Digest = item instanceof StreamSettingsItem && ((StreamSettingsItem) item).needMd5Digest() && localFile.uploadTime < lastModifiedTime && !Algorithms.isEmpty(lastMd5);
                    if (needM5Digest && file != null && file.exists()) {
                        FileInputStream is = null;
                        try {
                            is = new FileInputStream(file);
                            String md5 = new String(Hex.encodeHex(DigestUtils.md5(is)));
                            if (md5.equals(lastMd5)) {
                                item.setLocalModifiedTime(localFile.uploadTime);
                                localFile.localModifiedTime = localFile.uploadTime;
                            }
                        } catch (IOException e) {
                            LOG.error(e.getMessage(), e);
                        } finally {
                            Algorithms.closeStream(is);
                        }
                    }
                }
            }
            result.add(localFile);
            publishProgress(localFile);
        }

        private List<SettingsItem> getLocalItems() {
            List<ExportSettingsType> types = ExportSettingsType.getEnabledTypes();
            Iterator<ExportSettingsType> it = types.iterator();
            while (it.hasNext()) {
                ExportSettingsType type = it.next();
                if (!getBackupTypePref(type).get()) {
                    it.remove();
                }
            }
            return app.getFileSettingsHelper().getFilteredSettingsItems(types, true, true);
        }

        @Override
        protected void onProgressUpdate(LocalFile... localFiles) {
            if (listener != null) {
                listener.onFileCollected(localFiles[0]);
            }
        }

        @Override
        protected void onPostExecute(List<LocalFile> localFiles) {
            if (db != null) {
                db.close();
            }
            operationLog.finishOperation(" Files=" + localFiles.size());
            if (listener != null) {
                listener.onFilesCollected(localFiles);
            }
        }
    };
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ArrayList(java.util.ArrayList) OperationLog(net.osmand.OperationLog) UploadedFileInfo(net.osmand.plus.backup.BackupDbHelper.UploadedFileInfo) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) CollectionSettingsItem(net.osmand.plus.settings.backend.backup.items.CollectionSettingsItem) StreamSettingsItem(net.osmand.plus.settings.backend.backup.items.StreamSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) NonNull(androidx.annotation.NonNull) List(java.util.List) ArrayList(java.util.ArrayList) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType) AsyncTask(android.os.AsyncTask) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) StreamSettingsItem(net.osmand.plus.settings.backend.backup.items.StreamSettingsItem) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File) Nullable(androidx.annotation.Nullable) SuppressLint(android.annotation.SuppressLint)

Example 4 with GpxSettingsItem

use of net.osmand.plus.settings.backend.backup.items.GpxSettingsItem in project Osmand by osmandapp.

the class BackupImporter method getItemRemoteFiles.

@NonNull
private List<RemoteFile> getItemRemoteFiles(@NonNull SettingsItem item, @NonNull Map<String, RemoteFile> remoteFiles) {
    List<RemoteFile> res = new ArrayList<>();
    String fileName = item.getFileName();
    if (!Algorithms.isEmpty(fileName)) {
        if (fileName.charAt(0) != '/') {
            fileName = "/" + fileName;
        }
        if (item instanceof GpxSettingsItem) {
            GpxSettingsItem gpxItem = (GpxSettingsItem) item;
            String folder = gpxItem.getSubtype().getSubtypeFolder();
            if (!Algorithms.isEmpty(folder) && folder.charAt(0) != '/') {
                folder = "/" + folder;
            }
            if (fileName.startsWith(folder)) {
                fileName = fileName.substring(folder.length() - 1);
            }
        }
        String typeFileName = item.getType().name() + fileName;
        RemoteFile remoteFile = remoteFiles.remove(typeFileName);
        if (remoteFile != null) {
            res.add(remoteFile);
        }
        Iterator<Entry<String, RemoteFile>> it = remoteFiles.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, RemoteFile> fileEntry = it.next();
            String remoteFileName = fileEntry.getKey();
            if (remoteFileName.startsWith(typeFileName + "/")) {
                res.add(fileEntry.getValue());
                it.remove();
            }
        }
    }
    return res;
}
Also used : Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) NonNull(androidx.annotation.NonNull)

Example 5 with GpxSettingsItem

use of net.osmand.plus.settings.backend.backup.items.GpxSettingsItem in project Osmand by osmandapp.

the class SettingsHelper method prepareSettingsItems.

public List<SettingsItem> prepareSettingsItems(List<?> data, List<SettingsItem> settingsItems, boolean export) {
    List<SettingsItem> result = new ArrayList<>();
    List<QuickAction> quickActions = new ArrayList<>();
    List<PoiUIFilter> poiUIFilters = new ArrayList<>();
    List<ITileSource> tileSourceTemplates = new ArrayList<>();
    List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
    List<ApplicationModeBean> appModeBeans = new ArrayList<>();
    List<FavoriteGroup> favoriteGroups = new ArrayList<>();
    List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
    List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
    List<MapMarkersGroup> markersGroups = new ArrayList<>();
    List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
    List<HistoryEntry> historyEntries = new ArrayList<>();
    List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();
    List<MapMarkersGroup> itineraryGroups = new ArrayList<>();
    for (Object object : data) {
        if (object instanceof QuickAction) {
            quickActions.add((QuickAction) object);
        } else if (object instanceof PoiUIFilter) {
            poiUIFilters.add((PoiUIFilter) object);
        } else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) {
            tileSourceTemplates.add((ITileSource) object);
        } else if (object instanceof File) {
            try {
                File file = (File) object;
                if (file.getName().endsWith(IndexConstants.GPX_FILE_EXT)) {
                    result.add(new GpxSettingsItem(app, file));
                } else {
                    result.add(new FileSettingsItem(app, file));
                }
            } catch (IllegalArgumentException e) {
                LOG.warn("Trying to export unsuported file type", e);
            }
        } else if (object instanceof FileSettingsItem) {
            result.add((FileSettingsItem) object);
        } else if (object instanceof AvoidRoadInfo) {
            avoidRoads.add((AvoidRoadInfo) object);
        } else if (object instanceof ApplicationModeBean) {
            appModeBeans.add((ApplicationModeBean) object);
        } else if (object instanceof OsmNotesPoint) {
            osmNotesPointList.add((OsmNotesPoint) object);
        } else if (object instanceof OpenstreetmapPoint) {
            osmEditsPointList.add((OpenstreetmapPoint) object);
        } else if (object instanceof FavoriteGroup) {
            favoriteGroups.add((FavoriteGroup) object);
        } else if (object instanceof MapMarkersGroup) {
            MapMarkersGroup markersGroup = (MapMarkersGroup) object;
            if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
                markersGroups.add((MapMarkersGroup) object);
            } else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
                markersHistoryGroups.add((MapMarkersGroup) object);
            } else {
                itineraryGroups.add((MapMarkersGroup) object);
            }
        } else if (object instanceof HistoryEntry) {
            historyEntries.add((HistoryEntry) object);
        } else if (object instanceof GlobalSettingsItem) {
            result.add((GlobalSettingsItem) object);
        } else if (object instanceof OnlineRoutingEngine) {
            onlineRoutingEngines.add((OnlineRoutingEngine) object);
        }
    }
    if (!quickActions.isEmpty()) {
        QuickActionsSettingsItem baseItem = getBaseItem(SettingsItemType.QUICK_ACTIONS, QuickActionsSettingsItem.class, settingsItems);
        result.add(new QuickActionsSettingsItem(app, baseItem, quickActions));
    }
    if (!poiUIFilters.isEmpty()) {
        PoiUiFiltersSettingsItem baseItem = getBaseItem(SettingsItemType.POI_UI_FILTERS, PoiUiFiltersSettingsItem.class, settingsItems);
        result.add(new PoiUiFiltersSettingsItem(app, baseItem, poiUIFilters));
    }
    if (!tileSourceTemplates.isEmpty()) {
        MapSourcesSettingsItem baseItem = getBaseItem(SettingsItemType.MAP_SOURCES, MapSourcesSettingsItem.class, settingsItems);
        result.add(new MapSourcesSettingsItem(app, baseItem, tileSourceTemplates));
    }
    if (!avoidRoads.isEmpty()) {
        AvoidRoadsSettingsItem baseItem = getBaseItem(SettingsItemType.AVOID_ROADS, AvoidRoadsSettingsItem.class, settingsItems);
        result.add(new AvoidRoadsSettingsItem(app, baseItem, avoidRoads));
    }
    if (!appModeBeans.isEmpty()) {
        for (ApplicationModeBean modeBean : appModeBeans) {
            if (export) {
                ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
                if (mode != null) {
                    result.add(new ProfileSettingsItem(app, mode));
                }
            } else {
                result.add(new ProfileSettingsItem(app, getBaseProfileSettingsItem(modeBean, settingsItems), modeBean));
            }
        }
    }
    if (!osmNotesPointList.isEmpty()) {
        OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class, settingsItems);
        result.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList));
    }
    if (!osmEditsPointList.isEmpty()) {
        OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class, settingsItems);
        result.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList));
    }
    if (!favoriteGroups.isEmpty()) {
        FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class, settingsItems);
        result.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups));
    }
    if (!markersGroups.isEmpty()) {
        List<MapMarker> mapMarkers = new ArrayList<>();
        for (MapMarkersGroup group : markersGroups) {
            mapMarkers.addAll(group.getMarkers());
        }
        MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems);
        result.add(new MarkersSettingsItem(app, baseItem, mapMarkers));
    }
    if (!markersHistoryGroups.isEmpty()) {
        List<MapMarker> mapMarkers = new ArrayList<>();
        for (MapMarkersGroup group : markersHistoryGroups) {
            mapMarkers.addAll(group.getMarkers());
        }
        HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems);
        result.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers));
    }
    if (!historyEntries.isEmpty()) {
        SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class, settingsItems);
        result.add(new SearchHistorySettingsItem(app, baseItem, historyEntries));
    }
    if (!onlineRoutingEngines.isEmpty()) {
        OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class, settingsItems);
        result.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines));
    }
    if (!itineraryGroups.isEmpty()) {
        ItinerarySettingsItem baseItem = getBaseItem(SettingsItemType.ITINERARY_GROUPS, ItinerarySettingsItem.class, settingsItems);
        result.add(new ItinerarySettingsItem(app, baseItem, itineraryGroups));
    }
    return result;
}
Also used : SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) QuickAction(net.osmand.plus.quickaction.QuickAction) ApplicationModeBean(net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean) MapMarker(net.osmand.plus.mapmarkers.MapMarker) ArrayList(java.util.ArrayList) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) AvoidRoadInfo(net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) ITileSource(net.osmand.map.ITileSource) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) File(java.io.File) TileSourceTemplate(net.osmand.map.TileSourceManager.TileSourceTemplate) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) SQLiteTileSource(net.osmand.plus.resources.SQLiteTileSource) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem)

Aggregations

GpxSettingsItem (net.osmand.plus.settings.backend.backup.items.GpxSettingsItem)6 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 GlobalSettingsItem (net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem)4 SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)4 ITileSource (net.osmand.map.ITileSource)3 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)3 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)3 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)3 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)3 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)3 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)3 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)3 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)3 QuickAction (net.osmand.plus.quickaction.QuickAction)3 ApplicationModeBean (net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean)3 AvoidRoadsSettingsItem (net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem)3 FavoritesSettingsItem (net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem)3 HistoryMarkersSettingsItem (net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem)3