From ce3483cee20c58e7f275ceb008db0aa30bd001d1 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 8 Mar 2017 15:18:53 +0000 Subject: [PATCH] Create collection: update collection if already exists (info.url is set). --- .../syncadapter/ui/CreateCollectionFragment.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/CreateCollectionFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/CreateCollectionFragment.java index 14e473fa..c7980480 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/CreateCollectionFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/CreateCollectionFragment.java @@ -150,15 +150,20 @@ public class CreateCollectionFragment extends DialogFragment implements LoaderMa HttpUrl principal = HttpUrl.get(settings.getUri()); JournalManager journalManager = new JournalManager(HttpClient.create(getContext(), account), principal); - JournalManager.Journal journal = new JournalManager.Journal(settings.password(), info.toJson()); - // CollectionInfo doesn't have a url at this point, update it. - info.url = journal.getUuid(); - journalManager.putJournal(journal); + if (info.url == null) { + // CollectionInfo doesn't have a url at this point, update it. + JournalManager.Journal journal = new JournalManager.Journal(settings.password(), info.toJson()); + info.url = journal.getUuid(); + journalManager.putJournal(journal); + } else { + JournalManager.Journal journal = new JournalManager.Journal(settings.password(), info.toJson(), info.url); + journalManager.updateJournal(journal); + } // 2. add collection to service ContentValues values = info.toDB(); values.put(ServiceDB.Collections.SERVICE_ID, serviceID); - db.insert(ServiceDB.Collections._TABLE, null, values); + db.insertWithOnConflict(ServiceDB.Collections._TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); requestSync(authority); } catch (IllegalStateException | Exceptions.HttpException e) {