@@ -18,6 +18,7 @@ import android.provider.CalendarContract.Colors
1818import android.provider.CalendarContract.Events
1919import android.provider.CalendarContract.Reminders
2020import androidx.annotation.CallSuper
21+ import androidx.core.content.contentValuesOf
2122import at.bitfire.ical4android.AndroidCalendar.Companion.find
2223import at.bitfire.ical4android.util.MiscUtils.asSyncAdapter
2324import at.bitfire.ical4android.util.MiscUtils.toValues
@@ -41,7 +42,9 @@ class AndroidCalendar<out T : AndroidEvent>(
4142) {
4243
4344 companion object {
44-
45+
46+ private const val COLUMN_SYNC_STATE = Calendars .CAL_SYNC1
47+
4548 private val logger
4649 get() = Logger .getLogger(AndroidCalendar ::class .java.name)
4750
@@ -237,6 +240,20 @@ class AndroidCalendar<out T : AndroidEvent>(
237240 ? : throw FileNotFoundException ()
238241
239242
243+ fun getSyncState (): String? =
244+ provider.query(calendarSyncURI(), arrayOf(COLUMN_SYNC_STATE ), null , null , null )?.use { cursor ->
245+ if (cursor.moveToNext())
246+ return cursor.getString(0 )
247+ else
248+ null
249+ }
250+
251+ fun setSyncState (state : String? ) {
252+ val values = contentValuesOf(COLUMN_SYNC_STATE to state.toString())
253+ provider.update(calendarSyncURI(), values, null , null )
254+ }
255+
256+
240257 fun calendarSyncURI () = ContentUris .withAppendedId(Calendars .CONTENT_URI , id).asSyncAdapter(account)
241258
242259}
0 commit comments