Commit c9dab310 authored by Ricki Hirner's avatar Ricki Hirner 🐑

Webcal calendars: use UrlUtils.equals to find matching calendar; update dependencies

parent ac3e9fb8
Pipeline #112139014 passed with stages
in 13 minutes and 56 seconds
......@@ -112,21 +112,21 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.fragment:fragment-ktx:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
implementation 'androidx.fragment:fragment-ktx:1.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.paging:paging-runtime-ktx:2.1.1'
implementation 'androidx.preference:preference:1.1.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'com.google.android.material:material:1.2.0-alpha04'
def room_version = '2.2.3'
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation 'com.gitlab.bitfireAT:dav4jvm:1.0'
implementation 'com.gitlab.bitfireAT:dav4jvm:1.0.1'
implementation 'com.jaredrummler:colorpicker:1.1.0'
implementation('com.mikepenz:aboutlibraries:7.1.0')
implementation "com.squareup.okhttp3:okhttp:${versions.okhttp}"
......
......@@ -192,7 +192,7 @@ class WebcalFragment: CollectionsFragment() {
value = null
}
}
val subscribedUrls = object: MediatorLiveData<MutableMap<HttpUrl, Long>>() {
val subscribedUrls = object: MediatorLiveData<MutableMap<Long, HttpUrl>>() {
var provider: ContentProviderClient? = null
var observer: ContentObserver? = null
......@@ -244,19 +244,19 @@ class WebcalFragment: CollectionsFragment() {
@Transaction
private fun queryCalendars(provider: ContentProviderClient) {
// query subscribed URLs from Android calendar list
val subscriptions = mutableMapOf<HttpUrl, Long>()
val subscriptions = mutableMapOf<Long, HttpUrl>()
provider.query(Calendars.CONTENT_URI, arrayOf(Calendars._ID, Calendars.NAME),null, null, null)?.use { cursor ->
while (cursor.moveToNext())
cursor.getString(1)?.let { rawName ->
HttpUrl.parse(rawName)?.let { url ->
subscriptions[url] = cursor.getLong(0)
subscriptions[cursor.getLong(0)] = url
}
}
}
// update "sync" field in database accordingly (will update UI)
db.collectionDao().getByServiceAndType(serviceId, Collection.TYPE_WEBCAL).forEach { webcal ->
val newSync = subscriptions.keys
val newSync = subscriptions.values
.any { webcal.source?.let { source -> UrlUtils.equals(source, it) } ?: false }
if (newSync != webcal.sync)
db.collectionDao().update(webcal.copy(sync = newSync))
......@@ -278,8 +278,11 @@ class WebcalFragment: CollectionsFragment() {
fun unsubscribe(webcal: Collection) {
workerHandler.post {
subscribedUrls.value?.get(webcal.source)?.let { id ->
// delete subscription from Android calendar list
// find first matching source (Webcal) URL
subscribedUrls.value?.entries?.firstOrNull { (id, source) ->
UrlUtils.equals(source, webcal.source!!)
}?.key?.let { id ->
// delete first matching subscription from Android calendar list
calendarProvider.value?.delete(Calendars.CONTENT_URI,
"${Calendars._ID}=?", arrayOf(id.toString()))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment