use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class ServerFormsSynchronizer method synchronize.
public void synchronize() throws FormSourceException {
List<ServerFormDetails> formList = serverFormsDetailsFetcher.fetchFormDetails();
List<Form> formsOnDevice = formsRepository.getAll();
FormDeleter formDeleter = new FormDeleter(formsRepository, instancesRepository);
formsOnDevice.stream().forEach(form -> {
if (formList.stream().noneMatch(f -> form.getFormId().equals(f.getFormId()))) {
formDeleter.delete(form.getDbId());
}
});
boolean downloadException = false;
for (ServerFormDetails form : formList) {
if (form.isNotOnDevice() || form.isUpdated()) {
try {
formDownloader.downloadForm(form, null, null);
} catch (FormDownloadException.DownloadingInterrupted e) {
return;
} catch (FormDownloadException e) {
downloadException = true;
}
}
}
if (downloadException) {
throw new FormSourceException.FetchError();
}
}
use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class DownloadFormListTask method onPostExecute.
@Override
protected void onPostExecute(Pair<List<ServerFormDetails>, FormSourceException> result) {
synchronized (this) {
if (stateListener != null) {
if (result.first != null) {
HashMap<String, ServerFormDetails> detailsHashMap = new HashMap<>();
for (ServerFormDetails details : result.first) {
detailsHashMap.put(details.getFormId(), details);
}
stateListener.formListDownloadingComplete(detailsHashMap, result.second);
} else {
stateListener.formListDownloadingComplete(null, result.second);
}
}
}
}
use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class FormDownloadListActivity method init.
private void init(Bundle savedInstanceState) {
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
if (bundle.containsKey(DISPLAY_ONLY_UPDATED_FORMS)) {
displayOnlyUpdatedForms = (boolean) bundle.get(DISPLAY_ONLY_UPDATED_FORMS);
}
if (bundle.containsKey(ApplicationConstants.BundleKeys.FORM_IDS)) {
viewModel.setDownloadOnlyMode(true);
viewModel.setFormIdsToDownload(bundle.getStringArray(ApplicationConstants.BundleKeys.FORM_IDS));
if (viewModel.getFormIdsToDownload() == null) {
setReturnResult(false, "Form Ids is null", null);
finish();
}
if (bundle.containsKey(ApplicationConstants.BundleKeys.URL)) {
viewModel.setUrl(bundle.getString(ApplicationConstants.BundleKeys.URL));
if (bundle.containsKey(ApplicationConstants.BundleKeys.USERNAME) && bundle.containsKey(ApplicationConstants.BundleKeys.PASSWORD)) {
viewModel.setUsername(bundle.getString(ApplicationConstants.BundleKeys.USERNAME));
viewModel.setPassword(bundle.getString(ApplicationConstants.BundleKeys.PASSWORD));
}
}
}
}
downloadButton = findViewById(R.id.add_button);
downloadButton.setEnabled(listView.getCheckedItemCount() > 0);
downloadButton.setOnClickListener(v -> {
ArrayList<ServerFormDetails> filesToDownload = getFilesToDownload();
startFormsDownload(filesToDownload);
});
toggleButton = findViewById(R.id.toggle_button);
toggleButton.setEnabled(false);
toggleButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
downloadButton.setEnabled(toggleChecked(listView));
toggleButtonLabel(toggleButton, listView);
viewModel.clearSelectedFormIds();
if (listView.getCheckedItemCount() == listView.getCount()) {
for (HashMap<String, String> map : viewModel.getFormList()) {
viewModel.addSelectedFormId(map.get(FORMDETAIL_KEY));
}
}
}
});
Button refreshButton = findViewById(R.id.refresh_button);
refreshButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
viewModel.setLoadingCanceled(false);
viewModel.clearFormList();
updateAdapter();
clearChoices();
downloadFormList();
}
});
if (savedInstanceState != null) {
// Android should keep track of this, but broken on rotate...
if (savedInstanceState.containsKey(BUNDLE_SELECTED_COUNT)) {
downloadButton.setEnabled(savedInstanceState.getInt(BUNDLE_SELECTED_COUNT) > 0);
}
}
filteredFormList.addAll(viewModel.getFormList());
if (getLastCustomNonConfigurationInstance() instanceof DownloadFormListTask) {
downloadFormListTask = (DownloadFormListTask) getLastCustomNonConfigurationInstance();
if (downloadFormListTask.getStatus() == AsyncTask.Status.FINISHED) {
DialogFragmentUtils.dismissDialog(RefreshFormListDialogFragment.class, getSupportFragmentManager());
downloadFormsTask = null;
}
} else if (getLastCustomNonConfigurationInstance() instanceof DownloadFormsTask) {
downloadFormsTask = (DownloadFormsTask) getLastCustomNonConfigurationInstance();
if (downloadFormsTask.getStatus() == AsyncTask.Status.FINISHED) {
DialogFragmentUtils.dismissDialog(RefreshFormListDialogFragment.class, getSupportFragmentManager());
downloadFormsTask = null;
}
} else if (viewModel.getFormDetailsByFormId().isEmpty() && getLastCustomNonConfigurationInstance() == null && !viewModel.wasLoadingCanceled()) {
// first time, so get the formlist
downloadFormList();
}
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setItemsCanFocus(false);
sortingOptions = new int[] { R.string.sort_by_name_asc, R.string.sort_by_name_desc };
}
use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class FormDownloadListActivity method formsDownloadingComplete.
@Override
public void formsDownloadingComplete(Map<ServerFormDetails, FormDownloadException> result) {
if (downloadFormsTask != null) {
downloadFormsTask.setDownloaderListener(null);
}
cleanUpWebCredentials();
DialogFragmentUtils.dismissDialog(RefreshFormListDialogFragment.class, getSupportFragmentManager());
Bundle args = new Bundle();
args.putSerializable(FormsDownloadResultDialog.ARG_RESULT, (Serializable) result);
DialogFragmentUtils.showIfNotShowing(FormsDownloadResultDialog.class, args, getSupportFragmentManager());
// Set result to true for forms which were downloaded
if (viewModel.isDownloadOnlyMode()) {
for (ServerFormDetails serverFormDetails : result.keySet()) {
if (result.get(serverFormDetails) == null) {
if (viewModel.getFormResults().containsKey(serverFormDetails.getFormId())) {
viewModel.putFormResult(serverFormDetails.getFormId(), true);
}
}
}
setReturnResult(true, null, viewModel.getFormResults());
}
}
use of org.odk.collect.android.formmanagement.ServerFormDetails in project collect by opendatakit.
the class FormDownloadListActivity method performDownloadModeDownload.
private void performDownloadModeDownload() {
for (String formId : viewModel.getFormIdsToDownload()) {
viewModel.putFormResult(formId, false);
}
ArrayList<ServerFormDetails> filesToDownload = new ArrayList<>();
for (ServerFormDetails serverFormDetails : viewModel.getFormDetailsByFormId().values()) {
String formId = serverFormDetails.getFormId();
if (viewModel.getFormResults().containsKey(formId)) {
filesToDownload.add(serverFormDetails);
}
}
// 2. Select forms and start downloading
if (!filesToDownload.isEmpty()) {
startFormsDownload(filesToDownload);
} else {
// None of the forms was found
setReturnResult(false, "Forms not found on server", viewModel.getFormResults());
finish();
}
}
Aggregations