add All-day to events in list views
This commit is contained in:
parent
6c1c1e38fd
commit
367e30ea61
|
@ -15,8 +15,9 @@ import com.simplemobiletools.calendar.models.ListEvent
|
|||
import com.simplemobiletools.calendar.models.ListItem
|
||||
import com.simplemobiletools.calendar.models.ListSection
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.beInvisible
|
||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||
import kotlinx.android.synthetic.main.event_item_day_view.view.*
|
||||
import kotlinx.android.synthetic.main.event_list_item.view.*
|
||||
import java.util.*
|
||||
|
||||
class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>, val listener: EventListAdapter.ItemOperationsListener?, val itemClick: (Int) -> Unit) :
|
||||
|
@ -36,6 +37,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
|||
var primaryColor = 0
|
||||
var textColor = 0
|
||||
var todayDate = ""
|
||||
var allDayString = ""
|
||||
|
||||
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
|
||||
itemView.event_item_frame.isSelected = select
|
||||
|
@ -50,8 +52,10 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
|||
}
|
||||
|
||||
init {
|
||||
val res = activity.resources
|
||||
allDayString = res.getString(R.string.all_day)
|
||||
topDivider = res.getDrawable(R.drawable.divider_width)
|
||||
textColor = activity.config.textColor
|
||||
topDivider = activity.resources.getDrawable(R.drawable.divider_width)
|
||||
primaryColor = activity.config.primaryColor
|
||||
val mTodayCode = Formatter.getDayCodeFromTS(mNow)
|
||||
todayDate = Formatter.getDayTitle(activity, mTodayCode)
|
||||
|
@ -123,7 +127,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
|||
itemView.apply {
|
||||
event_item_title.text = item.title
|
||||
event_item_description.text = item.description
|
||||
event_item_start.text = Formatter.getTimeFromTS(context, item.startTS)
|
||||
event_item_start.text = if (item.isAllDay) allDayString else Formatter.getTimeFromTS(context, item.startTS)
|
||||
event_item_end.beInvisibleIf(item.startTS == item.endTS)
|
||||
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||
|
||||
|
@ -132,8 +136,15 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
|||
|
||||
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
||||
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
||||
|
||||
if (startCode != endCode) {
|
||||
event_item_end.append(" (${Formatter.getDate(context, endCode)})")
|
||||
if (item.isAllDay) {
|
||||
event_item_end.text = Formatter.getDateFromCode(context, endCode, true)
|
||||
} else {
|
||||
event_item_end.append(" (${Formatter.getDateFromCode(context, endCode, true)})")
|
||||
}
|
||||
} else if (item.isAllDay) {
|
||||
event_item_end.beInvisible()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
|||
var events: List<ListItem> = ArrayList()
|
||||
val textColor: Int = context.config.widgetTextColor
|
||||
var todayDate = ""
|
||||
val allDayString = context.resources.getString(R.string.all_day)
|
||||
|
||||
override fun getViewAt(position: Int): RemoteViews {
|
||||
val type = getItemViewType(position)
|
||||
|
@ -39,7 +40,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
|||
remoteView = RemoteViews(context.packageName, R.layout.event_list_item_widget).apply {
|
||||
setTextViewText(R.id.event_item_title, item.title)
|
||||
setTextViewText(R.id.event_item_description, item.description)
|
||||
setTextViewText(R.id.event_item_start, Formatter.getTimeFromTS(context, item.startTS))
|
||||
setTextViewText(R.id.event_item_start, if (item.isAllDay) allDayString else Formatter.getTimeFromTS(context, item.startTS))
|
||||
|
||||
if (item.startTS == item.endTS) {
|
||||
setViewVisibility(R.id.event_item_end, View.INVISIBLE)
|
||||
|
@ -48,8 +49,15 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
|||
var endString = Formatter.getTimeFromTS(context, item.endTS)
|
||||
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
||||
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
||||
|
||||
if (startCode != endCode) {
|
||||
endString += " (${Formatter.getDate(context, endCode)})"
|
||||
if (item.isAllDay) {
|
||||
endString = Formatter.getDateFromCode(context, endCode, true)
|
||||
} else {
|
||||
endString += " (${Formatter.getDateFromCode(context, endCode, true)})"
|
||||
}
|
||||
} else if (item.isAllDay) {
|
||||
setViewVisibility(R.id.event_item_end, View.INVISIBLE)
|
||||
}
|
||||
setTextViewText(R.id.event_item_end, endString)
|
||||
}
|
||||
|
@ -112,7 +120,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
|||
listItems.add(ListSection(day))
|
||||
prevCode = code
|
||||
}
|
||||
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description))
|
||||
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay()))
|
||||
}
|
||||
|
||||
this@EventListWidgetAdapter.events = listItems
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.simplemobiletools.calendar.models.ListEvent
|
|||
import com.simplemobiletools.calendar.models.ListItem
|
||||
import com.simplemobiletools.calendar.models.ListSection
|
||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||
import kotlinx.android.synthetic.main.event_item_day_view.view.*
|
||||
import kotlinx.android.synthetic.main.event_list_item_widget.view.*
|
||||
|
||||
class EventListWidgetAdapterOld(val context: Context, val mEvents: List<ListItem>) : BaseAdapter() {
|
||||
val ITEM_EVENT = 0
|
||||
|
@ -59,7 +59,7 @@ class EventListWidgetAdapterOld(val context: Context, val mEvents: List<ListItem
|
|||
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
||||
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
||||
if (startCode != endCode) {
|
||||
end?.append(" (${Formatter.getDate(context, endCode)})")
|
||||
end?.append(" (${Formatter.getDateFromCode(context, endCode)})")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
|
|||
listItems.add(ListSection(day))
|
||||
prevCode = code
|
||||
}
|
||||
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description))
|
||||
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay()))
|
||||
}
|
||||
|
||||
mAllEvents = events
|
||||
|
|
|
@ -16,12 +16,14 @@ object Formatter {
|
|||
private val PATTERN_TIME_12 = "hh:mm a"
|
||||
private val PATTERN_TIME_24 = "kk:mm"
|
||||
|
||||
fun getDate(context: Context, dayCode: String): String {
|
||||
fun getDateFromCode(context: Context, dayCode: String, shortMonth: Boolean = false): String {
|
||||
val dateTime = getDateTimeFromCode(dayCode)
|
||||
val day = dateTime.toString(DAY_PATTERN)
|
||||
val year = dateTime.toString(YEAR_PATTERN)
|
||||
val monthIndex = Integer.valueOf(dayCode.substring(4, 6))!!
|
||||
val month = getMonthName(context, monthIndex)
|
||||
var month = getMonthName(context, monthIndex)
|
||||
if (shortMonth)
|
||||
month = month.substring(0, Math.min(month.length, 3))
|
||||
var date = "$month $day"
|
||||
if (year != DateTime().toString(YEAR_PATTERN))
|
||||
date += " $year"
|
||||
|
@ -29,7 +31,7 @@ object Formatter {
|
|||
}
|
||||
|
||||
fun getDayTitle(context: Context, dayCode: String): String {
|
||||
val date = getDate(context, dayCode)
|
||||
val date = getDateFromCode(context, dayCode)
|
||||
val dateTime = getDateTimeFromCode(dayCode)
|
||||
val day = dateTime.toString(DAY_OF_WEEK_PATTERN)
|
||||
return "$date ($day)"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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 = "") : ListItem() {
|
||||
override fun toString(): String {
|
||||
return "Event {id=$id, startTS=$startTS, endTS=$endTS, title=$title, description=$description}"
|
||||
}
|
||||
class ListEvent(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
||||
var isAllDay: Boolean = false) : ListItem() {
|
||||
override fun toString() = "Event {id=$id, startTS=$startTS, endTS=$endTS, title=$title, description=$description, isAllDay=$isAllDay}"
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
android:id="@+id/event_item_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_marginLeft="@dimen/big_margin"
|
||||
android:layout_toRightOf="@+id/event_item_start"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
|
@ -46,7 +46,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_item_title"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_marginLeft="@dimen/big_margin"
|
||||
android:layout_toRightOf="@+id/event_item_start"
|
||||
android:alpha=".4"
|
||||
android:ellipsize="end"
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
android:id="@+id/event_item_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_marginLeft="@dimen/big_margin"
|
||||
android:layout_toRightOf="@+id/event_item_start"
|
||||
android:maxLines="1"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
|
@ -38,7 +38,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_item_title"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_marginLeft="@dimen/big_margin"
|
||||
android:layout_toRightOf="@+id/event_item_end"
|
||||
android:alpha=".4"
|
||||
android:maxLines="1"
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:drawablePadding="1dp"
|
||||
android:drawableTop="@drawable/divider_width"
|
||||
android:paddingTop="@dimen/small_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
android:textStyle="bold"/>
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:drawablePadding="1dp"
|
||||
android:drawableTop="@drawable/divider_width"
|
||||
android:paddingTop="@dimen/small_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
android:textStyle="bold"/>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/calendar_events_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
|
|
Loading…
Reference in New Issue