Search in sources :

Example 6 with FileSettingsItem

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

the class ExportBackupTask method getEstimatedItemsSize.

private long getEstimatedItemsSize() {
    long size = 0;
    BackupHelper backupHelper = helper.getApp().getBackupHelper();
    for (SettingsItem item : exporter.getItems()) {
        if (item instanceof FileSettingsItem) {
            List<File> filesToUpload = backupHelper.collectItemFilesForUpload((FileSettingsItem) item);
            for (File file : filesToUpload) {
                size += file.length() + APPROXIMATE_FILE_SIZE_BYTES;
            }
        } else {
            size += item.getEstimatedSize() + APPROXIMATE_FILE_SIZE_BYTES;
        }
    }
    Map<String, RemoteFile> remoteFilesMap = backupHelper.getBackup().getRemoteFiles(PrepareBackupResult.RemoteFilesType.UNIQUE);
    if (remoteFilesMap != null) {
        List<SettingsItem> itemsToDelete = exporter.getItemsToDelete();
        for (RemoteFile remoteFile : remoteFilesMap.values()) {
            for (SettingsItem item : itemsToDelete) {
                if (item.equals(remoteFile.item)) {
                    size += APPROXIMATE_FILE_SIZE_BYTES;
                }
            }
        }
        List<SettingsItem> oldItemsToDelete = exporter.getOldItemsToDelete();
        for (RemoteFile remoteFile : remoteFilesMap.values()) {
            for (SettingsItem item : oldItemsToDelete) {
                SettingsItem remoteFileItem = remoteFile.item;
                if (remoteFileItem != null && item.getType() == remoteFileItem.getType()) {
                    String itemFileName = item.getFileName();
                    if (itemFileName != null && itemFileName.startsWith("/")) {
                        itemFileName = itemFileName.substring(1);
                    }
                    if (Algorithms.stringsEqual(itemFileName, remoteFileItem.getFileName())) {
                        size += APPROXIMATE_FILE_SIZE_BYTES;
                    }
                }
            }
        }
    }
    return size;
}
Also used : FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) File(java.io.File)

Example 7 with FileSettingsItem

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

the class NetworkWriter method getUploadFileListener.

@NonNull
private OnUploadFileListener getUploadFileListener(@NonNull final SettingsItem item) {
    return new OnUploadFileListener() {

        @Override
        public void onFileUploadStarted(@NonNull String type, @NonNull String fileName, int work) {
            if (listener != null) {
                listener.onItemUploadStarted(item, fileName, work);
            }
        }

        @Override
        public void onFileUploadProgress(@NonNull String type, @NonNull String fileName, int progress, int deltaWork) {
            if (listener != null) {
                listener.onItemUploadProgress(item, fileName, progress, deltaWork);
            }
        }

        @Override
        public void onFileUploadDone(@NonNull String type, @NonNull String fileName, long uploadTime, @Nullable String error) {
            if (item instanceof FileSettingsItem) {
                FileSettingsItem fileItem = (FileSettingsItem) item;
                String itemFileName = BackupHelper.getFileItemName(fileItem);
                if (backupHelper.getApp().getAppPath(itemFileName).isDirectory()) {
                    backupHelper.updateFileUploadTime(item.getType().name(), itemFileName, uploadTime);
                }
                if (fileItem.needMd5Digest() && !Algorithms.isEmpty(fileItem.getMd5Digest())) {
                    backupHelper.updateFileMd5Digest(item.getType().name(), fileName, fileItem.getMd5Digest());
                }
            }
            if (listener != null) {
                listener.onItemFileUploadDone(item, fileName, uploadTime, error);
            }
        }

        @Override
        public boolean isUploadCancelled() {
            return isCancelled();
        }
    };
}
Also used : OnUploadFileListener(net.osmand.plus.backup.BackupListeners.OnUploadFileListener) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) NonNull(androidx.annotation.NonNull) Nullable(androidx.annotation.Nullable) NonNull(androidx.annotation.NonNull)

Example 8 with FileSettingsItem

use of net.osmand.plus.settings.backend.backup.items.FileSettingsItem in project OsmAnd by osmandapp.

the class ItemViewHolder method setupItemView.

