use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class FormDownloadListActivity method formListDownloadingComplete.
@Override
public void formListDownloadingComplete(HashMap<String, ServerFormDetails> formList, FormSourceException exception) {
DialogFragmentUtils.dismissDialog(RefreshFormListDialogFragment.class, getSupportFragmentManager());
downloadFormListTask.setDownloaderListener(null);
downloadFormListTask = null;
if (exception == null) {
// Everything worked. Clear the list and add the results.
viewModel.setFormDetailsByFormId(formList);
viewModel.clearFormList();
ArrayList<String> ids = new ArrayList<>(viewModel.getFormDetailsByFormId().keySet());
for (int i = 0; i < formList.size(); i++) {
String formDetailsKey = ids.get(i);
ServerFormDetails details = viewModel.getFormDetailsByFormId().get(formDetailsKey);
if (!displayOnlyUpdatedForms || details.isUpdated()) {
HashMap<String, String> item = new HashMap<>();
item.put(FORMNAME, details.getFormName());
item.put(FORMID_DISPLAY, ((details.getFormVersion() == null) ? "" : (getString(R.string.version) + " " + details.getFormVersion() + " ")) + "ID: " + details.getFormId());
item.put(FORMDETAIL_KEY, formDetailsKey);
item.put(FORM_ID_KEY, details.getFormId());
item.put(FORM_VERSION_KEY, details.getFormVersion());
// Insert the new form in alphabetical order.
if (viewModel.getFormList().isEmpty()) {
viewModel.addForm(item);
} else {
int j;
for (j = 0; j < viewModel.getFormList().size(); j++) {
HashMap<String, String> compareMe = viewModel.getFormList().get(j);
String name = compareMe.get(FORMNAME);
if (name.compareTo(viewModel.getFormDetailsByFormId().get(ids.get(i)).getFormName()) > 0) {
break;
}
}
viewModel.addForm(j, item);
}
}
}
filteredFormList.addAll(viewModel.getFormList());
updateAdapter();
selectSupersededForms();
downloadButton.setEnabled(listView.getCheckedItemCount() > 0);
toggleButton.setEnabled(listView.getCount() > 0);
toggleButtonLabel(toggleButton, listView);
if (viewModel.isDownloadOnlyMode()) {
performDownloadModeDownload();
}
} else {
if (exception instanceof FormSourceException.AuthRequired) {
createAuthDialog();
} else {
String dialogMessage = new FormSourceExceptionMapper(this).getMessage(exception);
String dialogTitle = getString(R.string.load_remote_form_error);
if (viewModel.isDownloadOnlyMode()) {
setReturnResult(false, dialogMessage, viewModel.getFormResults());
}
createAlertDialog(dialogTitle, dialogMessage, DO_NOT_EXIT);
}
}
}
use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class FormDownloadListActivity method getFilesToDownload.
private ArrayList<ServerFormDetails> getFilesToDownload() {
ArrayList<ServerFormDetails> filesToDownload = new ArrayList<>();
SparseBooleanArray sba = listView.getCheckedItemPositions();
for (int i = 0; i < listView.getCount(); i++) {
if (sba.get(i, false)) {
HashMap<String, String> item = (HashMap<String, String>) listView.getAdapter().getItem(i);
filesToDownload.add(viewModel.getFormDetailsByFormId().get(item.get(FORMDETAIL_KEY)));
}
}
return filesToDownload;
}
use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class DownloadFormListTask method doInBackground.
@Override
protected Pair<List<ServerFormDetails>, FormSourceException> doInBackground(Void... values) {
if (webCredentialsUtils != null) {
setTemporaryCredentials();
}
List<ServerFormDetails> formList = null;
FormSourceException exception = null;
try {
formList = serverFormsDetailsFetcher.fetchFormDetails();
} catch (FormSourceException e) {
exception = e;
} finally {
if (webCredentialsUtils != null) {
clearTemporaryCredentials();
}
}
return new Pair<>(formList, exception);
}
use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class DownloadFormsTask method doInBackground.
@Override
protected Map<ServerFormDetails, FormDownloadException> doInBackground(ArrayList<ServerFormDetails>... values) {
HashMap<ServerFormDetails, FormDownloadException> results = new HashMap<>();
int index = 1;
for (ServerFormDetails serverFormDetails : values[0]) {
try {
String currentFormNumber = String.valueOf(index);
String totalForms = String.valueOf(values[0].size());
publishProgress(serverFormDetails.getFormName(), currentFormNumber, totalForms);
formDownloader.downloadForm(serverFormDetails, count -> {
String message = getLocalizedString(Collect.getInstance(), R.string.form_download_progress, serverFormDetails.getFormName(), String.valueOf(count), String.valueOf(serverFormDetails.getManifest().getMediaFiles().size()));
publishProgress(message, currentFormNumber, totalForms);
}, this::isCancelled);
results.put(serverFormDetails, null);
} catch (FormDownloadException.DownloadingInterrupted e) {
return emptyMap();
} catch (FormDownloadException e) {
results.put(serverFormDetails, e);
}
index++;
}
return results;
}
Aggregations