use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class ActionButtonViewHolder method bindView.
public void bindView(@NonNull MapActivity mapActivity, @NonNull PrepareBackupResult backup, @Nullable BackupExportListener exportListener, boolean uploadItemsVisible, boolean nightMode) {
OsmandApplication app = (OsmandApplication) itemView.getContext().getApplicationContext();
BackupStatus status = BackupStatus.getBackupStatus(app, backup);
NetworkSettingsHelper settingsHelper = app.getNetworkSettingsHelper();
if (settingsHelper.isBackupExporting()) {
actionButton.setOnClickListener(v -> {
settingsHelper.cancelImport();
settingsHelper.cancelExport();
});
UiUtilities.setupDialogButton(nightMode, actionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.shared_string_cancel);
} else if (status == BackupStatus.MAKE_BACKUP || status == BackupStatus.CONFLICTS) {
actionButton.setOnClickListener(v -> {
try {
BackupInfo info = backup.getBackupInfo();
List<SettingsItem> items = info.itemsToUpload;
if (!items.isEmpty() || !Algorithms.isEmpty(info.filteredFilesToDelete)) {
settingsHelper.exportSettings(BACKUP_ITEMS_KEY, items, info.itemsToDelete, exportListener);
}
} catch (IllegalStateException e) {
log.error(e.getMessage(), e);
}
});
UiUtilities.setupDialogButton(nightMode, actionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.backup_now);
} else if (status == BackupStatus.NO_INTERNET_CONNECTION || status == BackupStatus.ERROR) {
actionButton.setOnClickListener(v -> app.getBackupHelper().prepareBackup());
UiUtilities.setupDialogButton(nightMode, actionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.retry);
} else if (status == BackupStatus.SUBSCRIPTION_EXPIRED) {
actionButton.setOnClickListener(v -> {
if (Version.isInAppPurchaseSupported()) {
OsmAndProPlanFragment.showInstance(mapActivity);
} else {
PromoCodeBottomSheet.showInstance(mapActivity.getSupportFragmentManager());
}
});
UiUtilities.setupDialogButton(nightMode, actionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.renew_subscription);
}
AndroidUiHelper.updateVisibility(divider, uploadItemsVisible);
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class BackupStatusAdapter method onImportFinished.
@Override
public void onImportFinished(boolean succeed, boolean needRestart, @NonNull List<SettingsItem> settingsItems) {
for (SettingsItem settingsItem : settingsItems) {
String fileName = BackupHelper.getItemFileName(settingsItem);
Object item = getBackupItem(settingsItem.getType().name(), fileName);
if (item != null) {
notifyItemChanged(items.indexOf(item));
}
}
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class ConflictViewHolder method bindView.
public void bindView(@NonNull Pair<LocalFile, RemoteFile> pair, @Nullable BackupExportListener exportListener, @Nullable ImportListener importListener, boolean nightMode) {
OsmandApplication app = getApplication();
NetworkSettingsHelper settingsHelper = app.getNetworkSettingsHelper();
SettingsItem item = pair.first.item;
String fileName = BackupHelper.getItemFileName(item);
setupItemView(fileName, item, false);
updateButtonsState(settingsHelper, fileName);
localVersionButton.setOnClickListener(v -> {
try {
settingsHelper.exportSettings(fileName, exportListener, item);
} catch (IllegalStateException e) {
log.error(e.getMessage(), e);
}
updateButtonsState(settingsHelper, fileName);
});
serverButton.setOnClickListener(v -> {
try {
SettingsItem settingsItem = pair.second.item;
settingsItem.setShouldReplace(true);
settingsHelper.importSettings(fileName, Collections.singletonList(settingsItem), true, importListener);
} catch (IllegalStateException e) {
log.error(e.getMessage(), e);
}
updateButtonsState(settingsHelper, fileName);
});
AndroidUiHelper.updateVisibility(serverButton, true);
AndroidUiHelper.updateVisibility(localVersionButton, true);
UiUtilities.setupDialogButton(nightMode, localVersionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.upload_local_version);
UiUtilities.setupDialogButton(nightMode, serverButton, DialogButtonType.SECONDARY_ACTIVE, R.string.download_server_version);
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class BackupInfo method createFilteredFilesToMerge.
private void createFilteredFilesToMerge(@NonNull OsmandApplication app) {
List<Pair<LocalFile, RemoteFile>> files = new ArrayList<>();
Set<SettingsItem> items = new HashSet<>();
BackupHelper helper = app.getBackupHelper();
for (Pair<LocalFile, RemoteFile> pair : filesToMerge) {
SettingsItem item = pair.first.item;
if (!items.contains(item)) {
ExportSettingsType exportType = ExportSettingsType.getExportSettingsTypeForRemoteFile(pair.second);
if (exportType != null && helper.getBackupTypePref(exportType).get()) {
files.add(pair);
items.add(item);
}
}
}
filteredFilesToMerge = files;
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem 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;
}
Aggregations