display event type items on widget list too

This commit is contained in:
tibbi 2016-11-29 20:00:15 +01:00
parent 98877c9fb0
commit d33b5e8f2d
3 changed files with 75 additions and 55 deletions

View File

@ -20,6 +20,9 @@ import org.joda.time.DateTime
import java.util.*
class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
val ITEM_EVENT = 0
val ITEM_HEADER = 1
val appWidgetId: Int
var events: List<ListItem>
val prefs: SharedPreferences
@ -29,22 +32,46 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
prefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
textColor = prefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE).adjustAlpha(HIGH_ALPHA)
appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
events = getListItems()
events = ArrayList<ListItem>()
}
override fun getViewAt(position: Int): RemoteViews {
val rv = RemoteViews(context.packageName, R.layout.event_list_section)
rv.setTextViewText(R.id.event_item_title, "hello")
rv.setInt(R.id.event_item_title, "setTextColor", textColor)
val type = getItemViewType(position)
val remoteView: RemoteViews
if (type == ITEM_EVENT) {
val item = events[position] as ListEvent
remoteView = RemoteViews(context.packageName, R.layout.event_list_item)
remoteView.apply {
setTextViewText(R.id.event_item_title, item.title)
setTextViewText(R.id.event_item_description, item.description)
setTextViewText(R.id.event_item_start, Formatter.getTime(item.startTS))
setTextViewText(R.id.event_item_end, Formatter.getTime(item.endTS))
return rv
setInt(R.id.event_item_title, "setTextColor", textColor)
setInt(R.id.event_item_description, "setTextColor", textColor)
setInt(R.id.event_item_start, "setTextColor", textColor)
setInt(R.id.event_item_end, "setTextColor", textColor)
}
} else {
val item = events[position] as ListSection
remoteView = RemoteViews(context.packageName, R.layout.event_list_section)
remoteView.apply {
setTextViewText(R.id.event_item_title, item.title)
setInt(R.id.event_item_title, "setTextColor", textColor)
}
}
return remoteView
}
fun getItemViewType(position: Int) = if (events[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
override fun getLoadingView() = null
override fun getViewTypeCount() = 1
override fun getViewTypeCount() = 2
override fun onCreate() {
events = getListItems()
}
override fun getItemId(position: Int) = position.toLong()

View File

@ -1,58 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/event_item_frame"
android:id="@+id/event_item_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:foreground="@drawable/selector">
android:background="@drawable/event_item_background">
<RelativeLayout
android:id="@+id/event_item_holder"
android:layout_width="match_parent"
<TextView
android:id="@+id/event_item_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/event_item_background"
android:paddingBottom="@dimen/event_padding"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/small_padding">
android:layout_marginLeft="@dimen/activity_margin"
android:text="13:00"
android:textSize="@dimen/day_text_size"/>
<TextView
android:id="@+id/event_item_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13:00"
android:textSize="@dimen/day_text_size"/>
<TextView
android:id="@+id/event_item_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/event_item_start"
android:layout_marginLeft="@dimen/activity_margin"
android:text="15:00"
android:textSize="@dimen/day_text_size"/>
<TextView
android:id="@+id/event_item_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/event_item_start"
android:text="15:00"
android:textSize="@dimen/day_text_size"/>
<TextView
android:id="@+id/event_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_toRightOf="@+id/event_item_start"
android:maxLines="1"
android:text="Event title"
android:textSize="@dimen/day_text_size"/>
<TextView
android:id="@+id/event_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_toRightOf="@+id/event_item_start"
android:maxLines="1"
android:text="Event title"
android:textSize="@dimen/day_text_size"/>
<TextView
android:id="@+id/event_item_description"
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_toRightOf="@+id/event_item_end"
android:alpha=".4"
android:maxLines="1"
android:text="Event description"
android:textSize="@dimen/day_text_size"/>
<TextView
android:id="@+id/event_item_description"
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_toRightOf="@+id/event_item_end"
android:alpha=".4"
android:maxLines="1"
android:text="Event description"
android:textSize="@dimen/day_text_size"/>
</RelativeLayout>
</FrameLayout>
</RelativeLayout>

View File

@ -3,4 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_event_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:divider="@null"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"/>