mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-20 05:30:40 +01:00
store caldav event type displayName and email separately
This commit is contained in:
parent
805823c58d
commit
6031a4596b
@ -142,12 +142,12 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
|
|
||||||
Thread({
|
Thread({
|
||||||
if (newCalendarIds.isNotEmpty()) {
|
if (newCalendarIds.isNotEmpty()) {
|
||||||
val existingEventTypeNames = dbHelper.fetchEventTypes().map { it.title.toLowerCase() } as ArrayList<String>
|
val existingEventTypeNames = dbHelper.fetchEventTypes().map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
|
||||||
getSyncedCalDAVCalendars().forEach {
|
getSyncedCalDAVCalendars().forEach {
|
||||||
val eventTypeTitle = "${it.displayName} (${it.accountName})"
|
val calendarTitle = it.getFullTitle()
|
||||||
if (!existingEventTypeNames.contains(eventTypeTitle.toLowerCase())) {
|
if (!existingEventTypeNames.contains(calendarTitle.toLowerCase())) {
|
||||||
val eventType = EventType(0, eventTypeTitle, it.color, it.id)
|
val eventType = EventType(0, it.displayName, it.color, it.id, it.displayName, it.accountName)
|
||||||
existingEventTypeNames.add(eventTypeTitle.toLowerCase())
|
existingEventTypeNames.add(calendarTitle.toLowerCase())
|
||||||
dbHelper.insertEventType(eventType)
|
dbHelper.insertEventType(eventType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ class EventTypeAdapter(val activity: SimpleActivity, val mItems: List<EventType>
|
|||||||
fun bindView(multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, eventType: EventType, pos: Int): View {
|
fun bindView(multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, eventType: EventType, pos: Int): View {
|
||||||
|
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
event_type_title.text = eventType.title
|
event_type_title.text = eventType.getDisplayTitle()
|
||||||
event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
|
event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
|
||||||
toggleItemSelection(this, markedItems.contains(pos), pos)
|
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class FilterEventTypeAdapter(val activity: SimpleActivity, val mItems: List<Even
|
|||||||
val id = eventType.id.toString()
|
val id = eventType.id.toString()
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
filter_event_type_checkbox.setColors(activity.config.textColor, activity.config.primaryColor, activity.config.backgroundColor)
|
filter_event_type_checkbox.setColors(activity.config.textColor, activity.config.primaryColor, activity.config.backgroundColor)
|
||||||
filter_event_type_checkbox.text = eventType.title
|
filter_event_type_checkbox.text = eventType.getDisplayTitle()
|
||||||
filter_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
|
filter_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
|
||||||
|
|
||||||
filter_event_type_holder.setOnClickListener {
|
filter_event_type_holder.setOnClickListener {
|
||||||
|
@ -46,7 +46,7 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
|
|||||||
|
|
||||||
private fun updateEventType(view: ViewGroup) {
|
private fun updateEventType(view: ViewGroup) {
|
||||||
val eventType = context.dbHelper.getEventType(currEventTypeId)
|
val eventType = context.dbHelper.getEventType(currEventTypeId)
|
||||||
view.import_event_type_title.text = eventType!!.title
|
view.import_event_type_title.text = eventType!!.getDisplayTitle()
|
||||||
view.import_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
|
view.import_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@ class NewEventTypeDialog(val activity: Activity, var eventType: EventType? = nul
|
|||||||
}
|
}
|
||||||
|
|
||||||
eventType!!.title = title
|
eventType!!.title = title
|
||||||
|
if (eventType!!.caldavCalendarId != 0)
|
||||||
|
eventType!!.caldavDisplayName = title
|
||||||
|
|
||||||
val eventTypeId = if (isNewEvent) {
|
val eventTypeId = if (isNewEvent) {
|
||||||
activity.dbHelper.insertEventType(eventType!!)
|
activity.dbHelper.insertEventType(eventType!!)
|
||||||
|
@ -30,7 +30,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
|
|||||||
activity.dbHelper.getEventTypes {
|
activity.dbHelper.getEventTypes {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
calendars.forEach {
|
calendars.forEach {
|
||||||
addRadioButton(it.displayName, it.id, it.color)
|
addRadioButton(it.getFullTitle(), it.id, it.color)
|
||||||
}
|
}
|
||||||
addRadioButton(activity.getString(R.string.store_locally_only), STORE_LOCALLY_ONLY, Color.TRANSPARENT)
|
addRadioButton(activity.getString(R.string.store_locally_only), STORE_LOCALLY_ONLY, Color.TRANSPARENT)
|
||||||
wasInit = true
|
wasInit = true
|
||||||
|
@ -34,7 +34,7 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val
|
|||||||
eventTypes = it
|
eventTypes = it
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
eventTypes.filter { it.caldavCalendarId == 0 }.forEach {
|
eventTypes.filter { it.caldavCalendarId == 0 }.forEach {
|
||||||
addRadioButton(it.title, it.id, it.color)
|
addRadioButton(it.getDisplayTitle(), it.id, it.color)
|
||||||
}
|
}
|
||||||
addRadioButton(activity.getString(R.string.add_new_type), NEW_TYPE_ID, Color.TRANSPARENT)
|
addRadioButton(activity.getString(R.string.add_new_type), NEW_TYPE_ID, Color.TRANSPARENT)
|
||||||
wasInit = true
|
wasInit = true
|
||||||
|
@ -21,7 +21,7 @@ import java.util.*
|
|||||||
class CalDAVHandler(val context: Context) {
|
class CalDAVHandler(val context: Context) {
|
||||||
fun refreshCalendars(callback: () -> Unit) {
|
fun refreshCalendars(callback: () -> Unit) {
|
||||||
getCalDAVCalendars(context.config.caldavSyncedCalendarIDs).forEach {
|
getCalDAVCalendars(context.config.caldavSyncedCalendarIDs).forEach {
|
||||||
val eventTypeId = context.dbHelper.getEventTypeIdWithTitle("${it.displayName} (${it.accountName})")
|
val eventTypeId = context.dbHelper.getEventTypeIdWithTitle(it.getFullTitle())
|
||||||
CalDAVHandler(context).fetchCalDAVCalendarEvents(it.id, eventTypeId)
|
CalDAVHandler(context).fetchCalDAVCalendarEvents(it.id, eventTypeId)
|
||||||
}
|
}
|
||||||
context.scheduleCalDAVSync(true)
|
context.scheduleCalDAVSync(true)
|
||||||
@ -73,32 +73,11 @@ class CalDAVHandler(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fillCalendarContentValues(eventType: EventType): ContentValues {
|
private fun fillCalendarContentValues(eventType: EventType): ContentValues {
|
||||||
val colorKey = getEventTypeColorKey(eventType)
|
|
||||||
return ContentValues().apply {
|
return ContentValues().apply {
|
||||||
put(CalendarContract.Calendars.CALENDAR_COLOR_KEY, colorKey)
|
|
||||||
put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, eventType.title)
|
put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, eventType.title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEventTypeColorKey(eventType: EventType): Int {
|
|
||||||
val uri = CalendarContract.Colors.CONTENT_URI
|
|
||||||
val projection = arrayOf(CalendarContract.Colors.COLOR_KEY)
|
|
||||||
val selection = "${CalendarContract.Colors.COLOR_TYPE} = ? AND ${CalendarContract.Colors.COLOR} = ?"
|
|
||||||
val selectionArgs = arrayOf(CalendarContract.Colors.TYPE_CALENDAR.toString(), eventType.color.toString())
|
|
||||||
|
|
||||||
var cursor: Cursor? = null
|
|
||||||
try {
|
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
|
||||||
if (cursor?.moveToFirst() == true) {
|
|
||||||
return cursor.getStringValue(CalendarContract.Colors.COLOR_KEY).toInt()
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
cursor?.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
|
private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
|
||||||
val importIdsMap = HashMap<String, Event>()
|
val importIdsMap = HashMap<String, Event>()
|
||||||
val fetchedEventIds = ArrayList<String>()
|
val fetchedEventIds = ArrayList<String>()
|
||||||
|
@ -50,6 +50,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
private val COL_TYPE_TITLE = "event_type_title"
|
private val COL_TYPE_TITLE = "event_type_title"
|
||||||
private val COL_TYPE_COLOR = "event_type_color"
|
private val COL_TYPE_COLOR = "event_type_color"
|
||||||
private val COL_TYPE_CALDAV_CALENDAR_ID = "event_caldav_calendar_id"
|
private val COL_TYPE_CALDAV_CALENDAR_ID = "event_caldav_calendar_id"
|
||||||
|
private val COL_TYPE_CALDAV_DISPLAY_NAME = "event_caldav_display_name"
|
||||||
|
private val COL_TYPE_CALDAV_EMAIL = "event_caldav_email"
|
||||||
|
|
||||||
private val EXCEPTIONS_TABLE_NAME = "event_repeat_exceptions"
|
private val EXCEPTIONS_TABLE_NAME = "event_repeat_exceptions"
|
||||||
private val COL_EXCEPTION_ID = "event_exception_id"
|
private val COL_EXCEPTION_ID = "event_exception_id"
|
||||||
@ -61,7 +63,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
private val mDb: SQLiteDatabase = writableDatabase
|
private val mDb: SQLiteDatabase = writableDatabase
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val DB_VERSION = 16
|
private val DB_VERSION = 17
|
||||||
val DB_NAME = "events.db"
|
val DB_NAME = "events.db"
|
||||||
val REGULAR_EVENT_TYPE_ID = 1
|
val REGULAR_EVENT_TYPE_ID = 1
|
||||||
var dbInstance: DBHelper? = null
|
var dbInstance: DBHelper? = null
|
||||||
@ -158,6 +160,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
if (oldVersion < 16) {
|
if (oldVersion < 16) {
|
||||||
db.execSQL("ALTER TABLE $TYPES_TABLE_NAME ADD COLUMN $COL_TYPE_CALDAV_CALENDAR_ID INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE $TYPES_TABLE_NAME ADD COLUMN $COL_TYPE_CALDAV_CALENDAR_ID INTEGER NOT NULL DEFAULT 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldVersion < 17) {
|
||||||
|
db.execSQL("ALTER TABLE $TYPES_TABLE_NAME ADD COLUMN $COL_TYPE_CALDAV_DISPLAY_NAME TEXT DEFAULT ''")
|
||||||
|
db.execSQL("ALTER TABLE $TYPES_TABLE_NAME ADD COLUMN $COL_TYPE_CALDAV_EMAIL TEXT DEFAULT ''")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createMetaTable(db: SQLiteDatabase) {
|
private fun createMetaTable(db: SQLiteDatabase) {
|
||||||
@ -167,7 +174,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
|
|
||||||
private fun createTypesTable(db: SQLiteDatabase) {
|
private fun createTypesTable(db: SQLiteDatabase) {
|
||||||
db.execSQL("CREATE TABLE $TYPES_TABLE_NAME ($COL_TYPE_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TYPE_TITLE TEXT, $COL_TYPE_COLOR INTEGER, " +
|
db.execSQL("CREATE TABLE $TYPES_TABLE_NAME ($COL_TYPE_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TYPE_TITLE TEXT, $COL_TYPE_COLOR INTEGER, " +
|
||||||
"$COL_TYPE_CALDAV_CALENDAR_ID INTEGER)")
|
"$COL_TYPE_CALDAV_CALENDAR_ID INTEGER, $COL_TYPE_CALDAV_DISPLAY_NAME TEXT, $COL_TYPE_CALDAV_EMAIL TEXT)")
|
||||||
addRegularEventType(db)
|
addRegularEventType(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,6 +301,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
put(COL_TYPE_TITLE, eventType.title)
|
put(COL_TYPE_TITLE, eventType.title)
|
||||||
put(COL_TYPE_COLOR, eventType.color)
|
put(COL_TYPE_COLOR, eventType.color)
|
||||||
put(COL_TYPE_CALDAV_CALENDAR_ID, eventType.caldavCalendarId)
|
put(COL_TYPE_CALDAV_CALENDAR_ID, eventType.caldavCalendarId)
|
||||||
|
put(COL_TYPE_CALDAV_DISPLAY_NAME, eventType.caldavDisplayName)
|
||||||
|
put(COL_TYPE_CALDAV_EMAIL, eventType.caldavEmail)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,7 +362,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getEventType(id: Int): EventType? {
|
fun getEventType(id: Int): EventType? {
|
||||||
val cols = arrayOf(COL_TYPE_TITLE, COL_TYPE_COLOR)
|
val cols = arrayOf(COL_TYPE_TITLE, COL_TYPE_COLOR, COL_TYPE_CALDAV_CALENDAR_ID, COL_TYPE_CALDAV_DISPLAY_NAME, COL_TYPE_CALDAV_EMAIL)
|
||||||
val selection = "$COL_TYPE_ID = ?"
|
val selection = "$COL_TYPE_ID = ?"
|
||||||
val selectionArgs = arrayOf(id.toString())
|
val selectionArgs = arrayOf(id.toString())
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
@ -362,7 +371,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
val title = cursor.getStringValue(COL_TYPE_TITLE)
|
val title = cursor.getStringValue(COL_TYPE_TITLE)
|
||||||
val color = cursor.getIntValue(COL_TYPE_COLOR)
|
val color = cursor.getIntValue(COL_TYPE_COLOR)
|
||||||
return EventType(id, title, color)
|
val calendarId = cursor.getIntValue(COL_TYPE_CALDAV_CALENDAR_ID)
|
||||||
|
val displayName = cursor.getStringValue(COL_TYPE_CALDAV_DISPLAY_NAME)
|
||||||
|
val email = cursor.getStringValue(COL_TYPE_CALDAV_EMAIL)
|
||||||
|
return EventType(id, title, color, calendarId, displayName, email)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
@ -787,7 +799,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
|
|
||||||
fun fetchEventTypes(): ArrayList<EventType> {
|
fun fetchEventTypes(): ArrayList<EventType> {
|
||||||
val eventTypes = ArrayList<EventType>(4)
|
val eventTypes = ArrayList<EventType>(4)
|
||||||
val cols = arrayOf(COL_TYPE_ID, COL_TYPE_TITLE, COL_TYPE_COLOR, COL_TYPE_CALDAV_CALENDAR_ID)
|
val cols = arrayOf(COL_TYPE_ID, COL_TYPE_TITLE, COL_TYPE_COLOR, COL_TYPE_CALDAV_CALENDAR_ID, COL_TYPE_CALDAV_DISPLAY_NAME, COL_TYPE_CALDAV_EMAIL)
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = mDb.query(TYPES_TABLE_NAME, cols, null, null, null, null, "$COL_TYPE_TITLE ASC")
|
cursor = mDb.query(TYPES_TABLE_NAME, cols, null, null, null, null, "$COL_TYPE_TITLE ASC")
|
||||||
@ -797,7 +809,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
val title = cursor.getStringValue(COL_TYPE_TITLE)
|
val title = cursor.getStringValue(COL_TYPE_TITLE)
|
||||||
val color = cursor.getIntValue(COL_TYPE_COLOR)
|
val color = cursor.getIntValue(COL_TYPE_COLOR)
|
||||||
val calendarId = cursor.getIntValue(COL_TYPE_CALDAV_CALENDAR_ID)
|
val calendarId = cursor.getIntValue(COL_TYPE_CALDAV_CALENDAR_ID)
|
||||||
val eventType = EventType(id, title, color, calendarId)
|
val displayName = cursor.getStringValue(COL_TYPE_CALDAV_DISPLAY_NAME)
|
||||||
|
val email = cursor.getStringValue(COL_TYPE_CALDAV_EMAIL)
|
||||||
|
val eventType = EventType(id, title, color, calendarId, displayName, email)
|
||||||
eventTypes.add(eventType)
|
eventTypes.add(eventType)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,6 @@ package com.simplemobiletools.calendar.models
|
|||||||
|
|
||||||
data class CalDAVCalendar(val id: Int, val displayName: String, val accountName: String, val ownerName: String, val color: Int, val accessLevel: Int) {
|
data class CalDAVCalendar(val id: Int, val displayName: String, val accountName: String, val ownerName: String, val color: Int, val accessLevel: Int) {
|
||||||
fun canWrite() = accessLevel >= 500
|
fun canWrite() = accessLevel >= 500
|
||||||
|
|
||||||
|
fun getFullTitle() = "$displayName ($accountName)"
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
package com.simplemobiletools.calendar.models
|
package com.simplemobiletools.calendar.models
|
||||||
|
|
||||||
data class EventType(var id: Int = 0, var title: String, var color: Int, var caldavCalendarId: Int = 0)
|
data class EventType(var id: Int = 0, var title: String, var color: Int, var caldavCalendarId: Int = 0, var caldavDisplayName: String = "", var caldavEmail: String = "") {
|
||||||
|
fun getDisplayTitle() = if (caldavCalendarId == 0) title else "$caldavDisplayName ($caldavEmail)"
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user