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;
}
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();
}
};
}
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);
}
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;
}
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);
}
}
Aggregations