# HG changeset patch # User Michael Schloh von Bennewitz # Date 1423605480 -3600 # Node ID 82795cac78327b3960c0522b0275a552a94f67a2 # Parent 262b0d479a9672a604a84b55b4c4e57234d10aa0 Creatively merge and construct new revision for modified API features. diff -r 262b0d479a96 -r 82795cac7832 src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java --- a/src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java Tue Feb 10 22:55:00 2015 +0100 +++ b/src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java Tue Feb 10 22:58:00 2015 +0100 @@ -1,43 +1,44 @@ package org.gege.caldavsyncadapter.caldav.entities; +import android.accounts.Account; +import android.content.ContentProviderClient; +import android.database.Cursor; +import android.net.Uri; +import android.os.RemoteException; +import android.provider.CalendarContract.Calendars; + +import org.gege.caldavsyncadapter.caldav.entities.DavCalendar.CalendarSource; +import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper; + import java.net.URI; import java.util.ArrayList; //import org.gege.caldavsyncadapter.CalendarColors; -import org.gege.caldavsyncadapter.caldav.entities.DavCalendar.CalendarSource; -import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper; - -import android.accounts.Account; -import android.content.ContentProviderClient; //import android.content.ContentUris; //import android.content.ContentValues; -import android.database.Cursor; -import android.net.Uri; -import android.os.RemoteException; -import android.provider.CalendarContract.Calendars; //import android.util.Log; public class CalendarList { // private static final String TAG = "CalendarList"; - - private java.util.ArrayList mList = new java.util.ArrayList(); - - private Account mAccount = null; - private ContentProviderClient mProvider = null; - - public CalendarSource Source = CalendarSource.undefined; - - public String ServerUrl = ""; - - public CalendarList(Account account, ContentProviderClient provider, CalendarSource source, String serverUrl) { - this.mAccount = account; - this.mProvider = provider; - this.Source = source; - this.ServerUrl = serverUrl; - } - + + private java.util.ArrayList mList = new java.util.ArrayList(); + + private Account mAccount = null; + private ContentProviderClient mProvider = null; + + public CalendarSource Source = CalendarSource.undefined; + + public String ServerUrl = ""; + + public CalendarList(Account account, ContentProviderClient provider, CalendarSource source, String serverUrl) { + this.mAccount = account; + this.mProvider = provider; + this.Source = source; + this.ServerUrl = serverUrl; + } + /* public Calendar getCalendarByAndroidCalendarId(int calendarId) { - Calendar Result = null; + Calendar Result = null; for (Calendar Item : mList) { if (Item.getAndroidCalendarId() == calendarId) @@ -46,110 +47,118 @@ return Result; }*/ - - public DavCalendar getCalendarByURI(URI calendarURI) { - DavCalendar Result = null; - - for (DavCalendar Item : mList) { - if (Item.getURI().equals(calendarURI)) - Result = Item; - } - - return Result; - } - - public DavCalendar getCalendarByAndroidUri(Uri androidCalendarUri) { - DavCalendar Result = null; - - for (DavCalendar Item : mList) { - if (Item.getAndroidCalendarUri().equals(androidCalendarUri)) - Result = Item; - } - - return Result; - } - - /** - * function to get all calendars from client side android - * @return - */ - public boolean readCalendarFromClient() { - boolean Result = false; - Cursor cur = null; - - Uri uri = Calendars.CONTENT_URI; - + + public DavCalendar getCalendarByURI(URI calendarURI) { + DavCalendar Result = null; + + for (DavCalendar Item : mList) { + if (Item.getURI().equals(calendarURI)) + Result = Item; + } + + return Result; + } + + public DavCalendar getCalendarByAndroidUri(Uri androidCalendarUri) { + DavCalendar Result = null; + + for (DavCalendar Item : mList) { + if (Item.getAndroidCalendarUri().equals(androidCalendarUri)) + Result = Item; + } + + return Result; + } + + /** + * function to get all calendars from client side android + * + * @return + */ + public boolean readCalendarFromClient() { + boolean Result = false; + Cursor cur = null; + + Uri uri = Calendars.CONTENT_URI; + /* COMPAT: in the past, the serverurl was not stored within a calendar. (see #98) - * so there was no chance to see which calendars belongs to a named account. + * so there was no chance to see which calendars belongs to a named account. * username + serverurl have to be unique * ((DavCalendar.SERVERURL = ?) OR (DavCalendar.SERVERURL IS NULL)) */ - String selection = "(" + "(" + Calendars.ACCOUNT_NAME + " = ?) AND " + - "(" + Calendars.ACCOUNT_TYPE + " = ?) AND " + - "((" + DavCalendar.SERVERURL + " = ?) OR " + - "(" + DavCalendar.SERVERURL + " IS NULL)) AND " + - "(" + Calendars.OWNER_ACCOUNT + " = ?)" + - ")"; - String[] selectionArgs = new String[] { mAccount.name, - mAccount.type, - this.ServerUrl, - mAccount.name - }; + String selection = "((" + + Calendars.ACCOUNT_NAME + " = ?) AND " + + "(" + Calendars.ACCOUNT_TYPE + " = ?))"; - // Submit the query and get a Cursor object back. - try { - cur = mProvider.query(uri, null, selection, selectionArgs, null); - } catch (RemoteException e) { - e.printStackTrace(); - } - - if (cur != null) { - while (cur.moveToNext()) { - mList.add(new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl)); - } - cur.close(); - Result = true; - } - - return Result; - } - - public boolean deleteCalendarOnClientSideOnly(android.content.Context context) { - boolean Result = false; - - for (DavCalendar androidCalendar : this.mList) { - if (!androidCalendar.foundServerSide) { - NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", "calendar deleted: " + androidCalendar.getCalendarDisplayName()); - androidCalendar.deleteAndroidCalendar(); - } - } - - return Result; - } - - public void addCalendar(DavCalendar item) { - item.setAccount(this.mAccount); - item.setProvider(this.mProvider); - item.ServerUrl = this.ServerUrl; - this.mList.add(item); - } - public java.util.ArrayList getCalendarList() { - return this.mList; - } - - public void setAccount(Account account) { - this.mAccount = account; - } - public void setProvider(ContentProviderClient provider) { - this.mProvider = provider; - } - public ArrayList getNotifyList() { - ArrayList Result = new ArrayList(); - - for (DavCalendar cal : this.mList) { - Result.addAll(cal.getNotifyList()); - } - - return Result; - } + String[] selectionArgs = new String[]{ + mAccount.name, + mAccount.type + }; + + String[] projection = new String[]{ + Calendars._ID, + Calendars.NAME, + Calendars.ACCOUNT_NAME, + Calendars.ACCOUNT_TYPE + }; + + // Submit the query and get a Cursor object back. + try { + cur = mProvider.query(uri, null, selection, selectionArgs, Calendars._ID + " ASC"); + } catch (RemoteException e) { + e.printStackTrace(); + } + if (cur != null) { + while (cur.moveToNext()) { + mList.add(new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl)); + } + cur.close(); + Result = true; + } + + return Result; + } + + public boolean deleteCalendarOnClientSideOnly(android.content.Context context) { + boolean Result = false; + + for (DavCalendar androidCalendar : this.mList) { + if (!androidCalendar.foundServerSide) { + NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", "calendar deleted: " + androidCalendar + .getCalendarDisplayName()); + androidCalendar.deleteAndroidCalendar(); + } + } + + return Result; + } + + public void addCalendar(DavCalendar item) { + item.setAccount(this.mAccount); + item.setProvider(this.mProvider); + item.ServerUrl = this.ServerUrl; + this.mList.add(item); + } + + public java.util.ArrayList getCalendarList() { + return this.mList; + } + + public void setAccount(Account account) { + this.mAccount = account; + } + + public void setProvider(ContentProviderClient provider) { + this.mProvider = provider; + } + + public ArrayList getNotifyList() { + ArrayList Result = new ArrayList(); + + for (DavCalendar cal : this.mList) { + Result.addAll(cal.getNotifyList()); + } + + return Result; + } }