converting some timestamp related fields from int to long
This commit is contained in:
parent
71e066ae15
commit
847db07d66
|
@ -45,11 +45,11 @@ class EventActivity : SimpleActivity() {
|
|||
private var mReminder2Minutes = 0
|
||||
private var mReminder3Minutes = 0
|
||||
private var mRepeatInterval = 0
|
||||
private var mRepeatLimit = 0
|
||||
private var mRepeatLimit = 0L
|
||||
private var mRepeatRule = 0
|
||||
private var mEventTypeId = REGULAR_EVENT_TYPE_ID
|
||||
private var mDialogTheme = 0
|
||||
private var mEventOccurrenceTS = 0
|
||||
private var mEventOccurrenceTS = 0L
|
||||
private var mEventCalendarId = STORED_LOCALLY_ONLY
|
||||
private var wasActivityInitialized = false
|
||||
|
||||
|
@ -89,7 +89,7 @@ class EventActivity : SimpleActivity() {
|
|||
|
||||
if (event != null) {
|
||||
mEvent = event
|
||||
mEventOccurrenceTS = intent.getIntExtra(EVENT_OCCURRENCE_TS, 0)
|
||||
mEventOccurrenceTS = intent.getLongExtra(EVENT_OCCURRENCE_TS, 0L)
|
||||
if (savedInstanceState == null) {
|
||||
setupEditEvent()
|
||||
}
|
||||
|
@ -178,16 +178,16 @@ class EventActivity : SimpleActivity() {
|
|||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putInt(START_TS, mEventStartDateTime.seconds())
|
||||
outState.putInt(END_TS, mEventEndDateTime.seconds())
|
||||
outState.putLong(START_TS, mEventStartDateTime.seconds())
|
||||
outState.putLong(END_TS, mEventEndDateTime.seconds())
|
||||
|
||||
outState.putInt(REMINDER_1_MINUTES, mReminder1Minutes)
|
||||
outState.putInt(REMINDER_2_MINUTES, mReminder2Minutes)
|
||||
outState.putInt(REMINDER_3_MINUTES, mReminder3Minutes)
|
||||
|
||||
outState.putInt(REPEAT_INTERVAL, mRepeatInterval)
|
||||
outState.putInt(REPEAT_LIMIT, mRepeatLimit)
|
||||
outState.putInt(REPEAT_RULE, mRepeatRule)
|
||||
outState.putLong(REPEAT_LIMIT, mRepeatLimit)
|
||||
|
||||
outState.putLong(EVENT_TYPE_ID, mEventTypeId)
|
||||
outState.putInt(EVENT_CALENDAR_ID, mEventCalendarId)
|
||||
|
@ -196,16 +196,16 @@ class EventActivity : SimpleActivity() {
|
|||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
savedInstanceState.apply {
|
||||
mEventStartDateTime = Formatter.getDateTimeFromTS(getInt(START_TS))
|
||||
mEventEndDateTime = Formatter.getDateTimeFromTS(getInt(END_TS))
|
||||
mEventStartDateTime = Formatter.getDateTimeFromTS(getLong(START_TS))
|
||||
mEventEndDateTime = Formatter.getDateTimeFromTS(getLong(END_TS))
|
||||
|
||||
mReminder1Minutes = getInt(REMINDER_1_MINUTES)
|
||||
mReminder2Minutes = getInt(REMINDER_2_MINUTES)
|
||||
mReminder3Minutes = getInt(REMINDER_3_MINUTES)
|
||||
|
||||
mRepeatInterval = getInt(REPEAT_INTERVAL)
|
||||
mRepeatLimit = getInt(REPEAT_LIMIT)
|
||||
mRepeatRule = getInt(REPEAT_RULE)
|
||||
mRepeatLimit = getLong(REPEAT_LIMIT)
|
||||
|
||||
mEventTypeId = getLong(EVENT_TYPE_ID)
|
||||
mEventCalendarId = getInt(EVENT_CALENDAR_ID)
|
||||
|
@ -226,7 +226,7 @@ class EventActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupEditEvent() {
|
||||
val realStart = if (mEventOccurrenceTS == 0) mEvent.startTS else mEventOccurrenceTS
|
||||
val realStart = if (mEventOccurrenceTS == 0L) mEvent.startTS else mEventOccurrenceTS
|
||||
val duration = mEvent.endTS - mEvent.startTS
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
||||
updateActionBarTitle(getString(R.string.edit_event))
|
||||
|
@ -255,10 +255,10 @@ class EventActivity : SimpleActivity() {
|
|||
mEventCalendarId = if (isLastCaldavCalendarOK) config.lastUsedCaldavCalendarId else STORED_LOCALLY_ONLY
|
||||
|
||||
if (intent.action == Intent.ACTION_EDIT || intent.action == Intent.ACTION_INSERT) {
|
||||
val startTS = (intent.getLongExtra("beginTime", System.currentTimeMillis()) / 1000).toInt()
|
||||
val startTS = intent.getLongExtra("beginTime", System.currentTimeMillis()) / 1000L
|
||||
mEventStartDateTime = Formatter.getDateTimeFromTS(startTS)
|
||||
|
||||
val endTS = (intent.getLongExtra("endTime", System.currentTimeMillis()) / 1000).toInt()
|
||||
val endTS = intent.getLongExtra("endTime", System.currentTimeMillis()) / 1000L
|
||||
mEventEndDateTime = Formatter.getDateTimeFromTS(endTS)
|
||||
|
||||
event_title.setText(intent.getStringExtra("title"))
|
||||
|
@ -268,7 +268,7 @@ class EventActivity : SimpleActivity() {
|
|||
event_description.movementMethod = LinkMovementMethod.getInstance()
|
||||
}
|
||||
} else {
|
||||
val startTS = intent.getIntExtra(NEW_EVENT_START_TS, 0)
|
||||
val startTS = intent.getLongExtra(NEW_EVENT_START_TS, 0L)
|
||||
val dateTime = Formatter.getDateTimeFromTS(startTS)
|
||||
mEventStartDateTime = dateTime
|
||||
|
||||
|
@ -341,14 +341,14 @@ class EventActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setRepeatLimit(limit: Int) {
|
||||
private fun setRepeatLimit(limit: Long) {
|
||||
mRepeatLimit = limit
|
||||
checkRepetitionLimitText()
|
||||
}
|
||||
|
||||
private fun checkRepetitionLimitText() {
|
||||
event_repetition_limit.text = when {
|
||||
mRepeatLimit == 0 -> {
|
||||
mRepeatLimit == 0L -> {
|
||||
event_repetition_limit_label.text = getString(R.string.repeat)
|
||||
resources.getString(R.string.forever)
|
||||
}
|
||||
|
@ -946,7 +946,7 @@ class EventActivity : SimpleActivity() {
|
|||
updateStartDateText()
|
||||
checkRepeatRule()
|
||||
|
||||
mEventEndDateTime = mEventStartDateTime.plusSeconds(diff)
|
||||
mEventEndDateTime = mEventStartDateTime.plusSeconds(diff.toInt())
|
||||
updateEndTexts()
|
||||
} else {
|
||||
mEventEndDateTime = mEventEndDateTime.withDate(year, month + 1, day)
|
||||
|
@ -961,7 +961,7 @@ class EventActivity : SimpleActivity() {
|
|||
mEventStartDateTime = mEventStartDateTime.withHourOfDay(hours).withMinuteOfHour(minutes)
|
||||
updateStartTimeText()
|
||||
|
||||
mEventEndDateTime = mEventStartDateTime.plusSeconds(diff)
|
||||
mEventEndDateTime = mEventStartDateTime.plusSeconds(diff.toInt())
|
||||
updateEndTexts()
|
||||
} else {
|
||||
mEventEndDateTime = mEventEndDateTime.withHourOfDay(hours).withMinuteOfHour(minutes)
|
||||
|
|
|
@ -498,10 +498,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
date.year = 70
|
||||
}
|
||||
|
||||
val timestamp = (date.time / 1000).toInt()
|
||||
val timestamp = date.time / 1000L
|
||||
val source = if (birthdays) SOURCE_CONTACT_BIRTHDAY else SOURCE_CONTACT_ANNIVERSARY
|
||||
val lastUpdated = cursor.getLongValue(ContactsContract.CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP)
|
||||
val event = Event(0, timestamp, timestamp, name, importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR,
|
||||
val event = Event(null, timestamp, timestamp, name, importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR,
|
||||
eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
|
||||
|
||||
if (!importIDs.contains(contactId)) {
|
||||
|
@ -775,7 +775,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
}
|
||||
|
||||
private fun openDayAt(timestamp: Long) {
|
||||
val dayCode = Formatter.getDayCodeFromTS((timestamp / 1000).toInt())
|
||||
val dayCode = Formatter.getDayCodeFromTS(timestamp / 1000L)
|
||||
calendar_fab.beVisible()
|
||||
config.storedView = DAILY_VIEW
|
||||
updateViewPager(dayCode)
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.simplemobiletools.calendar.pro.R
|
|||
import com.simplemobiletools.calendar.pro.R.id.event_item_holder
|
||||
import com.simplemobiletools.calendar.pro.R.id.event_section_title
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||
import com.simplemobiletools.calendar.pro.helpers.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
|
@ -156,7 +156,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
|||
mediumFontSize = context.config.getFontSize()
|
||||
val fromTS = DateTime().seconds() - context.config.displayPastEvents * 60
|
||||
val toTS = DateTime().plusYears(1).seconds()
|
||||
context.dbHelper.getEventsInBackground(fromTS, toTS, applyTypeFilter = true) {
|
||||
context.eventsHelper.getEventsSync(fromTS, toTS, applyTypeFilter = true) {
|
||||
val listItems = ArrayList<ListItem>(it.size)
|
||||
val replaceDescription = context.config.replaceDescription
|
||||
val sorted = it.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.simplemobiletools.calendar.pro.fragments.WeekFragment
|
|||
import com.simplemobiletools.calendar.pro.helpers.WEEK_START_TIMESTAMP
|
||||
import com.simplemobiletools.calendar.pro.interfaces.WeekFragmentListener
|
||||
|
||||
class MyWeekPagerAdapter(fm: FragmentManager, val mWeekTimestamps: List<Int>, val mListener: WeekFragmentListener) : FragmentStatePagerAdapter(fm) {
|
||||
class MyWeekPagerAdapter(fm: FragmentManager, val mWeekTimestamps: List<Long>, val mListener: WeekFragmentListener) : FragmentStatePagerAdapter(fm) {
|
||||
private val mFragments = SparseArray<WeekFragment>()
|
||||
|
||||
override fun getCount() = mWeekTimestamps.size
|
||||
|
@ -17,7 +17,7 @@ class MyWeekPagerAdapter(fm: FragmentManager, val mWeekTimestamps: List<Int>, va
|
|||
override fun getItem(position: Int): Fragment {
|
||||
val bundle = Bundle()
|
||||
val weekTimestamp = mWeekTimestamps[position]
|
||||
bundle.putInt(WEEK_START_TIMESTAMP, weekTimestamp)
|
||||
bundle.putLong(WEEK_START_TIMESTAMP, weekTimestamp)
|
||||
|
||||
val fragment = WeekFragment()
|
||||
fragment.arguments = bundle
|
||||
|
|
|
@ -16,7 +16,7 @@ import kotlinx.android.synthetic.main.dialog_repeat_limit_type_picker.view.*
|
|||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int, val startTS: Int, val callback: (repeatLimit: Int) -> Unit) {
|
||||
class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Long, val startTS: Long, val callback: (repeatLimit: Long) -> Unit) {
|
||||
lateinit var dialog: AlertDialog
|
||||
var view: View
|
||||
|
||||
|
@ -76,14 +76,14 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int,
|
|||
} else {
|
||||
"-$count"
|
||||
}
|
||||
callback(count.toInt())
|
||||
callback(count.toLong())
|
||||
}
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
private fun showRepetitionLimitDialog() {
|
||||
val repeatLimitDateTime = Formatter.getDateTimeFromTS(if (repeatLimit != 0) repeatLimit else getNowSeconds())
|
||||
val repeatLimitDateTime = Formatter.getDateTimeFromTS(if (repeatLimit != 0L) repeatLimit else getNowSeconds())
|
||||
val datepicker = DatePickerDialog(activity, activity.getDialogTheme(), repetitionLimitDateSetListener, repeatLimitDateTime.year,
|
||||
repeatLimitDateTime.monthOfYear - 1, repeatLimitDateTime.dayOfMonth)
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ fun Context.scheduleNextEventReminder(event: Event, dbHelper: DBHelper, activity
|
|||
|
||||
val now = getNowSeconds()
|
||||
val reminderSeconds = event.getReminders().reversed().map { it * 60 }
|
||||
dbHelper.getEvents(now, now + YEAR, event.id!!, false) {
|
||||
eventsHelper.getEvents(now, now + YEAR, event.id!!, false) {
|
||||
if (it.isNotEmpty()) {
|
||||
for (curEvent in it) {
|
||||
for (curReminder in reminderSeconds) {
|
||||
|
@ -300,7 +300,7 @@ fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode()) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.getNewEventTimestampFromCode(dayCode: String): Int {
|
||||
fun Context.getNewEventTimestampFromCode(dayCode: String): Long {
|
||||
val currHour = DateTime(System.currentTimeMillis(), DateTimeZone.getDefault()).hourOfDay
|
||||
val dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour)
|
||||
val newDateTime = dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)
|
||||
|
@ -441,7 +441,7 @@ fun Context.getEventListItems(events: List<Event>): ArrayList<ListItem> {
|
|||
return listItems
|
||||
}
|
||||
|
||||
fun Context.handleEventDeleting(eventIds: List<Long>, timestamps: List<Int>, action: Int) {
|
||||
fun Context.handleEventDeleting(eventIds: List<Long>, timestamps: List<Long>, action: Int) {
|
||||
when (action) {
|
||||
DELETE_SELECTED_OCCURRENCE -> {
|
||||
eventIds.forEachIndexed { index, value ->
|
||||
|
|
|
@ -2,4 +2,4 @@ package com.simplemobiletools.calendar.pro.extensions
|
|||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
fun DateTime.seconds() = (millis / 1000).toInt()
|
||||
fun DateTime.seconds() = millis / 1000L
|
||||
|
|
|
@ -1,16 +1,8 @@
|
|||
package com.simplemobiletools.calendar.pro.extensions
|
||||
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.pro.helpers.MONTH
|
||||
import com.simplemobiletools.calendar.pro.helpers.WEEK
|
||||
import com.simplemobiletools.calendar.pro.helpers.YEAR
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
|
||||
fun Int.isTsOnProperDay(event: Event): Boolean {
|
||||
val dateTime = Formatter.getDateTimeFromTS(this)
|
||||
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
||||
return event.repeatRule and power != 0
|
||||
}
|
||||
|
||||
fun Int.isXWeeklyRepetition() = this != 0 && this % WEEK == 0
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package com.simplemobiletools.calendar.pro.extensions
|
||||
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
|
||||
fun Long.isTsOnProperDay(event: Event): Boolean {
|
||||
val dateTime = Formatter.getDateTimeFromTS(this)
|
||||
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
||||
return event.repeatRule and power != 0
|
||||
}
|
|
@ -14,7 +14,7 @@ import com.simplemobiletools.calendar.pro.activities.EventActivity
|
|||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.adapters.DayEventsAdapter
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.helpers.DAY_CODE
|
||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_OCCURRENCE_TS
|
||||
|
@ -105,7 +105,7 @@ class DayFragment : Fragment() {
|
|||
fun updateCalendar() {
|
||||
val startTS = Formatter.getDayStartTS(mDayCode)
|
||||
val endTS = Formatter.getDayEndTS(mDayCode)
|
||||
context?.dbHelper?.getEvents(startTS, endTS) {
|
||||
context?.eventsHelper?.getEvents(startTS, endTS) {
|
||||
receivedEvents(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||
private var MIN_EVENTS_TRESHOLD = 30
|
||||
|
||||
private var mEvents = ArrayList<Event>()
|
||||
private var minFetchedTS = 0
|
||||
private var maxFetchedTS = 0
|
||||
private var minFetchedTS = 0L
|
||||
private var maxFetchedTS = 0L
|
||||
private var wereInitialEventsAdded = false
|
||||
|
||||
private var use24HourFormat = false
|
||||
|
@ -76,7 +76,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||
maxFetchedTS = DateTime().plusMonths(6).seconds()
|
||||
}
|
||||
|
||||
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
||||
context!!.eventsHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
||||
if (it.size >= MIN_EVENTS_TRESHOLD) {
|
||||
receivedEvents(it, false)
|
||||
} else {
|
||||
|
@ -84,7 +84,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||
minFetchedTS -= FETCH_INTERVAL
|
||||
maxFetchedTS += FETCH_INTERVAL
|
||||
}
|
||||
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
||||
context!!.eventsHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
||||
mEvents = it
|
||||
receivedEvents(mEvents, false, !wereInitialEventsAdded)
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||
private fun fetchPreviousPeriod() {
|
||||
val oldMinFetchedTS = minFetchedTS - 1
|
||||
minFetchedTS -= FETCH_INTERVAL
|
||||
context!!.dbHelper.getEvents(minFetchedTS, oldMinFetchedTS) {
|
||||
context!!.eventsHelper.getEvents(minFetchedTS, oldMinFetchedTS) {
|
||||
mEvents.addAll(0, it)
|
||||
receivedEvents(mEvents, false)
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||
private fun fetchNextPeriod(scrollAfterUpdating: Boolean) {
|
||||
val oldMaxFetchedTS = maxFetchedTS + 1
|
||||
maxFetchedTS += FETCH_INTERVAL
|
||||
context!!.dbHelper.getEvents(oldMaxFetchedTS, maxFetchedTS) {
|
||||
context!!.eventsHelper.getEvents(oldMaxFetchedTS, maxFetchedTS) {
|
||||
mEvents.addAll(it)
|
||||
receivedEvents(mEvents, scrollAfterUpdating)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
private val PLUS_FADEOUT_DELAY = 5000L
|
||||
|
||||
var mListener: WeekFragmentListener? = null
|
||||
private var mWeekTimestamp = 0
|
||||
private var mWeekTimestamp = 0L
|
||||
private var mRowHeight = 0f
|
||||
private var minScrollY = -1
|
||||
private var maxScrollY = -1
|
||||
|
@ -75,7 +75,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
mConfig = context!!.config
|
||||
mRowHeight = mRes.getDimension(R.dimen.weekly_view_row_height)
|
||||
minScrollY = (mRowHeight * mConfig.startWeeklyAt).toInt()
|
||||
mWeekTimestamp = arguments!!.getInt(WEEK_START_TIMESTAMP)
|
||||
mWeekTimestamp = arguments!!.getLong(WEEK_START_TIMESTAMP)
|
||||
dimPastEvents = mConfig.dimPastEvents
|
||||
primaryColor = context!!.getAdjustedPrimaryColor()
|
||||
allDayRows.add(HashSet())
|
||||
|
|
|
@ -28,8 +28,8 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
|||
|
||||
private var weekHolder: ViewGroup? = null
|
||||
private var defaultWeeklyPage = 0
|
||||
private var thisWeekTS = 0
|
||||
private var currentWeekTS = 0
|
||||
private var thisWeekTS = 0L
|
||||
private var currentWeekTS = 0L
|
||||
private var isGoToTodayVisible = false
|
||||
private var weekScrollY = 0
|
||||
|
||||
|
@ -95,15 +95,15 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
|||
updateActionBarTitle()
|
||||
}
|
||||
|
||||
private fun getWeekTimestamps(targetSeconds: Int): List<Int> {
|
||||
val weekTSs = ArrayList<Int>(PREFILLED_WEEKS)
|
||||
private fun getWeekTimestamps(targetSeconds: Long): List<Long> {
|
||||
val weekTSs = ArrayList<Long>(PREFILLED_WEEKS)
|
||||
for (i in -PREFILLED_WEEKS / 2..PREFILLED_WEEKS / 2) {
|
||||
weekTSs.add(Formatter.getDateTimeFromTS(targetSeconds).plusWeeks(i).seconds())
|
||||
}
|
||||
return weekTSs
|
||||
}
|
||||
|
||||
private fun setupWeeklyActionbarTitle(timestamp: Int) {
|
||||
private fun setupWeeklyActionbarTitle(timestamp: Long) {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(timestamp)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(timestamp + WEEK_SECONDS)
|
||||
val startMonthName = Formatter.getMonthName(context!!, startDateTime.monthOfYear)
|
||||
|
|
|
@ -183,8 +183,8 @@ class CalDAVHelper(val context: Context) {
|
|||
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
||||
val title = cursor.getStringValue(CalendarContract.Events.TITLE) ?: ""
|
||||
val description = cursor.getStringValue(CalendarContract.Events.DESCRIPTION) ?: ""
|
||||
val startTS = (cursor.getLongValue(CalendarContract.Events.DTSTART) / 1000).toInt()
|
||||
var endTS = (cursor.getLongValue(CalendarContract.Events.DTEND) / 1000).toInt()
|
||||
val startTS = cursor.getLongValue(CalendarContract.Events.DTSTART) / 1000L
|
||||
var endTS = cursor.getLongValue(CalendarContract.Events.DTEND) / 1000L
|
||||
val allDay = cursor.getIntValue(CalendarContract.Events.ALL_DAY)
|
||||
val rrule = cursor.getStringValue(CalendarContract.Events.RRULE) ?: ""
|
||||
val location = cursor.getStringValue(CalendarContract.Events.EVENT_LOCATION) ?: ""
|
||||
|
@ -192,7 +192,7 @@ class CalDAVHelper(val context: Context) {
|
|||
val originalInstanceTime = cursor.getLongValue(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
|
||||
val reminders = getCalDAVEventReminders(id)
|
||||
|
||||
if (endTS == 0) {
|
||||
if (endTS == 0L) {
|
||||
val duration = cursor.getStringValue(CalendarContract.Events.DURATION) ?: ""
|
||||
endTS = startTS + Parser().parseDurationSeconds(duration)
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ class CalDAVHelper(val context: Context) {
|
|||
val parentEventId = context.eventsDB.getEventIdWithImportId(parentImportId)
|
||||
if (parentEventId != null) {
|
||||
event.parentId = parentEventId
|
||||
eventsHelper.addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt(), false, event.importId)
|
||||
eventsHelper.addEventRepeatException(parentEventId, originalInstanceTime / 1000L, false, event.importId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ class CalDAVHelper(val context: Context) {
|
|||
val dur = Math.max(1, (event.endTS - event.startTS) / DAY)
|
||||
"P${dur}D"
|
||||
} else {
|
||||
Parser().getDurationCode((event.endTS - event.startTS) / 60)
|
||||
Parser().getDurationCode((event.endTS - event.startTS) / 60L)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,7 +373,7 @@ class CalDAVHelper(val context: Context) {
|
|||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun insertEventRepeatException(event: Event, occurrenceTS: Int): Long {
|
||||
fun insertEventRepeatException(event: Event, occurrenceTS: Long): Long {
|
||||
val uri = CalendarContract.Events.CONTENT_URI
|
||||
val values = fillEventRepeatExceptionValues(event, occurrenceTS)
|
||||
val newUri = context.contentResolver.insert(uri, values)
|
||||
|
@ -381,7 +381,7 @@ class CalDAVHelper(val context: Context) {
|
|||
return java.lang.Long.parseLong(newUri.lastPathSegment)
|
||||
}
|
||||
|
||||
private fun fillEventRepeatExceptionValues(event: Event, occurrenceTS: Int): ContentValues {
|
||||
private fun fillEventRepeatExceptionValues(event: Event, occurrenceTS: Long): ContentValues {
|
||||
return ContentValues().apply {
|
||||
put(CalendarContract.Events.CALENDAR_ID, event.getCalDAVCalendarId())
|
||||
put(CalendarContract.Events.DTSTART, occurrenceTS)
|
||||
|
|
|
@ -143,4 +143,4 @@ const val DELETE_SELECTED_OCCURRENCE = 0
|
|||
const val DELETE_FUTURE_OCCURRENCES = 1
|
||||
const val DELETE_ALL_OCCURRENCES = 2
|
||||
|
||||
fun getNowSeconds() = (System.currentTimeMillis() / 1000).toInt()
|
||||
fun getNowSeconds() = System.currentTimeMillis() / 1000L
|
||||
|
|
|
@ -55,49 +55,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
|
||||
|
||||
fun getEvents(fromTS: Int, toTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean = true, callback: (events: ArrayList<Event>) -> Unit) {
|
||||
Thread {
|
||||
getEventsInBackground(fromTS, toTS, eventId, applyTypeFilter, callback)
|
||||
}.start()
|
||||
}
|
||||
|
||||
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"
|
||||
var selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_START_TS != 0"
|
||||
if (eventId != -1L) {
|
||||
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
|
||||
}
|
||||
|
||||
if (applyTypeFilter) {
|
||||
val displayEventTypes = context.config.displayEventTypes
|
||||
if (displayEventTypes.isEmpty()) {
|
||||
callback(ArrayList())
|
||||
return
|
||||
} else {
|
||||
val types = TextUtils.join(",", displayEventTypes)
|
||||
selection += " AND $COL_EVENT_TYPE IN ($types)"
|
||||
}
|
||||
}
|
||||
|
||||
val selectionArgs = arrayOf(toTS.toString(), fromTS.toString())
|
||||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
events.addAll(fillEvents(cursor))
|
||||
|
||||
//events.addAll(getRepeatableEventsFor(fromTS, toTS, eventId, applyTypeFilter))
|
||||
|
||||
events.addAll(getAllDayEvents(fromTS, eventId, applyTypeFilter))
|
||||
|
||||
events = events
|
||||
.asSequence()
|
||||
.distinct()
|
||||
.filterNot { context.eventsHelper.getEventRepetitionIgnoredOccurrences(it).contains(Formatter.getDayCodeFromTS(it.startTS)) }
|
||||
.toMutableList() as ArrayList<Event>
|
||||
callback(events)
|
||||
}
|
||||
|
||||
fun getRepeatableEventsFor(fromTS: Int, toTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean = false): List<Event> {
|
||||
fun getRepeatableEventsFor(fromTS: Long, toTS: Long, 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"
|
||||
var selection = "$COL_START_TS <= $toTS AND $COL_START_TS != 0"
|
||||
|
@ -115,7 +73,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
val events = getEvents(selection)
|
||||
val startTimes = LongSparseArray<Int>()
|
||||
val startTimes = LongSparseArray<Long>()
|
||||
events.forEach {
|
||||
startTimes.put(it.id!!, it.startTS)
|
||||
if (it.repeatLimit >= 0) {
|
||||
|
@ -128,10 +86,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return newEvents
|
||||
}
|
||||
|
||||
private fun getEventsRepeatingTillDateOrForever(fromTS: Int, toTS: Int, startTimes: LongSparseArray<Int>, event: Event): ArrayList<Event> {
|
||||
private fun getEventsRepeatingTillDateOrForever(fromTS: Long, toTS: Long, startTimes: LongSparseArray<Long>, event: Event): ArrayList<Event> {
|
||||
val original = event.copy()
|
||||
val events = ArrayList<Event>()
|
||||
while (event.startTS <= toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) {
|
||||
while (event.startTS <= toTS && (event.repeatLimit == 0L || event.repeatLimit >= event.startTS)) {
|
||||
if (event.endTS >= fromTS) {
|
||||
if (event.repeatInterval.isXWeeklyRepetition()) {
|
||||
if (event.startTS.isTsOnProperDay(event)) {
|
||||
|
@ -180,7 +138,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return events
|
||||
}
|
||||
|
||||
private fun getEventsRepeatingXTimes(fromTS: Int, toTS: Int, startTimes: LongSparseArray<Int>, event: Event): ArrayList<Event> {
|
||||
private fun getEventsRepeatingXTimes(fromTS: Long, toTS: Long, startTimes: LongSparseArray<Long>, event: Event): ArrayList<Event> {
|
||||
val original = event.copy()
|
||||
val events = ArrayList<Event>()
|
||||
while (event.repeatLimit < 0 && event.startTS <= toTS) {
|
||||
|
@ -222,7 +180,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return events
|
||||
}
|
||||
|
||||
private fun getAllDayEvents(fromTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean = false): List<Event> {
|
||||
private fun getAllDayEvents(fromTS: Long, eventId: Long = -1L, applyTypeFilter: Boolean = false): List<Event> {
|
||||
val events = ArrayList<Event>()
|
||||
var selection = "($COL_FLAGS & $FLAG_ALL_DAY) != 0"
|
||||
if (eventId != -1L)
|
||||
|
@ -326,14 +284,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
val id = cursor.getLongValue(COL_ID)
|
||||
val startTS = cursor.getIntValue(COL_START_TS)
|
||||
val endTS = cursor.getIntValue(COL_END_TS)
|
||||
val startTS = cursor.getLongValue(COL_START_TS)
|
||||
val endTS = cursor.getLongValue(COL_END_TS)
|
||||
val reminder1Minutes = cursor.getIntValue(COL_REMINDER_MINUTES)
|
||||
val reminder2Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_2)
|
||||
val reminder3Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_3)
|
||||
val repeatInterval = 0
|
||||
var repeatRule = 0
|
||||
val repeatLimit = 0
|
||||
val repeatLimit = 0L
|
||||
val title = cursor.getStringValue(COL_TITLE)
|
||||
val location = cursor.getStringValue(COL_LOCATION)
|
||||
val description = cursor.getStringValue(COL_DESCRIPTION)
|
||||
|
|
|
@ -181,7 +181,7 @@ class EventsHelper(val context: Context) {
|
|||
deleteEvents(eventIds, true)
|
||||
}
|
||||
|
||||
fun addEventRepeatLimit(eventId: Long, limitTS: Int) {
|
||||
fun addEventRepeatLimit(eventId: Long, limitTS: Long) {
|
||||
val time = Formatter.getDateTimeFromTS(limitTS)
|
||||
eventRepetitionsDB.updateEventRepetitionLimit(limitTS - time.hourOfDay, eventId)
|
||||
|
||||
|
@ -212,7 +212,7 @@ class EventsHelper(val context: Context) {
|
|||
}.start()
|
||||
}
|
||||
|
||||
fun addEventRepeatException(parentEventId: Long, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String? = null) {
|
||||
fun addEventRepeatException(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean, childImportId: String? = null) {
|
||||
fillExceptionValues(parentEventId, occurrenceTS, addToCalDAV, childImportId) {
|
||||
context.eventRepetitionExceptionsDB.insert(it)
|
||||
|
||||
|
@ -223,7 +223,7 @@ class EventsHelper(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun fillExceptionValues(parentEventId: Long, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String?, callback: (eventRepetitionException: EventRepetitionException) -> Unit) {
|
||||
private fun fillExceptionValues(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean, childImportId: String?, callback: (eventRepetitionException: EventRepetitionException) -> Unit) {
|
||||
val childEvent = eventsDB.getEventWithId(parentEventId) ?: return
|
||||
|
||||
childEvent.apply {
|
||||
|
@ -253,4 +253,46 @@ class EventsHelper(val context: Context) {
|
|||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun getEvents(fromTS: Long, toTS: Long, eventId: Long = -1L, applyTypeFilter: Boolean = true, callback: (events: ArrayList<Event>) -> Unit) {
|
||||
Thread {
|
||||
getEventsSync(fromTS, toTS, eventId, applyTypeFilter, callback)
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun getEventsSync(fromTS: Long, toTS: Long, 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"
|
||||
var selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_START_TS != 0"
|
||||
if (eventId != -1L) {
|
||||
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
|
||||
}
|
||||
|
||||
if (applyTypeFilter) {
|
||||
val displayEventTypes = context.config.displayEventTypes
|
||||
if (displayEventTypes.isEmpty()) {
|
||||
callback(ArrayList())
|
||||
return
|
||||
} else {
|
||||
val types = TextUtils.join(",", displayEventTypes)
|
||||
selection += " AND $COL_EVENT_TYPE IN ($types)"
|
||||
}
|
||||
}
|
||||
|
||||
val selectionArgs = arrayOf(toTS.toString(), fromTS.toString())
|
||||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
events.addAll(fillEvents(cursor))
|
||||
|
||||
events.addAll(getRepeatableEventsFor(fromTS, toTS, eventId, applyTypeFilter))
|
||||
|
||||
events.addAll(getAllDayEvents(fromTS, eventId, applyTypeFilter))
|
||||
|
||||
events = events
|
||||
.asSequence()
|
||||
.distinct()
|
||||
.filterNot { context.eventsHelper.getEventRepetitionIgnoredOccurrences(it).contains(Formatter.getDayCodeFromTS(it.startTS)) }
|
||||
.toMutableList() as ArrayList<Event>
|
||||
callback(events)*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ object Formatter {
|
|||
date
|
||||
}
|
||||
|
||||
fun getLongestDate(ts: Int) = getDateTimeFromTS(ts).toString(LONGEST_PATTERN)
|
||||
fun getLongestDate(ts: Long) = getDateTimeFromTS(ts).toString(LONGEST_PATTERN)
|
||||
|
||||
fun getDate(context: Context, dateTime: DateTime, addDayOfWeek: Boolean = true) = getDayTitle(context, getDayCodeFromDateTime(dateTime), addDayOfWeek)
|
||||
|
||||
|
@ -68,7 +68,7 @@ object Formatter {
|
|||
|
||||
fun getLocalDateTimeFromCode(dayCode: String) = DateTimeFormat.forPattern(DAYCODE_PATTERN).withZone(DateTimeZone.getDefault()).parseLocalDate(dayCode).toDateTimeAtStartOfDay()
|
||||
|
||||
fun getTimeFromTS(context: Context, ts: Int) = getTime(context, getDateTimeFromTS(ts))
|
||||
fun getTimeFromTS(context: Context, ts: Long) = getTime(context, getDateTimeFromTS(ts))
|
||||
|
||||
fun getDayStartTS(dayCode: String) = getLocalDateTimeFromCode(dayCode).seconds()
|
||||
|
||||
|
@ -76,11 +76,11 @@ object Formatter {
|
|||
|
||||
fun getDayCodeFromDateTime(dateTime: DateTime) = dateTime.toString(DAYCODE_PATTERN)
|
||||
|
||||
fun getDateFromTS(ts: Int) = LocalDate(ts * 1000L, DateTimeZone.getDefault())
|
||||
fun getDateFromTS(ts: Long) = LocalDate(ts * 1000L, DateTimeZone.getDefault())
|
||||
|
||||
fun getDateTimeFromTS(ts: Int) = DateTime(ts * 1000L, DateTimeZone.getDefault())
|
||||
fun getDateTimeFromTS(ts: Long) = DateTime(ts * 1000L, DateTimeZone.getDefault())
|
||||
|
||||
fun getUTCDateTimeFromTS(ts: Int) = DateTime(ts * 1000L, DateTimeZone.UTC)
|
||||
fun getUTCDateTimeFromTS(ts: Long) = DateTime(ts * 1000L, DateTimeZone.UTC)
|
||||
|
||||
// use manually translated month names, as DateFormat and Joda have issues with a lot of languages
|
||||
fun getMonthName(context: Context, id: Int) = context.resources.getStringArray(R.array.months)[id - 1]
|
||||
|
@ -94,7 +94,7 @@ object Formatter {
|
|||
return "${dateTime.toString(DAYCODE_PATTERN)}T${dateTime.toString(TIME_PATTERN)}Z"
|
||||
}
|
||||
|
||||
fun getDayCodeFromTS(ts: Int): String {
|
||||
fun getDayCodeFromTS(ts: Long): String {
|
||||
val daycode = getDateTimeFromTS(ts).toString(DAYCODE_PATTERN)
|
||||
return if (daycode.isNotEmpty()) {
|
||||
daycode
|
||||
|
@ -103,5 +103,5 @@ object Formatter {
|
|||
}
|
||||
}
|
||||
|
||||
fun getShiftedImportTimestamp(ts: Int) = getUTCDateTimeFromTS(ts).withTime(13, 0, 0, 0).withZoneRetainFields(DateTimeZone.getDefault()).seconds()
|
||||
fun getShiftedImportTimestamp(ts: Long) = getUTCDateTimeFromTS(ts).withTime(13, 0, 0, 0).withZoneRetainFields(DateTimeZone.getDefault()).seconds()
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ class IcsExporter {
|
|||
out.apply {
|
||||
writeLn(BEGIN_ALARM)
|
||||
writeLn("$ACTION$DISPLAY")
|
||||
writeLn("$TRIGGER-${Parser().getDurationCode(minutes)}")
|
||||
writeLn("$TRIGGER-${Parser().getDurationCode(minutes.toLong())}")
|
||||
writeLn(END_ALARM)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,17 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL
|
||||
}
|
||||
|
||||
private var curStart = -1
|
||||
private var curEnd = -1
|
||||
private var curStart = -1L
|
||||
private var curEnd = -1L
|
||||
private var curTitle = ""
|
||||
private var curLocation = ""
|
||||
private var curDescription = ""
|
||||
private var curImportId = ""
|
||||
private var curFlags = 0
|
||||
private var curReminderMinutes = ArrayList<Int>()
|
||||
private var curRepeatExceptions = ArrayList<Int>()
|
||||
private var curRepeatExceptions = ArrayList<Long>()
|
||||
private var curRepeatInterval = 0
|
||||
private var curRepeatLimit = 0
|
||||
private var curRepeatLimit = 0L
|
||||
private var curRepeatRule = 0
|
||||
private var curEventTypeId = REGULAR_EVENT_TYPE_ID
|
||||
private var curLastModified = 0L
|
||||
|
@ -126,11 +126,11 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
curReminderMinutes.add(curReminderTriggerMinutes)
|
||||
}
|
||||
} else if (line == END_EVENT) {
|
||||
if (curStart != -1 && curEnd == -1) {
|
||||
if (curStart != -1L && curEnd == -1L) {
|
||||
curEnd = curStart
|
||||
}
|
||||
|
||||
if (curTitle.isEmpty() || curStart == -1) {
|
||||
if (curTitle.isEmpty() || curStart == -1L) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getTimestamp(fullString: String): Int {
|
||||
private fun getTimestamp(fullString: String): Long {
|
||||
return try {
|
||||
if (fullString.startsWith(';')) {
|
||||
val value = fullString.substring(fullString.lastIndexOf(':') + 1)
|
||||
|
@ -244,8 +244,8 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
}
|
||||
|
||||
private fun resetValues() {
|
||||
curStart = -1
|
||||
curEnd = -1
|
||||
curStart = -1L
|
||||
curEnd = -1L
|
||||
curTitle = ""
|
||||
curLocation = ""
|
||||
curDescription = ""
|
||||
|
@ -254,7 +254,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
curReminderMinutes = ArrayList()
|
||||
curRepeatExceptions = ArrayList()
|
||||
curRepeatInterval = 0
|
||||
curRepeatLimit = 0
|
||||
curRepeatLimit = 0L
|
||||
curRepeatRule = 0
|
||||
curEventTypeId = REGULAR_EVENT_TYPE_ID
|
||||
curLastModified = 0L
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simplemobiletools.calendar.pro.helpers
|
|||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||
import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar
|
||||
import com.simplemobiletools.calendar.pro.models.DayMonthly
|
||||
|
@ -24,7 +24,7 @@ class MonthlyCalendarImpl(val callback: MonthlyCalendar, val context: Context) {
|
|||
mTargetDate = targetDate
|
||||
val startTS = mTargetDate.minusDays(7).seconds()
|
||||
val endTS = mTargetDate.plusDays(43).seconds()
|
||||
context.dbHelper.getEvents(startTS, endTS) {
|
||||
context.eventsHelper.getEvents(startTS, endTS) {
|
||||
gotEvents(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ import org.joda.time.format.DateTimeFormat
|
|||
|
||||
class Parser {
|
||||
// from RRULE:FREQ=DAILY;COUNT=5 to Daily, 5x...
|
||||
fun parseRepeatInterval(fullString: String, startTS: Int): EventRepetition {
|
||||
fun parseRepeatInterval(fullString: String, startTS: Long): EventRepetition {
|
||||
val parts = fullString.split(";").filter { it.isNotEmpty() }
|
||||
var repeatInterval = 0
|
||||
var repeatRule = 0
|
||||
var repeatLimit = 0
|
||||
var repeatLimit = 0L
|
||||
|
||||
for (part in parts) {
|
||||
val keyValue = part.split("=")
|
||||
|
@ -31,7 +31,7 @@ class Parser {
|
|||
repeatRule = REPEAT_SAME_DAY
|
||||
}
|
||||
} else if (key == COUNT) {
|
||||
repeatLimit = -value.toInt()
|
||||
repeatLimit = -value.toLong()
|
||||
} else if (key == UNTIL) {
|
||||
repeatLimit = parseDateTimeValue(value)
|
||||
} else if (key == INTERVAL) {
|
||||
|
@ -76,7 +76,7 @@ class Parser {
|
|||
return newRepeatRule
|
||||
}
|
||||
|
||||
fun parseDateTimeValue(value: String): Int {
|
||||
fun parseDateTimeValue(value: String): Long {
|
||||
val edited = value.replace("T", "").replace("Z", "")
|
||||
return if (edited.length == 14) {
|
||||
parseLongFormat(edited, value.endsWith("Z"))
|
||||
|
@ -86,7 +86,7 @@ class Parser {
|
|||
}
|
||||
}
|
||||
|
||||
private fun parseLongFormat(digitString: String, useUTC: Boolean): Int {
|
||||
private fun parseLongFormat(digitString: String, useUTC: Boolean): Long {
|
||||
val dateTimeFormat = DateTimeFormat.forPattern("yyyyMMddHHmmss")
|
||||
val dateTimeZone = if (useUTC) DateTimeZone.UTC else DateTimeZone.getDefault()
|
||||
return dateTimeFormat.parseDateTime(digitString).withZoneRetainFields(dateTimeZone).seconds()
|
||||
|
@ -121,7 +121,7 @@ class Parser {
|
|||
}
|
||||
|
||||
private fun getRepeatLimitString(event: Event) = when {
|
||||
event.repeatLimit == 0 -> ""
|
||||
event.repeatLimit == 0L -> ""
|
||||
event.repeatLimit < 0 -> ";$COUNT=${-event.repeatLimit}"
|
||||
else -> ";$UNTIL=${Formatter.getDayCodeFromTS(event.repeatLimit)}"
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ class Parser {
|
|||
private fun getDurationValue(duration: String, char: String) = Regex("[0-9]+(?=$char)").find(duration)?.value?.toInt() ?: 0
|
||||
|
||||
// from 65 to P0DT1H5M0S
|
||||
fun getDurationCode(minutes: Int): String {
|
||||
fun getDurationCode(minutes: Long): String {
|
||||
var days = 0
|
||||
var hours = 0
|
||||
var remainder = minutes
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.simplemobiletools.calendar.pro.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.interfaces.WeeklyCalendar
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.commons.helpers.WEEK_SECONDS
|
||||
|
@ -10,9 +10,9 @@ import java.util.*
|
|||
class WeeklyCalendarImpl(val callback: WeeklyCalendar, val context: Context) {
|
||||
var mEvents = ArrayList<Event>()
|
||||
|
||||
fun updateWeeklyCalendar(weekStartTS: Int) {
|
||||
fun updateWeeklyCalendar(weekStartTS: Long) {
|
||||
val endTS = weekStartTS + WEEK_SECONDS
|
||||
context.dbHelper.getEvents(weekStartTS, endTS) {
|
||||
context.eventsHelper.getEvents(weekStartTS, endTS) {
|
||||
mEvents = it
|
||||
callback.updateWeeklyCalendar(it)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simplemobiletools.calendar.pro.helpers
|
|||
|
||||
import android.content.Context
|
||||
import android.util.SparseArray
|
||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||
import com.simplemobiletools.calendar.pro.interfaces.YearlyCalendar
|
||||
import com.simplemobiletools.calendar.pro.models.DayYearly
|
||||
|
@ -16,7 +16,7 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val
|
|||
val startDateTime = DateTime().withTime(0, 0, 0, 0).withDate(year, 1, 1)
|
||||
val startTS = startDateTime.seconds()
|
||||
val endTS = startDateTime.plusYears(1).minusSeconds(1).seconds()
|
||||
context.dbHelper.getEvents(startTS, endTS) {
|
||||
context.eventsHelper.getEvents(startTS, endTS) {
|
||||
gotEvents(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,5 +15,5 @@ interface EventRepetitionsDao {
|
|||
fun deleteEventRepetitionsOfEvent(eventId: Long)
|
||||
|
||||
@Query("UPDATE event_repetitions SET repeat_limit = :repeatLimit WHERE event_id = :eventId")
|
||||
fun updateEventRepetitionLimit(repeatLimit: Int, eventId: Long)
|
||||
fun updateEventRepetitionLimit(repeatLimit: Long, eventId: Long)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ interface EventsDao {
|
|||
@Query("SELECT id FROM events")
|
||||
fun getEventIds(): List<Long>
|
||||
|
||||
@Query("SELECT * FROM events WHERE start_ts <= :startTS AND end_ts >= :endTS AND start_ts != 0")
|
||||
fun getEventsFromTo(startTS: Long, endTS: Long): List<Event>
|
||||
|
||||
@Query("SELECT id FROM events WHERE import_id = :importId")
|
||||
fun getEventIdWithImportId(importId: String): Long?
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ import java.io.Serializable
|
|||
@Entity(tableName = "events", indices = [(Index(value = ["id"], unique = true))])
|
||||
data class Event(
|
||||
@PrimaryKey(autoGenerate = true) var id: Long?,
|
||||
@ColumnInfo(name = "start_ts") var startTS: Int = 0,
|
||||
@ColumnInfo(name = "end_ts") var endTS: Int = 0,
|
||||
@ColumnInfo(name = "start_ts") var startTS: Long = 0L,
|
||||
@ColumnInfo(name = "end_ts") var endTS: Long = 0L,
|
||||
@ColumnInfo(name = "title") var title: String = "",
|
||||
@ColumnInfo(name = "location") var location: String = "",
|
||||
@ColumnInfo(name = "description") var description: String = "",
|
||||
|
@ -25,7 +25,7 @@ data class Event(
|
|||
@ColumnInfo(name = "reminder_3_minutes") var reminder3Minutes: Int = -1,
|
||||
@ColumnInfo(name = "repeat_interval") var repeatInterval: Int = 0,
|
||||
@ColumnInfo(name = "repeat_rule") var repeatRule: Int = 0,
|
||||
@ColumnInfo(name = "repeat_limit") var repeatLimit: Int = 0,
|
||||
@ColumnInfo(name = "repeat_limit") var repeatLimit: Long = 0L,
|
||||
@ColumnInfo(name = "import_id") var importId: String = "",
|
||||
@ColumnInfo(name = "flags") var flags: Int = 0,
|
||||
@ColumnInfo(name = "event_type") var eventType: Long = REGULAR_EVENT_TYPE_ID,
|
||||
|
@ -118,7 +118,7 @@ data class Event(
|
|||
fun getReminders() = setOf(reminder1Minutes, reminder2Minutes, reminder3Minutes).filter { it != REMINDER_OFF }
|
||||
|
||||
// properly return the start time of all-day events as midnight
|
||||
fun getEventStartTS(): Int {
|
||||
fun getEventStartTS(): Long {
|
||||
return if (getIsAllDay()) {
|
||||
Formatter.getDateTimeFromTS(startTS).withTime(0, 0, 0, 0).seconds()
|
||||
} else {
|
||||
|
@ -139,7 +139,7 @@ data class Event(
|
|||
fun getEventRepetition() = EventRepetition(null, id!!, repeatInterval, repeatRule, repeatLimit)
|
||||
|
||||
// check if its the proper week, for events repeating every x weeks
|
||||
fun isOnProperWeek(startTimes: LongSparseArray<Int>): Boolean {
|
||||
fun isOnProperWeek(startTimes: LongSparseArray<Long>): Boolean {
|
||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[id!!]!!).weekOfWeekyear
|
||||
val currentWeekOfYear = Formatter.getDateTimeFromTS(startTS).weekOfWeekyear
|
||||
return (currentWeekOfYear - initialWeekOfYear) % (repeatInterval / WEEK) == 0
|
||||
|
|
|
@ -11,4 +11,4 @@ data class EventRepetition(
|
|||
@ColumnInfo(name = "event_id") val eventId: Long,
|
||||
@ColumnInfo(name = "repeat_interval") val repeatInterval: Int,
|
||||
@ColumnInfo(name = "repeat_rule") val repeatRule: Int,
|
||||
@ColumnInfo(name = "repeat_limit") val repeatLimit: Int)
|
||||
@ColumnInfo(name = "repeat_limit") val repeatLimit: Long)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.simplemobiletools.calendar.pro.models
|
||||
|
||||
data class ListEvent(var id: Long, 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: Long, var endTS: Long, var title: String, var description: String, var isAllDay: Boolean, var color: Int,
|
||||
var location: String, var isPastEvent: Boolean, var isRepeatable: Boolean) : ListItem()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.simplemobiletools.calendar.pro.models
|
||||
|
||||
data class MonthViewEvent(val id: Long, 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: Long, val color: Int, val startDayIndex: Int, val daysCnt: Int, val originalStartDayIndex: Int,
|
||||
val isAllDay: Boolean, val isPastEvent: Boolean)
|
||||
|
|
Loading…
Reference in New Issue