changing the event Id type to Long

This commit is contained in:
tibbi 2018-11-11 15:53:03 +01:00
parent e535072247
commit 895c55d72e
16 changed files with 76 additions and 77 deletions

View File

@ -64,10 +64,10 @@ class EventActivity : SimpleActivity() {
val intent = intent ?: return
mDialogTheme = getDialogTheme()
val eventId = intent.getIntExtra(EVENT_ID, 0)
val eventId = intent.getLongExtra(EVENT_ID, 0)
val event = dbHelper.getEventWithId(eventId)
if (eventId != 0 && event == null) {
if (eventId != 0L && event == null) {
finish()
return
}
@ -150,9 +150,9 @@ class EventActivity : SimpleActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_event, menu)
if (wasActivityInitialized) {
menu.findItem(R.id.delete).isVisible = mEvent.id != 0
menu.findItem(R.id.share).isVisible = mEvent.id != 0
menu.findItem(R.id.duplicate).isVisible = mEvent.id != 0
menu.findItem(R.id.delete).isVisible = mEvent.id != 0L
menu.findItem(R.id.share).isVisible = mEvent.id != 0L
menu.findItem(R.id.duplicate).isVisible = mEvent.id != 0L
}
return true
}
@ -698,7 +698,7 @@ class EventActivity : SimpleActivity() {
val wasRepeatable = mEvent.repeatInterval > 0
val oldSource = mEvent.source
val newImportId = if (mEvent.id != 0) mEvent.importId else UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
val newImportId = if (mEvent.id != 0L) mEvent.importId else UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendarId == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) {
mEventTypeId
@ -748,7 +748,7 @@ class EventActivity : SimpleActivity() {
}
// recreate the event if it was moved in a different CalDAV calendar
if (mEvent.id != 0 && oldSource != newSource) {
if (mEvent.id != 0L && oldSource != newSource) {
dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
mEvent.id = 0
}
@ -757,7 +757,7 @@ class EventActivity : SimpleActivity() {
}
private fun storeEvent(wasRepeatable: Boolean) {
if (mEvent.id == 0) {
if (mEvent.id == 0L) {
dbHelper.insert(mEvent, true, this) {
if (DateTime.now().isAfter(mEventStartDateTime.millis)) {
if (mEvent.repeatInterval == 0 && mEvent.getReminders().isNotEmpty()) {

View File

@ -267,11 +267,11 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
return true
}
val eventIdToOpen = intent.getIntExtra(EVENT_ID, 0)
val eventIdToOpen = intent.getLongExtra(EVENT_ID, 0)
val eventOccurrenceToOpen = intent.getIntExtra(EVENT_OCCURRENCE_TS, 0)
intent.removeExtra(EVENT_ID)
intent.removeExtra(EVENT_OCCURRENCE_TS)
if (eventIdToOpen != 0 && eventOccurrenceToOpen != 0) {
if (eventIdToOpen != 0L && eventOccurrenceToOpen != 0) {
Intent(this, EventActivity::class.java).apply {
putExtra(EVENT_ID, eventIdToOpen)
putExtra(EVENT_OCCURRENCE_TS, eventOccurrenceToOpen)
@ -290,7 +290,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
// intents like content://com.android.calendar/events/1756
val eventId = uri.lastPathSegment
val id = dbHelper.getEventIdWithLastImportId(eventId)
if (id != 0) {
if (id != 0L) {
Intent(this, EventActivity::class.java).apply {
putExtra(EVENT_ID, id)
startActivity(this)

View File

@ -13,7 +13,7 @@ class SnoozeReminderActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
showPickSecondsDialogHelper(config.snoozeTime, true, cancelCallback = { dialogCancelled() }) {
val eventId = intent.getIntExtra(EVENT_ID, 0)
val eventId = intent.getLongExtra(EVENT_ID, 0L)
val event = dbHelper.getEventWithId(eventId)
config.snoozeTime = it / 60
rescheduleReminder(event, it / 60)

View File

@ -13,7 +13,7 @@ class SplashActivity : BaseSplashActivity() {
startActivity(this)
}
intent.extras?.containsKey(EVENT_ID) == true -> Intent(this, MainActivity::class.java).apply {
putExtra(EVENT_ID, intent.getIntExtra(EVENT_ID, 0))
putExtra(EVENT_ID, intent.getLongExtra(EVENT_ID, 0L))
putExtra(EVENT_OCCURRENCE_TS, intent.getIntExtra(EVENT_OCCURRENCE_TS, 0))
startActivity(this)
}

View File

@ -49,9 +49,9 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = events.getOrNull(position)?.id
override fun getItemSelectionKey(position: Int) = events.getOrNull(position)?.id?.toInt()
override fun getItemKeyPosition(key: Int) = events.indexOfFirst { it.id == key }
override fun getItemKeyPosition(key: Int) = events.indexOfFirst { it.id?.toInt() == key }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyRecyclerViewAdapter.ViewHolder {
val layoutId = when (viewType) {
@ -93,7 +93,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
private fun setupView(view: View, event: Event) {
view.apply {
event_item_frame.isSelected = selectedKeys.contains(event.id)
event_item_frame.isSelected = selectedKeys.contains(event.id?.toInt())
event_item_title.text = event.title
event_item_description?.text = if (replaceDescriptionWithLocation) event.location else event.description
event_item_start.text = if (event.getIsAllDay()) allDayString else Formatter.getTimeFromTS(context, event.startTS)
@ -130,11 +130,11 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
}
}
private fun shareEvents() = activity.shareEvents(selectedKeys.distinct())
private fun shareEvents() = activity.shareEvents(selectedKeys.distinct().map { it.toLong() })
private fun askConfirmDelete() {
val eventIds = selectedKeys.toMutableList()
val eventsToDelete = events.filter { selectedKeys.contains(it.id) }
val eventIds = selectedKeys.map { it.toLong() }.toMutableList()
val eventsToDelete = events.filter { selectedKeys.contains(it.id?.toInt()) }
val timestamps = eventsToDelete.map { it.startTS }
val positions = getSelectedItemPositions()

View File

@ -70,9 +70,9 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
override fun getIsItemSelectable(position: Int) = listItems[position] is ListEvent
override fun getItemSelectionKey(position: Int) = (listItems.getOrNull(position) as? ListEvent)?.id
override fun getItemSelectionKey(position: Int) = (listItems.getOrNull(position) as? ListEvent)?.id?.toInt()
override fun getItemKeyPosition(key: Int) = listItems.indexOfFirst { (it as? ListEvent)?.id == key }
override fun getItemKeyPosition(key: Int) = listItems.indexOfFirst { (it as? ListEvent)?.id?.toInt() == key }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyRecyclerViewAdapter.ViewHolder {
val layoutId = when (viewType) {
@ -136,7 +136,7 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
private fun setupListEvent(view: View, listEvent: ListEvent) {
view.apply {
event_item_frame.isSelected = selectedKeys.contains(listEvent.id)
event_item_frame.isSelected = selectedKeys.contains(listEvent.id.toInt())
event_item_title.text = listEvent.title
event_item_description?.text = if (replaceDescription) listEvent.location else listEvent.description
event_item_start.text = if (listEvent.isAllDay) allDayString else Formatter.getTimeFromTS(context, listEvent.startTS)
@ -195,11 +195,11 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
}
}
private fun shareEvents() = activity.shareEvents(selectedKeys.distinct())
private fun shareEvents() = activity.shareEvents(selectedKeys.distinct().map { it.toLong() })
private fun askConfirmDelete() {
val eventIds = selectedKeys.toMutableList()
val eventsToDelete = listItems.filter { selectedKeys.contains((it as? ListEvent)?.id) } as List<ListEvent>
val eventIds = selectedKeys.toMutableList().map { it.toLong() }
val eventsToDelete = listItems.filter { selectedKeys.contains((it as? ListEvent)?.id?.toInt()) } as List<ListEvent>
val timestamps = eventsToDelete.mapNotNull { (it as? ListEvent)?.startTS }
val hasRepeatableEvent = eventsToDelete.any { it.isRepeatable }

View File

@ -11,7 +11,7 @@ import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_delete_event.view.*
class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, hasRepeatableEvent: Boolean, val callback: (deleteRule: Int) -> Unit) {
class DeleteEventDialog(val activity: Activity, eventIds: List<Long>, hasRepeatableEvent: Boolean, val callback: (deleteRule: Int) -> Unit) {
val dialog: AlertDialog?
init {

View File

@ -15,7 +15,7 @@ import java.io.File
import java.util.TreeSet
import kotlin.collections.ArrayList
fun BaseSimpleActivity.shareEvents(ids: List<Int>) {
fun BaseSimpleActivity.shareEvents(ids: List<Long>) {
val file = getTempFile()
if (file == null) {
toast(R.string.unknown_error_occurred)

View File

@ -119,15 +119,15 @@ fun Context.scheduleEventIn(notifTS: Long, event: Event, activity: SimpleActivit
AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, newNotifTS, pendingIntent)
}
fun Context.cancelNotification(id: Int) {
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(id)
fun Context.cancelNotification(id: Long) {
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(id.toInt())
}
private fun getNotificationIntent(context: Context, event: Event): PendingIntent {
val intent = Intent(context, NotificationReceiver::class.java)
intent.putExtra(EVENT_ID, event.id)
intent.putExtra(EVENT_OCCURRENCE_TS, event.startTS)
return PendingIntent.getBroadcast(context, event.id!!, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getBroadcast(context, event.id!!.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
fun Context.getRepetitionText(seconds: Int) = when (seconds) {
@ -186,7 +186,7 @@ fun Context.notifyEvent(originalEvent: Event) {
val content = "$displayedStartDate $timeRange $descriptionOrLocation".trim()
val notification = getNotification(pendingIntent, event, content)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(event.id!!, notification)
notificationManager.notify(event.id!!.toInt(), notification)
}
@SuppressLint("NewApi")
@ -262,7 +262,7 @@ private fun getPendingIntent(context: Context, event: Event): PendingIntent {
val intent = Intent(context, EventActivity::class.java)
intent.putExtra(EVENT_ID, event.id)
intent.putExtra(EVENT_OCCURRENCE_TS, event.startTS)
return PendingIntent.getActivity(context, event.id!!, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getActivity(context, event.id!!.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
private fun getSnoozePendingIntent(context: Context, event: Event): PendingIntent {
@ -270,17 +270,16 @@ private fun getSnoozePendingIntent(context: Context, event: Event): PendingInten
val intent = Intent(context, snoozeClass).setAction("Snooze")
intent.putExtra(EVENT_ID, event.id)
return if (context.config.useSameSnooze) {
PendingIntent.getService(context, event.id!!, intent, PendingIntent.FLAG_UPDATE_CURRENT)
PendingIntent.getService(context, event.id!!.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
} else {
PendingIntent.getActivity(context, event.id!!, intent, PendingIntent.FLAG_UPDATE_CURRENT)
PendingIntent.getActivity(context, event.id!!.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
}
fun Context.rescheduleReminder(event: Event?, minutes: Int) {
if (event != null) {
applicationContext.scheduleEventIn(System.currentTimeMillis() + minutes * 60000, event)
val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.cancel(event.id!!)
cancelNotification(event.id!!)
}
}
@ -435,7 +434,7 @@ fun Context.getEventListItems(events: List<Event>): ArrayList<ListItem> {
return listItems
}
fun Context.handleEventDeleting(eventIds: List<Int>, timestamps: List<Int>, action: Int) {
fun Context.handleEventDeleting(eventIds: List<Long>, timestamps: List<Int>, action: Int) {
when (action) {
DELETE_SELECTED_OCCURRENCE -> {
eventIds.forEachIndexed { index, value ->

View File

@ -235,8 +235,8 @@ class CalDAVHandler(val context: Context) {
if (originalInstanceTime != 0L) {
val parentImportId = "$source-$originalId"
val parentEventId = context.dbHelper.getEventIdWithImportId(parentImportId)
if (parentEventId != 0) {
event.parentId = parentEventId.toLong()
if (parentEventId != 0L) {
event.parentId = parentEventId
context.dbHelper.addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt(), false, event.importId)
}
}

View File

@ -7,7 +7,6 @@ import android.database.sqlite.SQLiteDatabase
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
@ -114,7 +113,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
addEventType(eventType, db)
}
fun insert(event: Event, addToCalDAV: Boolean, activity: SimpleActivity? = null, callback: (id: Int) -> Unit) {
fun insert(event: Event, addToCalDAV: Boolean, activity: SimpleActivity? = null, callback: (id: Long) -> Unit) {
if (event.startTS > event.endTS) {
callback(0)
return
@ -122,7 +121,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val eventValues = fillEventValues(event)
val id = mDb.insert(MAIN_TABLE_NAME, null, eventValues)
event.id = id.toInt()
event.id = id
if (event.repeatInterval != 0 && event.parentId == 0L) {
val metaValues = fillMetaValues(event)
@ -149,7 +148,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val eventValues = fillEventValues(event)
val id = mDb.insert(MAIN_TABLE_NAME, null, eventValues)
event.id = id.toInt()
event.id = id
if (event.repeatInterval != 0 && event.parentId == 0L) {
val metaValues = fillMetaValues(event)
@ -262,7 +261,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
}
private fun fillExceptionValues(parentEventId: Int, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String?, callback: (values: ContentValues) -> Unit) {
private fun fillExceptionValues(parentEventId: Long, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String?, callback: (values: ContentValues) -> Unit) {
val childEvent = getEventWithId(parentEventId)
if (childEvent == null) {
callback(ContentValues())
@ -271,7 +270,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
childEvent.apply {
id = 0
parentId = parentEventId.toLong()
parentId = parentEventId
startTS = 0
endTS = 0
if (childImportId != null) {
@ -392,7 +391,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
context.updateWidgets()
ids.forEach {
context.cancelNotification(it.toInt())
context.cancelNotification(it.toLong())
}
if (deleteFromCalDAV && context.config.caldavSync) {
@ -432,7 +431,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return fillEvents(cursor).filter { it.importId.isNotEmpty() }
}
fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String? = null) {
fun addEventRepeatException(parentEventId: Long, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String? = null) {
fillExceptionValues(parentEventId, occurrenceTS, addToCalDAV, childImportId) {
mDb.insert(EXCEPTIONS_TABLE_NAME, null, it)
@ -443,7 +442,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
}
fun addEventRepeatLimit(eventId: Int, limitTS: Int) {
fun addEventRepeatLimit(eventId: Long, limitTS: Int) {
val values = ContentValues()
val time = Formatter.getDateTimeFromTS(limitTS)
values.put(COL_REPEAT_LIMIT, limitTS - time.hourOfDay)
@ -507,7 +506,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs)
}
fun updateEventImportIdAndSource(eventId: Int, importId: String, source: String) {
fun updateEventImportIdAndSource(eventId: Long, importId: String, source: String) {
val values = ContentValues()
values.put(COL_IMPORT_ID, importId)
values.put(COL_EVENT_SOURCE, source)
@ -519,7 +518,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
fun getEventsWithImportIds() = getEvents("").filter { it.importId.trim().isNotEmpty() } as ArrayList<Event>
fun getEventWithId(id: Int): Event? {
fun getEventWithId(id: Long): Event? {
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
val selectionArgs = arrayOf(id.toString())
val cursor = getEventsCursor(selection, selectionArgs)
@ -531,27 +530,27 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
}
fun getEventIdWithImportId(id: String): Int {
fun getEventIdWithImportId(id: String): Long {
val selection = "$MAIN_TABLE_NAME.$COL_IMPORT_ID = ?"
val selectionArgs = arrayOf(id)
val cursor = getEventsCursor(selection, selectionArgs)
val events = fillEvents(cursor)
return if (events.isNotEmpty()) {
events.minBy { it.id!! }?.id ?: 0
events.minBy { it.id!! }?.id ?: 0L
} else {
0
0L
}
}
fun getEventIdWithLastImportId(id: String): Int {
fun getEventIdWithLastImportId(id: String): Long {
val selection = "$MAIN_TABLE_NAME.$COL_IMPORT_ID LIKE ?"
val selectionArgs = arrayOf("%-$id")
val cursor = getEventsCursor(selection, selectionArgs)
val events = fillEvents(cursor)
return if (events.isNotEmpty()) {
events.minBy { it.id!! }?.id ?: 0
events.minBy { it.id!! }?.id ?: 0L
} else {
0
0L
}
}
@ -569,18 +568,19 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}.start()
}
fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, applyTypeFilter: Boolean = false, callback: (events: ArrayList<Event>) -> Unit) {
fun getEvents(fromTS: Int, toTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean = false, callback: (events: ArrayList<Event>) -> Unit) {
Thread {
getEventsInBackground(fromTS, toTS, eventId, applyTypeFilter, callback)
}.start()
}
fun getEventsInBackground(fromTS: Int, toTS: Int, eventId: Int = -1, applyTypeFilter: Boolean, callback: (events: ArrayList<Event>) -> Unit) {
fun getEventsInBackground(fromTS: Int, toTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean, callback: (events: ArrayList<Event>) -> Unit) {
var events = ArrayList<Event>()
var selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS NULL AND $COL_START_TS != 0"
if (eventId != -1)
if (eventId != -1L) {
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
}
if (applyTypeFilter) {
val displayEventTypes = context.config.displayEventTypes
@ -606,11 +606,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
callback(events)
}
fun getRepeatableEventsFor(fromTS: Int, toTS: Int, eventId: Int = -1, applyTypeFilter: Boolean = false): List<Event> {
fun getRepeatableEventsFor(fromTS: Int, toTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean = false): List<Event> {
val newEvents = ArrayList<Event>()
var selection = "$COL_REPEAT_INTERVAL != 0 AND $COL_START_TS <= $toTS AND $COL_START_TS != 0"
if (eventId != -1)
if (eventId != -1L)
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
if (applyTypeFilter) {
@ -622,7 +622,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
val events = getEvents(selection)
val startTimes = SparseIntArray(events.size)
val startTimes = LongSparseArray<Int>()
events.forEach {
startTimes.put(it.id!!, it.startTS)
if (it.repeatLimit >= 0) {
@ -635,7 +635,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return newEvents
}
private fun getEventsRepeatingTillDateOrForever(fromTS: Int, toTS: Int, startTimes: SparseIntArray, event: Event): ArrayList<Event> {
private fun getEventsRepeatingTillDateOrForever(fromTS: Int, toTS: Int, startTimes: LongSparseArray<Int>, event: Event): ArrayList<Event> {
val original = event.copy()
val events = ArrayList<Event>()
while (event.startTS <= toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) {
@ -671,7 +671,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return events
}
private fun getEventsRepeatingXTimes(fromTS: Int, toTS: Int, startTimes: SparseIntArray, event: Event): ArrayList<Event> {
private fun getEventsRepeatingXTimes(fromTS: Int, toTS: Int, startTimes: LongSparseArray<Int>, event: Event): ArrayList<Event> {
val original = event.copy()
val events = ArrayList<Event>()
while (event.repeatLimit < 0 && event.startTS <= toTS) {
@ -701,10 +701,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return events
}
private fun getAllDayEvents(fromTS: Int, eventId: Int = -1, applyTypeFilter: Boolean = false): List<Event> {
private fun getAllDayEvents(fromTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean = false): List<Event> {
val events = ArrayList<Event>()
var selection = "($COL_FLAGS & $FLAG_ALL_DAY) != 0"
if (eventId != -1)
if (eventId != -1L)
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
if (applyTypeFilter) {
@ -722,8 +722,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
// check if its the proper week, for events repeating every x weeks
private fun isOnProperWeek(event: Event, startTimes: SparseIntArray): Boolean {
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id!!]).weekOfWeekyear
private fun isOnProperWeek(event: Event, startTimes: LongSparseArray<Int>): Boolean {
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id!!]!!).weekOfWeekyear
val currentWeekOfYear = Formatter.getDateTimeFromTS(event.startTS).weekOfWeekyear
return (currentWeekOfYear - initialWeekOfYear) % (event.repeatInterval / WEEK) == 0
}
@ -757,7 +757,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return events
}
fun getEventsWithIds(ids: List<Int>): ArrayList<Event> {
fun getEventsWithIds(ids: List<Long>): ArrayList<Event> {
val args = TextUtils.join(", ", ids)
val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)"
return getEvents(selection) as ArrayList<Event>
@ -825,7 +825,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
cursor?.use {
if (cursor.moveToFirst()) {
do {
val id = cursor.getIntValue(COL_ID)
val id = cursor.getLongValue(COL_ID)
val startTS = cursor.getIntValue(COL_START_TS)
val endTS = cursor.getIntValue(COL_END_TS)
val reminder1Minutes = cursor.getIntValue(COL_REMINDER_MINUTES)
@ -914,7 +914,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
}
private fun getIgnoredOccurrences(eventId: Int): ArrayList<Int> {
private fun getIgnoredOccurrences(eventId: Long): ArrayList<Int> {
val projection = arrayOf(COL_OCCURRENCE_DAYCODE)
val selection = "$COL_PARENT_EVENT_ID = ?"
val selectionArgs = arrayOf(eventId.toString())

View File

@ -7,7 +7,7 @@ import org.joda.time.DateTime
import java.io.Serializable
import java.util.*
data class Event(var id: Int?, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
data class Event(var id: Long?, 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: Long = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = ArrayList(),

View File

@ -1,4 +1,4 @@
package com.simplemobiletools.calendar.pro.models
data class ListEvent(var id: Int, var startTS: Int, var endTS: Int, var title: String, var description: String, var isAllDay: Boolean, var color: Int,
data class ListEvent(var id: Long, var startTS: Int, var endTS: Int, var title: String, var description: String, var isAllDay: Boolean, var color: Int,
var location: String, var isPastEvent: Boolean, var isRepeatable: Boolean) : ListItem()

View File

@ -1,4 +1,4 @@
package com.simplemobiletools.calendar.pro.models
data class MonthViewEvent(val id: Int, val title: String, val startTS: Int, val color: Int, val startDayIndex: Int, val daysCnt: Int, val originalStartDayIndex: Int,
data class MonthViewEvent(val id: Long, val title: String, val startTS: Int, val color: Int, val startDayIndex: Int, val daysCnt: Int, val originalStartDayIndex: Int,
val isAllDay: Boolean, val isPastEvent: Boolean)

View File

@ -23,8 +23,8 @@ class NotificationReceiver : BroadcastReceiver() {
}
private fun handleIntent(context: Context, intent: Intent) {
val id = intent.getIntExtra(EVENT_ID, -1)
if (id == -1) {
val id = intent.getLongExtra(EVENT_ID, -1L)
if (id == -1L) {
return
}

View File

@ -9,7 +9,7 @@ import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
class SnoozeService : IntentService("Snooze") {
override fun onHandleIntent(intent: Intent) {
val eventId = intent.getIntExtra(EVENT_ID, 0)
val eventId = intent.getLongExtra(EVENT_ID, 0L)
val event = dbHelper.getEventWithId(eventId)
rescheduleReminder(event, config.snoozeTime)
}