use of org.odk.collect.android.listeners.FormDownloaderListener in project collect by opendatakit.
the class ServerFormDownloader method downloadForm.
@Override
public void downloadForm(ServerFormDetails form, @Nullable ProgressReporter progressReporter, @Nullable Supplier<Boolean> isCancelled) throws FormDownloadException {
Form formOnDevice;
try {
formOnDevice = formsRepository.getOneByMd5Hash(validateHash(form.getHash()));
} catch (IllegalArgumentException e) {
throw new FormDownloadException.FormWithNoHash();
}
if (formOnDevice != null) {
if (formOnDevice.isDeleted()) {
formsRepository.restore(formOnDevice.getDbId());
}
} else {
List<Form> allSameFormIdVersion = formsRepository.getAllByFormIdAndVersion(form.getFormId(), form.getFormVersion());
if (!allSameFormIdVersion.isEmpty() && !form.getDownloadUrl().contains("/draft.xml")) {
analytics.logEventWithParam(DOWNLOAD_SAME_FORMID_VERSION_DIFFERENT_HASH, "form", AnalyticsUtils.getFormHash(form.getFormId(), form.getFormName()));
}
}
File tempDir = new File(cacheDir, "download-" + UUID.randomUUID().toString());
tempDir.mkdirs();
try {
FormDownloaderListener stateListener = new ProgressReporterAndSupplierStateListener(progressReporter, isCancelled);
processOneForm(form, stateListener, tempDir, formsDirPath, formMetadataParser);
} catch (FormSourceException e) {
throw new FormDownloadException.FormSourceError(e);
} finally {
try {
deleteDirectory(tempDir);
} catch (IOException ignored) {
// ignored
}
}
}
Aggregations