making EventType id a Long type, instead of Int
This commit is contained in:
parent
aef5e4b3b7
commit
c78b15a629
14 changed files with 87 additions and 59 deletions
|
@ -181,7 +181,7 @@ class EventActivity : SimpleActivity() {
|
|||
outState.putInt(REPEAT_LIMIT, mRepeatLimit)
|
||||
outState.putInt(REPEAT_RULE, mRepeatRule)
|
||||
|
||||
outState.putInt(EVENT_TYPE_ID, mEventTypeId)
|
||||
outState.putLong(EVENT_TYPE_ID, mEventTypeId)
|
||||
outState.putInt(EVENT_CALENDAR_ID, mEventCalendarId)
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ class EventActivity : SimpleActivity() {
|
|||
mRepeatLimit = getInt(REPEAT_LIMIT)
|
||||
mRepeatRule = getInt(REPEAT_RULE)
|
||||
|
||||
mEventTypeId = getInt(EVENT_TYPE_ID)
|
||||
mEventTypeId = getLong(EVENT_TYPE_ID)
|
||||
mEventCalendarId = getInt(EVENT_CALENDAR_ID)
|
||||
}
|
||||
|
||||
|
@ -523,7 +523,7 @@ class EventActivity : SimpleActivity() {
|
|||
private fun showEventTypeDialog() {
|
||||
hideKeyboard()
|
||||
SelectEventTypeDialog(this, mEventTypeId, false) {
|
||||
mEventTypeId = it.id
|
||||
mEventTypeId = it.id!!
|
||||
updateEventType()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -391,7 +391,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
Thread {
|
||||
val holidays = getString(R.string.holidays)
|
||||
var eventTypeId = dbHelper.getEventTypeIdWithTitle(holidays)
|
||||
if (eventTypeId == -1) {
|
||||
if (eventTypeId == -1L) {
|
||||
val eventType = EventType(0, holidays, resources.getColor(R.color.default_holidays_color))
|
||||
eventTypeId = dbHelper.insertEventType(eventType)
|
||||
}
|
||||
|
@ -514,20 +514,20 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getBirthdaysEventTypeId(): Int {
|
||||
private fun getBirthdaysEventTypeId(): Long {
|
||||
val birthdays = getString(R.string.birthdays)
|
||||
var eventTypeId = dbHelper.getEventTypeIdWithTitle(birthdays)
|
||||
if (eventTypeId == -1) {
|
||||
if (eventTypeId == -1L) {
|
||||
val eventType = EventType(0, birthdays, resources.getColor(R.color.default_birthdays_color))
|
||||
eventTypeId = dbHelper.insertEventType(eventType)
|
||||
}
|
||||
return eventTypeId
|
||||
}
|
||||
|
||||
private fun getAnniversariesEventTypeId(): Int {
|
||||
private fun getAnniversariesEventTypeId(): Long {
|
||||
val anniversaries = getString(R.string.anniversaries)
|
||||
var eventTypeId = dbHelper.getEventTypeIdWithTitle(anniversaries)
|
||||
if (eventTypeId == -1) {
|
||||
if (eventTypeId == -1L) {
|
||||
val eventType = EventType(0, anniversaries, resources.getColor(R.color.default_anniversaries_color))
|
||||
eventTypeId = dbHelper.insertEventType(eventType)
|
||||
}
|
||||
|
|
|
@ -14,19 +14,19 @@ import java.util.*
|
|||
|
||||
class FilterEventTypeAdapter(val activity: SimpleActivity, val eventTypes: List<EventType>, val displayEventTypes: Set<String>) :
|
||||
RecyclerView.Adapter<FilterEventTypeAdapter.ViewHolder>() {
|
||||
private val selectedKeys = HashSet<Int>()
|
||||
private val selectedKeys = HashSet<Long>()
|
||||
|
||||
init {
|
||||
eventTypes.forEachIndexed { index, eventType ->
|
||||
if (displayEventTypes.contains(eventType.id.toString())) {
|
||||
selectedKeys.add(eventType.id)
|
||||
selectedKeys.add(eventType.id!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleItemSelection(select: Boolean, eventType: EventType, pos: Int) {
|
||||
if (select) {
|
||||
selectedKeys.add(eventType.id)
|
||||
selectedKeys.add(eventType.id!!)
|
||||
} else {
|
||||
selectedKeys.remove(eventType.id)
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ class ManageEventTypesAdapter(activity: SimpleActivity, val eventTypes: ArrayLis
|
|||
|
||||
override fun getIsItemSelectable(position: Int) = true
|
||||
|
||||
override fun getItemSelectionKey(position: Int) = eventTypes.getOrNull(position)?.id
|
||||
override fun getItemSelectionKey(position: Int) = eventTypes.getOrNull(position)?.id?.toInt()
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = eventTypes.indexOfFirst { it.id == key }
|
||||
override fun getItemKeyPosition(key: Int) = eventTypes.indexOfFirst { it.id?.toInt() == key }
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_event_type, parent)
|
||||
|
||||
|
@ -57,13 +57,13 @@ class ManageEventTypesAdapter(activity: SimpleActivity, val eventTypes: ArrayLis
|
|||
|
||||
override fun getItemCount() = eventTypes.size
|
||||
|
||||
private fun getItemWithKey(key: Int): EventType? = eventTypes.firstOrNull { it.id == key }
|
||||
private fun getItemWithKey(key: Int): EventType? = eventTypes.firstOrNull { it.id?.toInt() == key }
|
||||
|
||||
private fun getSelectedItems() = eventTypes.filter { selectedKeys.contains(it.id) } as ArrayList<EventType>
|
||||
private fun getSelectedItems() = eventTypes.filter { selectedKeys.contains(it.id?.toInt()) } as ArrayList<EventType>
|
||||
|
||||
private fun setupView(view: View, eventType: EventType) {
|
||||
view.apply {
|
||||
event_item_frame.isSelected = selectedKeys.contains(eventType.id)
|
||||
event_item_frame.isSelected = selectedKeys.contains(eventType.id?.toInt())
|
||||
event_type_title.text = eventType.getDisplayTitle()
|
||||
event_type_color.setFillWithStroke(eventType.color, activity.config.backgroundColor)
|
||||
event_type_title.setTextColor(textColor)
|
||||
|
@ -71,7 +71,7 @@ class ManageEventTypesAdapter(activity: SimpleActivity, val eventTypes: ArrayLis
|
|||
}
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
val eventTypes = eventTypes.filter { selectedKeys.contains(it.id) } as ArrayList<EventType>
|
||||
val eventTypes = eventTypes.filter { selectedKeys.contains(it.id?.toInt()) } as ArrayList<EventType>
|
||||
|
||||
if (activity.dbHelper.doEventTypesContainEvent(eventTypes)) {
|
||||
val MOVE_EVENTS = 0
|
||||
|
@ -99,7 +99,7 @@ class ManageEventTypesAdapter(activity: SimpleActivity, val eventTypes: ArrayLis
|
|||
if (type.id == DBHelper.REGULAR_EVENT_TYPE_ID) {
|
||||
activity.toast(R.string.cannot_delete_default_type)
|
||||
eventTypesToDelete.remove(type)
|
||||
toggleItemSelection(false, getItemKeyPosition(type.id))
|
||||
toggleItemSelection(false, getItemKeyPosition(type.id!!.toInt()))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
|||
|
||||
init {
|
||||
if (eventType == null)
|
||||
eventType = EventType(0, "", activity.config.primaryColor)
|
||||
eventType = EventType(null, "", activity.config.primaryColor)
|
||||
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_event_type, null).apply {
|
||||
setupColor(type_color)
|
||||
|
@ -47,9 +47,9 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
|||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val title = view.type_title.value
|
||||
val eventIdWithTitle = activity.dbHelper.getEventTypeIdWithTitle(title)
|
||||
var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1
|
||||
var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1L
|
||||
if (!isEventTypeTitleTaken)
|
||||
isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1
|
||||
isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1L
|
||||
|
||||
if (title.isEmpty()) {
|
||||
activity.toast(R.string.title_empty)
|
||||
|
@ -69,7 +69,7 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
|||
activity.dbHelper.updateEventType(eventType!!)
|
||||
}
|
||||
|
||||
if (eventType!!.id != -1) {
|
||||
if (eventType!!.id != -1L) {
|
||||
dismiss()
|
||||
callback(eventType!!)
|
||||
} else {
|
||||
|
|
|
@ -29,7 +29,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
|||
val lastUsedCalDAVCalendar = activity.dbHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendarId)
|
||||
if (lastUsedCalDAVCalendar != null) {
|
||||
currEventTypeCalDAVCalendarId = config.lastUsedCaldavCalendarId
|
||||
lastUsedCalDAVCalendar.id
|
||||
lastUsedCalDAVCalendar.id!!
|
||||
} else {
|
||||
DBHelper.REGULAR_EVENT_TYPE_ID
|
||||
}
|
||||
|
@ -41,10 +41,10 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
|||
updateEventType(this)
|
||||
import_event_type_holder.setOnClickListener {
|
||||
SelectEventTypeDialog(activity, currEventTypeId, true) {
|
||||
currEventTypeId = it.id
|
||||
currEventTypeId = it.id!!
|
||||
currEventTypeCalDAVCalendarId = it.caldavCalendarId
|
||||
|
||||
config.lastUsedLocalEventTypeId = it.id
|
||||
config.lastUsedLocalEventTypeId = it.id!!
|
||||
config.lastUsedCaldavCalendarId = it.caldavCalendarId
|
||||
|
||||
updateEventType(this)
|
||||
|
|
|
@ -18,9 +18,9 @@ import kotlinx.android.synthetic.main.dialog_select_radio_group.view.*
|
|||
import kotlinx.android.synthetic.main.radio_button_with_color.view.*
|
||||
import java.util.*
|
||||
|
||||
class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val showCalDAVCalendars: Boolean,
|
||||
class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val showCalDAVCalendars: Boolean,
|
||||
val callback: (eventType: EventType) -> Unit) {
|
||||
private val NEW_TYPE_ID = -2
|
||||
private val NEW_TYPE_ID = -2L
|
||||
|
||||
private val dialog: AlertDialog?
|
||||
private val radioGroup: RadioGroup
|
||||
|
@ -55,7 +55,7 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val
|
|||
(view.dialog_radio_button as MyCompatRadioButton).apply {
|
||||
text = eventType.getDisplayTitle()
|
||||
isChecked = eventType.id == currEventType
|
||||
id = eventType.id
|
||||
id = eventType.id!!.toInt()
|
||||
}
|
||||
|
||||
if (eventType.color != Color.TRANSPARENT) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.res.Resources
|
|||
import android.graphics.Rect
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.util.SparseIntArray
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
|
@ -13,6 +12,7 @@ import android.view.ViewGroup
|
|||
import android.widget.ImageView
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.collection.LongSparseArray
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.EventActivity
|
||||
|
@ -56,7 +56,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
private var events = ArrayList<Event>()
|
||||
private var allDayHolders = ArrayList<RelativeLayout>()
|
||||
private var allDayRows = ArrayList<HashSet<Int>>()
|
||||
private var eventTypeColors = SparseIntArray()
|
||||
private var eventTypeColors = LongSparseArray<Int>()
|
||||
|
||||
lateinit var inflater: LayoutInflater
|
||||
lateinit var mView: View
|
||||
|
@ -68,7 +68,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
context!!.dbHelper.getEventTypes {
|
||||
it.map { eventTypeColors.put(it.id, it.color) }
|
||||
it.map { eventTypeColors.put(it.id!!, it.color) }
|
||||
}
|
||||
|
||||
mRes = context!!.resources
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.calendar.pro.helpers
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ContentUris
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
|
@ -33,12 +34,13 @@ class CalDAVHandler(val context: Context) {
|
|||
context.dbHelper.updateLocalEventType(this)
|
||||
}
|
||||
|
||||
CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id, activity)
|
||||
CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id!!, activity)
|
||||
}
|
||||
context.scheduleCalDAVSync(true)
|
||||
callback()
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun getCalDAVCalendars(activity: SimpleActivity? = null, ids: String = ""): List<CalDAVCalendar> {
|
||||
val calendars = ArrayList<CalDAVCalendar>()
|
||||
if (!context.hasPermission(PERMISSION_WRITE_CALENDAR) || !context.hasPermission(PERMISSION_READ_CALENDAR)) {
|
||||
|
@ -98,6 +100,7 @@ class CalDAVHandler(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun getEventTypeColorKey(eventType: EventType): Int {
|
||||
val uri = CalendarContract.Colors.CONTENT_URI
|
||||
val projection = arrayOf(CalendarContract.Colors.COLOR_KEY)
|
||||
|
@ -117,6 +120,7 @@ class CalDAVHandler(val context: Context) {
|
|||
return -1
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun getAvailableCalDAVCalendarColors(eventType: EventType): ArrayList<Int> {
|
||||
val colors = SparseIntArray()
|
||||
val uri = CalendarContract.Colors.CONTENT_URI
|
||||
|
@ -147,7 +151,8 @@ class CalDAVHandler(val context: Context) {
|
|||
return sortedColors
|
||||
}
|
||||
|
||||
private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int, activity: SimpleActivity?) {
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Long, activity: SimpleActivity?) {
|
||||
val importIdsMap = HashMap<String, Event>()
|
||||
val fetchedEventIds = ArrayList<String>()
|
||||
val existingEvents = context.dbHelper.getEventsFromCalDAVCalendar(calendarId)
|
||||
|
@ -263,6 +268,7 @@ class CalDAVHandler(val context: Context) {
|
|||
context.dbHelper.deleteEvents(eventIdsToDelete.toTypedArray(), false)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun insertCalDAVEvent(event: Event) {
|
||||
val uri = CalendarContract.Events.CONTENT_URI
|
||||
val values = fillEventContentValues(event)
|
||||
|
@ -291,6 +297,7 @@ class CalDAVHandler(val context: Context) {
|
|||
refreshCalDAVCalendar(event)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun setupCalDAVEventReminders(event: Event) {
|
||||
clearEventReminders(event)
|
||||
event.getReminders().forEach {
|
||||
|
@ -338,6 +345,7 @@ class CalDAVHandler(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun clearEventReminders(event: Event) {
|
||||
val selection = "${Reminders.EVENT_ID} = ?"
|
||||
val selectionArgs = arrayOf(event.getCalDAVEventId().toString())
|
||||
|
@ -369,6 +377,7 @@ class CalDAVHandler(val context: Context) {
|
|||
refreshCalDAVCalendar(event)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun insertEventRepeatException(event: Event, occurrenceTS: Int): Long {
|
||||
val uri = CalendarContract.Events.CONTENT_URI
|
||||
val values = fillEventRepeatExceptionValues(event, occurrenceTS)
|
||||
|
@ -388,6 +397,7 @@ class CalDAVHandler(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun getCalDAVEventReminders(eventId: Long): List<Int> {
|
||||
val reminders = ArrayList<Int>()
|
||||
val uri = CalendarContract.Reminders.CONTENT_URI
|
||||
|
|
|
@ -95,9 +95,9 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
get() = prefs.getInt(LAST_USED_CALDAV_CALENDAR, getSyncedCalendarIdsAsList().first().toInt())
|
||||
set(calendarId) = prefs.edit().putInt(LAST_USED_CALDAV_CALENDAR, calendarId).apply()
|
||||
|
||||
var lastUsedLocalEventTypeId: Int
|
||||
get() = prefs.getInt(LAST_USED_LOCAL_EVENT_TYPE_ID, DBHelper.REGULAR_EVENT_TYPE_ID)
|
||||
set(lastUsedLocalEventTypeId) = prefs.edit().putInt(LAST_USED_LOCAL_EVENT_TYPE_ID, lastUsedLocalEventTypeId).apply()
|
||||
var lastUsedLocalEventTypeId: Long
|
||||
get() = prefs.getLong(LAST_USED_LOCAL_EVENT_TYPE_ID, DBHelper.REGULAR_EVENT_TYPE_ID)
|
||||
set(lastUsedLocalEventTypeId) = prefs.edit().putLong(LAST_USED_LOCAL_EVENT_TYPE_ID, lastUsedLocalEventTypeId).apply()
|
||||
|
||||
var reminderAudioStream: Int
|
||||
get() = prefs.getInt(REMINDER_AUDIO_STREAM, AudioManager.STREAM_ALARM)
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper
|
|||
import android.database.sqlite.SQLiteQueryBuilder
|
||||
import android.text.TextUtils
|
||||
import android.util.SparseIntArray
|
||||
import androidx.collection.LongSparseArray
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
|
@ -66,7 +67,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
companion object {
|
||||
private const val DB_VERSION = 19
|
||||
const val DB_NAME = "events_old.db"
|
||||
const val REGULAR_EVENT_TYPE_ID = 1
|
||||
const val REGULAR_EVENT_TYPE_ID = 1L
|
||||
var dbInstance: DBHelper? = null
|
||||
|
||||
fun newInstance(context: Context): DBHelper {
|
||||
|
@ -224,14 +225,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
insertEventType(eventType, db)
|
||||
}
|
||||
|
||||
fun insertEventType(eventType: EventType, db: SQLiteDatabase = mDb): Int {
|
||||
fun insertEventType(eventType: EventType, db: SQLiteDatabase = mDb): Long {
|
||||
val values = fillEventTypeValues(eventType)
|
||||
val insertedId = db.insert(TYPES_TABLE_NAME, null, values).toInt()
|
||||
val insertedId = db.insert(TYPES_TABLE_NAME, null, values)
|
||||
context.config.addDisplayEventType(insertedId.toString())
|
||||
return insertedId
|
||||
}
|
||||
|
||||
fun updateEventType(eventType: EventType): Int {
|
||||
fun updateEventType(eventType: EventType): Long {
|
||||
if (eventType.caldavCalendarId != 0) {
|
||||
CalDAVHandler(context).updateCalDAVCalendar(eventType)
|
||||
}
|
||||
|
@ -239,11 +240,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return updateLocalEventType(eventType)
|
||||
}
|
||||
|
||||
fun updateLocalEventType(eventType: EventType): Int {
|
||||
fun updateLocalEventType(eventType: EventType): Long {
|
||||
val selectionArgs = arrayOf(eventType.id.toString())
|
||||
val values = fillEventTypeValues(eventType)
|
||||
val selection = "$COL_TYPE_ID = ?"
|
||||
return mDb.update(TYPES_TABLE_NAME, values, selection, selectionArgs)
|
||||
val updated = mDb.update(TYPES_TABLE_NAME, values, selection, selectionArgs)
|
||||
return if (updated > 0) {
|
||||
eventType.id!!
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
private fun fillEventTypeValues(eventType: EventType): ContentValues {
|
||||
|
@ -296,7 +302,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
}
|
||||
|
||||
fun getEventTypeIdWithTitle(title: String): Int {
|
||||
fun getEventTypeIdWithTitle(title: String): Long {
|
||||
val cols = arrayOf(COL_TYPE_ID)
|
||||
val selection = "$COL_TYPE_TITLE = ? COLLATE NOCASE"
|
||||
val selectionArgs = arrayOf(title)
|
||||
|
@ -304,7 +310,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
try {
|
||||
cursor = mDb.query(TYPES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
return cursor.getIntValue(COL_TYPE_ID)
|
||||
return cursor.getIntValue(COL_TYPE_ID).toLong()
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
|
@ -320,7 +326,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
try {
|
||||
cursor = mDb.query(TYPES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
return getEventType(cursor.getIntValue(COL_TYPE_ID))
|
||||
return getEventType(cursor.getLongValue(COL_TYPE_ID))
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
|
@ -328,7 +334,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return null
|
||||
}
|
||||
|
||||
fun getEventType(id: Int): EventType? {
|
||||
fun getEventType(id: Long): EventType? {
|
||||
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 selectionArgs = arrayOf(id.toString())
|
||||
|
@ -456,7 +462,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
|
||||
fun deleteEventTypes(eventTypes: ArrayList<EventType>, deleteEvents: Boolean, callback: (deletedCnt: Int) -> Unit) {
|
||||
var deleteIds = eventTypes.asSequence().filter { it.caldavCalendarId == 0 }.map { it.id }.toList()
|
||||
deleteIds = deleteIds.filter { it != REGULAR_EVENT_TYPE_ID } as ArrayList<Int>
|
||||
deleteIds = deleteIds.filter { it != REGULAR_EVENT_TYPE_ID } as ArrayList<Long>
|
||||
|
||||
val deletedSet = HashSet<String>()
|
||||
deleteIds.map { deletedSet.add(it.toString()) }
|
||||
|
@ -483,7 +489,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
mDb.delete(TYPES_TABLE_NAME, selection, null)
|
||||
}
|
||||
|
||||
private fun deleteEventsWithType(eventTypeId: Int) {
|
||||
private fun deleteEventsWithType(eventTypeId: Long) {
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_EVENT_TYPE = ?"
|
||||
val selectionArgs = arrayOf(eventTypeId.toString())
|
||||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
|
@ -492,7 +498,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
deleteEvents(eventIDs, true)
|
||||
}
|
||||
|
||||
private fun resetEventsWithType(eventTypeId: Int) {
|
||||
private fun resetEventsWithType(eventTypeId: Long) {
|
||||
val values = ContentValues()
|
||||
values.put(COL_EVENT_TYPE, REGULAR_EVENT_TYPE_ID)
|
||||
|
||||
|
@ -810,9 +816,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
COL_IS_DST_INCLUDED, COL_LAST_UPDATED, COL_EVENT_SOURCE, COL_LOCATION)
|
||||
|
||||
private fun fillEvents(cursor: Cursor?): List<Event> {
|
||||
val eventTypeColors = SparseIntArray()
|
||||
val eventTypeColors = LongSparseArray<Int>()
|
||||
getEventTypesSync().forEach {
|
||||
eventTypeColors.put(it.id, it.color)
|
||||
eventTypeColors.put(it.id!!, it.color)
|
||||
}
|
||||
|
||||
val events = ArrayList<Event>()
|
||||
|
@ -832,13 +838,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val importId = cursor.getStringValue(COL_IMPORT_ID) ?: ""
|
||||
val flags = cursor.getIntValue(COL_FLAGS)
|
||||
val repeatLimit = cursor.getIntValue(COL_REPEAT_LIMIT)
|
||||
val eventType = cursor.getIntValue(COL_EVENT_TYPE)
|
||||
val eventType = cursor.getLongValue(COL_EVENT_TYPE)
|
||||
val offset = cursor.getStringValue(COL_OFFSET)
|
||||
val isDstIncluded = cursor.getIntValue(COL_IS_DST_INCLUDED) == 1
|
||||
val lastUpdated = cursor.getLongValue(COL_LAST_UPDATED)
|
||||
val source = cursor.getStringValue(COL_EVENT_SOURCE)
|
||||
val location = cursor.getStringValue(COL_LOCATION)
|
||||
val color = eventTypeColors[eventType]
|
||||
val color = eventTypeColors.get(eventType)!!
|
||||
val isPastEvent = false
|
||||
|
||||
val ignoreEventOccurrences = if (repeatInterval != 0) {
|
||||
|
@ -877,7 +883,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
cursor = mDb.query(TYPES_TABLE_NAME, cols, null, null, null, null, "$COL_TYPE_TITLE ASC")
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val id = cursor.getIntValue(COL_TYPE_ID)
|
||||
val id = cursor.getLongValue(COL_TYPE_ID)
|
||||
val title = cursor.getStringValue(COL_TYPE_TITLE)
|
||||
val color = cursor.getIntValue(COL_TYPE_COLOR)
|
||||
val calendarId = cursor.getIntValue(COL_TYPE_CALDAV_CALENDAR_ID)
|
||||
|
|
|
@ -40,7 +40,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
private var eventsImported = 0
|
||||
private var eventsFailed = 0
|
||||
|
||||
fun importEvents(path: String, defaultEventTypeId: Int, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
|
||||
fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
|
||||
try {
|
||||
val eventTypes = activity.dbHelper.getEventTypesSync()
|
||||
val existingEvents = activity.dbHelper.getEventsWithImportIds()
|
||||
|
@ -219,9 +219,9 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
}
|
||||
|
||||
val eventId = context.dbHelper.getEventTypeIdWithTitle(eventTypeTitle)
|
||||
curEventTypeId = if (eventId == -1) {
|
||||
curEventTypeId = if (eventId == -1L) {
|
||||
val newTypeColor = if (curCategoryColor == -2) context.resources.getColor(R.color.color_primary) else curCategoryColor
|
||||
val eventType = EventType(0, eventTypeTitle, newTypeColor)
|
||||
val eventType = EventType(null, eventTypeTitle, newTypeColor)
|
||||
context.dbHelper.insertEventType(eventType)
|
||||
} else {
|
||||
eventId
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.*
|
|||
data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
||||
var reminder1Minutes: Int = -1, var reminder2Minutes: Int = -1, var reminder3Minutes: Int = -1, var repeatInterval: Int = 0,
|
||||
var importId: String = "", var flags: Int = 0, var repeatLimit: Int = 0, var repeatRule: Int = 0,
|
||||
var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = ArrayList(),
|
||||
var eventType: Long = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = ArrayList(),
|
||||
var offset: String = "", var isDstIncluded: Boolean = false, var parentId: Int = 0, var lastUpdated: Long = 0L,
|
||||
var source: String = SOURCE_SIMPLE_CALENDAR, var color: Int = 0, var location: String = "", var isPastEvent: Boolean = false)
|
||||
: Serializable {
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
package com.simplemobiletools.calendar.pro.models
|
||||
|
||||
data class EventType(var id: Int = 0, var title: String, var color: Int, var caldavCalendarId: Int = 0, var caldavDisplayName: String = "", var caldavEmail: String = "") {
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "event_types", indices = [(Index(value = ["id"], unique = true))])
|
||||
data class EventType(
|
||||
@PrimaryKey(autoGenerate = true) var id: Long?,
|
||||
@ColumnInfo(name = "title") var title: String,
|
||||
@ColumnInfo(name = "color") var color: Int,
|
||||
@ColumnInfo(name = "caldav_calendar_id") var caldavCalendarId: Int = 0,
|
||||
@ColumnInfo(name = "caldav_display_name") var caldavDisplayName: String = "",
|
||||
@ColumnInfo(name = "caldav_email") var caldavEmail: String = "") {
|
||||
fun getDisplayTitle() = if (caldavCalendarId == 0) title else "$caldavDisplayName ($caldavEmail)"
|
||||
|
||||
fun isSyncedEventType() = caldavCalendarId != 0
|
||||
|
|
Loading…
Reference in a new issue