mirror of
https://github.com/etesync/android
synced 2024-11-25 17:38:13 +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
|
// Declare any non-default types here with import statements
|
||||||
import com.etesync.syncadapter.remote.Journal;
|
import com.etesync.syncadapter.remote.Journal;
|
||||||
|
import com.etesync.syncadapter.remote.JournalEntry;
|
||||||
|
|
||||||
interface IEteSyncService {
|
interface IEteSyncService {
|
||||||
boolean hasPermission(String journalType);
|
boolean hasPermission(String journalType);
|
||||||
@ -10,4 +11,5 @@ interface IEteSyncService {
|
|||||||
void requestPermission(String journalType);
|
void requestPermission(String journalType);
|
||||||
|
|
||||||
Journal[] getJournals(String journalType);
|
Journal[] getJournals(String journalType);
|
||||||
|
JournalEntry[] getJournalEntries(String journalUid, String lastUid);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
// CollectionInfo.aidl
|
|
||||||
package com.etesync.syncadapter.remote;
|
package com.etesync.syncadapter.remote;
|
||||||
|
|
||||||
parcelable Journal;
|
parcelable Journal;
|
||||||
|
@ -13,9 +13,7 @@ public class Journal implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Journal(Parcel in) {
|
protected Journal(Parcel in) {
|
||||||
account = in.readString();
|
readFromParcel(in);
|
||||||
id = in.readString();
|
|
||||||
readOnly = in.readByte() == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<Journal> CREATOR = new Creator<Journal>() {
|
public static final Creator<Journal> CREATOR = new Creator<Journal>() {
|
||||||
@ -41,4 +39,10 @@ public class Journal implements Parcelable {
|
|||||||
parcel.writeString(id);
|
parcel.writeString(id);
|
||||||
parcel.writeByte((byte) (readOnly ? 1 : 0));
|
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.App;
|
||||||
import com.etesync.syncadapter.IEteSyncService;
|
import com.etesync.syncadapter.IEteSyncService;
|
||||||
import com.etesync.syncadapter.model.CollectionInfo;
|
import com.etesync.syncadapter.model.CollectionInfo;
|
||||||
|
import com.etesync.syncadapter.model.EntryEntity;
|
||||||
import com.etesync.syncadapter.model.JournalEntity;
|
import com.etesync.syncadapter.model.JournalEntity;
|
||||||
|
import com.etesync.syncadapter.model.JournalModel;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -60,6 +62,25 @@ public class RemoteService extends Service {
|
|||||||
return ret;
|
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 - query journals?
|
||||||
//todo - add insert. - returns uid
|
//todo - add insert. - returns uid
|
||||||
//todo add update?
|
//todo add update?
|
||||||
|
@ -36,6 +36,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
} else {
|
} else {
|
||||||
for (Journal journal : journals) {
|
for (Journal journal : journals) {
|
||||||
Log.i(TAG, "Received collection info: " + journal.id);
|
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 class Journal implements Parcelable {
|
||||||
public String account;
|
public String account;
|
||||||
public String id;
|
public String id;
|
||||||
|
public boolean readOnly = false;
|
||||||
|
|
||||||
public String getId() {
|
public Journal(String id) {
|
||||||
return id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Journal(Parcel in) {
|
protected Journal(Parcel in) {
|
||||||
account = in.readString();
|
readFromParcel(in);
|
||||||
id = in.readString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<Journal> CREATOR = new Creator<Journal>() {
|
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) {
|
public void writeToParcel(Parcel parcel, int i) {
|
||||||
parcel.writeString(account);
|
parcel.writeString(account);
|
||||||
parcel.writeString(id);
|
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