Tue, 10 Feb 2015 22:58:00 +0100
Creatively merge and construct new revision for modified API features.
src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java Tue Feb 10 22:55:00 2015 +0100 1.2 +++ b/src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java Tue Feb 10 22:58:00 2015 +0100 1.3 @@ -1,43 +1,44 @@ 1.4 package org.gege.caldavsyncadapter.caldav.entities; 1.5 1.6 +import android.accounts.Account; 1.7 +import android.content.ContentProviderClient; 1.8 +import android.database.Cursor; 1.9 +import android.net.Uri; 1.10 +import android.os.RemoteException; 1.11 +import android.provider.CalendarContract.Calendars; 1.12 + 1.13 +import org.gege.caldavsyncadapter.caldav.entities.DavCalendar.CalendarSource; 1.14 +import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper; 1.15 + 1.16 import java.net.URI; 1.17 import java.util.ArrayList; 1.18 1.19 //import org.gege.caldavsyncadapter.CalendarColors; 1.20 -import org.gege.caldavsyncadapter.caldav.entities.DavCalendar.CalendarSource; 1.21 -import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper; 1.22 - 1.23 -import android.accounts.Account; 1.24 -import android.content.ContentProviderClient; 1.25 //import android.content.ContentUris; 1.26 //import android.content.ContentValues; 1.27 -import android.database.Cursor; 1.28 -import android.net.Uri; 1.29 -import android.os.RemoteException; 1.30 -import android.provider.CalendarContract.Calendars; 1.31 //import android.util.Log; 1.32 1.33 public class CalendarList { 1.34 // private static final String TAG = "CalendarList"; 1.35 - 1.36 - private java.util.ArrayList<DavCalendar> mList = new java.util.ArrayList<DavCalendar>(); 1.37 - 1.38 - private Account mAccount = null; 1.39 - private ContentProviderClient mProvider = null; 1.40 - 1.41 - public CalendarSource Source = CalendarSource.undefined; 1.42 - 1.43 - public String ServerUrl = ""; 1.44 - 1.45 - public CalendarList(Account account, ContentProviderClient provider, CalendarSource source, String serverUrl) { 1.46 - this.mAccount = account; 1.47 - this.mProvider = provider; 1.48 - this.Source = source; 1.49 - this.ServerUrl = serverUrl; 1.50 - } 1.51 - 1.52 + 1.53 + private java.util.ArrayList<DavCalendar> mList = new java.util.ArrayList<DavCalendar>(); 1.54 + 1.55 + private Account mAccount = null; 1.56 + private ContentProviderClient mProvider = null; 1.57 + 1.58 + public CalendarSource Source = CalendarSource.undefined; 1.59 + 1.60 + public String ServerUrl = ""; 1.61 + 1.62 + public CalendarList(Account account, ContentProviderClient provider, CalendarSource source, String serverUrl) { 1.63 + this.mAccount = account; 1.64 + this.mProvider = provider; 1.65 + this.Source = source; 1.66 + this.ServerUrl = serverUrl; 1.67 + } 1.68 + 1.69 /* public Calendar getCalendarByAndroidCalendarId(int calendarId) { 1.70 - Calendar Result = null; 1.71 + Calendar Result = null; 1.72 1.73 for (Calendar Item : mList) { 1.74 if (Item.getAndroidCalendarId() == calendarId) 1.75 @@ -46,110 +47,118 @@ 1.76 1.77 return Result; 1.78 }*/ 1.79 - 1.80 - public DavCalendar getCalendarByURI(URI calendarURI) { 1.81 - DavCalendar Result = null; 1.82 - 1.83 - for (DavCalendar Item : mList) { 1.84 - if (Item.getURI().equals(calendarURI)) 1.85 - Result = Item; 1.86 - } 1.87 - 1.88 - return Result; 1.89 - } 1.90 - 1.91 - public DavCalendar getCalendarByAndroidUri(Uri androidCalendarUri) { 1.92 - DavCalendar Result = null; 1.93 - 1.94 - for (DavCalendar Item : mList) { 1.95 - if (Item.getAndroidCalendarUri().equals(androidCalendarUri)) 1.96 - Result = Item; 1.97 - } 1.98 - 1.99 - return Result; 1.100 - } 1.101 - 1.102 - /** 1.103 - * function to get all calendars from client side android 1.104 - * @return 1.105 - */ 1.106 - public boolean readCalendarFromClient() { 1.107 - boolean Result = false; 1.108 - Cursor cur = null; 1.109 - 1.110 - Uri uri = Calendars.CONTENT_URI; 1.111 - 1.112 + 1.113 + public DavCalendar getCalendarByURI(URI calendarURI) { 1.114 + DavCalendar Result = null; 1.115 + 1.116 + for (DavCalendar Item : mList) { 1.117 + if (Item.getURI().equals(calendarURI)) 1.118 + Result = Item; 1.119 + } 1.120 + 1.121 + return Result; 1.122 + } 1.123 + 1.124 + public DavCalendar getCalendarByAndroidUri(Uri androidCalendarUri) { 1.125 + DavCalendar Result = null; 1.126 + 1.127 + for (DavCalendar Item : mList) { 1.128 + if (Item.getAndroidCalendarUri().equals(androidCalendarUri)) 1.129 + Result = Item; 1.130 + } 1.131 + 1.132 + return Result; 1.133 + } 1.134 + 1.135 + /** 1.136 + * function to get all calendars from client side android 1.137 + * 1.138 + * @return 1.139 + */ 1.140 + public boolean readCalendarFromClient() { 1.141 + boolean Result = false; 1.142 + Cursor cur = null; 1.143 + 1.144 + Uri uri = Calendars.CONTENT_URI; 1.145 + 1.146 /* COMPAT: in the past, the serverurl was not stored within a calendar. (see #98) 1.147 - * so there was no chance to see which calendars belongs to a named account. 1.148 + * so there was no chance to see which calendars belongs to a named account. 1.149 * username + serverurl have to be unique 1.150 * ((DavCalendar.SERVERURL = ?) OR (DavCalendar.SERVERURL IS NULL)) 1.151 */ 1.152 - String selection = "(" + "(" + Calendars.ACCOUNT_NAME + " = ?) AND " + 1.153 - "(" + Calendars.ACCOUNT_TYPE + " = ?) AND " + 1.154 - "((" + DavCalendar.SERVERURL + " = ?) OR " + 1.155 - "(" + DavCalendar.SERVERURL + " IS NULL)) AND " + 1.156 - "(" + Calendars.OWNER_ACCOUNT + " = ?)" + 1.157 - ")"; 1.158 - String[] selectionArgs = new String[] { mAccount.name, 1.159 - mAccount.type, 1.160 - this.ServerUrl, 1.161 - mAccount.name 1.162 - }; 1.163 + String selection = "((" 1.164 + + Calendars.ACCOUNT_NAME + " = ?) AND " + 1.165 + "(" + Calendars.ACCOUNT_TYPE + " = ?))"; 1.166 1.167 - // Submit the query and get a Cursor object back. 1.168 - try { 1.169 - cur = mProvider.query(uri, null, selection, selectionArgs, null); 1.170 - } catch (RemoteException e) { 1.171 - e.printStackTrace(); 1.172 - } 1.173 - 1.174 - if (cur != null) { 1.175 - while (cur.moveToNext()) { 1.176 - mList.add(new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl)); 1.177 - } 1.178 - cur.close(); 1.179 - Result = true; 1.180 - } 1.181 - 1.182 - return Result; 1.183 - } 1.184 - 1.185 - public boolean deleteCalendarOnClientSideOnly(android.content.Context context) { 1.186 - boolean Result = false; 1.187 - 1.188 - for (DavCalendar androidCalendar : this.mList) { 1.189 - if (!androidCalendar.foundServerSide) { 1.190 - NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", "calendar deleted: " + androidCalendar.getCalendarDisplayName()); 1.191 - androidCalendar.deleteAndroidCalendar(); 1.192 - } 1.193 - } 1.194 - 1.195 - return Result; 1.196 - } 1.197 - 1.198 - public void addCalendar(DavCalendar item) { 1.199 - item.setAccount(this.mAccount); 1.200 - item.setProvider(this.mProvider); 1.201 - item.ServerUrl = this.ServerUrl; 1.202 - this.mList.add(item); 1.203 - } 1.204 - public java.util.ArrayList<DavCalendar> getCalendarList() { 1.205 - return this.mList; 1.206 - } 1.207 - 1.208 - public void setAccount(Account account) { 1.209 - this.mAccount = account; 1.210 - } 1.211 - public void setProvider(ContentProviderClient provider) { 1.212 - this.mProvider = provider; 1.213 - } 1.214 - public ArrayList<Uri> getNotifyList() { 1.215 - ArrayList<Uri> Result = new ArrayList<Uri>(); 1.216 - 1.217 - for (DavCalendar cal : this.mList) { 1.218 - Result.addAll(cal.getNotifyList()); 1.219 - } 1.220 - 1.221 - return Result; 1.222 - } 1.223 + String[] selectionArgs = new String[]{ 1.224 + mAccount.name, 1.225 + mAccount.type 1.226 + }; 1.227 + 1.228 + String[] projection = new String[]{ 1.229 + Calendars._ID, 1.230 + Calendars.NAME, 1.231 + Calendars.ACCOUNT_NAME, 1.232 + Calendars.ACCOUNT_TYPE 1.233 + }; 1.234 + 1.235 + // Submit the query and get a Cursor object back. 1.236 + try { 1.237 + cur = mProvider.query(uri, null, selection, selectionArgs, Calendars._ID + " ASC"); 1.238 + } catch (RemoteException e) { 1.239 + e.printStackTrace(); 1.240 + } 1.241 + if (cur != null) { 1.242 + while (cur.moveToNext()) { 1.243 + mList.add(new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl)); 1.244 + } 1.245 + cur.close(); 1.246 + Result = true; 1.247 + } 1.248 + 1.249 + return Result; 1.250 + } 1.251 + 1.252 + public boolean deleteCalendarOnClientSideOnly(android.content.Context context) { 1.253 + boolean Result = false; 1.254 + 1.255 + for (DavCalendar androidCalendar : this.mList) { 1.256 + if (!androidCalendar.foundServerSide) { 1.257 + NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", "calendar deleted: " + androidCalendar 1.258 + .getCalendarDisplayName()); 1.259 + androidCalendar.deleteAndroidCalendar(); 1.260 + } 1.261 + } 1.262 + 1.263 + return Result; 1.264 + } 1.265 + 1.266 + public void addCalendar(DavCalendar item) { 1.267 + item.setAccount(this.mAccount); 1.268 + item.setProvider(this.mProvider); 1.269 + item.ServerUrl = this.ServerUrl; 1.270 + this.mList.add(item); 1.271 + } 1.272 + 1.273 + public java.util.ArrayList<DavCalendar> getCalendarList() { 1.274 + return this.mList; 1.275 + } 1.276 + 1.277 + public void setAccount(Account account) { 1.278 + this.mAccount = account; 1.279 + } 1.280 + 1.281 + public void setProvider(ContentProviderClient provider) { 1.282 + this.mProvider = provider; 1.283 + } 1.284 + 1.285 + public ArrayList<Uri> getNotifyList() { 1.286 + ArrayList<Uri> Result = new ArrayList<Uri>(); 1.287 + 1.288 + for (DavCalendar cal : this.mList) { 1.289 + Result.addAll(cal.getNotifyList()); 1.290 + } 1.291 + 1.292 + return Result; 1.293 + } 1.294 }