diff --git a/app/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl b/app/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl index 05fe0030..db303c72 100644 --- a/app/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl +++ b/app/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl @@ -2,15 +2,12 @@ package com.etesync.syncadapter; // Declare any non-default types here with import statements -import com.etesync.syncadapter.model.CollectionInfo; +import com.etesync.syncadapter.remote.Journal; interface IEteSyncService { boolean hasPermission(String journalType); void requestPermission(String journalType); - CollectionInfo[] getJournalEntries(String journalType); - - + Journal[] getJournals(String journalType); } - diff --git a/app/src/main/aidl/com/etesync/syncadapter/model/CollectionInfo.aidl b/app/src/main/aidl/com/etesync/syncadapter/model/CollectionInfo.aidl deleted file mode 100644 index 5ed502b7..00000000 --- a/app/src/main/aidl/com/etesync/syncadapter/model/CollectionInfo.aidl +++ /dev/null @@ -1,4 +0,0 @@ -// CollectionInfo.aidl -package com.etesync.syncadapter.model; - -parcelable CollectionInfo; diff --git a/app/src/main/aidl/com/etesync/syncadapter/remote/Journal.aidl b/app/src/main/aidl/com/etesync/syncadapter/remote/Journal.aidl new file mode 100644 index 00000000..40c2d719 --- /dev/null +++ b/app/src/main/aidl/com/etesync/syncadapter/remote/Journal.aidl @@ -0,0 +1,4 @@ +// 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 new file mode 100644 index 00000000..554c3952 --- /dev/null +++ b/app/src/main/java/com/etesync/syncadapter/remote/Journal.java @@ -0,0 +1,44 @@ +package com.etesync.syncadapter.remote; + +import android.os.Parcel; +import android.os.Parcelable; + +public class Journal implements Parcelable { + public String account; + public String id; + public boolean readOnly = false; + + public Journal(String id) { + this.id = id; + } + + protected Journal(Parcel in) { + account = in.readString(); + id = in.readString(); + readOnly = in.readByte() == 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public Journal createFromParcel(Parcel in) { + return new Journal(in); + } + + @Override + public Journal[] newArray(int size) { + return new Journal[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(account); + parcel.writeString(id); + parcel.writeByte((byte) (readOnly ? 1 : 0)); + } +} 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 c3f2a2ed..af770e87 100644 --- a/app/src/main/java/com/etesync/syncadapter/remote/RemoteService.java +++ b/app/src/main/java/com/etesync/syncadapter/remote/RemoteService.java @@ -12,9 +12,18 @@ import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.os.RemoteException; +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.JournalEntity; + +import java.util.LinkedList; +import java.util.List; + +import io.requery.Persistable; +import io.requery.sql.EntityDataStore; public class RemoteService extends Service { @@ -36,10 +45,19 @@ public class RemoteService extends Service { mApiPermissionHelper.getCurrentCallingPackage(), journalType); } - public CollectionInfo[] getJournalEntries(String journalType) throws RemoteException { + public Journal[] getJournals(String journalType) throws RemoteException { if (!mApiPermissionHelper.isAllowedIgnoreErrors(journalType)) return null; - return new CollectionInfo[0]; //todo implement + EntityDataStore data = ((App) getApplicationContext()).getData(); + List journals = data.select(JournalEntity.class).where((JournalEntity.DELETED.eq(false))).get().toList(); + Journal ret[] = new Journal[journals.size()]; + int i = 0; + for (JournalEntity journal : journals) { + ret[i] = new Journal(journal.getUid()); + i++; + } + + return ret; } //todo - query journals? diff --git a/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.java b/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.java index dc8d554d..8a32d002 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.java @@ -32,6 +32,7 @@ import org.apache.commons.codec.Charsets; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.Serializable; import java.util.Formatter; import java.util.List; import java.util.Locale; @@ -63,7 +64,7 @@ public class JournalItemActivity extends BaseActivity implements Refreshable { public static Intent newIntent(Context context, CollectionInfo info, SyncEntry syncEntry) { Intent intent = new Intent(context, JournalItemActivity.class); - intent.putExtra(Constants.KEY_COLLECTION_INFO, info); + intent.putExtra(Constants.KEY_COLLECTION_INFO, (Serializable) info); intent.putExtra(KEY_SYNC_ENTRY, syncEntry); return intent; } diff --git a/remoteexample/build.gradle b/remoteexample/build.gradle index eb4009c2..17bb5e10 100644 --- a/remoteexample/build.gradle +++ b/remoteexample/build.gradle @@ -26,6 +26,6 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.3.0' + compile 'com.android.support:appcompat-v7:25.+' testCompile 'junit:junit:4.12' } diff --git a/remoteexample/src/main/aidl b/remoteexample/src/main/aidl new file mode 120000 index 00000000..b7522088 --- /dev/null +++ b/remoteexample/src/main/aidl @@ -0,0 +1 @@ +../../../app/src/main/aidl \ No newline at end of file diff --git a/remoteexample/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl b/remoteexample/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl deleted file mode 100644 index dc15a1a2..00000000 --- a/remoteexample/src/main/aidl/com/etesync/syncadapter/IEteSyncService.aidl +++ /dev/null @@ -1,13 +0,0 @@ -// IEteSyncService.aidl -package com.etesync.syncadapter; - -// Declare any non-default types here with import statements -import com.etesync.syncadapter.model.CollectionInfo; - -interface IEteSyncService { - boolean hasPermission(String journalType); - - void requestPermission(String journalType); - - CollectionInfo[] getJournalEntries(String journalType); -} diff --git a/remoteexample/src/main/aidl/com/etesync/syncadapter/model/CollectionInfo.aidl b/remoteexample/src/main/aidl/com/etesync/syncadapter/model/CollectionInfo.aidl deleted file mode 100644 index 5ed502b7..00000000 --- a/remoteexample/src/main/aidl/com/etesync/syncadapter/model/CollectionInfo.aidl +++ /dev/null @@ -1,4 +0,0 @@ -// CollectionInfo.aidl -package com.etesync.syncadapter.model; - -parcelable CollectionInfo; diff --git a/remoteexample/src/main/java/com/etesync/remotecontroller/MainActivity.java b/remoteexample/src/main/java/com/etesync/remotecontroller/MainActivity.java index 2c1e166d..6cd4da47 100644 --- a/remoteexample/src/main/java/com/etesync/remotecontroller/MainActivity.java +++ b/remoteexample/src/main/java/com/etesync/remotecontroller/MainActivity.java @@ -10,12 +10,12 @@ import android.support.v7.app.AppCompatActivity; import android.util.Log; import com.etesync.syncadapter.IEteSyncService; -import com.etesync.syncadapter.model.CollectionInfo; +import com.etesync.syncadapter.remote.Journal; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; - private static final String JOURNAL_TYPE = "ToDo"; + private static final String JOURNAL_TYPE = "CALENDAR"; private IEteSyncService mEteSyncService; @@ -30,12 +30,12 @@ public class MainActivity extends AppCompatActivity { if (!isAllowed) { mEteSyncService.requestPermission(JOURNAL_TYPE); } else { - CollectionInfo[] collectionInfo = mEteSyncService.getJournalEntries(JOURNAL_TYPE); - if (collectionInfo == null) { + Journal[] journals = mEteSyncService.getJournals(JOURNAL_TYPE); + if (journals == null) { Log.i(TAG, "Received no collection infos"); } else { - for (CollectionInfo collectionInfo1 : collectionInfo) { - Log.i(TAG, "Received collection info: " + collectionInfo1.displayName); + for (Journal journal : journals) { + Log.i(TAG, "Received collection info: " + journal.id); } } } diff --git a/remoteexample/src/main/java/com/etesync/syncadapter/model/CollectionInfo.java b/remoteexample/src/main/java/com/etesync/syncadapter/model/CollectionInfo.java deleted file mode 100644 index 2ba89ffd..00000000 --- a/remoteexample/src/main/java/com/etesync/syncadapter/model/CollectionInfo.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering). - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html - */ - -package com.etesync.syncadapter.model; - -import android.os.Parcel; -import android.os.Parcelable; - -import java.io.Serializable; - -public class CollectionInfo implements Serializable, Parcelable { - public int serviceID; - - public long id; - - public enum Type { - ADDRESS_BOOK, - CALENDAR - } - - public int version = -1; - - public Type type; - - public String uid; - - public String displayName, description; - public Integer color; - - public String timeZone; - - public boolean selected; - - protected CollectionInfo(Parcel in) { - id = in.readLong(); - serviceID = in.readInt(); - version = in.readInt(); - uid = in.readString(); - displayName = in.readString(); - description = in.readString(); - timeZone = in.readString(); - selected = in.readByte() != 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public CollectionInfo createFromParcel(Parcel in) { - return new CollectionInfo(in); - } - - @Override - public CollectionInfo[] newArray(int size) { - return new CollectionInfo[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel aParcel, int aI) { - aParcel.writeLong(id); - aParcel.writeInt(serviceID); - aParcel.writeInt(version); - aParcel.writeString(uid); - aParcel.writeString(displayName); - aParcel.writeString(description); - aParcel.writeString(timeZone); - aParcel.writeByte((byte) (selected ? 1 : 0)); - } -} diff --git a/remoteexample/src/main/java/com/etesync/syncadapter/remote/Journal.java b/remoteexample/src/main/java/com/etesync/syncadapter/remote/Journal.java new file mode 100644 index 00000000..32eaaed7 --- /dev/null +++ b/remoteexample/src/main/java/com/etesync/syncadapter/remote/Journal.java @@ -0,0 +1,41 @@ +package com.etesync.syncadapter.remote; + +import android.os.Parcel; +import android.os.Parcelable; + +public class Journal implements Parcelable { + public String account; + public String id; + + public String getId() { + return id; + } + + protected Journal(Parcel in) { + account = in.readString(); + id = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public Journal createFromParcel(Parcel in) { + return new Journal(in); + } + + @Override + public Journal[] newArray(int size) { + return new Journal[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(account); + parcel.writeString(id); + } +}