add the events to the monthly widget too

This commit is contained in:
tibbi 2017-10-08 18:30:40 +02:00
parent a13e8f1147
commit 669a931224
2 changed files with 32 additions and 13 deletions

View File

@ -166,23 +166,41 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
textColor = primaryColor.getContrastColor()
val id = mRes.getIdentifier("day_$i", "id", packageName)
mRemoteViews!!.removeAllViews(id)
addDayNumber(day, packageName, textColor, id, primaryColor)
day.dayEvents.forEach {
var backgroundColor = it.color
var eventTextColor = backgroundColor.getContrastColor().adjustAlpha(MEDIUM_ALPHA)
if (!day.isThisMonth) {
eventTextColor = eventTextColor.adjustAlpha(0.25f)
backgroundColor = backgroundColor.adjustAlpha(0.25f)
}
mRemoteViews!!.apply {
removeAllViews(id)
val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_item_view).apply {
setTextViewText(R.id.day_monthly_number_id, day.value.toString())
setTextColor(R.id.day_monthly_number_id, textColor)
setTextViewText(R.id.day_monthly_id, it.title.replace(" ", "\u00A0"))
setTextColor(R.id.day_monthly_id, eventTextColor)
setBackgroundColor(R.id.day_monthly_id, backgroundColor)
}
mRemoteViews!!.addView(id, newRemoteView)
}
}
}
private fun addDayNumber(day: DayMonthly, packageName: String, textColor: Int, id: Int, primaryColor: Int) {
val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_item_view).apply {
setTextViewText(R.id.day_monthly_id, day.value.toString())
setTextColor(R.id.day_monthly_id, textColor)
if (day.isToday) {
setViewPadding(R.id.day_monthly_number_id, 10, 0, 10, 0)
setBackgroundColor(R.id.day_monthly_number_id, primaryColor)
setViewPadding(R.id.day_monthly_id, 10, 0, 10, 0)
setBackgroundColor(R.id.day_monthly_id, primaryColor)
}
}
addView(id, newRemoteView)
mRemoteViews!!.addView(id, newRemoteView)
setupDayOpenIntent(id, day.code)
}
}
}
private fun updateTopViews() {
mRemoteViews?.setTextColor(R.id.top_value, mTextColor)

View File

@ -2,12 +2,13 @@
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/day_monthly_number_id"
android:layout_width="wrap_content"
android:id="@+id/day_monthly_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/tiny_margin"
android:layout_marginRight="@dimen/tiny_margin"
android:ellipsize="none"
android:gravity="start"
android:maxLines="1"
android:paddingLeft="@dimen/tiny_margin"
android:paddingRight="@dimen/tiny_margin"