fix #361, allow changing every caldav calendars color
This commit is contained in:
parent
178d7cf665
commit
97bc9ec85b
|
@ -1,10 +1,10 @@
|
|||
package com.simplemobiletools.calendar.dialogs
|
||||
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import android.text.TextUtils
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
|
@ -33,7 +33,7 @@ class SelectCalendarsDialog(val activity: SimpleActivity, val callback: () -> Un
|
|||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmSelection() })
|
||||
.setPositiveButton(R.string.ok) { dialogInterface, i -> confirmSelection() }
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.select_caldav_calendars)
|
||||
|
|
|
@ -2,10 +2,10 @@ package com.simplemobiletools.calendar.dialogs
|
|||
|
||||
import android.app.Activity
|
||||
import android.graphics.Color
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||
|
@ -29,6 +29,11 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
|
|||
activity.dbHelper.getEventTypes {
|
||||
activity.runOnUiThread {
|
||||
calendars.forEach {
|
||||
val localEventType = activity.dbHelper.getEventTypeWithCalDAVCalendarId(it.id)
|
||||
if (localEventType != null) {
|
||||
it.color = localEventType.color
|
||||
}
|
||||
|
||||
addRadioButton(it.getFullTitle(), it.id, it.color)
|
||||
}
|
||||
addRadioButton(activity.getString(R.string.store_locally_only), STORED_LOCALLY_ONLY, Color.TRANSPARENT)
|
||||
|
|
|
@ -30,7 +30,6 @@ class CalDAVHandler(val context: Context) {
|
|||
title = calendar.displayName
|
||||
caldavDisplayName = calendar.displayName
|
||||
caldavEmail = calendar.accountName
|
||||
color = calendar.color
|
||||
context.dbHelper.updateLocalEventType(this)
|
||||
}
|
||||
|
||||
|
@ -81,14 +80,13 @@ class CalDAVHandler(val context: Context) {
|
|||
return calendars
|
||||
}
|
||||
|
||||
fun updateCalDAVCalendar(eventType: EventType): Boolean {
|
||||
fun updateCalDAVCalendar(eventType: EventType) {
|
||||
val uri = CalendarContract.Calendars.CONTENT_URI
|
||||
val values = fillCalendarContentValues(eventType)
|
||||
val newUri = ContentUris.withAppendedId(uri, eventType.caldavCalendarId.toLong())
|
||||
return try {
|
||||
context.contentResolver.update(newUri, values, null, null) == 1
|
||||
try {
|
||||
context.contentResolver.update(newUri, values, null, null)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -320,15 +320,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
fun updateEventType(eventType: EventType): Int {
|
||||
return if (eventType.caldavCalendarId != 0) {
|
||||
if (CalDAVHandler(context).updateCalDAVCalendar(eventType)) {
|
||||
updateLocalEventType(eventType)
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
} else {
|
||||
updateLocalEventType(eventType)
|
||||
if (eventType.caldavCalendarId != 0) {
|
||||
CalDAVHandler(context).updateCalDAVCalendar(eventType)
|
||||
}
|
||||
|
||||
return updateLocalEventType(eventType)
|
||||
}
|
||||
|
||||
fun updateLocalEventType(eventType: EventType): Int {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.simplemobiletools.calendar.models
|
||||
|
||||
data class CalDAVCalendar(val id: Int, val displayName: String, val accountName: String, val accountType: String, val ownerName: String,
|
||||
val color: Int, val accessLevel: Int) {
|
||||
var color: Int, val accessLevel: Int) {
|
||||
fun canWrite() = accessLevel >= 500
|
||||
|
||||
fun getFullTitle() = "$displayName ($accountName)"
|
||||
|
|
Loading…
Reference in New Issue