change some extensions into constants
This commit is contained in:
parent
a3265d3f6c
commit
89891e939b
|
@ -19,7 +19,10 @@ import com.simplemobiletools.calendar.adapters.MyWeekPagerAdapter
|
|||
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
|
||||
import com.simplemobiletools.calendar.dialogs.ChangeViewDialog
|
||||
import com.simplemobiletools.calendar.dialogs.ImportEventsDialog
|
||||
import com.simplemobiletools.calendar.extensions.*
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode
|
||||
import com.simplemobiletools.calendar.extensions.seconds
|
||||
import com.simplemobiletools.calendar.extensions.updateWidgets
|
||||
import com.simplemobiletools.calendar.fragments.EventListFragment
|
||||
import com.simplemobiletools.calendar.fragments.WeekFragment
|
||||
import com.simplemobiletools.calendar.helpers.*
|
||||
|
@ -268,14 +271,14 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
|
|||
private fun getWeekTimestamps(targetWeekTS: Int): List<Int> {
|
||||
val weekTSs = ArrayList<Int>(PREFILLED_WEEKS)
|
||||
for (i in -PREFILLED_WEEKS / 2..PREFILLED_WEEKS / 2) {
|
||||
weekTSs.add(targetWeekTS + i * secondsInWeek)
|
||||
weekTSs.add(targetWeekTS + i * WEEK_SECONDS)
|
||||
}
|
||||
return weekTSs
|
||||
}
|
||||
|
||||
private fun setupActionbarTitle(timestamp: Int) {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(timestamp)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(timestamp + secondsInWeek)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(timestamp + WEEK_SECONDS)
|
||||
val startMonthName = Formatter.getMonthName(this, startDateTime.monthOfYear)
|
||||
if (startDateTime.monthOfYear == endDateTime.monthOfYear) {
|
||||
var newTitle = startMonthName
|
||||
|
|
|
@ -114,7 +114,3 @@ fun Context.getReminderText(minutes: Int) = when (minutes) {
|
|||
fun Context.getNewEventTimestampFromCode(dayCode: String) = Formatter.getLocalDateTimeFromCode(dayCode).withTime(13, 0, 0, 0).seconds()
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(this)
|
||||
|
||||
val Context.secondsInDay: Int get() = 24 * 60 * 60
|
||||
|
||||
val Context.secondsInWeek: Int get() = 7 * secondsInDay
|
||||
|
|
|
@ -15,8 +15,6 @@ import com.simplemobiletools.calendar.activities.EventActivity
|
|||
import com.simplemobiletools.calendar.activities.MainActivity
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.seconds
|
||||
import com.simplemobiletools.calendar.extensions.secondsInDay
|
||||
import com.simplemobiletools.calendar.extensions.secondsInWeek
|
||||
import com.simplemobiletools.calendar.helpers.*
|
||||
import com.simplemobiletools.calendar.interfaces.WeeklyCalendar
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
|
@ -187,7 +185,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
y = hour * rowHeight
|
||||
|
||||
setOnClickListener {
|
||||
val timestamp = mWeekTimestamp + index * context.secondsInDay + hour * 60 * 60
|
||||
val timestamp = mWeekTimestamp + index * DAY_SECONDS + hour * 60 * 60
|
||||
Intent(context, EventActivity::class.java).apply {
|
||||
putExtra(NEW_EVENT_START_TS, timestamp)
|
||||
startActivity(this)
|
||||
|
@ -275,7 +273,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
|
||||
|
||||
val minTS = Math.max(startDateTime.withTimeAtStartOfDay().seconds(), mWeekTimestamp)
|
||||
val maxTS = Math.min(endDateTime.withTimeAtStartOfDay().seconds(), mWeekTimestamp + context.secondsInWeek)
|
||||
val maxTS = Math.min(endDateTime.withTimeAtStartOfDay().seconds(), mWeekTimestamp + WEEK_SECONDS)
|
||||
val startDateTimeInWeek = Formatter.getDateTimeFromTS(minTS)
|
||||
val firstDayIndex = (startDateTimeInWeek.dayOfWeek - if (context.config.isSundayFirst) 0 else 1) % 7
|
||||
val daysCnt = Days.daysBetween(Formatter.getDateTimeFromTS(minTS), Formatter.getDateTimeFromTS(maxTS)).days
|
||||
|
|
|
@ -24,6 +24,9 @@ val BIWEEK = 1209600
|
|||
val MONTH = 2592000 // exact value not taken into account, Joda is used for adding months and years
|
||||
val YEAR = 31536000
|
||||
|
||||
val DAY_SECONDS = 24 * 60 * 60
|
||||
val WEEK_SECONDS = 7 * DAY_SECONDS
|
||||
|
||||
// Shared Preferences
|
||||
val SUNDAY_FIRST = "sunday_first"
|
||||
val WEEK_NUMBERS = "week_numbers"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simplemobiletools.calendar.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.calendar.extensions.secondsInWeek
|
||||
import com.simplemobiletools.calendar.interfaces.WeeklyCalendar
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import java.util.*
|
||||
|
@ -15,7 +14,7 @@ class WeeklyCalendarImpl(val mCallback: WeeklyCalendar, val mContext: Context) :
|
|||
|
||||
fun updateWeeklyCalendar(weekStartTS: Int) {
|
||||
val startTS = weekStartTS
|
||||
val endTS = startTS + mContext.secondsInWeek
|
||||
val endTS = startTS + WEEK_SECONDS
|
||||
DBHelper(mContext).getEvents(startTS, endTS, this)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue