1
0
mirror of https://github.com/etesync/android synced 2024-11-22 07:58:09 +00:00
This commit is contained in:
Tom Hacohen 2017-11-28 12:36:11 +00:00
parent 3cb24fe7f2
commit f44a6c7d42
13 changed files with 121 additions and 114 deletions

View File

@ -2,15 +2,12 @@
package com.etesync.syncadapter; 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.model.CollectionInfo; import com.etesync.syncadapter.remote.Journal;
interface IEteSyncService { interface IEteSyncService {
boolean hasPermission(String journalType); boolean hasPermission(String journalType);
void requestPermission(String journalType); void requestPermission(String journalType);
CollectionInfo[] getJournalEntries(String journalType); Journal[] getJournals(String journalType);
} }

View File

@ -1,4 +0,0 @@
// CollectionInfo.aidl
package com.etesync.syncadapter.model;
parcelable CollectionInfo;

View File

@ -0,0 +1,4 @@
// CollectionInfo.aidl
package com.etesync.syncadapter.remote;
parcelable Journal;

View File

@ -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));
}
}

View File

@ -12,9 +12,18 @@ import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log;
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.JournalEntity;
import java.util.LinkedList;
import java.util.List;
import io.requery.Persistable;
import io.requery.sql.EntityDataStore;
public class RemoteService extends Service { public class RemoteService extends Service {
@ -36,10 +45,19 @@ public class RemoteService extends Service {
mApiPermissionHelper.getCurrentCallingPackage(), journalType); mApiPermissionHelper.getCurrentCallingPackage(), journalType);
} }
public CollectionInfo[] getJournalEntries(String journalType) throws RemoteException { public Journal[] getJournals(String journalType) throws RemoteException {
if (!mApiPermissionHelper.isAllowedIgnoreErrors(journalType)) return null; 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? //todo - query journals?

View File

@ -32,6 +32,7 @@ import org.apache.commons.codec.Charsets;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable;
import java.util.Formatter; import java.util.Formatter;
import java.util.List; import java.util.List;
import java.util.Locale; 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) { public static Intent newIntent(Context context, CollectionInfo info, SyncEntry syncEntry) {
Intent intent = new Intent(context, JournalItemActivity.class); 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); intent.putExtra(KEY_SYNC_ENTRY, syncEntry);
return intent; return intent;
} }

View File

@ -26,6 +26,6 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' 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' testCompile 'junit:junit:4.12'
} }

1
remoteexample/src/main/aidl Symbolic link
View File

@ -0,0 +1 @@
../../../app/src/main/aidl

View File

@ -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);
}

View File

@ -1,4 +0,0 @@
// CollectionInfo.aidl
package com.etesync.syncadapter.model;
parcelable CollectionInfo;

View File

@ -10,12 +10,12 @@ import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import com.etesync.syncadapter.IEteSyncService; import com.etesync.syncadapter.IEteSyncService;
import com.etesync.syncadapter.model.CollectionInfo; import com.etesync.syncadapter.remote.Journal;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
private static final String JOURNAL_TYPE = "ToDo"; private static final String JOURNAL_TYPE = "CALENDAR";
private IEteSyncService mEteSyncService; private IEteSyncService mEteSyncService;
@ -30,12 +30,12 @@ public class MainActivity extends AppCompatActivity {
if (!isAllowed) { if (!isAllowed) {
mEteSyncService.requestPermission(JOURNAL_TYPE); mEteSyncService.requestPermission(JOURNAL_TYPE);
} else { } else {
CollectionInfo[] collectionInfo = mEteSyncService.getJournalEntries(JOURNAL_TYPE); Journal[] journals = mEteSyncService.getJournals(JOURNAL_TYPE);
if (collectionInfo == null) { if (journals == null) {
Log.i(TAG, "Received no collection infos"); Log.i(TAG, "Received no collection infos");
} else { } else {
for (CollectionInfo collectionInfo1 : collectionInfo) { for (Journal journal : journals) {
Log.i(TAG, "Received collection info: " + collectionInfo1.displayName); Log.i(TAG, "Received collection info: " + journal.id);
} }
} }
} }

View File

@ -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));
}
}

View File

@ -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);
}
}