protected void setupItemView(@NonNull String exportKey, @NonNull SettingsItem item, boolean deleteItem) {
    OsmandApplication app = getApplication();
    String publicName = item.getPublicName(app);
    if (item instanceof FileSettingsItem) {
        FileSettingsItem settingsItem = (FileSettingsItem) item;
        if (settingsItem.getSubtype() == FileSubtype.VOICE) {
            publicName += " (" + app.getString(R.string.shared_string_recorded) + ")";
        } else if (settingsItem.getSubtype() == FileSubtype.TTS_VOICE) {
            publicName += " (" + app.getString(R.string.tts_title) + ")";
        }
    }
    title.setText(publicName);
    String fileName = BackupHelper.getItemFileName(item);
    String summary = app.getString(R.string.last_backup);
    UploadedFileInfo info = app.getBackupHelper().getDbHelper().getUploadedFileInfo(item.getType().name(), fileName);
    if (info != null) {
        String time = OsmAndFormatter.getFormattedPassedTime(app, info.getUploadTime(), app.getString(R.string.shared_string_never));
        description.setText(app.getString(R.string.ltr_or_rtl_combine_via_colon, summary, time));
    } else {
        description.setText(app.getString(R.string.ltr_or_rtl_combine_via_colon, summary, app.getString(R.string.shared_string_never)));
    }
    icon.setImageDrawable(getItemIcon(item));
    NetworkSettingsHelper settingsHelper = app.getNetworkSettingsHelper();
    ImportBackupTask importTask = settingsHelper.getImportTask(exportKey);
    ExportBackupTask exportTask = settingsHelper.getExportTask(exportKey);
    if (exportTask == null && importTask == null) {
        AndroidUiHelper.updateVisibility(secondIcon, deleteItem);
        AndroidUiHelper.updateVisibility(progressBar, false);
        secondIcon.setImageDrawable(getContentIcon(deleteItem ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_cloud_done));
    } else {
        ItemProgressInfo progressInfo = null;
        if (exportTask != null) {
            progressInfo = exportTask.getItemProgressInfo(item.getType().name(), fileName);
        }
        if (importTask != null) {
            progressInfo = importTask.getItemProgressInfo(item.getType().name(), fileName);
        }
        setupProgress(progressInfo);
    }
    itemView.setTag(item);
}
Also used : NetworkSettingsHelper(net.osmand.plus.backup.NetworkSettingsHelper) ImportBackupTask(net.osmand.plus.backup.ImportBackupTask) OsmandApplication(net.osmand.plus.OsmandApplication) ItemProgressInfo(net.osmand.plus.backup.ExportBackupTask.ItemProgressInfo) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) UploadedFileInfo(net.osmand.plus.backup.BackupDbHelper.UploadedFileInfo) ExportBackupTask(net.osmand.plus.backup.ExportBackupTask)

Example 9 with FileSettingsItem

use of net.osmand.plus.settings.backend.backup.items.FileSettingsItem 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)

Example 10 with FileSettingsItem

use of net.osmand.plus.settings.backend.backup.items.FileSettingsItem in project OsmAnd by osmandapp.

the class ZipWriter method writeDirWithFiles.

private void writeDirWithFiles(@NonNull SettingsItemWriter<? extends SettingsItem> itemWriter, @NonNull File file, @NonNull ZipOutputStream zos) throws IOException {
    FileSettingsItem fileSettingsItem = (FileSettingsItem) itemWriter.getItem();
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null) {
            for (File subfolderFile : files) {
                writeDirWithFiles(itemWriter, subfolderFile, zos);
            }
        }
    } else {
        String subtypeFolder = fileSettingsItem.getSubtype().getSubtypeFolder();
        String zipEntryName = Algorithms.isEmpty(subtypeFolder) ? file.getName() : file.getPath().substring(file.getPath().indexOf(subtypeFolder) - 1);
        fileSettingsItem.setFileToWrite(file);
        writeItemToStream(itemWriter, zipEntryName, zos);
    }
}
Also used : FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) File(java.io.File)

Aggregations

FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)40 File (java.io.File)20 SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)14 GpxSettingsItem (net.osmand.plus.settings.backend.backup.items.GpxSettingsItem)12 Nullable (androidx.annotation.Nullable)10 NonNull (androidx.annotation.NonNull)8 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)8 GlobalSettingsItem (net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem)8 ArrayList (java.util.ArrayList)6 ITileSource (net.osmand.map.ITileSource)6 OnUploadFileListener (net.osmand.plus.backup.BackupListeners.OnUploadFileListener)6 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)6 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)6 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)6 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)6 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)6 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)6 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)6 QuickAction (net.osmand.plus.quickaction.QuickAction)6 ApplicationModeBean (net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean)6