mirror of
https://github.com/etesync/android
synced 2024-12-23 07:08:16 +00:00
works.
This commit is contained in:
parent
f44a6c7d42
commit
ffd0ea1c07
@ -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);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
// CollectionInfo.aidl
|
||||
package com.etesync.syncadapter.remote;
|
||||
|
||||
parcelable Journal;
|
||||
|
@ -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<Journal> CREATOR = new Creator<Journal>() {
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<JournalEntry> CREATOR = new Creator<JournalEntry>() {
|
||||
@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();
|
||||
}
|
||||
}
|
@ -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<Persistable> 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<EntryEntity> 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?
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Journal> CREATOR = new Creator<Journal>() {
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user