Search in sources :

Example 1 with FormEndView

use of org.odk.collect.android.formentry.FormEndView in project collect by opendatakit.

the class FormEntryActivity method createViewForFormEnd.

/**
 * Creates the final screen in a form-filling interaction. Allows the user to set a display
 * name for the instance and to decide whether the form should be finalized or not. Presents
 * a button for saving and exiting.
 */
private View createViewForFormEnd(FormController formController) {
    if (formController.getSubmissionMetadata().instanceName != null) {
        saveName = formController.getSubmissionMetadata().instanceName;
    } else {
        // no meta/instanceName field in the form -- see if we have a
        // name for this instance from a previous save attempt...
        String uriMimeType = null;
        Uri instanceUri = getIntent().getData();
        if (instanceUri != null) {
            uriMimeType = getContentResolver().getType(instanceUri);
        }
        if (saveName == null && uriMimeType != null && uriMimeType.equals(InstancesContract.CONTENT_ITEM_TYPE)) {
            Instance instance = new InstancesRepositoryProvider(Collect.getInstance()).get().get(ContentUriHelper.getIdFromUri(instanceUri));
            if (instance != null) {
                saveName = instance.getDisplayName();
            }
        }
        if (saveName == null) {
            saveName = formSaveViewModel.getFormName();
        }
    }
    FormEndView endView = new FormEndView(this, formSaveViewModel.getFormName(), saveName, InstancesDaoHelper.isInstanceComplete(true, settingsProvider.getUnprotectedSettings().getBoolean(KEY_COMPLETED_DEFAULT)), new FormEndView.Listener() {

        @Override
        public void onSaveAsChanged(String saveAs) {
            // Seems like this is needed for rotation?
            saveName = saveAs;
        }

        @Override
        public void onSaveClicked(boolean markAsFinalized) {
            if (saveName.length() < 1) {
                showShortToast(FormEntryActivity.this, R.string.save_as_error);
            } else {
                formSaveViewModel.saveForm(getIntent().getData(), markAsFinalized, saveName, true);
            }
        }
    });
    if (!settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.KEY_MARK_AS_FINALIZED)) {
        endView.findViewById(R.id.mark_finished).setVisibility(View.GONE);
    }
    if (formController.getSubmissionMetadata().instanceName != null) {
        // if instanceName is defined in form, this is the name -- no
        // revisions
        // display only the name, not the prompt, and disable edits
        endView.findViewById(R.id.save_form_as).setVisibility(View.GONE);
        endView.findViewById(R.id.save_name).setEnabled(false);
        endView.findViewById(R.id.save_name).setVisibility(View.VISIBLE);
    }
    // override the visibility settings based upon admin preferences
    if (!settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.KEY_SAVE_AS)) {
        endView.findViewById(R.id.save_form_as).setVisibility(View.GONE);
        endView.findViewById(R.id.save_name).setVisibility(View.GONE);
    }
    if (showNavigationButtons) {
        updateNavigationButtonVisibility();
    }
    return endView;
}
Also used : InstancesRepositoryProvider(org.odk.collect.android.utilities.InstancesRepositoryProvider) Instance(org.odk.collect.forms.instances.Instance) FormEndView(org.odk.collect.android.formentry.FormEndView) Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)1 FormEndView (org.odk.collect.android.formentry.FormEndView)1 InstancesRepositoryProvider (org.odk.collect.android.utilities.InstancesRepositoryProvider)1 Instance (org.odk.collect.forms.instances.Instance)1