use of org.odk.collect.forms.instances.Instance 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;
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class InstancesRepositoryTest method getAllByFormIdAndVersionNotDeleted_excludesDeleted.
@Test
public void getAllByFormIdAndVersionNotDeleted_excludesDeleted() {
InstancesRepository instancesRepository = buildSubject();
instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
instancesRepository.save(InstanceUtils.buildInstance("formid", "1", "display", Instance.STATUS_COMPLETE, null, getInstancesDir()).build());
instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
instancesRepository.save(InstanceUtils.buildInstance("formid", "1", "display", Instance.STATUS_COMPLETE, System.currentTimeMillis(), getInstancesDir()).build());
instancesRepository.save(InstanceUtils.buildInstance("formid2", "1", "display", Instance.STATUS_COMPLETE, null, getInstancesDir()).build());
List<Instance> instances = instancesRepository.getAllNotDeletedByFormIdAndVersion("formid", "1");
assertThat(instances.size(), is(3));
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class InstancesRepositoryTest method save_whenStatusIsNull_usesIncomplete.
@Test
public void save_whenStatusIsNull_usesIncomplete() {
InstancesRepository instancesRepository = buildSubject();
Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).status(null).build());
assertThat(instancesRepository.get(instance.getDbId()).getStatus(), is(Instance.STATUS_INCOMPLETE));
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class InstancesRepositoryTest method save_whenInstanceHasId_updatesExisting.
@Test
public void save_whenInstanceHasId_updatesExisting() {
InstancesRepository instancesRepository = buildSubject();
Instance originalInstance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).displayName("Blah").build());
instancesRepository.save(new Instance.Builder(originalInstance).displayName("A different blah").build());
assertThat(instancesRepository.get(originalInstance.getDbId()).getDisplayName(), is("A different blah"));
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class InMemInstancesRepository method delete.
@Override
public void delete(Long id) {
Instance instance = get(id);
deleteInstanceFiles(instance);
instances.remove(instance);
}
Aggregations