use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class InstancesDaoHelper method isInstanceComplete.
/**
* Checks the database to determine if the current instance being edited has
* already been 'marked completed'. A form can be 'unmarked' complete and
* then resaved.
*
* @return true if form has been marked completed, false otherwise.
* <p>
* TODO: replace with method in {@link InstancesRepository}
* that returns an {@link Instance} object from a path.
*/
public static boolean isInstanceComplete(boolean end, boolean completedByDefault) {
// default to false if we're mid form
boolean complete = false;
FormController formController = Collect.getInstance().getFormController();
if (formController != null && formController.getInstanceFile() != null) {
// First check if we're at the end of the form, then check the preferences
complete = end && completedByDefault;
// Then see if we've already marked this form as complete before
String path = formController.getInstanceFile().getAbsolutePath();
Instance instance = new InstancesRepositoryProvider(Collect.getInstance()).get().getOneByPath(path);
if (instance != null && instance.getStatus().equals(Instance.STATUS_COMPLETE)) {
complete = true;
}
} else {
Timber.w("FormController or its instanceFile field has a null value");
}
return complete;
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class DatabaseInstancesRepository method getOneByPath.
@Override
public Instance getOneByPath(String instancePath) {
String selection = INSTANCE_FILE_PATH + "=?";
String[] args = { getRelativeFilePath(instancesPath, instancePath) };
try (Cursor cursor = query(null, selection, args, null)) {
List<Instance> instances = getInstancesFromCursor(cursor, instancesPath);
if (instances.size() == 1) {
return instances.get(0);
} else {
return null;
}
}
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class DatabaseInstancesRepository method get.
@Override
public Instance get(Long databaseId) {
String selection = _ID + "=?";
String[] selectionArgs = { Long.toString(databaseId) };
try (Cursor cursor = query(null, selection, selectionArgs, null)) {
List<Instance> result = getInstancesFromCursor(cursor, instancesPath);
return !result.isEmpty() ? result.get(0) : null;
}
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class DatabaseInstancesRepository method getInstancesFromCursor.
private static List<Instance> getInstancesFromCursor(Cursor cursor, String instancesPath) {
List<Instance> instances = new ArrayList<>();
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
Instance instance = getInstanceFromCurrentCursorPosition(cursor, instancesPath);
instances.add(instance);
}
return instances;
}
use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.
the class DatabaseInstancesRepository method deleteAll.
@Override
public void deleteAll() {
List<Instance> instances = getAll();
databaseConnection.getWriteableDatabase().delete(INSTANCES_TABLE_NAME, null, null);
for (Instance instance : instances) {
deleteInstanceFiles(instance);
}
}
Aggregations