src/org/gege/caldavsyncadapter/caldav/entities/CalendarList.java

Tue, 10 Feb 2015 22:58:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 22:58:00 +0100
changeset 11
82795cac7832
parent 0
fb9019fb1bf7
permissions
-rw-r--r--

Creatively merge and construct new revision for modified API features.

michael@0 1 package org.gege.caldavsyncadapter.caldav.entities;
michael@0 2
michael@11 3 import android.accounts.Account;
michael@11 4 import android.content.ContentProviderClient;
michael@11 5 import android.database.Cursor;
michael@11 6 import android.net.Uri;
michael@11 7 import android.os.RemoteException;
michael@11 8 import android.provider.CalendarContract.Calendars;
michael@11 9
michael@11 10 import org.gege.caldavsyncadapter.caldav.entities.DavCalendar.CalendarSource;
michael@11 11 import org.gege.caldavsyncadapter.syncadapter.notifications.NotificationsHelper;
michael@11 12
michael@0 13 import java.net.URI;
michael@0 14 import java.util.ArrayList;
michael@0 15
michael@0 16 //import org.gege.caldavsyncadapter.CalendarColors;
michael@0 17 //import android.content.ContentUris;
michael@0 18 //import android.content.ContentValues;
michael@0 19 //import android.util.Log;
michael@0 20
michael@0 21 public class CalendarList {
michael@0 22 // private static final String TAG = "CalendarList";
michael@11 23
michael@11 24 private java.util.ArrayList<DavCalendar> mList = new java.util.ArrayList<DavCalendar>();
michael@11 25
michael@11 26 private Account mAccount = null;
michael@11 27 private ContentProviderClient mProvider = null;
michael@11 28
michael@11 29 public CalendarSource Source = CalendarSource.undefined;
michael@11 30
michael@11 31 public String ServerUrl = "";
michael@11 32
michael@11 33 public CalendarList(Account account, ContentProviderClient provider, CalendarSource source, String serverUrl) {
michael@11 34 this.mAccount = account;
michael@11 35 this.mProvider = provider;
michael@11 36 this.Source = source;
michael@11 37 this.ServerUrl = serverUrl;
michael@11 38 }
michael@11 39
michael@0 40 /* public Calendar getCalendarByAndroidCalendarId(int calendarId) {
michael@11 41 Calendar Result = null;
michael@0 42
michael@0 43 for (Calendar Item : mList) {
michael@0 44 if (Item.getAndroidCalendarId() == calendarId)
michael@0 45 Result = Item;
michael@0 46 }
michael@0 47
michael@0 48 return Result;
michael@0 49 }*/
michael@11 50
michael@11 51 public DavCalendar getCalendarByURI(URI calendarURI) {
michael@11 52 DavCalendar Result = null;
michael@11 53
michael@11 54 for (DavCalendar Item : mList) {
michael@11 55 if (Item.getURI().equals(calendarURI))
michael@11 56 Result = Item;
michael@11 57 }
michael@11 58
michael@11 59 return Result;
michael@11 60 }
michael@11 61
michael@11 62 public DavCalendar getCalendarByAndroidUri(Uri androidCalendarUri) {
michael@11 63 DavCalendar Result = null;
michael@11 64
michael@11 65 for (DavCalendar Item : mList) {
michael@11 66 if (Item.getAndroidCalendarUri().equals(androidCalendarUri))
michael@11 67 Result = Item;
michael@11 68 }
michael@11 69
michael@11 70 return Result;
michael@11 71 }
michael@11 72
michael@11 73 /**
michael@11 74 * function to get all calendars from client side android
michael@11 75 *
michael@11 76 * @return
michael@11 77 */
michael@11 78 public boolean readCalendarFromClient() {
michael@11 79 boolean Result = false;
michael@11 80 Cursor cur = null;
michael@11 81
michael@11 82 Uri uri = Calendars.CONTENT_URI;
michael@11 83
michael@0 84 /* COMPAT: in the past, the serverurl was not stored within a calendar. (see #98)
michael@11 85 * so there was no chance to see which calendars belongs to a named account.
michael@0 86 * username + serverurl have to be unique
michael@0 87 * ((DavCalendar.SERVERURL = ?) OR (DavCalendar.SERVERURL IS NULL))
michael@0 88 */
michael@11 89 String selection = "(("
michael@11 90 + Calendars.ACCOUNT_NAME + " = ?) AND " +
michael@11 91 "(" + Calendars.ACCOUNT_TYPE + " = ?))";
michael@0 92
michael@11 93 String[] selectionArgs = new String[]{
michael@11 94 mAccount.name,
michael@11 95 mAccount.type
michael@11 96 };
michael@11 97
michael@11 98 String[] projection = new String[]{
michael@11 99 Calendars._ID,
michael@11 100 Calendars.NAME,
michael@11 101 Calendars.ACCOUNT_NAME,
michael@11 102 Calendars.ACCOUNT_TYPE
michael@11 103 };
michael@11 104
michael@11 105 // Submit the query and get a Cursor object back.
michael@11 106 try {
michael@11 107 cur = mProvider.query(uri, null, selection, selectionArgs, Calendars._ID + " ASC");
michael@11 108 } catch (RemoteException e) {
michael@11 109 e.printStackTrace();
michael@11 110 }
michael@11 111 if (cur != null) {
michael@11 112 while (cur.moveToNext()) {
michael@11 113 mList.add(new DavCalendar(mAccount, mProvider, cur, this.Source, this.ServerUrl));
michael@11 114 }
michael@11 115 cur.close();
michael@11 116 Result = true;
michael@11 117 }
michael@11 118
michael@11 119 return Result;
michael@11 120 }
michael@11 121
michael@11 122 public boolean deleteCalendarOnClientSideOnly(android.content.Context context) {
michael@11 123 boolean Result = false;
michael@11 124
michael@11 125 for (DavCalendar androidCalendar : this.mList) {
michael@11 126 if (!androidCalendar.foundServerSide) {
michael@11 127 NotificationsHelper.signalSyncErrors(context, "CalDAV Sync Adapter", "calendar deleted: " + androidCalendar
michael@11 128 .getCalendarDisplayName());
michael@11 129 androidCalendar.deleteAndroidCalendar();
michael@11 130 }
michael@11 131 }
michael@11 132
michael@11 133 return Result;
michael@11 134 }
michael@11 135
michael@11 136 public void addCalendar(DavCalendar item) {
michael@11 137 item.setAccount(this.mAccount);
michael@11 138 item.setProvider(this.mProvider);
michael@11 139 item.ServerUrl = this.ServerUrl;
michael@11 140 this.mList.add(item);
michael@11 141 }
michael@11 142
michael@11 143 public java.util.ArrayList<DavCalendar> getCalendarList() {
michael@11 144 return this.mList;
michael@11 145 }
michael@11 146
michael@11 147 public void setAccount(Account account) {
michael@11 148 this.mAccount = account;
michael@11 149 }
michael@11 150
michael@11 151 public void setProvider(ContentProviderClient provider) {
michael@11 152 this.mProvider = provider;
michael@11 153 }
michael@11 154
michael@11 155 public ArrayList<Uri> getNotifyList() {
michael@11 156 ArrayList<Uri> Result = new ArrayList<Uri>();
michael@11 157
michael@11 158 for (DavCalendar cal : this.mList) {
michael@11 159 Result.addAll(cal.getNotifyList());
michael@11 160 }
michael@11 161
michael@11 162 return Result;
michael@11 163 }
michael@0 164 }

mercurial