use of de.symeda.sormas.app.util.Callback in project SORMAS-Project by hzi-braunschweig.
the class SettingsFragment method showRepullDataConfirmationDialog.
private void showRepullDataConfirmationDialog() {
final ConfirmationDialog confirmationDialog = new ConfirmationDialog(getActivity(), R.string.heading_confirmation_dialog, R.string.info_resync_duration);
confirmationDialog.setPositiveCallback(() -> {
// Collect unsynchronized changes
final List<Case> modifiedCases = DatabaseHelper.getCaseDao().getModifiedEntities();
final List<Contact> modifiedContacts = DatabaseHelper.getContactDao().getModifiedEntities();
final List<Person> modifiedPersons = DatabaseHelper.getPersonDao().getModifiedEntities();
final List<Event> modifiedEvents = DatabaseHelper.getEventDao().getModifiedEntities();
final List<EventParticipant> modifiedEventParticipants = DatabaseHelper.getEventParticipantDao().getModifiedEntities();
final List<Sample> modifiedSamples = DatabaseHelper.getSampleDao().getModifiedEntities();
final List<Visit> modifiedVisits = DatabaseHelper.getVisitDao().getModifiedEntities();
getBaseActivity().synchronizeData(SynchronizeDataAsync.SyncMode.CompleteAndRepull, true, true, null, new Callback() {
@Override
public void call() {
// Add deleted entities that had unsynchronized changes to sync log
for (Case caze : modifiedCases) {
if (DatabaseHelper.getCaseDao().queryUuidReference(caze.getUuid()) == null) {
DatabaseHelper.getSyncLogDao().createWithParentStack(caze.toString(), getResources().getString(R.string.caption_changed_data_lost));
}
}
for (Contact contact : modifiedContacts) {
if (DatabaseHelper.getContactDao().queryUuidReference(contact.getUuid()) == null) {
DatabaseHelper.getSyncLogDao().createWithParentStack(contact.toString(), getResources().getString(R.string.caption_changed_data_lost));
}
}
for (Person person : modifiedPersons) {
if (DatabaseHelper.getPersonDao().queryUuidReference(person.getUuid()) == null) {
DatabaseHelper.getSyncLogDao().createWithParentStack(person.toString(), getResources().getString(R.string.caption_changed_data_lost));
}
}
for (Event event : modifiedEvents) {
if (DatabaseHelper.getEventDao().queryUuidReference(event.getUuid()) == null) {
DatabaseHelper.getSyncLogDao().createWithParentStack(event.toString(), getResources().getString(R.string.caption_changed_data_lost));
}
}
for (EventParticipant eventParticipant : modifiedEventParticipants) {
if (DatabaseHelper.getEventParticipantDao().queryUuidReference(eventParticipant.getUuid()) == null) {
DatabaseHelper.getSyncLogDao().createWithParentStack(eventParticipant.toString(), getResources().getString(R.string.caption_changed_data_lost));
}
}
for (Sample sample : modifiedSamples) {
if (DatabaseHelper.getSampleDao().queryUuidReference(sample.getUuid()) == null) {
DatabaseHelper.getSyncLogDao().createWithParentStack(sample.toString(), getResources().getString(R.string.caption_changed_data_lost));
}
}
for (Visit visit : modifiedVisits) {
if (DatabaseHelper.getVisitDao().queryUuidReference(visit.getUuid()) == null) {
DatabaseHelper.getSyncLogDao().createWithParentStack(visit.toString(), getResources().getString(R.string.caption_changed_data_lost));
}
}
}
}, new Callback() {
@Override
public void call() {
DatabaseHelper.clearTables(false);
}
});
});
confirmationDialog.show();
}
Aggregations