From bd5beaaf918c21c052711ab60984b68f655c73d2 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 9 Mar 2017 20:01:23 +0000 Subject: [PATCH] Move SyncEntry to the models package. This unties it from the sync manager, and will let us better reuse it. --- .../etesync/syncadapter/model/SyncEntry.java | 51 +++++++++++++++++++ .../syncadapter/CalendarSyncManager.java | 1 + .../syncadapter/ContactsSyncManager.java | 1 + .../syncadapter/syncadapter/SyncManager.java | 47 +---------------- 4 files changed, 54 insertions(+), 46 deletions(-) create mode 100644 app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java diff --git a/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java b/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java new file mode 100644 index 00000000..6afd715f --- /dev/null +++ b/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java @@ -0,0 +1,51 @@ +package com.etesync.syncadapter.model; + +import com.etesync.syncadapter.GsonHelper; +import com.etesync.syncadapter.journalmanager.JournalEntryManager; + +import lombok.Getter; + +public class SyncEntry { + @Getter + private String content; + @Getter + private Actions action; + + public enum Actions { + ADD("ADD"), + CHANGE("CHANGE"), + DELETE("DELETE"); + + private final String text; + + Actions(final String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + } + + @SuppressWarnings("unused") + private SyncEntry() { + } + + public SyncEntry(String content, Actions action) { + this.content = content; + this.action = action; + } + + public boolean isAction(Actions action) { + return this.action.equals(action); + } + + public static SyncEntry fromJournalEntry(String keyBase64, JournalEntryManager.Entry entry) { + return GsonHelper.gson.fromJson(entry.getContent(keyBase64), SyncEntry.class); + } + + public String toJson() { + return GsonHelper.gson.toJson(this, this.getClass()); + } +} diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.java b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.java index a0b30e7f..23b1b439 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.java +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.java @@ -26,6 +26,7 @@ import com.etesync.syncadapter.InvalidAccountException; import com.etesync.syncadapter.R; import com.etesync.syncadapter.journalmanager.JournalEntryManager; import com.etesync.syncadapter.model.CollectionInfo; +import com.etesync.syncadapter.model.SyncEntry; import com.etesync.syncadapter.resource.LocalCalendar; import com.etesync.syncadapter.resource.LocalEvent; import com.etesync.syncadapter.resource.LocalResource; diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/ContactsSyncManager.java b/app/src/main/java/com/etesync/syncadapter/syncadapter/ContactsSyncManager.java index b5a34cf9..57febeeb 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/ContactsSyncManager.java +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/ContactsSyncManager.java @@ -34,6 +34,7 @@ import com.etesync.syncadapter.InvalidAccountException; import com.etesync.syncadapter.R; import com.etesync.syncadapter.journalmanager.JournalEntryManager; import com.etesync.syncadapter.model.CollectionInfo; +import com.etesync.syncadapter.model.SyncEntry; import com.etesync.syncadapter.resource.LocalAddressBook; import com.etesync.syncadapter.resource.LocalContact; import com.etesync.syncadapter.resource.LocalGroup; diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java index 2a46f1f6..8850869a 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java @@ -17,7 +17,6 @@ import android.os.Bundle; import com.etesync.syncadapter.AccountSettings; import com.etesync.syncadapter.App; import com.etesync.syncadapter.Constants; -import com.etesync.syncadapter.GsonHelper; import com.etesync.syncadapter.HttpClient; import com.etesync.syncadapter.InvalidAccountException; import com.etesync.syncadapter.NotificationHelper; @@ -27,6 +26,7 @@ import com.etesync.syncadapter.journalmanager.JournalEntryManager; import com.etesync.syncadapter.model.CollectionInfo; import com.etesync.syncadapter.model.EntryEntity; import com.etesync.syncadapter.model.JournalEntity; +import com.etesync.syncadapter.model.SyncEntry; import com.etesync.syncadapter.resource.LocalCollection; import com.etesync.syncadapter.resource.LocalResource; import com.etesync.syncadapter.ui.DebugInfoActivity; @@ -46,7 +46,6 @@ import at.bitfire.ical4android.InvalidCalendarException; import at.bitfire.vcard4android.ContactsStorageException; import io.requery.Persistable; import io.requery.sql.EntityDataStore; -import lombok.Getter; import okhttp3.OkHttpClient; import static com.etesync.syncadapter.Constants.KEY_ACCOUNT; @@ -444,48 +443,4 @@ abstract public class SyncManager { } - static class SyncEntry { - @Getter - private String content; - @Getter - private Actions action; - - enum Actions { - ADD("ADD"), - CHANGE("CHANGE"), - DELETE("DELETE"); - - private final String text; - - Actions(final String text) { - this.text = text; - } - - @Override - public String toString() { - return text; - } - } - - @SuppressWarnings("unused") - private SyncEntry() { - } - - protected SyncEntry(String content, Actions action) { - this.content = content; - this.action = action; - } - - boolean isAction(Actions action) { - return this.action.equals(action); - } - - static SyncEntry fromJournalEntry(String keyBase64, JournalEntryManager.Entry entry) { - return GsonHelper.gson.fromJson(entry.getContent(keyBase64), SyncEntry.class); - } - - String toJson() { - return GsonHelper.gson.toJson(this, this.getClass()); - } - } }