mirror of
https://github.com/etesync/android
synced 2024-11-22 07:58:09 +00:00
snap
This commit is contained in:
parent
3cb24fe7f2
commit
f44a6c7d42
@ -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);
|
||||
}
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
// CollectionInfo.aidl
|
||||
package com.etesync.syncadapter.model;
|
||||
|
||||
parcelable CollectionInfo;
|
@ -0,0 +1,4 @@
|
||||
// CollectionInfo.aidl
|
||||
package com.etesync.syncadapter.remote;
|
||||
|
||||
parcelable Journal;
|
@ -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<Journal> CREATOR = new Creator<Journal>() {
|
||||
@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));
|
||||
}
|
||||
}
|
@ -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<Persistable> data = ((App) getApplicationContext()).getData();
|
||||
List<JournalEntity> 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?
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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'
|
||||
}
|
||||
|
1
remoteexample/src/main/aidl
Symbolic link
1
remoteexample/src/main/aidl
Symbolic link
@ -0,0 +1 @@
|
||||
../../../app/src/main/aidl
|
@ -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);
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
// CollectionInfo.aidl
|
||||
package com.etesync.syncadapter.model;
|
||||
|
||||
parcelable CollectionInfo;
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<CollectionInfo> CREATOR = new Creator<CollectionInfo>() {
|
||||
@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));
|
||||
}
|
||||
}
|
@ -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<Journal> CREATOR = new Creator<Journal>() {
|
||||
@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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user