diff options
Diffstat (limited to 'android/app/src/main/java/org')
| -rw-r--r-- | android/app/src/main/java/org/terst/doot/widget/ui/DootWidget.kt | 82 |
1 files changed, 51 insertions, 31 deletions
diff --git a/android/app/src/main/java/org/terst/doot/widget/ui/DootWidget.kt b/android/app/src/main/java/org/terst/doot/widget/ui/DootWidget.kt index 4a352fc..12de781 100644 --- a/android/app/src/main/java/org/terst/doot/widget/ui/DootWidget.kt +++ b/android/app/src/main/java/org/terst/doot/widget/ui/DootWidget.kt @@ -48,9 +48,10 @@ class DootWidget : GlanceAppWidget() { val now = prefs[Keys.NOW]?.let { runCatching { Instant.parse(it) }.getOrNull() } ?: Instant.now() val isRefreshing = prefs[Keys.IS_REFRESHING] ?: false + val textSize = WidgetTextSize.fromPref(prefs[Keys.TEXT_SIZE]) provideContent { - WidgetRoot(items, now, isRefreshing) + WidgetRoot(items, now, isRefreshing, textSize) } } @@ -61,7 +62,7 @@ class DootWidget : GlanceAppWidget() { } @Composable -fun WidgetRoot(items: List<WidgetItem>, now: Instant, isRefreshing: Boolean) { +fun WidgetRoot(items: List<WidgetItem>, now: Instant, isRefreshing: Boolean, textSize: WidgetTextSize) { val zone = ZoneId.systemDefault() val nowZoned: ZonedDateTime = now.atZone(zone) val todayStart = nowZoned.toLocalDate().atStartOfDay(zone).toInstant() @@ -125,8 +126,8 @@ fun WidgetRoot(items: List<WidgetItem>, now: Instant, isRefreshing: Boolean) { "TODAY", style = TextStyle( color = ColorProvider(Color(0x66FFFFFF)), - fontSize = 11.sp, - fontWeight = FontWeight.Bold + fontSize = textSize.scaledHeaderSize(11), + fontWeight = textSize.scaledHeaderWeight(FontWeight.Bold) ), modifier = GlanceModifier.defaultWeight() ) @@ -137,23 +138,23 @@ fun WidgetRoot(items: List<WidgetItem>, now: Instant, isRefreshing: Boolean) { } items(count = todayAllDay.size) { index -> - AllDayRow(todayAllDay[index]) + AllDayRow(todayAllDay[index], textSize) } items(count = gridEnd - gridStart + 1) { index -> - HourRow(gridStart + index, nowZoned, scheduledEvents, fragments, zone) + HourRow(gridStart + index, nowZoned, scheduledEvents, fragments, zone, textSize) } if (showTomorrow) { item { - TomorrowSection(tomorrowItems, tomorrowFrags, tomorrowAllDay, zone) + TomorrowSection(tomorrowItems, tomorrowFrags, tomorrowAllDay, zone, textSize) } } } } @Composable -fun AllDayRow(event: WidgetItem) { +fun AllDayRow(event: WidgetItem, textSize: WidgetTextSize) { val context = LocalContext.current val detailIntent = Intent(context, EventDetailActivity::class.java).apply { putExtra(EventDetailActivity.EXTRA_TITLE, event.title) @@ -173,7 +174,11 @@ fun AllDayRow(event: WidgetItem) { Box(modifier = GlanceModifier.width(3.dp).height(16.dp).background(color)) {} Text( text = event.title, - style = TextStyle(color = ColorProvider(Color.White.copy(alpha = 0.9f)), fontSize = 13.sp, fontWeight = FontWeight.Medium), + style = TextStyle( + color = ColorProvider(Color.White.copy(alpha = 0.9f)), + fontSize = textSize.scaledContentSize(13), + fontWeight = textSize.scaledContentWeight(FontWeight.Medium) + ), modifier = GlanceModifier.padding(start = 8.dp), maxLines = 1 ) @@ -227,7 +232,8 @@ fun HourRow( nowZoned: ZonedDateTime, scheduled: List<WidgetItem>, fragments: List<TaskFragment>, - @Suppress("UNUSED_PARAMETER") zone: ZoneId + @Suppress("UNUSED_PARAMETER") zone: ZoneId, + textSize: WidgetTextSize ) { val hourStart = nowZoned.withHour(hour).withMinute(0).withSecond(0).withNano(0).toInstant() val hourEnd = hourStart.plus(1, ChronoUnit.HOURS) @@ -249,7 +255,11 @@ fun HourRow( ) { Text( text = hourLabel(hour), - style = TextStyle(color = ColorProvider(Color(0x4DFFFFFF)), fontSize = 10.sp), + style = TextStyle( + color = ColorProvider(Color(0x4DFFFFFF)), + fontSize = textSize.scaledHeaderSize(10), + fontWeight = textSize.scaledHeaderWeight(FontWeight.Normal) + ), modifier = GlanceModifier.width(32.dp).padding(top = 2.dp) ) @@ -270,18 +280,18 @@ fun HourRow( eventsHere.forEach { event -> val isPast = event.end?.let { Instant.parse(it) < nowZoned.toInstant() } ?: false - EventBlock(event, isPast) + EventBlock(event, isPast, textSize) } fragsHere.forEach { frag -> - TaskFragmentBlock(frag) + TaskFragmentBlock(frag, textSize) } } } } @Composable -fun EventBlock(event: WidgetItem, isPast: Boolean) { +fun EventBlock(event: WidgetItem, isPast: Boolean, textSize: WidgetTextSize) { val context = LocalContext.current val detailIntent = Intent(context, EventDetailActivity::class.java).apply { putExtra(EventDetailActivity.EXTRA_TITLE, event.title) @@ -309,7 +319,8 @@ fun EventBlock(event: WidgetItem, isPast: Boolean) { text = event.title, style = TextStyle( color = ColorProvider(Color.White.copy(alpha = alpha)), - fontSize = 14.sp + fontSize = textSize.scaledContentSize(14), + fontWeight = textSize.scaledContentWeight(FontWeight.Normal) ), modifier = GlanceModifier.padding(start = 8.dp), maxLines = 1 @@ -318,7 +329,7 @@ fun EventBlock(event: WidgetItem, isPast: Boolean) { } @Composable -fun TaskFragmentBlock(fragment: TaskFragment) { +fun TaskFragmentBlock(fragment: TaskFragment, textSize: WidgetTextSize) { Column( modifier = GlanceModifier .fillMaxWidth() @@ -328,19 +339,19 @@ fun TaskFragmentBlock(fragment: TaskFragment) { "TODAY", style = TextStyle( color = ColorProvider(Color(0x73FFFFFF)), - fontSize = 9.sp, - fontWeight = FontWeight.Bold + fontSize = textSize.scaledHeaderSize(9), + fontWeight = textSize.scaledHeaderWeight(FontWeight.Bold) ), modifier = GlanceModifier.padding(start = 8.dp, top = 3.dp, bottom = 1.dp) ) fragment.slots.forEach { slot -> - TaskRow(slot.task) + TaskRow(slot.task, textSize) } } } @Composable -fun TaskRow(task: WidgetItem) { +fun TaskRow(task: WidgetItem, textSize: WidgetTextSize) { val context = LocalContext.current val detailIntent = Intent(context, TaskDetailActivity::class.java).apply { putExtra(TaskDetailActivity.EXTRA_ID, task.id) @@ -401,7 +412,8 @@ fun TaskRow(task: WidgetItem) { color = ColorProvider( if (task.isOverdue) Color(0xFFF87171) else Color(0xFFDDDDDD.toInt()) ), - fontSize = 14.sp + fontSize = textSize.scaledContentSize(14), + fontWeight = textSize.scaledContentWeight(FontWeight.Normal) ), maxLines = 1 ) @@ -410,7 +422,7 @@ fun TaskRow(task: WidgetItem) { } @Composable -fun TomorrowSection(items: List<WidgetItem>, fragments: List<TaskFragment>, allDayEvents: List<WidgetItem>, zone: ZoneId) { +fun TomorrowSection(items: List<WidgetItem>, fragments: List<TaskFragment>, allDayEvents: List<WidgetItem>, zone: ZoneId, textSize: WidgetTextSize) { Box(modifier = GlanceModifier.fillMaxWidth().height(1.dp).padding(vertical = 4.dp).background(Color(0x1AFFFFFF))) {} Row(modifier = GlanceModifier.fillMaxWidth().padding(top = 6.dp, bottom = 2.dp)) { @@ -418,30 +430,30 @@ fun TomorrowSection(items: List<WidgetItem>, fragments: List<TaskFragment>, allD "TOMORROW", style = TextStyle( color = ColorProvider(Color(0x66FFFFFF)), - fontSize = 11.sp, - fontWeight = FontWeight.Bold + fontSize = textSize.scaledHeaderSize(11), + fontWeight = textSize.scaledHeaderWeight(FontWeight.Bold) ) ) } - allDayEvents.forEach { AllDayRow(it) } + allDayEvents.forEach { AllDayRow(it, textSize) } items.forEach { item -> val isPast = false if (item.type == "event") { - TomorrowEventRow(item, zone) + TomorrowEventRow(item, zone, textSize) } else { - TaskRow(item) + TaskRow(item, textSize) } } fragments.forEach { frag -> - frag.slots.forEach { slot -> TaskRow(slot.task) } + frag.slots.forEach { slot -> TaskRow(slot.task, textSize) } } } @Composable -fun TomorrowEventRow(event: WidgetItem, zone: ZoneId) { +fun TomorrowEventRow(event: WidgetItem, zone: ZoneId, textSize: WidgetTextSize) { val context = LocalContext.current val detailIntent = Intent(context, EventDetailActivity::class.java).apply { putExtra(EventDetailActivity.EXTRA_TITLE, event.title) @@ -464,13 +476,21 @@ fun TomorrowEventRow(event: WidgetItem, zone: ZoneId) { ) { Text( text = timeLabel, - style = TextStyle(color = ColorProvider(Color(0x4DFFFFFF)), fontSize = 10.sp), + style = TextStyle( + color = ColorProvider(Color(0x4DFFFFFF)), + fontSize = textSize.scaledHeaderSize(10), + fontWeight = textSize.scaledHeaderWeight(FontWeight.Normal) + ), modifier = GlanceModifier.width(32.dp) ) Box(modifier = GlanceModifier.width(3.dp).height(16.dp).background(color)) {} Text( text = event.title, - style = TextStyle(color = ColorProvider(Color.White.copy(alpha = 0.75f)), fontSize = 13.sp), + style = TextStyle( + color = ColorProvider(Color.White.copy(alpha = 0.75f)), + fontSize = textSize.scaledContentSize(13), + fontWeight = textSize.scaledContentWeight(FontWeight.Normal) + ), modifier = GlanceModifier.padding(start = 8.dp), maxLines = 1 ) |
