fix #441, add a setting for dimming past events, enabled by default
This commit is contained in:
parent
614b17e36f
commit
a6960b0844
|
@ -145,7 +145,7 @@ class WidgetListConfigureActivity : SimpleActivity() {
|
||||||
var dateTime = DateTime.now().withTime(0, 0, 0, 0).plusDays(1)
|
var dateTime = DateTime.now().withTime(0, 0, 0, 0).plusDays(1)
|
||||||
var code = Formatter.getDayCodeFromTS(dateTime.seconds())
|
var code = Formatter.getDayCodeFromTS(dateTime.seconds())
|
||||||
var day = Formatter.getDayTitle(this, code)
|
var day = Formatter.getDayTitle(this, code)
|
||||||
listItems.add(ListSection(day, code))
|
listItems.add(ListSection(day, code, false, false))
|
||||||
|
|
||||||
var time = dateTime.withHourOfDay(7)
|
var time = dateTime.withHourOfDay(7)
|
||||||
listItems.add(ListEvent(1, time.seconds(), time.plusMinutes(30).seconds(), getString(R.string.sample_title_1), getString(R.string.sample_description_1), false, config.primaryColor))
|
listItems.add(ListEvent(1, time.seconds(), time.plusMinutes(30).seconds(), getString(R.string.sample_title_1), getString(R.string.sample_description_1), false, config.primaryColor))
|
||||||
|
@ -155,7 +155,7 @@ class WidgetListConfigureActivity : SimpleActivity() {
|
||||||
dateTime = dateTime.plusDays(1)
|
dateTime = dateTime.plusDays(1)
|
||||||
code = Formatter.getDayCodeFromTS(dateTime.seconds())
|
code = Formatter.getDayCodeFromTS(dateTime.seconds())
|
||||||
day = Formatter.getDayTitle(this, code)
|
day = Formatter.getDayTitle(this, code)
|
||||||
listItems.add(ListSection(day, code))
|
listItems.add(ListSection(day, code, false, false))
|
||||||
|
|
||||||
time = dateTime.withHourOfDay(8)
|
time = dateTime.withHourOfDay(8)
|
||||||
listItems.add(ListEvent(3, time.seconds(), time.plusHours(1).seconds(), getString(R.string.sample_title_3), "", false, config.primaryColor))
|
listItems.add(ListEvent(3, time.seconds(), time.plusHours(1).seconds(), getString(R.string.sample_title_3), "", false, config.primaryColor))
|
||||||
|
|
|
@ -10,8 +10,10 @@ import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.extensions.shareEvents
|
import com.simplemobiletools.calendar.extensions.shareEvents
|
||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
|
import com.simplemobiletools.calendar.helpers.LOW_ALPHA
|
||||||
import com.simplemobiletools.calendar.models.Event
|
import com.simplemobiletools.calendar.models.Event
|
||||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
|
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||||
import com.simplemobiletools.commons.extensions.beInvisible
|
import com.simplemobiletools.commons.extensions.beInvisible
|
||||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||||
|
@ -21,8 +23,9 @@ import kotlinx.android.synthetic.main.event_item_day_view.view.*
|
||||||
class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit)
|
class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit)
|
||||||
: MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
: MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||||
|
|
||||||
private var allDayString = resources.getString(R.string.all_day)
|
private val allDayString = resources.getString(R.string.all_day)
|
||||||
private var replaceDescriptionWithLocation = activity.config.replaceDescription
|
private val replaceDescriptionWithLocation = activity.config.replaceDescription
|
||||||
|
private val dimPastEvents = activity.config.dimPastEvents
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setupDragListener(true)
|
setupDragListener(true)
|
||||||
|
@ -85,10 +88,15 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event_item_start.setTextColor(textColor)
|
var newTextColor = textColor
|
||||||
event_item_end.setTextColor(textColor)
|
if (dimPastEvents && event.isPastEvent) {
|
||||||
event_section_title.setTextColor(textColor)
|
newTextColor = newTextColor.adjustAlpha(LOW_ALPHA)
|
||||||
event_item_description.setTextColor(textColor)
|
}
|
||||||
|
|
||||||
|
event_item_start.setTextColor(newTextColor)
|
||||||
|
event_item_end.setTextColor(newTextColor)
|
||||||
|
event_section_title.setTextColor(newTextColor)
|
||||||
|
event_item_description.setTextColor(newTextColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,15 @@ import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||||
import com.simplemobiletools.calendar.dialogs.DeleteEventDialog
|
import com.simplemobiletools.calendar.dialogs.DeleteEventDialog
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.extensions.getNowSeconds
|
|
||||||
import com.simplemobiletools.calendar.extensions.shareEvents
|
import com.simplemobiletools.calendar.extensions.shareEvents
|
||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
|
import com.simplemobiletools.calendar.helpers.LOW_ALPHA
|
||||||
|
import com.simplemobiletools.calendar.helpers.getNowSeconds
|
||||||
import com.simplemobiletools.calendar.models.ListEvent
|
import com.simplemobiletools.calendar.models.ListEvent
|
||||||
import com.simplemobiletools.calendar.models.ListItem
|
import com.simplemobiletools.calendar.models.ListItem
|
||||||
import com.simplemobiletools.calendar.models.ListSection
|
import com.simplemobiletools.calendar.models.ListSection
|
||||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
|
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||||
import com.simplemobiletools.commons.extensions.beInvisible
|
import com.simplemobiletools.commons.extensions.beInvisible
|
||||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||||
|
@ -32,9 +34,8 @@ class EventListAdapter(activity: SimpleActivity, val listItems: ArrayList<ListIt
|
||||||
private val topDivider = resources.getDrawable(R.drawable.divider_width)
|
private val topDivider = resources.getDrawable(R.drawable.divider_width)
|
||||||
private val allDayString = resources.getString(R.string.all_day)
|
private val allDayString = resources.getString(R.string.all_day)
|
||||||
private val replaceDescriptionWithLocation = activity.config.replaceDescription
|
private val replaceDescriptionWithLocation = activity.config.replaceDescription
|
||||||
private val redTextColor = resources.getColor(R.color.red_text)
|
private val dimPastEvents = activity.config.dimPastEvents
|
||||||
private val now = activity.getNowSeconds()
|
private val now = getNowSeconds()
|
||||||
private val todayDate = Formatter.getDayTitle(activity, Formatter.getDayCodeFromTS(now))
|
|
||||||
private var use24HourFormat = activity.config.use24HourFormat
|
private var use24HourFormat = activity.config.use24HourFormat
|
||||||
|
|
||||||
override fun getActionMenuId() = R.menu.cab_event_list
|
override fun getActionMenuId() = R.menu.cab_event_list
|
||||||
|
@ -112,12 +113,15 @@ class EventListAdapter(activity: SimpleActivity, val listItems: ArrayList<ListIt
|
||||||
var endTextColor = textColor
|
var endTextColor = textColor
|
||||||
if (listEvent.startTS <= now && listEvent.endTS <= now) {
|
if (listEvent.startTS <= now && listEvent.endTS <= now) {
|
||||||
if (listEvent.isAllDay) {
|
if (listEvent.isAllDay) {
|
||||||
if (Formatter.getDayCodeFromTS(listEvent.startTS) == Formatter.getDayCodeFromTS(now))
|
if (Formatter.getDayCodeFromTS(listEvent.startTS) == Formatter.getDayCodeFromTS(now)) {
|
||||||
startTextColor = primaryColor
|
startTextColor = primaryColor
|
||||||
} else {
|
}
|
||||||
startTextColor = redTextColor
|
}
|
||||||
|
|
||||||
|
if (dimPastEvents && listEvent.isPastEvent) {
|
||||||
|
startTextColor = startTextColor.adjustAlpha(LOW_ALPHA)
|
||||||
|
endTextColor = endTextColor.adjustAlpha(LOW_ALPHA)
|
||||||
}
|
}
|
||||||
endTextColor = redTextColor
|
|
||||||
} else if (listEvent.startTS <= now && listEvent.endTS >= now) {
|
} else if (listEvent.startTS <= now && listEvent.endTS >= now) {
|
||||||
startTextColor = primaryColor
|
startTextColor = primaryColor
|
||||||
}
|
}
|
||||||
|
@ -133,7 +137,11 @@ class EventListAdapter(activity: SimpleActivity, val listItems: ArrayList<ListIt
|
||||||
view.event_section_title.apply {
|
view.event_section_title.apply {
|
||||||
text = listSection.title
|
text = listSection.title
|
||||||
setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else topDivider, null, null)
|
setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else topDivider, null, null)
|
||||||
setTextColor(if (listSection.title == todayDate) primaryColor else textColor)
|
var color = if (listSection.isToday) primaryColor else textColor
|
||||||
|
if (dimPastEvents && listSection.isPastSection) {
|
||||||
|
color = color.adjustAlpha(LOW_ALPHA)
|
||||||
|
}
|
||||||
|
setTextColor(color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,12 @@ import com.simplemobiletools.calendar.R.id.event_section_title
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.helpers.DAY_CODE
|
import com.simplemobiletools.calendar.helpers.*
|
||||||
import com.simplemobiletools.calendar.helpers.EVENT_ID
|
|
||||||
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
|
|
||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
import com.simplemobiletools.calendar.models.ListEvent
|
import com.simplemobiletools.calendar.models.ListEvent
|
||||||
import com.simplemobiletools.calendar.models.ListItem
|
import com.simplemobiletools.calendar.models.ListItem
|
||||||
import com.simplemobiletools.calendar.models.ListSection
|
import com.simplemobiletools.calendar.models.ListSection
|
||||||
|
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||||
import com.simplemobiletools.commons.extensions.getColoredBitmap
|
import com.simplemobiletools.commons.extensions.getColoredBitmap
|
||||||
import com.simplemobiletools.commons.extensions.setText
|
import com.simplemobiletools.commons.extensions.setText
|
||||||
import com.simplemobiletools.commons.extensions.setTextSize
|
import com.simplemobiletools.commons.extensions.setTextSize
|
||||||
|
@ -31,12 +30,15 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
||||||
private val allDayString = context.resources.getString(R.string.all_day)
|
private val allDayString = context.resources.getString(R.string.all_day)
|
||||||
private var events = ArrayList<ListItem>()
|
private var events = ArrayList<ListItem>()
|
||||||
private val textColor = context.config.widgetTextColor
|
private val textColor = context.config.widgetTextColor
|
||||||
|
private val weakTextColor = textColor.adjustAlpha(LOW_ALPHA)
|
||||||
private val replaceDescription = context.config.replaceDescription
|
private val replaceDescription = context.config.replaceDescription
|
||||||
|
private val dimPastEvents = context.config.dimPastEvents
|
||||||
private var mediumFontSize = context.config.getFontSize()
|
private var mediumFontSize = context.config.getFontSize()
|
||||||
|
|
||||||
override fun getViewAt(position: Int): RemoteViews? {
|
override fun getViewAt(position: Int): RemoteViews? {
|
||||||
val type = getItemViewType(position)
|
val type = getItemViewType(position)
|
||||||
val remoteView: RemoteViews
|
val remoteView: RemoteViews
|
||||||
|
var curTextColor = textColor
|
||||||
|
|
||||||
if (type == ITEM_EVENT) {
|
if (type == ITEM_EVENT) {
|
||||||
val item = events[position] as ListEvent
|
val item = events[position] as ListEvent
|
||||||
|
@ -66,10 +68,14 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
||||||
setText(R.id.event_item_end, endString)
|
setText(R.id.event_item_end, endString)
|
||||||
}
|
}
|
||||||
|
|
||||||
setTextColor(R.id.event_section_title, textColor)
|
if (dimPastEvents && item.isPastEvent) {
|
||||||
setTextColor(R.id.event_item_description, textColor)
|
curTextColor = weakTextColor
|
||||||
setTextColor(R.id.event_item_start, textColor)
|
}
|
||||||
setTextColor(R.id.event_item_end, textColor)
|
|
||||||
|
setTextColor(R.id.event_section_title, curTextColor)
|
||||||
|
setTextColor(R.id.event_item_description, curTextColor)
|
||||||
|
setTextColor(R.id.event_item_start, curTextColor)
|
||||||
|
setTextColor(R.id.event_item_end, curTextColor)
|
||||||
|
|
||||||
setTextSize(R.id.event_section_title, mediumFontSize)
|
setTextSize(R.id.event_section_title, mediumFontSize)
|
||||||
setTextSize(R.id.event_item_description, mediumFontSize)
|
setTextSize(R.id.event_item_description, mediumFontSize)
|
||||||
|
@ -84,8 +90,12 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val item = events[position] as ListSection
|
val item = events[position] as ListSection
|
||||||
|
if (dimPastEvents && item.isPastSection) {
|
||||||
|
curTextColor = weakTextColor
|
||||||
|
}
|
||||||
|
|
||||||
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget).apply {
|
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget).apply {
|
||||||
setTextColor(R.id.event_section_title, textColor)
|
setTextColor(R.id.event_section_title, curTextColor)
|
||||||
setTextSize(R.id.event_section_title, mediumFontSize)
|
setTextSize(R.id.event_section_title, mediumFontSize)
|
||||||
setText(R.id.event_section_title, item.title)
|
setText(R.id.event_section_title, item.title)
|
||||||
|
|
||||||
|
@ -119,14 +129,21 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
||||||
val sorted = it.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
val sorted = it.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
||||||
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
||||||
var prevCode = ""
|
var prevCode = ""
|
||||||
|
val now = getNowSeconds()
|
||||||
|
val today = Formatter.getDayTitle(context, Formatter.getDayCodeFromTS(now))
|
||||||
|
|
||||||
sublist.forEach {
|
sublist.forEach {
|
||||||
val code = Formatter.getDayCodeFromTS(it.startTS)
|
val code = Formatter.getDayCodeFromTS(it.startTS)
|
||||||
if (code != prevCode) {
|
if (code != prevCode) {
|
||||||
val day = Formatter.getDayTitle(context, code)
|
val day = Formatter.getDayTitle(context, code)
|
||||||
listItems.add(ListSection(day, code))
|
val isToday = day == today
|
||||||
|
val listSection = ListSection(day, code, isToday, !isToday && it.startTS < now)
|
||||||
|
listItems.add(listSection)
|
||||||
prevCode = code
|
prevCode = code
|
||||||
}
|
}
|
||||||
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location))
|
|
||||||
|
val listEvent = ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location, it.isPastEvent)
|
||||||
|
listItems.add(listEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
this@EventListWidgetAdapter.events = listItems
|
this@EventListWidgetAdapter.events = listItems
|
||||||
|
|
|
@ -7,9 +7,9 @@ import android.support.v7.app.AlertDialog
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.getNowSeconds
|
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
|
import com.simplemobiletools.calendar.helpers.getNowSeconds
|
||||||
import com.simplemobiletools.commons.extensions.getDialogTheme
|
import com.simplemobiletools.commons.extensions.getDialogTheme
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.commons.extensions.value
|
import com.simplemobiletools.commons.extensions.value
|
||||||
|
@ -57,7 +57,7 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int,
|
||||||
|
|
||||||
private fun updateRepeatLimitText() {
|
private fun updateRepeatLimitText() {
|
||||||
if (repeatLimit <= 0)
|
if (repeatLimit <= 0)
|
||||||
repeatLimit = activity.getNowSeconds()
|
repeatLimit = getNowSeconds()
|
||||||
|
|
||||||
val repeatLimitDateTime = Formatter.getDateTimeFromTS(repeatLimit)
|
val repeatLimitDateTime = Formatter.getDateTimeFromTS(repeatLimit)
|
||||||
view.repeat_type_date.text = Formatter.getFullDate(activity, repeatLimitDateTime)
|
view.repeat_type_date.text = Formatter.getFullDate(activity, repeatLimitDateTime)
|
||||||
|
@ -82,7 +82,7 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int,
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private fun showRepetitionLimitDialog() {
|
private fun showRepetitionLimitDialog() {
|
||||||
val repeatLimitDateTime = Formatter.getDateTimeFromTS(if (repeatLimit != 0) repeatLimit else activity.getNowSeconds())
|
val repeatLimitDateTime = Formatter.getDateTimeFromTS(if (repeatLimit != 0) repeatLimit else getNowSeconds())
|
||||||
val datepicker = DatePickerDialog(activity, activity.getDialogTheme(), repetitionLimitDateSetListener, repeatLimitDateTime.year,
|
val datepicker = DatePickerDialog(activity, activity.getDialogTheme(), repetitionLimitDateSetListener, repeatLimitDateTime.year,
|
||||||
repeatLimitDateTime.monthOfYear - 1, repeatLimitDateTime.dayOfMonth)
|
repeatLimitDateTime.monthOfYear - 1, repeatLimitDateTime.dayOfMonth)
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,6 @@ val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||||
|
|
||||||
val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
|
val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
|
||||||
|
|
||||||
fun Context.getNowSeconds() = (System.currentTimeMillis() / 1000).toInt()
|
|
||||||
|
|
||||||
fun Context.updateWidgets() {
|
fun Context.updateWidgets() {
|
||||||
val widgetIDs = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetMonthlyProvider::class.java))
|
val widgetIDs = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetMonthlyProvider::class.java))
|
||||||
if (widgetIDs.isNotEmpty()) {
|
if (widgetIDs.isNotEmpty()) {
|
||||||
|
@ -150,7 +148,7 @@ fun Context.notifyRunningEvents() {
|
||||||
|
|
||||||
fun Context.notifyEvent(originalEvent: Event) {
|
fun Context.notifyEvent(originalEvent: Event) {
|
||||||
var event = originalEvent.copy()
|
var event = originalEvent.copy()
|
||||||
val currentSeconds = (System.currentTimeMillis() / 1000).toInt()
|
val currentSeconds = getNowSeconds()
|
||||||
|
|
||||||
// make sure refer to the proper repeatable event instance with "Tomorrow", or the specific date
|
// make sure refer to the proper repeatable event instance with "Tomorrow", or the specific date
|
||||||
if (event.repeatInterval != 0 && event.startTS - event.reminder1Minutes * 60 < currentSeconds) {
|
if (event.repeatInterval != 0 && event.startTS - event.reminder1Minutes * 60 < currentSeconds) {
|
||||||
|
@ -401,14 +399,20 @@ fun Context.getEventListItems(events: List<Event>): ArrayList<ListItem> {
|
||||||
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
||||||
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
||||||
var prevCode = ""
|
var prevCode = ""
|
||||||
|
val now = getNowSeconds()
|
||||||
|
val today = Formatter.getDayTitle(this, Formatter.getDayCodeFromTS(now))
|
||||||
|
|
||||||
sublist.forEach {
|
sublist.forEach {
|
||||||
val code = Formatter.getDayCodeFromTS(it.startTS)
|
val code = Formatter.getDayCodeFromTS(it.startTS)
|
||||||
if (code != prevCode) {
|
if (code != prevCode) {
|
||||||
val day = Formatter.getDayTitle(this, code)
|
val day = Formatter.getDayTitle(this, code)
|
||||||
listItems.add(ListSection(day, code))
|
val isToday = day == today
|
||||||
|
val listSection = ListSection(day, code, isToday, !isToday && it.startTS < now)
|
||||||
|
listItems.add(listSection)
|
||||||
prevCode = code
|
prevCode = code
|
||||||
}
|
}
|
||||||
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location))
|
val listEvent = ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location, it.isPastEvent)
|
||||||
|
listItems.add(listEvent)
|
||||||
}
|
}
|
||||||
return listItems
|
return listItems
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.simplemobiletools.calendar.fragments
|
package com.simplemobiletools.calendar.fragments
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Resources
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
|
@ -37,12 +36,10 @@ class DayFragment : Fragment() {
|
||||||
private var mDayCode = ""
|
private var mDayCode = ""
|
||||||
private var lastHash = 0
|
private var lastHash = 0
|
||||||
|
|
||||||
lateinit var mRes: Resources
|
|
||||||
lateinit var mHolder: RelativeLayout
|
lateinit var mHolder: RelativeLayout
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
val view = inflater.inflate(R.layout.fragment_day, container, false)
|
val view = inflater.inflate(R.layout.fragment_day, container, false)
|
||||||
mRes = resources
|
|
||||||
mHolder = view.day_holder
|
mHolder = view.day_holder
|
||||||
|
|
||||||
mDayCode = arguments!!.getString(DAY_CODE)
|
mDayCode = arguments!!.getString(DAY_CODE)
|
||||||
|
|
|
@ -122,3 +122,5 @@ const val SOURCE_SIMPLE_CALENDAR = "simple-calendar"
|
||||||
const val SOURCE_IMPORTED_ICS = "imported-ics"
|
const val SOURCE_IMPORTED_ICS = "imported-ics"
|
||||||
const val SOURCE_CONTACT_BIRTHDAY = "contact-birthday"
|
const val SOURCE_CONTACT_BIRTHDAY = "contact-birthday"
|
||||||
const val SOURCE_CONTACT_ANNIVERSARY = "contact-anniversary"
|
const val SOURCE_CONTACT_ANNIVERSARY = "contact-anniversary"
|
||||||
|
|
||||||
|
fun getNowSeconds() = (System.currentTimeMillis() / 1000).toInt()
|
||||||
|
|
|
@ -788,7 +788,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
|
|
||||||
fun getRunningEvents(): List<Event> {
|
fun getRunningEvents(): List<Event> {
|
||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
val ts = context.getNowSeconds()
|
val ts = getNowSeconds()
|
||||||
|
|
||||||
val selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS 0 AND $COL_START_TS != 0"
|
val selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS 0 AND $COL_START_TS != 0"
|
||||||
val selectionArgs = arrayOf(ts.toString(), ts.toString())
|
val selectionArgs = arrayOf(ts.toString(), ts.toString())
|
||||||
|
@ -829,7 +829,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEventsToExport(includePast: Boolean): ArrayList<Event> {
|
fun getEventsToExport(includePast: Boolean): ArrayList<Event> {
|
||||||
val currTime = context.getNowSeconds().toString()
|
val currTime = getNowSeconds().toString()
|
||||||
var events = ArrayList<Event>()
|
var events = ArrayList<Event>()
|
||||||
|
|
||||||
// non repeating events
|
// non repeating events
|
||||||
|
@ -914,7 +914,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
repeatRule = REPEAT_MONTH_SAME_DAY
|
repeatRule = REPEAT_MONTH_SAME_DAY
|
||||||
}
|
}
|
||||||
|
|
||||||
val isPastEvent = endTS < System.currentTimeMillis() / 1000
|
val isPastEvent = endTS < getNowSeconds()
|
||||||
|
|
||||||
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
||||||
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded,
|
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded,
|
||||||
|
@ -1044,5 +1044,5 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getIsPastEvent(event: Event) = event.endTS < System.currentTimeMillis() / 1000
|
private fun getIsPastEvent(event: Event) = event.endTS < getNowSeconds()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.calendar.helpers
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.getNowSeconds
|
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
|
@ -11,17 +10,17 @@ import org.joda.time.LocalDate
|
||||||
import org.joda.time.format.DateTimeFormat
|
import org.joda.time.format.DateTimeFormat
|
||||||
|
|
||||||
object Formatter {
|
object Formatter {
|
||||||
val DAYCODE_PATTERN = "YYYYMMdd"
|
const val DAYCODE_PATTERN = "YYYYMMdd"
|
||||||
val YEAR_PATTERN = "YYYY"
|
const val YEAR_PATTERN = "YYYY"
|
||||||
val TIME_PATTERN = "HHmmss"
|
const val TIME_PATTERN = "HHmmss"
|
||||||
private val DAY_PATTERN = "d"
|
private const val DAY_PATTERN = "d"
|
||||||
private val DAY_OF_WEEK_PATTERN = "EEE"
|
private const val DAY_OF_WEEK_PATTERN = "EEE"
|
||||||
private val LONGEST_PATTERN = "MMMM dd YYYY (EEEE)"
|
private const val LONGEST_PATTERN = "MMMM dd YYYY (EEEE)"
|
||||||
private val PATTERN_TIME_12 = "hh:mm a"
|
private const val PATTERN_TIME_12 = "hh:mm a"
|
||||||
private val PATTERN_TIME_24 = "HH:mm"
|
private const val PATTERN_TIME_24 = "HH:mm"
|
||||||
|
|
||||||
private val PATTERN_HOURS_12 = "h a"
|
private const val PATTERN_HOURS_12 = "h a"
|
||||||
private val PATTERN_HOURS_24 = "HH"
|
private const val PATTERN_HOURS_24 = "HH"
|
||||||
|
|
||||||
fun getDateFromCode(context: Context, dayCode: String, shortMonth: Boolean = false): String {
|
fun getDateFromCode(context: Context, dayCode: String, shortMonth: Boolean = false): String {
|
||||||
val dateTime = getDateTimeFromCode(dayCode)
|
val dateTime = getDateTimeFromCode(dayCode)
|
||||||
|
@ -59,7 +58,7 @@ object Formatter {
|
||||||
return "$month $day $year"
|
return "$month $day $year"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTodayCode(context: Context) = Formatter.getDayCodeFromTS(context.getNowSeconds())
|
fun getTodayCode(context: Context) = Formatter.getDayCodeFromTS(getNowSeconds())
|
||||||
|
|
||||||
fun getHours(context: Context, dateTime: DateTime) = dateTime.toString(getHourPattern(context))
|
fun getHours(context: Context, dateTime: DateTime) = dateTime.toString(getHourPattern(context))
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import android.widget.RemoteViews
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.activities.SplashActivity
|
import com.simplemobiletools.calendar.activities.SplashActivity
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.getNowSeconds
|
|
||||||
import com.simplemobiletools.calendar.extensions.launchNewEventIntent
|
import com.simplemobiletools.calendar.extensions.launchNewEventIntent
|
||||||
import com.simplemobiletools.calendar.services.WidgetService
|
import com.simplemobiletools.calendar.services.WidgetService
|
||||||
import com.simplemobiletools.commons.extensions.getColoredBitmap
|
import com.simplemobiletools.commons.extensions.getColoredBitmap
|
||||||
|
@ -43,7 +42,7 @@ class MyWidgetListProvider : AppWidgetProvider() {
|
||||||
setTextSize(R.id.widget_event_list_today, fontSize)
|
setTextSize(R.id.widget_event_list_today, fontSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
val todayText = Formatter.getLongestDate(context.getNowSeconds())
|
val todayText = Formatter.getLongestDate(getNowSeconds())
|
||||||
views.setText(R.id.widget_event_list_today, todayText)
|
views.setText(R.id.widget_event_list_today, todayText)
|
||||||
|
|
||||||
views.setImageViewBitmap(R.id.widget_event_new_event, context.resources.getColoredBitmap(R.drawable.ic_plus, textColor))
|
views.setImageViewBitmap(R.id.widget_event_new_event, context.resources.getColoredBitmap(R.drawable.ic_plus, textColor))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.simplemobiletools.calendar.models
|
package com.simplemobiletools.calendar.models
|
||||||
|
|
||||||
class ListEvent(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
data class ListEvent(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
||||||
var isAllDay: Boolean, var color: Int, var location: String = "") : ListItem()
|
var isAllDay: Boolean, var color: Int, var location: String = "", var isPastEvent: Boolean = false) : ListItem()
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package com.simplemobiletools.calendar.models
|
package com.simplemobiletools.calendar.models
|
||||||
|
|
||||||
data class ListSection(val title: String, val code: String, val isToday: Boolean = false) : ListItem()
|
data class ListSection(val title: String, val code: String, val isToday: Boolean, val isPastSection: Boolean) : ListItem()
|
||||||
|
|
|
@ -18,14 +18,14 @@
|
||||||
android:paddingBottom="@dimen/medium_margin"
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
android:paddingTop="@dimen/medium_margin">
|
android:paddingTop="@dimen/medium_margin">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<TextView
|
||||||
android:id="@+id/event_item_start"
|
android:id="@+id/event_item_start"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="@dimen/day_text_size"
|
android:textSize="@dimen/day_text_size"
|
||||||
tools:text="13:00"/>
|
tools:text="13:00"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<TextView
|
||||||
android:id="@+id/event_item_end"
|
android:id="@+id/event_item_end"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
android:text="15:00"
|
android:text="15:00"
|
||||||
android:textSize="@dimen/day_text_size"/>
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<TextView
|
||||||
android:id="@+id/event_section_title"
|
android:id="@+id/event_section_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
android:textSize="@dimen/day_text_size"
|
android:textSize="@dimen/day_text_size"
|
||||||
tools:text="Event title"/>
|
tools:text="Event title"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<TextView
|
||||||
android:id="@+id/event_item_description"
|
android:id="@+id/event_item_description"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -54,7 +54,6 @@
|
||||||
android:layout_marginLeft="@dimen/activity_margin"
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
android:layout_toLeftOf="@+id/event_item_color"
|
android:layout_toLeftOf="@+id/event_item_color"
|
||||||
android:layout_toRightOf="@+id/event_item_end"
|
android:layout_toRightOf="@+id/event_item_end"
|
||||||
android:alpha=".4"
|
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
|
|
@ -20,14 +20,14 @@
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
android:paddingTop="@dimen/small_margin">
|
android:paddingTop="@dimen/small_margin">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<TextView
|
||||||
android:id="@+id/event_item_start"
|
android:id="@+id/event_item_start"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="@dimen/day_text_size"
|
android:textSize="@dimen/day_text_size"
|
||||||
tools:text="13:00"/>
|
tools:text="13:00"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<TextView
|
||||||
android:id="@+id/event_item_end"
|
android:id="@+id/event_item_end"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
android:text="15:00"
|
android:text="15:00"
|
||||||
android:textSize="@dimen/day_text_size"/>
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<TextView
|
||||||
android:id="@+id/event_section_title"
|
android:id="@+id/event_section_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
android:textSize="@dimen/day_text_size"
|
android:textSize="@dimen/day_text_size"
|
||||||
tools:text="Event title"/>
|
tools:text="Event title"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<TextView
|
||||||
android:id="@+id/event_item_description"
|
android:id="@+id/event_item_description"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -56,7 +56,6 @@
|
||||||
android:layout_marginLeft="@dimen/activity_margin"
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
android:layout_toLeftOf="@+id/event_item_color"
|
android:layout_toLeftOf="@+id/event_item_color"
|
||||||
android:layout_toRightOf="@+id/event_item_end"
|
android:layout_toRightOf="@+id/event_item_end"
|
||||||
android:alpha=".4"
|
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
android:layout_marginLeft="@dimen/big_margin"
|
android:layout_marginLeft="@dimen/big_margin"
|
||||||
android:layout_toLeftOf="@+id/event_item_color"
|
android:layout_toLeftOf="@+id/event_item_color"
|
||||||
android:layout_toRightOf="@+id/event_item_end"
|
android:layout_toRightOf="@+id/event_item_end"
|
||||||
android:alpha=".4"
|
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
|
Loading…
Reference in New Issue