use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class FormDeleter method delete.
public void delete(Long id) {
Form form = formsRepository.get(id);
List<Instance> instancesForVersion = instancesRepository.getAllNotDeletedByFormIdAndVersion(form.getFormId(), form.getVersion());
// If there's more than one form with the same formid/version, trust the user that they want to truly delete this one
// because otherwise it may not ever be removed (instance deletion only deletes one corresponding form).
List<Form> formsWithSameFormIdVersion = formsRepository.getAllByFormIdAndVersion(form.getFormId(), form.getVersion());
if (instancesForVersion.isEmpty() || formsWithSameFormIdVersion.size() > 1) {
formsRepository.delete(id);
} else {
formsRepository.softDelete(form.getDbId());
}
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class QuitFormDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
String title = formSaveViewModel.getFormName() == null ? getActivity().getString(R.string.no_form_loaded) : formSaveViewModel.getFormName();
List<IconMenuItem> items;
if (settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.KEY_SAVE_MID)) {
items = ImmutableList.of(new IconMenuItem(R.drawable.ic_save, R.string.keep_changes), new IconMenuItem(R.drawable.ic_delete, R.string.do_not_save));
} else {
items = ImmutableList.of(new IconMenuItem(R.drawable.ic_delete, R.string.do_not_save));
}
ListView listView = DialogUtils.createActionListView(getActivity());
final IconMenuListAdapter adapter = new IconMenuListAdapter(getActivity(), items);
listView.setAdapter(adapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
IconMenuItem item = (IconMenuItem) adapter.getItem(position);
if (item.getTextResId() == R.string.keep_changes) {
if (listener != null) {
listener.onSaveChangesClicked();
}
} else {
formSaveViewModel.ignoreChanges();
String action = getActivity().getIntent().getAction();
if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_EDIT.equals(action)) {
// caller is waiting on a picked form
Uri uri = null;
String path = formSaveViewModel.getAbsoluteInstancePath();
if (path != null) {
Instance instance = new InstancesRepositoryProvider(requireContext()).get().getOneByPath(path);
if (instance != null) {
uri = InstancesContract.getUri(currentProjectProvider.getCurrentProject().getUuid(), instance.getDbId());
}
}
if (uri != null) {
getActivity().setResult(RESULT_OK, new Intent().setData(uri));
}
}
getActivity().finish();
}
if (getDialog() != null) {
getDialog().dismiss();
}
});
return new MaterialAlertDialogBuilder(getActivity()).setTitle(getString(R.string.quit_application, title)).setNegativeButton(getActivity().getString(R.string.do_not_exit), (dialog, id) -> {
dialog.cancel();
dismiss();
}).setView(listView).create();
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class FormMapActivityTest method tappingOnDeletedInstances_showsSubmissionSummaryWithAppropriateMessage.
// Geometry is removed from the database on instance deletion but just in case there is a
// deleted instance with geometry available, show a deleted toast.
@Test
public void tappingOnDeletedInstances_showsSubmissionSummaryWithAppropriateMessage() {
Pair<Instance, MapPoint> deleted = new Pair<>(testInstances[0], new MapPoint(10.0, 125.6));
int featureId = map.getFeatureIdFor(deleted.second);
activity.onFeatureClicked(featureId);
assertSubmissionSummaryContent(deleted.first.getDisplayName(), deleted.first.getStatus(), new Date(deleted.first.getLastStatusChangeDate()), DELETED_TOAST);
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class FormMapViewModelTest method addingAnInstance_isReflectedInInstanceCountsAndList.
@Test
public void addingAnInstance_isReflectedInInstanceCountsAndList() {
FormMapViewModel viewModel = new FormMapViewModel(TEST_FORM_1, testInstancesRepository);
List<FormMapViewModel.MappableFormInstance> instances = viewModel.getMappableFormInstances();
assertThat(viewModel.getTotalInstanceCount(), is(7));
assertThat(instances.size(), is(6));
Instance newInstance = new Instance.Builder().dbId(8L).formId("formId1").formVersion("2019103101").geometryType("Point").geometry("{\"type\":\"Point\",\"coordinates\":[127.6, 11.1]}").canEditWhenComplete(true).status(Instance.STATUS_COMPLETE).build();
((InMemInstancesRepository) testInstancesRepository).save(newInstance);
instances = viewModel.getMappableFormInstances();
assertThat(viewModel.getTotalInstanceCount(), is(8));
assertThat(instances.size(), is(7));
assertThat(instances.get(6).getClickAction(), is(FormMapViewModel.ClickAction.OPEN_EDIT));
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class FormMapActivityTest method tappingOnUneditableInstances_showsSubmissionSummaryWithAppropriateMessage.
@Test
public void tappingOnUneditableInstances_showsSubmissionSummaryWithAppropriateMessage() {
Pair<Instance, MapPoint> sent = new Pair<>(testInstances[5], new MapPoint(10.3, 125.7));
int featureId = map.getFeatureIdFor(sent.second);
activity.onFeatureClicked(featureId);
assertSubmissionSummaryContent(sent.first.getDisplayName(), sent.first.getStatus(), new Date(sent.first.getLastStatusChangeDate()), OPEN_READ_ONLY);
}
Aggregations