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.* import java.util.*
class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory { class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
val ITEM_EVENT = 0
val ITEM_HEADER = 1
val appWidgetId: Int val appWidgetId: Int
var events: List<ListItem> var events: List<ListItem>
val prefs: SharedPreferences val prefs: SharedPreferences
@@ -29,22 +32,46 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
prefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE) prefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
textColor = prefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE).adjustAlpha(HIGH_ALPHA) textColor = prefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE).adjustAlpha(HIGH_ALPHA)
appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
events = getListItems() events = ArrayList<ListItem>()
} }
override fun getViewAt(position: Int): RemoteViews { override fun getViewAt(position: Int): RemoteViews {
val rv = RemoteViews(context.packageName, R.layout.event_list_section) val type = getItemViewType(position)
rv.setTextViewText(R.id.event_item_title, "hello") val remoteView: RemoteViews
rv.setInt(R.id.event_item_title, "setTextColor", textColor) 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 getLoadingView() = null
override fun getViewTypeCount() = 1 override fun getViewTypeCount() = 2
override fun onCreate() { override fun onCreate() {
events = getListItems()
} }
override fun getItemId(position: Int) = position.toLong() override fun getItemId(position: Int) = position.toLong()

View File

@@ -1,26 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/event_item_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:foreground="@drawable/selector">
<RelativeLayout
android:id="@+id/event_item_holder" android:id="@+id/event_item_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/event_item_background" 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">
<TextView <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:layout_marginLeft="@dimen/activity_margin"
android:text="13:00" android:text="13:00"
android:textSize="@dimen/day_text_size"/> android:textSize="@dimen/day_text_size"/>
@@ -29,6 +19,7 @@
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_start" android:layout_below="@+id/event_item_start"
android:layout_marginLeft="@dimen/activity_margin"
android:text="15:00" android:text="15:00"
android:textSize="@dimen/day_text_size"/> android:textSize="@dimen/day_text_size"/>
@@ -54,5 +45,4 @@
android:text="Event description" android:text="Event description"
android:textSize="@dimen/day_text_size"/> android:textSize="@dimen/day_text_size"/>
</RelativeLayout> </RelativeLayout>
</FrameLayout>

View File

@@ -3,4 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_event_list" android:id="@+id/widget_event_list"
android:layout_width="match_parent" 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"/>