Update local contacts

This commit is contained in:
M66B 2022-03-28 21:01:55 +02:00
parent d7094c3845
commit 65849dcd20
1 changed files with 31 additions and 20 deletions

View File

@ -585,33 +585,44 @@ public class FragmentContacts extends FragmentBase {
group = null; group = null;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityContact contact; boolean update = false;
if (id > 0) EntityContact contact = db.contact().getContact(id);
contact = db.contact().getContact(id); EntityContact existing = db.contact().getContact(account, type, email);
else {
contact = db.contact().getContact(account, type, email);
if (contact == null)
contact = new EntityContact();
else
id = contact.id;
}
contact.account = account; if (contact == null) {
contact.type = type; if (existing == null)
contact.email = email; contact = new EntityContact();
contact.name = name; else {
contact.group = group; update = true;
contact = existing;
}
} else {
update = true;
if (existing != null && !existing.id.equals(contact.id))
db.contact().deleteContact(existing.id);
}
if (id > 0) contact.account = account;
db.contact().updateContact(contact); contact.type = type;
else { contact.email = email;
contact.name = name;
contact.group = group;
contact.times_contacted = 0; contact.times_contacted = 0;
contact.first_contacted = new Date().getTime(); contact.first_contacted = new Date().getTime();
contact.last_contacted = contact.first_contacted; contact.last_contacted = contact.first_contacted;
contact.id = db.contact().insertContact(contact);
}
if (update)
db.contact().updateContact(contact);
else
contact.id = db.contact().insertContact(contact);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null; return null;
} }