Search in sources :

Example 6 with ServerFormDetails

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);
        }
    }
}
Also used : ServerFormDetails(org.odk.collect.android.formmanagement.ServerFormDetails) FormSourceExceptionMapper(org.odk.collect.android.formmanagement.FormSourceExceptionMapper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 7 with ServerFormDetails

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;
}
Also used : ServerFormDetails(org.odk.collect.android.formmanagement.ServerFormDetails) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SparseBooleanArray(android.util.SparseBooleanArray)

Example 8 with ServerFormDetails

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);
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) ServerFormDetails(org.odk.collect.android.formmanagement.ServerFormDetails) Pair(androidx.core.util.Pair)

Example 9 with ServerFormDetails

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;
}
Also used : ServerFormDetails(org.odk.collect.android.formmanagement.ServerFormDetails) HashMap(java.util.HashMap) LocalizedApplicationKt.getLocalizedString(org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString) FormDownloadException(org.odk.collect.android.formmanagement.FormDownloadException)

Aggregations

ServerFormDetails (org.odk.collect.android.formmanagement.ServerFormDetails)9 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)3 Bundle (android.os.Bundle)2 FormDownloadException (org.odk.collect.android.formmanagement.FormDownloadException)2 SparseBooleanArray (android.util.SparseBooleanArray)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 Pair (androidx.core.util.Pair)1 RefreshFormListDialogFragment (org.odk.collect.android.formentry.RefreshFormListDialogFragment)1 FormDeleter (org.odk.collect.android.formmanagement.FormDeleter)1 FormSourceExceptionMapper (org.odk.collect.android.formmanagement.FormSourceExceptionMapper)1 DownloadFormListTask (org.odk.collect.android.tasks.DownloadFormListTask)1 DownloadFormsTask (org.odk.collect.android.tasks.DownloadFormsTask)1 Form (org.odk.collect.forms.Form)1 FormSourceException (org.odk.collect.forms.FormSourceException)1 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)1