Skip to content

Commit 87f9b76

Browse files
committed
Add methods to get and set calendar sync state
1 parent d5063fb commit 87f9b76

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/src/main/kotlin/at/bitfire/ical4android/AndroidCalendar.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import android.provider.CalendarContract.Colors
1818
import android.provider.CalendarContract.Events
1919
import android.provider.CalendarContract.Reminders
2020
import androidx.annotation.CallSuper
21+
import androidx.core.content.contentValuesOf
2122
import at.bitfire.ical4android.AndroidCalendar.Companion.find
2223
import at.bitfire.ical4android.util.MiscUtils.asSyncAdapter
2324
import 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

Comments
 (0)