mirror of
https://github.com/etesync/android
synced 2025-07-04 05:42:36 +00:00

* new Settings activity * Settings: display/change user name, password, preemptive auth. * Settings: display/change sync. interval for contacts and calendars * requires permission GET_ACCOUNTS to list accounts in Settings * requires permission READ_SYNC_SETTINGS to display current sync intervals * remove obsolete files from res/ * update copyright notices * version bump to 0.7
83 lines
2.4 KiB
Java
83 lines
2.4 KiB
Java
/*
|
||
* Copyright (c) 2013 – 2015 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 at.bitfire.davdroid.syncadapter;
|
||
|
||
import android.accounts.Account;
|
||
import android.app.Service;
|
||
import android.content.ContentProviderClient;
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.os.IBinder;
|
||
import android.os.RemoteException;
|
||
import android.util.Log;
|
||
|
||
import java.net.URISyntaxException;
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
|
||
import at.bitfire.davdroid.resource.CalDavCalendar;
|
||
import at.bitfire.davdroid.resource.LocalCalendar;
|
||
import at.bitfire.davdroid.resource.LocalCollection;
|
||
import at.bitfire.davdroid.resource.RemoteCollection;
|
||
|
||
public class CalendarsSyncAdapterService extends Service {
|
||
private static SyncAdapter syncAdapter;
|
||
|
||
|
||
@Override
|
||
public void onCreate() {
|
||
if (syncAdapter == null)
|
||
syncAdapter = new SyncAdapter(getApplicationContext());
|
||
}
|
||
|
||
@Override
|
||
public void onDestroy() {
|
||
syncAdapter.close();
|
||
syncAdapter = null;
|
||
}
|
||
|
||
@Override
|
||
public IBinder onBind(Intent intent) {
|
||
return syncAdapter.getSyncAdapterBinder();
|
||
}
|
||
|
||
|
||
private static class SyncAdapter extends DavSyncAdapter {
|
||
private final static String TAG = "davdroid.CalendarsSyncAdapter";
|
||
|
||
|
||
private SyncAdapter(Context context) {
|
||
super(context);
|
||
}
|
||
|
||
@Override
|
||
protected Map<LocalCollection<?>, RemoteCollection<?>> getSyncPairs(Account account, ContentProviderClient provider) {
|
||
AccountSettings settings = new AccountSettings(getContext(), account);
|
||
String userName = settings.getUserName(),
|
||
password = settings.getPassword();
|
||
boolean preemptive = settings.getPreemptiveAuth();
|
||
|
||
try {
|
||
Map<LocalCollection<?>, RemoteCollection<?>> map = new HashMap<LocalCollection<?>, RemoteCollection<?>>();
|
||
|
||
for (LocalCalendar calendar : LocalCalendar.findAll(account, provider)) {
|
||
RemoteCollection<?> dav = new CalDavCalendar(httpClient, calendar.getUrl(), userName, password, preemptive);
|
||
map.put(calendar, dav);
|
||
}
|
||
return map;
|
||
} catch (RemoteException ex) {
|
||
Log.e(TAG, "Couldn't find local calendars", ex);
|
||
} catch (URISyntaxException ex) {
|
||
Log.e(TAG, "Couldn't build calendar URI", ex);
|
||
}
|
||
|
||
return null;
|
||
}
|
||
}
|
||
}
|