From ffd0ea1c07e79630e894b7aa75626801d988f3e5 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 28 Nov 2017 13:41:38 +0000 Subject: [PATCH] works. --- .../etesync/syncadapter/IEteSyncService.aidl | 2 + .../etesync/syncadapter/remote/Journal.aidl | 1 - .../etesync/syncadapter/remote/Journal.java | 10 ++-- .../syncadapter/remote/JournalEntry.java | 48 +++++++++++++++++++ .../syncadapter/remote/RemoteService.java | 21 ++++++++ .../remotecontroller/MainActivity.java | 1 + .../etesync/syncadapter/remote/Journal.java | 15 ++++-- 7 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/etesync/syncadapter/remote/JournalEntry.java diff --git a/app/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl b/app/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl index db303c72..888aef76 100644 --- a/app/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl +++ b/app/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl @@ -3,6 +3,7 @@ package com.etesync.syncadapter; // Declare any non-default types here with import statements import com.etesync.syncadapter.remote.Journal; +import com.etesync.syncadapter.remote.JournalEntry; interface IEteSyncService { boolean hasPermission(String journalType); @@ -10,4 +11,5 @@ interface IEteSyncService { void requestPermission(String journalType); Journal[] getJournals(String journalType); + JournalEntry[] getJournalEntries(String journalUid, String lastUid); } diff --git a/app/src/main/aidl/com/etesync/syncadapter/remote/Journal.aidl b/app/src/main/aidl/com/etesync/syncadapter/remote/Journal.aidl index 40c2d719..2358e3f7 100644 --- a/app/src/main/aidl/com/etesync/syncadapter/remote/Journal.aidl +++ b/app/src/main/aidl/com/etesync/syncadapter/remote/Journal.aidl @@ -1,4 +1,3 @@ -// CollectionInfo.aidl package com.etesync.syncadapter.remote; parcelable Journal; diff --git a/app/src/main/java/com/etesync/syncadapter/remote/Journal.java b/app/src/main/java/com/etesync/syncadapter/remote/Journal.java index 554c3952..6c1e9d65 100644 --- a/app/src/main/java/com/etesync/syncadapter/remote/Journal.java +++ b/app/src/main/java/com/etesync/syncadapter/remote/Journal.java @@ -13,9 +13,7 @@ public class Journal implements Parcelable { } protected Journal(Parcel in) { - account = in.readString(); - id = in.readString(); - readOnly = in.readByte() == 0; + readFromParcel(in); } public static final Creator CREATOR = new Creator() { @@ -41,4 +39,10 @@ public class Journal implements Parcelable { parcel.writeString(id); parcel.writeByte((byte) (readOnly ? 1 : 0)); } + + public void readFromParcel(Parcel in) { + account = in.readString(); + id = in.readString(); + readOnly = in.readByte() == 0; + } } diff --git a/app/src/main/java/com/etesync/syncadapter/remote/JournalEntry.java b/app/src/main/java/com/etesync/syncadapter/remote/JournalEntry.java new file mode 100644 index 00000000..9e26b0ad --- /dev/null +++ b/app/src/main/java/com/etesync/syncadapter/remote/JournalEntry.java @@ -0,0 +1,48 @@ +package com.etesync.syncadapter.remote; + +import android.os.Parcel; +import android.os.Parcelable; + +public class JournalEntry implements Parcelable { + public String account; + public String id; + public String content; + + public JournalEntry(String id) { + this.id = id; + } + + protected JournalEntry(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public JournalEntry createFromParcel(Parcel in) { + return new JournalEntry(in); + } + + @Override + public JournalEntry[] newArray(int size) { + return new JournalEntry[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(account); + parcel.writeString(id); + parcel.writeString(content); + } + + public void readFromParcel(Parcel in) { + account = in.readString(); + id = in.readString(); + content = in.readString(); + } +} diff --git a/app/src/main/java/com/etesync/syncadapter/remote/RemoteService.java b/app/src/main/java/com/etesync/syncadapter/remote/RemoteService.java index af770e87..513e163d 100644 --- a/app/src/main/java/com/etesync/syncadapter/remote/RemoteService.java +++ b/app/src/main/java/com/etesync/syncadapter/remote/RemoteService.java @@ -17,7 +17,9 @@ import android.util.Log; import com.etesync.syncadapter.App; import com.etesync.syncadapter.IEteSyncService; import com.etesync.syncadapter.model.CollectionInfo; +import com.etesync.syncadapter.model.EntryEntity; import com.etesync.syncadapter.model.JournalEntity; +import com.etesync.syncadapter.model.JournalModel; import java.util.LinkedList; import java.util.List; @@ -60,6 +62,25 @@ public class RemoteService extends Service { return ret; } + public JournalEntry[] getJournalEntries(String journalUid, String lastUid) throws RemoteException { + EntityDataStore data = ((App) getApplicationContext()).getData(); + JournalEntity journal = data.select(JournalEntity.class).where((JournalEntity.DELETED.eq(false))).limit(1).get().firstOrNull(); + // FIXME: Should support generic type + if (!mApiPermissionHelper.isAllowedIgnoreErrors(journal.getInfo().type.toString())) return null; + + List entries = data.select(EntryEntity.class).where(EntryEntity.JOURNAL.eq(journal)).orderBy(EntryEntity.ID.desc()).get().toList(); + + JournalEntry ret[] = new JournalEntry[entries.size()]; + int i = 0; + for (EntryEntity entry : entries) { + ret[i] = new JournalEntry(entry.getUid()); + ret[i].content = entry.getContent().toJson(); + i++; + } + + return ret; + } + //todo - query journals? //todo - add insert. - returns uid //todo add update? diff --git a/remoteexample/src/main/java/com/etesync/remotecontroller/MainActivity.java b/remoteexample/src/main/java/com/etesync/remotecontroller/MainActivity.java index 6cd4da47..98fda4fd 100644 --- a/remoteexample/src/main/java/com/etesync/remotecontroller/MainActivity.java +++ b/remoteexample/src/main/java/com/etesync/remotecontroller/MainActivity.java @@ -36,6 +36,7 @@ public class MainActivity extends AppCompatActivity { } else { for (Journal journal : journals) { Log.i(TAG, "Received collection info: " + journal.id); + Log.i(TAG, "Size: " + mEteSyncService.getJournalEntries(journal.id, null)); } } } diff --git a/remoteexample/src/main/java/com/etesync/syncadapter/remote/Journal.java b/remoteexample/src/main/java/com/etesync/syncadapter/remote/Journal.java index 32eaaed7..6c1e9d65 100644 --- a/remoteexample/src/main/java/com/etesync/syncadapter/remote/Journal.java +++ b/remoteexample/src/main/java/com/etesync/syncadapter/remote/Journal.java @@ -6,14 +6,14 @@ import android.os.Parcelable; public class Journal implements Parcelable { public String account; public String id; + public boolean readOnly = false; - public String getId() { - return id; + public Journal(String id) { + this.id = id; } protected Journal(Parcel in) { - account = in.readString(); - id = in.readString(); + readFromParcel(in); } public static final Creator CREATOR = new Creator() { @@ -37,5 +37,12 @@ public class Journal implements Parcelable { public void writeToParcel(Parcel parcel, int i) { parcel.writeString(account); parcel.writeString(id); + parcel.writeByte((byte) (readOnly ? 1 : 0)); + } + + public void readFromParcel(Parcel in) { + account = in.readString(); + id = in.readString(); + readOnly = in.readByte() == 0; } }