fix #285, rework the event list widgets top

This commit is contained in:
tibbi 2018-01-11 20:17:10 +01:00
parent 9614997324
commit 136e5e2fcf
4 changed files with 25 additions and 22 deletions

View File

@ -31,7 +31,6 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
private val textColor = context.config.widgetTextColor private val textColor = context.config.widgetTextColor
private val replaceDescription = context.config.replaceDescription private val replaceDescription = context.config.replaceDescription
private var mediumFontSize = context.config.getFontSize() private var mediumFontSize = context.config.getFontSize()
private var todayDate = ""
override fun getViewAt(position: Int): RemoteViews? { override fun getViewAt(position: Int): RemoteViews? {
val type = getItemViewType(position) val type = getItemViewType(position)
@ -99,11 +98,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
override fun getViewTypeCount() = 2 override fun getViewTypeCount() = 2
override fun onCreate() { override fun onCreate() {}
val now = (System.currentTimeMillis() / 1000).toInt()
val todayCode = Formatter.getDayCodeFromTS(now)
todayDate = Formatter.getDayTitle(context, todayCode)
}
override fun getItemId(position: Int) = position.toLong() override fun getItemId(position: Int) = position.toLong()
@ -121,8 +116,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
val code = Formatter.getDayCodeFromTS(it.startTS) val code = Formatter.getDayCodeFromTS(it.startTS)
if (code != prevCode) { if (code != prevCode) {
val day = Formatter.getDayTitle(context, code) val day = Formatter.getDayTitle(context, code)
if (day != todayDate) listItems.add(ListSection(day))
listItems.add(ListSection(day))
prevCode = code prevCode = code
} }
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location)) listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location))

View File

@ -14,6 +14,7 @@ object Formatter {
val TIME_PATTERN = "HHmmss" val TIME_PATTERN = "HHmmss"
private val DAY_PATTERN = "d" private val DAY_PATTERN = "d"
private val DAY_OF_WEEK_PATTERN = "EEE" private val DAY_OF_WEEK_PATTERN = "EEE"
private val LONGEST_PATTERN = "MMMM dd YYYY (EEEE)"
private val PATTERN_TIME_12 = "hh:mm a" private val PATTERN_TIME_12 = "hh:mm a"
private val PATTERN_TIME_24 = "HH:mm" private val PATTERN_TIME_24 = "HH:mm"
@ -44,6 +45,8 @@ object Formatter {
date date
} }
fun getLongestDate(ts: Int) = getDateTimeFromTS(ts).toString(LONGEST_PATTERN)
fun getDate(context: Context, dateTime: DateTime, addDayOfWeek: Boolean = true) = getDayTitle(context, getDayCodeFromDateTime(dateTime), addDayOfWeek) fun getDate(context: Context, dateTime: DateTime, addDayOfWeek: Boolean = true) = getDayTitle(context, getDayCodeFromDateTime(dateTime), addDayOfWeek)
fun getFullDate(context: Context, dateTime: DateTime): String { fun getFullDate(context: Context, dateTime: DateTime): String {

View File

@ -40,12 +40,11 @@ class MyWidgetListProvider : AppWidgetProvider() {
setTextSize(R.id.widget_event_list_empty, fontSize) setTextSize(R.id.widget_event_list_empty, fontSize)
setTextColor(R.id.widget_event_list_today, textColor) setTextColor(R.id.widget_event_list_today, textColor)
setTextSize(R.id.widget_event_list_today, fontSize + 3) setTextSize(R.id.widget_event_list_today, fontSize)
} }
val now = (System.currentTimeMillis() / 1000).toInt() val now = (System.currentTimeMillis() / 1000).toInt()
val todayCode = Formatter.getDayCodeFromTS(now) val todayText = Formatter.getLongestDate(now)
val todayText = Formatter.getDayTitle(context, todayCode)
views.setText(R.id.widget_event_list_today, todayText) views.setText(R.id.widget_event_list_today, todayText)
views.setImageViewBitmap(R.id.widget_event_new_event, context.resources.getColoredBitmap(R.drawable.ic_plus, textColor)) views.setImageViewBitmap(R.id.widget_event_new_event, context.resources.getColoredBitmap(R.drawable.ic_plus, textColor))

View File

@ -7,22 +7,29 @@
<TextView <TextView
android:id="@+id/widget_event_list_today" android:id="@+id/widget_event_list_today"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/activity_margin" android:layout_alignBottom="@+id/widget_event_new_event"
android:textSize="@dimen/actionbar_text_size"/> android:layout_alignTop="@+id/widget_event_new_event"
android:layout_toLeftOf="@+id/widget_event_new_event"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:textSize="@dimen/normal_text_size"/>
<ImageView <ImageView
android:id="@+id/widget_event_new_event" android:id="@+id/widget_event_new_event"
style="@style/ArrowStyle" style="@style/ArrowStyle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_above="@+id/widget_event_list"
android:layout_alignBottom="@+id/widget_event_list_today"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignTop="@+id/widget_event_list_today" android:layout_alignParentTop="true"
android:paddingLeft="@dimen/activity_margin" android:paddingBottom="@dimen/medium_margin"
android:paddingRight="@dimen/activity_margin" android:paddingLeft="@dimen/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/ic_plus"/> android:src="@drawable/ic_plus"/>
@ -30,11 +37,11 @@
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:layout_below="@+id/widget_event_list_today" android:layout_below="@+id/widget_event_new_event"
android:clipToPadding="false" android:clipToPadding="false"
android:divider="@null" android:divider="@null"
android:dividerHeight="@dimen/medium_margin" android:dividerHeight="@dimen/medium_margin"
android:paddingBottom="@dimen/activity_margin" android:paddingBottom="@dimen/medium_margin"
android:paddingLeft="@dimen/activity_margin"/> android:paddingLeft="@dimen/activity_margin"/>
<TextView <TextView