use of net.osmand.plus.backup.BackupListeners.OnUploadFileListener 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.backup.BackupListeners.OnUploadFileListener in project OsmAnd by osmandapp.
the class NetworkWriter method getUploadDirListener.
@NonNull
private OnUploadFileListener getUploadDirListener(@NonNull SettingsItem item, @NonNull String itemFileName, int itemWork) {
return new OnUploadFileListener() {
private int itemProgress = 0;
private int deltaProgress = 0;
private boolean uploadStarted = false;
@Override
public void onFileUploadStarted(@NonNull String type, @NonNull String fileName, int work) {
if (!uploadStarted && listener != null) {
uploadStarted = true;
listener.onItemUploadStarted(item, itemFileName, itemWork);
}
}
@Override
public void onFileUploadProgress(@NonNull String type, @NonNull String fileName, int progress, int deltaWork) {
if (listener != null) {
deltaProgress += deltaWork;
if ((deltaProgress > (itemWork / 100)) || ((itemProgress + deltaProgress) >= itemWork)) {
itemProgress += deltaProgress;
listener.onItemUploadProgress(item, itemFileName, itemProgress, deltaProgress);
deltaProgress = 0;
}
}
}
@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.backup.BackupListeners.OnUploadFileListener in project Osmand by osmandapp.
the class NetworkWriter method uploadDirWithFiles.
@Nullable
private String uploadDirWithFiles(@NonNull SettingsItemWriter<? extends SettingsItem> itemWriter, @NonNull String fileName, long uploadTime) throws UserNotRegisteredException, IOException {
FileSettingsItem item = (FileSettingsItem) itemWriter.getItem();
List<File> filesToUpload = backupHelper.collectItemFilesForUpload(item);
long size = 0;
for (File file : filesToUpload) {
size += file.length();
}
OnUploadFileListener uploadListener = getUploadDirListener(item, fileName, (int) (size / 1024));
for (File file : filesToUpload) {
item.setFileToWrite(file);
String name = BackupHelper.getFileItemName(file, item);
String error = uploadItemFile(itemWriter, name, uploadListener, uploadTime);
if (error != null) {
return error;
}
}
return null;
}
use of net.osmand.plus.backup.BackupListeners.OnUploadFileListener in project Osmand by osmandapp.
the class NetworkWriter method getUploadDirListener.
@NonNull
private OnUploadFileListener getUploadDirListener(@NonNull SettingsItem item, @NonNull String itemFileName, int itemWork) {
return new OnUploadFileListener() {
private int itemProgress = 0;
private int deltaProgress = 0;
private boolean uploadStarted = false;
@Override
public void onFileUploadStarted(@NonNull String type, @NonNull String fileName, int work) {
if (!uploadStarted && listener != null) {
uploadStarted = true;
listener.onItemUploadStarted(item, itemFileName, itemWork);
}
}
@Override
public void onFileUploadProgress(@NonNull String type, @NonNull String fileName, int progress, int deltaWork) {
if (listener != null) {
deltaProgress += deltaWork;
if ((deltaProgress > (itemWork / 100)) || ((itemProgress + deltaProgress) >= itemWork)) {
itemProgress += deltaProgress;
listener.onItemUploadProgress(item, itemFileName, itemProgress, deltaProgress);
deltaProgress = 0;
}
}
}
@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.backup.BackupListeners.OnUploadFileListener in project OsmAnd by osmandapp.
the class NetworkWriter method uploadDirWithFiles.
@Nullable
private String uploadDirWithFiles(@NonNull SettingsItemWriter<? extends SettingsItem> itemWriter, @NonNull String fileName, long uploadTime) throws UserNotRegisteredException, IOException {
FileSettingsItem item = (FileSettingsItem) itemWriter.getItem();
List<File> filesToUpload = backupHelper.collectItemFilesForUpload(item);
long size = 0;
for (File file : filesToUpload) {
size += file.length();
}
OnUploadFileListener uploadListener = getUploadDirListener(item, fileName, (int) (size / 1024));
for (File file : filesToUpload) {
item.setFileToWrite(file);
String name = BackupHelper.getFileItemName(file, item);
String error = uploadItemFile(itemWriter, name, uploadListener, uploadTime);
if (error != null) {
return error;
}
}
return null;
}
Aggregations