use of net.osmand.plus.backup.NetworkSettingsHelper.BackupCollectListener in project Osmand by osmandapp.
the class RestoreSettingsFragment method collectAndReadSettings.
private void collectAndReadSettings() {
BackupCollectListener collectListener = new BackupCollectListener() {
@Nullable
private SettingsItem getRestoreItem(@NonNull List<SettingsItem> items, @NonNull RemoteFile remoteFile) {
for (SettingsItem item : items) {
if (BackupHelper.applyItem(item, remoteFile.getType(), remoteFile.getName())) {
return item;
}
}
return null;
}
@Override
public void onBackupCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items, @NonNull List<RemoteFile> remoteFiles) {
FragmentActivity activity = getActivity();
if (AndroidUtils.isActivityNotDestroyed(activity)) {
toolbarLayout.setTitle(getString(R.string.restore_from_osmand_cloud));
description.setText(R.string.choose_what_to_restore);
buttonsContainer.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
if (succeed) {
PrepareBackupResult backup = app.getBackupHelper().getBackup();
BackupInfo info = backup.getBackupInfo();
Set<SettingsItem> itemsForRestore = new HashSet<>();
if (info != null) {
for (RemoteFile remoteFile : info.filesToDownload) {
SettingsItem restoreItem = getRestoreItem(items, remoteFile);
if (restoreItem != null) {
itemsForRestore.add(restoreItem);
}
}
}
setSettingsItems(new ArrayList<>(itemsForRestore));
dataList = SettingsHelper.getSettingsToOperateByCategory(settingsItems, false, false);
adapter.updateSettingsItems(dataList, selectedItemsMap);
}
}
}
};
try {
settingsHelper.collectSettings(RESTORE_ITEMS_KEY, true, collectListener);
} catch (IllegalStateException e) {
LOG.error(e.getMessage(), e);
}
}
Aggregations