mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-20 05:30:40 +01:00
sort the available colors by color key
This commit is contained in:
parent
d27f849946
commit
c88ccbe83f
@ -6,6 +6,7 @@ import android.content.Context
|
|||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.provider.CalendarContract
|
import android.provider.CalendarContract
|
||||||
import android.provider.CalendarContract.Reminders
|
import android.provider.CalendarContract.Reminders
|
||||||
|
import android.util.SparseIntArray
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.extensions.hasCalendarPermission
|
import com.simplemobiletools.calendar.extensions.hasCalendarPermission
|
||||||
@ -17,6 +18,7 @@ import com.simplemobiletools.commons.extensions.getIntValue
|
|||||||
import com.simplemobiletools.commons.extensions.getLongValue
|
import com.simplemobiletools.commons.extensions.getLongValue
|
||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class CalDAVHandler(val context: Context) {
|
class CalDAVHandler(val context: Context) {
|
||||||
fun refreshCalendars(callback: () -> Unit) {
|
fun refreshCalendars(callback: () -> Unit) {
|
||||||
@ -147,9 +149,9 @@ class CalDAVHandler(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getAvailableCalDAVCalendarColors(eventType: EventType): ArrayList<Int> {
|
fun getAvailableCalDAVCalendarColors(eventType: EventType): ArrayList<Int> {
|
||||||
val colors = ArrayList<Int>()
|
val colors = SparseIntArray()
|
||||||
val uri = CalendarContract.Colors.CONTENT_URI
|
val uri = CalendarContract.Colors.CONTENT_URI
|
||||||
val projection = arrayOf(CalendarContract.Colors.COLOR)
|
val projection = arrayOf(CalendarContract.Colors.COLOR, CalendarContract.Colors.COLOR_KEY)
|
||||||
val selection = "${CalendarContract.Colors.COLOR_TYPE} = ? AND ${CalendarContract.Colors.ACCOUNT_NAME} = ?"
|
val selection = "${CalendarContract.Colors.COLOR_TYPE} = ? AND ${CalendarContract.Colors.ACCOUNT_NAME} = ?"
|
||||||
val selectionArgs = arrayOf(CalendarContract.Colors.TYPE_CALENDAR.toString(), eventType.caldavEmail)
|
val selectionArgs = arrayOf(CalendarContract.Colors.TYPE_CALENDAR.toString(), eventType.caldavEmail)
|
||||||
|
|
||||||
@ -158,14 +160,21 @@ class CalDAVHandler(val context: Context) {
|
|||||||
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
colors.add(cursor.getIntValue(CalendarContract.Colors.COLOR))
|
val colorKey = cursor.getIntValue(CalendarContract.Colors.COLOR_KEY)
|
||||||
|
val color = cursor.getIntValue(CalendarContract.Colors.COLOR)
|
||||||
|
colors.put(colorKey, color)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
return colors
|
val sortedColors = ArrayList<Int>(colors.size())
|
||||||
|
for (i in 0 until colors.size()) {
|
||||||
|
sortedColors.add(colors[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortedColors
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
|
private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user