Month widget: day cells and weekday pills, shaded outside days, new-event button (#71)
This commit is contained in:
1 parent
7e45656479
commit
610409012f
6 files changed
+211
-24
No files matched your search
@@ -295,7 +295,7 @@ private fun AgendaHeader() {
|
||||
WidgetHeader(
|
||||
title = context.getString(R.string.widget_agenda_title),
|
||||
titleAction = actionStartActivity(MainActivity.openViewIntent(context, view = null)),
|
||||
modifier = GlanceModifier.padding(start = 4.dp),
|
||||
titleInset = 4.dp,
|
||||
) {
|
||||
WidgetHeaderAction(
|
||||
icon = ImageProvider(R.drawable.ic_widget_add),
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.text.style.StrikethroughSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import de.jeanlucmakiola.calendula.MainActivity
|
||||
import de.jeanlucmakiola.calendula.R
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
@@ -30,6 +31,7 @@ internal data class GridColors(
|
||||
val onSurfaceVariant: RemoteColor,
|
||||
val primary: RemoteColor,
|
||||
val onPrimary: RemoteColor,
|
||||
val cell: RemoteColor,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -69,6 +71,15 @@ private fun weekViews(
|
||||
week.removeAllViews(R.id.week_lanes)
|
||||
layout.week.days.forEachIndexed { col, date ->
|
||||
week.setOnClickPendingIntent(STRIP_IDS[col], openDayIntent(context, date))
|
||||
// Each day its own rounded cell, as in the app's month grid. Days around
|
||||
// the month get a shade over their (opaque) cell, so they recede without
|
||||
// letting a wallpaper show through.
|
||||
week.setImageTint(context, CELL_IDS[col], colors.cell)
|
||||
val outside = date.month != currentMonth
|
||||
week.setViewVisibility(CELL_DIM_IDS[col], if (outside) View.VISIBLE else View.GONE)
|
||||
if (outside) {
|
||||
week.setImageTint(context, CELL_DIM_IDS[col], mode.remoteColor(OUTSIDE_SHADE_DAY, OUTSIDE_SHADE_NIGHT))
|
||||
}
|
||||
val dayId = DAY_IDS[col]
|
||||
val isToday = date == today
|
||||
week.setTextViewText(dayId, if (isToday) bold(date.day.toString()) else date.day.toString())
|
||||
@@ -136,6 +147,14 @@ private fun openDayIntent(context: Context, date: LocalDate): PendingIntent = Pe
|
||||
)
|
||||
|
||||
private val STRIP_IDS = intArrayOf(R.id.strip_0, R.id.strip_1, R.id.strip_2, R.id.strip_3, R.id.strip_4, R.id.strip_5, R.id.strip_6)
|
||||
/** The shade over a day outside the month: a dark cell needs more of it to read as dimmed. */
|
||||
private val OUTSIDE_SHADE_DAY = Color.Black.copy(alpha = 0.18f)
|
||||
private val OUTSIDE_SHADE_NIGHT = Color.Black.copy(alpha = 0.50f)
|
||||
|
||||
private val CELL_DIM_IDS = intArrayOf(
|
||||
R.id.cell_dim_0, R.id.cell_dim_1, R.id.cell_dim_2, R.id.cell_dim_3, R.id.cell_dim_4, R.id.cell_dim_5, R.id.cell_dim_6,
|
||||
)
|
||||
private val CELL_IDS = intArrayOf(R.id.cell_0, R.id.cell_1, R.id.cell_2, R.id.cell_3, R.id.cell_4, R.id.cell_5, R.id.cell_6)
|
||||
private val DAY_IDS = intArrayOf(R.id.day_0, R.id.day_1, R.id.day_2, R.id.day_3, R.id.day_4, R.id.day_5, R.id.day_6)
|
||||
private val TODAY_IDS = intArrayOf(
|
||||
R.id.today_bg_0, R.id.today_bg_1, R.id.today_bg_2, R.id.today_bg_3, R.id.today_bg_4, R.id.today_bg_5, R.id.today_bg_6,
|
||||
|
||||
@@ -21,6 +21,10 @@ import androidx.glance.action.ActionParameters
|
||||
import androidx.glance.action.actionParametersOf
|
||||
import androidx.glance.appwidget.GlanceAppWidget
|
||||
import androidx.glance.appwidget.AndroidRemoteViews
|
||||
import de.jeanlucmakiola.floret.glance.WidgetBackground
|
||||
import de.jeanlucmakiola.floret.glance.LocalWidgetBackground
|
||||
import androidx.glance.background
|
||||
import androidx.glance.appwidget.cornerRadius
|
||||
import androidx.glance.appwidget.SizeMode
|
||||
import androidx.glance.appwidget.action.ActionCallback
|
||||
import androidx.glance.appwidget.action.actionRunCallback
|
||||
@@ -88,11 +92,11 @@ private val GRID_HPADDING = 8.dp
|
||||
|
||||
/**
|
||||
* Height around the week rows: body padding, the header's bottom padding and
|
||||
* spacer, then the header (its 28dp pills, or a title line in its transparent
|
||||
* spacer and the weekday pills' padding, then the header (its 28dp pills, or a title line in its transparent
|
||||
* pill when that's taller) and the weekday row, the text lines at [fontScale].
|
||||
*/
|
||||
private fun gridChromeHeight(fontScale: Float): Dp =
|
||||
18.dp + maxOf(28.dp, 19.dp * fontScale + 8.dp) + 15.dp * fontScale
|
||||
21.dp + maxOf(28.dp, 19.dp * fontScale + 8.dp) + 15.dp * fontScale
|
||||
|
||||
private fun currentMonthIndex(zone: TimeZone): Int = monthIndexOf(today(zone))
|
||||
|
||||
@@ -248,12 +252,15 @@ private fun MonthWidgetBody(source: MonthWidgetSource, index: Int) {
|
||||
onSurfaceVariant = remoteColor(WidgetColorRole.ON_SURFACE_VARIANT),
|
||||
primary = remoteColor(WidgetColorRole.PRIMARY),
|
||||
onPrimary = remoteColor(WidgetColorRole.ON_PRIMARY),
|
||||
cell = remoteColor(monthCellRole()),
|
||||
)
|
||||
|
||||
MonthHeader(label = monthLabel(ym, source.today.year), today = source.today)
|
||||
Spacer(GlanceModifier.height(4.dp))
|
||||
// One backing for the whole grid on a transparent widget (#292).
|
||||
Column(modifier = GlanceModifier.fillMaxWidth().defaultWeight().wallpaperBacking()) {
|
||||
// No backing behind the grid: the weekday pills and day cells
|
||||
// each carry their own fill, so a transparent widget stays
|
||||
// readable without one blob over the wallpaper (#292).
|
||||
Column(modifier = GlanceModifier.fillMaxWidth().defaultWeight()) {
|
||||
WeekdayHeader(weekStart = source.weekStart, colW = colW)
|
||||
AndroidRemoteViews(
|
||||
remoteViews = monthGridViews(context, layouts, ym.month, source.today, source.soften, colors, mode),
|
||||
@@ -273,7 +280,8 @@ private fun MonthHeader(label: String, today: LocalDate) {
|
||||
WidgetHeader(
|
||||
title = label,
|
||||
titleAction = actionStartActivity(MainActivity.openViewIntent(context, CalendarView.Month)),
|
||||
modifier = GlanceModifier.padding(start = 4.dp, bottom = 2.dp),
|
||||
modifier = GlanceModifier.padding(bottom = 2.dp),
|
||||
titleInset = 4.dp,
|
||||
) {
|
||||
WidgetHeaderAction(
|
||||
icon = ImageProvider(R.drawable.ic_widget_chevron_left),
|
||||
@@ -288,6 +296,7 @@ private fun MonthHeader(label: String, today: LocalDate) {
|
||||
text = today.day.toString(),
|
||||
contentDescription = context.getString(R.string.widget_today),
|
||||
action = actionRunCallback<ResetMonthAction>(),
|
||||
style = WidgetActionStyle.TONAL,
|
||||
)
|
||||
WidgetHeaderActionGap()
|
||||
WidgetHeaderAction(
|
||||
@@ -296,26 +305,47 @@ private fun MonthHeader(label: String, today: LocalDate) {
|
||||
action = actionRunCallback<ShiftMonthAction>(actionParametersOf(ShiftMonthAction.deltaKey to 1)),
|
||||
style = WidgetActionStyle.TONAL,
|
||||
)
|
||||
WidgetHeaderActionGap()
|
||||
WidgetHeaderAction(
|
||||
icon = ImageProvider(R.drawable.ic_widget_add),
|
||||
contentDescription = context.getString(R.string.widget_new_event),
|
||||
action = actionStartActivity(MainActivity.openCreateIntent(context, today)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WeekdayHeader(weekStart: DayOfWeek, colW: Dp) {
|
||||
Row(modifier = GlanceModifier.fillMaxWidth()) {
|
||||
Row(modifier = GlanceModifier.fillMaxWidth().padding(bottom = 1.dp)) {
|
||||
weekdayNarrowNames(weekStart).forEach { name ->
|
||||
Text(
|
||||
text = name,
|
||||
style = TextStyle(
|
||||
color = GlanceTheme.colors.onSurfaceVariant,
|
||||
fontSize = 11.sp,
|
||||
textAlign = TextAlign.Center,
|
||||
),
|
||||
modifier = GlanceModifier.width(colW),
|
||||
)
|
||||
Box(modifier = GlanceModifier.width(colW).padding(horizontal = 1.dp)) {
|
||||
Text(
|
||||
text = name,
|
||||
style = TextStyle(
|
||||
color = GlanceTheme.colors.onPrimaryContainer,
|
||||
fontSize = 11.sp,
|
||||
textAlign = TextAlign.Center,
|
||||
),
|
||||
modifier = GlanceModifier
|
||||
.fillMaxWidth()
|
||||
.cornerRadius(8.dp)
|
||||
.background(GlanceTheme.colors.primaryContainer)
|
||||
.padding(vertical = 1.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The fill of a day cell: one tone off a filled root, the widget surface over a wallpaper. */
|
||||
private fun monthCellRole(background: WidgetBackground): WidgetColorRole = when (background) {
|
||||
WidgetBackground.SOLID -> WidgetColorRole.SURFACE_VARIANT
|
||||
WidgetBackground.TINTED, WidgetBackground.TRANSPARENT -> WidgetColorRole.WIDGET_BACKGROUND
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun monthCellRole(): WidgetColorRole = monthCellRole(LocalWidgetBackground.current)
|
||||
|
||||
/** Narrow weekday initials starting at [weekStart], in the device locale.
|
||||
* Computed outside the composable so the locale read stays observable-safe. */
|
||||
private fun weekdayNarrowNames(weekStart: DayOfWeek): List<String> {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<corners android:radius="8dp" />
|
||||
<solid android:color="@android:color/white" />
|
||||
</shape>
|
||||
@@ -13,43 +13,176 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground" />
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_dim_0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/strip_1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground" />
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_dim_1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/strip_2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground" />
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_dim_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/strip_3"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground" />
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_dim_3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/strip_4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground" />
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_dim_4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/strip_5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground" />
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_dim_5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/strip_6"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground" />
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="1dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_6"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cell_dim_6"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/widget_month_cell_bg"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
+1
-1
Submodule floret-kit updated: 76e07fe8cb...f2ffaed925.
Reference in new issue
Block a user