add All-day to daily view

This commit is contained in:
tibbi 2017-02-05 20:25:26 +01:00
parent 5e180f7fc1
commit feed23017c
7 changed files with 39 additions and 25 deletions

View File

@ -12,6 +12,7 @@ import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.beInvisible
import com.simplemobiletools.commons.extensions.beInvisibleIf import com.simplemobiletools.commons.extensions.beInvisibleIf
import kotlinx.android.synthetic.main.event_item_day_view.view.* import kotlinx.android.synthetic.main.event_item_day_view.view.*
import java.util.* import java.util.*
@ -25,6 +26,7 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
var actMode: ActionMode? = null var actMode: ActionMode? = null
val markedItems = HashSet<Int>() val markedItems = HashSet<Int>()
var textColor = 0 var textColor = 0
var allDayString = ""
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) { fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
itemView.event_item_frame.isSelected = select itemView.event_item_frame.isSelected = select
@ -40,6 +42,7 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
init { init {
textColor = activity.config.textColor textColor = activity.config.textColor
allDayString = activity.resources.getString(R.string.all_day)
} }
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
@ -97,23 +100,33 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
itemView.apply { itemView.apply {
event_item_title.text = event.title event_item_title.text = event.title
event_item_title.setTextColor(textColor)
event_item_description.text = event.description event_item_description.text = event.description
event_item_description.setTextColor(textColor) event_item_start.text = if (event.isAllDay) allDayString else Formatter.getTimeFromTS(context, event.startTS)
event_item_start.text = Formatter.getTimeFromTS(context, event.startTS)
event_item_start.setTextColor(textColor)
toggleItemSelection(this, markedItems.contains(pos), pos)
event_item_end.beInvisibleIf(event.startTS == event.endTS) event_item_end.beInvisibleIf(event.startTS == event.endTS)
toggleItemSelection(this, markedItems.contains(pos), pos)
if (event.startTS != event.endTS) { if (event.startTS != event.endTS) {
val startCode = Formatter.getDayCodeFromTS(event.startTS)
val endCode = Formatter.getDayCodeFromTS(event.endTS)
event_item_end.apply { event_item_end.apply {
text = Formatter.getTimeFromTS(context, event.endTS) text = Formatter.getTimeFromTS(context, event.endTS)
setTextColor(textColor) if (startCode != endCode) {
if (event.isAllDay) {
text = Formatter.getDateFromCode(context, endCode, true)
} else {
append(" (${Formatter.getDateFromCode(context, endCode, true)})")
}
} else if (event.isAllDay) {
beInvisible()
} }
} }
}
event_item_start.setTextColor(textColor)
event_item_end.setTextColor(textColor)
event_item_title.setTextColor(textColor)
event_item_description.setTextColor(textColor)
setOnClickListener { viewClicked(multiSelector, event, pos) } setOnClickListener { viewClicked(multiSelector, event, pos) }
setOnLongClickListener { setOnLongClickListener {

View File

@ -132,19 +132,20 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
toggleItemSelection(this, markedItems.contains(pos), pos) toggleItemSelection(this, markedItems.contains(pos), pos)
if (item.startTS != item.endTS) { if (item.startTS != item.endTS) {
event_item_end.text = Formatter.getTimeFromTS(context, item.endTS)
val startCode = Formatter.getDayCodeFromTS(item.startTS) val startCode = Formatter.getDayCodeFromTS(item.startTS)
val endCode = Formatter.getDayCodeFromTS(item.endTS) val endCode = Formatter.getDayCodeFromTS(item.endTS)
event_item_end.apply {
text = Formatter.getTimeFromTS(context, item.endTS)
if (startCode != endCode) { if (startCode != endCode) {
if (item.isAllDay) { if (item.isAllDay) {
event_item_end.text = Formatter.getDateFromCode(context, endCode, true) text = Formatter.getDateFromCode(context, endCode, true)
} else { } else {
event_item_end.append(" (${Formatter.getDateFromCode(context, endCode, true)})") append(" (${Formatter.getDateFromCode(context, endCode, true)})")
} }
} else if (item.isAllDay) { } else if (item.isAllDay) {
event_item_end.beInvisible() beInvisible()
}
} }
} }

View File

@ -120,7 +120,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
listItems.add(ListSection(day)) listItems.add(ListSection(day))
prevCode = code prevCode = code
} }
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay())) listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay))
} }
this@EventListWidgetAdapter.events = listItems this@EventListWidgetAdapter.events = listItems

View File

@ -70,7 +70,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
listItems.add(ListSection(day)) listItems.add(ListSection(day))
prevCode = code prevCode = code
} }
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay())) listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay))
} }
mAllEvents = events mAllEvents = events

View File

@ -215,7 +215,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
var hadAllDayEvent = false var hadAllDayEvent = false
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })) val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
for (event in sorted) { for (event in sorted) {
if (event.isAllDay() || Formatter.getDayCodeFromTS(event.startTS) != Formatter.getDayCodeFromTS(event.endTS)) { if (event.isAllDay || Formatter.getDayCodeFromTS(event.startTS) != Formatter.getDayCodeFromTS(event.endTS)) {
hadAllDayEvent = true hadAllDayEvent = true
addAllDayEvent(event) addAllDayEvent(event)
} else { } else {

View File

@ -28,5 +28,5 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
endTS = newEndTS endTS = newEndTS
} }
fun isAllDay() = flags and FLAG_ALL_DAY != 0 val isAllDay = flags and FLAG_ALL_DAY != 0
} }

View File

@ -33,7 +33,7 @@
android:id="@+id/event_item_title" android:id="@+id/event_item_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/big_margin" android:layout_marginLeft="@dimen/activity_margin"
android:layout_toRightOf="@+id/event_item_start" android:layout_toRightOf="@+id/event_item_start"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
@ -46,8 +46,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/event_item_title" android:layout_below="@+id/event_item_title"
android:layout_marginLeft="@dimen/big_margin" android:layout_marginLeft="@dimen/activity_margin"
android:layout_toRightOf="@+id/event_item_start" android:layout_toRightOf="@+id/event_item_end"
android:alpha=".4" android:alpha=".4"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"