mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
display event type items on widget list too
This commit is contained in:
@@ -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()
|
||||||
|
@@ -1,58 +1,48 @@
|
|||||||
<?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: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="?attr/selectableItemBackground"
|
android:background="@drawable/event_item_background">
|
||||||
android:foreground="@drawable/selector">
|
|
||||||
|
|
||||||
<RelativeLayout
|
<TextView
|
||||||
android:id="@+id/event_item_holder"
|
android:id="@+id/event_item_start"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/event_item_background"
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
android:paddingBottom="@dimen/event_padding"
|
android:text="13:00"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:textSize="@dimen/day_text_size"/>
|
||||||
android:paddingRight="@dimen/activity_margin"
|
|
||||||
android:paddingTop="@dimen/small_padding">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/event_item_start"
|
android:id="@+id/event_item_end"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="13:00"
|
android:layout_below="@+id/event_item_start"
|
||||||
android:textSize="@dimen/day_text_size"/>
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
|
android:text="15:00"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/event_item_end"
|
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_below="@+id/event_item_start"
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
android:text="15:00"
|
android:layout_toRightOf="@+id/event_item_start"
|
||||||
android:textSize="@dimen/day_text_size"/>
|
android:maxLines="1"
|
||||||
|
android:text="Event title"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/event_item_title"
|
android:id="@+id/event_item_description"
|
||||||
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:layout_below="@+id/event_item_title"
|
||||||
android:layout_toRightOf="@+id/event_item_start"
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
android:maxLines="1"
|
android:layout_toRightOf="@+id/event_item_end"
|
||||||
android:text="Event title"
|
android:alpha=".4"
|
||||||
android:textSize="@dimen/day_text_size"/>
|
android:maxLines="1"
|
||||||
|
android:text="Event description"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
<TextView
|
</RelativeLayout>
|
||||||
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>
|
|
||||||
|
@@ -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"/>
|
||||||
|
Reference in New Issue
Block a user