setup widget list creation into separate functions

This commit is contained in:
tibbi 2018-05-05 21:11:33 +02:00
parent 2e4f24dee5
commit 5c4014c76e

View File

@ -38,11 +38,21 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
override fun getViewAt(position: Int): RemoteViews? {
val type = getItemViewType(position)
val remoteView: RemoteViews
var curTextColor = textColor
if (type == ITEM_EVENT) {
val item = events[position] as ListEvent
remoteView = RemoteViews(context.packageName, R.layout.event_list_item_widget).apply {
remoteView = RemoteViews(context.packageName, R.layout.event_list_item_widget)
setupListEvent(remoteView, events[position] as ListEvent)
} else {
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget)
setupListSection(remoteView, events[position] as ListSection)
}
return remoteView
}
private fun setupListEvent(remoteView: RemoteViews, item: ListEvent) {
var curTextColor = textColor
remoteView.apply {
setText(R.id.event_section_title, item.title)
setText(R.id.event_item_description, if (replaceDescription) item.location else item.description)
setText(R.id.event_item_start, if (item.isAllDay) allDayString else Formatter.getTimeFromTS(context, item.startTS))
@ -88,13 +98,15 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
setOnClickFillInIntent(event_item_holder, this)
}
}
} else {
val item = events[position] as ListSection
}
private fun setupListSection(remoteView: RemoteViews, item: ListSection) {
var curTextColor = textColor
if (dimPastEvents && item.isPastSection) {
curTextColor = weakTextColor
}
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget).apply {
remoteView.apply {
setTextColor(R.id.event_section_title, curTextColor)
setTextSize(R.id.event_section_title, mediumFontSize)
setText(R.id.event_section_title, item.title)
@ -106,9 +118,6 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
}
}
return remoteView
}
private fun getItemViewType(position: Int) = if (events[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
override fun getLoadingView() = null