From 536bef9815555487fe03edf42302db6c39b5522f Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 22 Jan 2018 15:39:58 +0000 Subject: [PATCH] Import: always import, don't try to find duplicates based on UID. This was causing issues when importing from a Google account in some cases because we were getting weird UIDs. This was also problematic when importing from other sources that reported weird UIDs. --- .../ui/importlocal/ImportFragment.java | 24 +++++-------------- .../LocalCalendarImportFragment.java | 14 +++-------- .../LocalContactImportFragment.java | 18 ++++++-------- 3 files changed, 16 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.java index b2f8ae42..49d6b0e0 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.java @@ -277,15 +277,9 @@ public class ImportFragment extends DialogFragment { for (Event event : events) { try { - LocalEvent localEvent = localCalendar.getByUid(event.uid); - if (localEvent != null) { - localEvent.updateAsDirty(event); - result.updated++; - } else { - localEvent = new LocalEvent(localCalendar, event, event.uid, null); - localEvent.addAsDirty(); - result.added++; - } + LocalEvent localEvent = new LocalEvent(localCalendar, event, event.uid, null); + localEvent.addAsDirty(); + result.added++; } catch (CalendarStorageException e) { e.printStackTrace(); } @@ -311,15 +305,9 @@ public class ImportFragment extends DialogFragment { for (Contact contact : contacts) { try { - LocalContact localContact = (LocalContact) localAddressBook.getByUid(contact.uid); - if (localContact != null) { - localContact.updateAsDirty(contact); - result.updated++; - } else { - localContact = new LocalContact(localAddressBook, contact, contact.uid, null); - localContact.createAsDirty(); - result.added++; - } + LocalContact localContact = new LocalContact(localAddressBook, contact, null, null); + localContact.createAsDirty(); + result.added++; } catch (ContactsStorageException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.java index bac94757..873140c8 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.java @@ -248,17 +248,9 @@ public class LocalCalendarImportFragment extends ListFragment { for (LocalEvent currentLocalEvent : localEvents) { Event event = currentLocalEvent.getEvent(); try { - LocalEvent localEvent = event.uid == null ? null : - localCalendar.getByUid(event.uid); - - if (localEvent != null) { - localEvent.updateAsDirty(event); - result.updated++; - } else { - localEvent = new LocalEvent(localCalendar, event, event.uid, null); - localEvent.addAsDirty(); - result.added++; - } + LocalEvent localEvent = new LocalEvent(localCalendar, event, null, null); + localEvent.addAsDirty(); + result.added++; } catch (CalendarStorageException e) { e.printStackTrace(); diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.java index 487a19e6..65f1a15a 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.java @@ -108,6 +108,9 @@ public class LocalContactImportFragment extends Fragment { } } + cursor.close(); + provider.release(); + recyclerView.setAdapter(new ImportContactAdapter(getContext(), localAddressBooks, new OnAccountSelected() { @Override public void accountSelected(int index) { @@ -162,19 +165,12 @@ public class LocalContactImportFragment extends Fragment { int progress = 0; for (LocalContact currentLocalContact : localContacts) { Contact contact = currentLocalContact.getContact(); - (new LocalContact(addressBook, contact, contact.uid, null)).createAsDirty(); + (new LocalContact(addressBook, contact, null, null)).createAsDirty(); try { - LocalContact localContact = contact.uid == null ? - null : (LocalContact) addressBook.getByUid(contact.uid); - if (localContact != null) { - localContact.updateAsDirty(contact); - result.updated++; - } else { - localContact = new LocalContact(addressBook, contact, contact.uid, null); - localContact.createAsDirty(); - result.added++; - } + LocalContact localContact = new LocalContact(addressBook, contact, null, null); + localContact.createAsDirty(); + result.added++; } catch (ContactsStorageException e) { e.printStackTrace(); result.e = e;