use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class BackupImporter method updateFilesInfo.
private void updateFilesInfo(@NonNull Map<String, RemoteFile> remoteFiles, @NonNull List<SettingsItem> settingsItemList) {
Map<String, RemoteFile> remoteFilesMap = new HashMap<>(remoteFiles);
for (SettingsItem settingsItem : settingsItemList) {
List<RemoteFile> foundRemoteFiles = getItemRemoteFiles(settingsItem, remoteFilesMap);
for (RemoteFile remoteFile : foundRemoteFiles) {
settingsItem.setLastModifiedTime(remoteFile.getClienttimems());
remoteFile.item = settingsItem;
if (settingsItem instanceof FileSettingsItem) {
FileSettingsItem fileSettingsItem = (FileSettingsItem) settingsItem;
fileSettingsItem.setSize(remoteFile.getFilesize());
}
}
}
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class BackupImporter method importItems.
void importItems(@NonNull List<SettingsItem> items, boolean forceReadData) throws IllegalArgumentException {
if (Algorithms.isEmpty(items)) {
throw new IllegalArgumentException("No items");
}
Collection<RemoteFile> remoteFiles = backupHelper.getBackup().getRemoteFiles(RemoteFilesType.UNIQUE).values();
if (Algorithms.isEmpty(remoteFiles)) {
throw new IllegalArgumentException("No remote files");
}
OperationLog operationLog = new OperationLog("importItems", BackupHelper.DEBUG);
operationLog.startOperation();
List<ItemFileImportTask> tasks = new ArrayList<>();
Map<RemoteFile, SettingsItem> remoteFileItems = new HashMap<>();
for (RemoteFile remoteFile : remoteFiles) {
SettingsItem item = null;
for (SettingsItem settingsItem : items) {
String fileName = remoteFile.item != null ? remoteFile.item.getFileName() : null;
if (fileName != null && settingsItem.applyFileName(fileName)) {
item = settingsItem;
remoteFileItems.put(remoteFile, item);
break;
}
}
if (item != null && (!item.shouldReadOnCollecting() || forceReadData)) {
tasks.add(new ItemFileImportTask(remoteFile, item, forceReadData));
}
}
ThreadPoolTaskExecutor<ItemFileImportTask> executor = createExecutor();
executor.run(tasks);
for (Entry<RemoteFile, SettingsItem> fileItem : remoteFileItems.entrySet()) {
fileItem.getValue().setLocalModifiedTime(fileItem.getKey().getClienttimems());
}
operationLog.finishOperation();
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class NetworkWriter method uploadItemInfo.
@Nullable
private String uploadItemInfo(@NonNull SettingsItem item, @NonNull String fileName, long uploadTime) throws IOException {
try {
JSONObject json = item.toJsonObj();
boolean hasFile = json.has("file");
boolean hasSubtype = json.has("subtype");
if (json.length() > (hasFile ? 2 + (hasSubtype ? 1 : 0) : 1)) {
String itemJson = json.toString();
InputStream inputStream = new ByteArrayInputStream(itemJson.getBytes("UTF-8"));
StreamWriter streamWriter = (outputStream, progress) -> {
Algorithms.streamCopy(inputStream, outputStream, progress, 1024);
outputStream.flush();
};
return backupHelper.uploadFile(fileName, item.getType().name(), streamWriter, uploadTime, getUploadFileListener(item));
} else {
return null;
}
} catch (JSONException | UserNotRegisteredException e) {
throw new IOException(e.getMessage(), e);
}
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class BackupInfo method createItemsToDelete.
private void createItemsToDelete() {
Set<SettingsItem> items = new HashSet<>();
for (RemoteFile remoteFile : filteredFilesToDelete) {
SettingsItem item = remoteFile.item;
if (item != null) {
items.add(item);
}
}
itemsToDelete = new ArrayList<>(items);
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class BackupInfo method createItemsToUpload.
private void createItemsToUpload() {
Set<SettingsItem> items = new HashSet<>();
for (LocalFile localFile : filteredFilesToUpload) {
SettingsItem item = localFile.item;
if (item != null) {
items.add(item);
}
}
itemsToUpload = new ArrayList<>(items);
}
Aggregations