Skip to content

Commit

Permalink
[BUG] Widget font color does not adjust to dark mode #1560
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickunterwegs committed Nov 11, 2024
1 parent 6db1851 commit 02151ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/at/techbee/jtx/widgets/ListWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ class ListWidget : GlanceAppWidget() {
)
}

val defaultOnSurfaceVariantColor = GlanceTheme.colors.onSurfaceVariant
val entryHeaderTextColor = remember(listWidgetConfig) {
if (listWidgetConfig.widgetColorEntries == null)
defaultOnSurfaceVariantColor
else
FixedColorProvider(
if(UiUtil.isDarkColor(entryColor.getColor(context)))
Color.White.copy(alpha = if(listWidgetConfig.widgetAlphaEntries < MIN_ALPHA_FOR_TEXT) MIN_ALPHA_FOR_TEXT else listWidgetConfig.widgetAlphaEntries)
else
Color.Black.copy(alpha = if(listWidgetConfig.widgetAlphaEntries < MIN_ALPHA_FOR_TEXT) MIN_ALPHA_FOR_TEXT else listWidgetConfig.widgetAlphaEntries)
)
}

GlanceTheme {
ListWidgetContent(
listWidgetConfig,
Expand All @@ -194,6 +207,7 @@ class ListWidget : GlanceAppWidget() {
textColor = textColor,
entryColor = entryColor,
entryTextColor = entryTextColor,
entryHeaderTextColor = entryHeaderTextColor,
onCheckedChange = { iCalObjectId, checked ->
scope.launch(Dispatchers.IO) {
val settingsStateHolder = SettingsStateHolder(context)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/at/techbee/jtx/widgets/ListWidgetContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fun ListWidgetContent(
textColor: ColorProvider,
entryColor: ColorProvider,
entryTextColor: ColorProvider,
entryHeaderTextColor: ColorProvider,
onCheckedChange: (iCalObjectId: Long, checked: Boolean) -> Unit,
onOpenWidgetConfig: () -> Unit,
onAddNew: () -> Unit,
Expand Down Expand Up @@ -149,6 +150,7 @@ fun ListWidgetContent(
obj = entry.iCal4List,
entryColor = entryColor,
textColor = entryTextColor,
headerTextColor = entryHeaderTextColor,
checkboxPosition = listWidgetConfig.checkboxPosition,
showDescription = listWidgetConfig.showDescription,
onCheckedChange = onCheckedChange,
Expand Down Expand Up @@ -177,6 +179,7 @@ fun ListWidgetContent(
obj = subtask.iCal4List,
entryColor = entryColor,
textColor = entryTextColor,
headerTextColor = entryHeaderTextColor,
checkboxPosition = listWidgetConfig.checkboxPosition,
showDescription = listWidgetConfig.showDescription,
onCheckedChange = onCheckedChange,
Expand Down Expand Up @@ -204,6 +207,7 @@ fun ListWidgetContent(
obj = subnote.iCal4List,
entryColor = entryColor,
textColor = entryTextColor,
headerTextColor = entryHeaderTextColor,
checkboxPosition = listWidgetConfig.checkboxPosition,
showDescription = listWidgetConfig.showDescription,
onCheckedChange = onCheckedChange,
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/at/techbee/jtx/widgets/ListWidgetEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ fun ListEntry(
obj: ICal4List,
entryColor: ColorProvider,
textColor: ColorProvider,
headerTextColor: ColorProvider,
checkboxPosition: CheckboxPosition,
showDescription: Boolean,
onCheckedChange: (iCalObjectId: Long, checked: Boolean) -> Unit,
modifier: GlanceModifier = GlanceModifier
) {

val context = LocalContext.current
val metaBarColor = ColorProvider(textColor.getColor(context).copy(alpha = 0.7f))
val textStyleMetaInfo = TextStyle(fontStyle = FontStyle.Italic, fontSize = 12.sp, color = metaBarColor)
val textStyleMetaInfo = TextStyle(fontStyle = FontStyle.Italic, fontSize = 12.sp, color = headerTextColor)
val textStyleDateOverdue = textStyleMetaInfo.copy(color = ColorProvider(Color.Red), fontWeight = FontWeight.Bold)
val textStyleSummary = TextStyle(fontWeight = FontWeight.Bold, fontSize = 14.sp, color = textColor)
val textStyleDescription = TextStyle(color = textColor, fontSize = 12.sp)
Expand Down Expand Up @@ -108,7 +108,7 @@ fun ListEntry(
provider = ImageProvider(if (obj.module == Module.TODO.name) R.drawable.ic_widget_start else R.drawable.ic_start2),
contentDescription = context.getString(R.string.started),
modifier = GlanceModifier.size(imageSize).padding(end = 4.dp),
colorFilter = ColorFilter.tint(metaBarColor)
colorFilter = ColorFilter.tint(textStyleMetaInfo.color)
)
Text(
text = ICalObject.getDtstartTextInfo(
Expand All @@ -128,7 +128,7 @@ fun ListEntry(
provider = ImageProvider(R.drawable.ic_widget_due),
contentDescription = context.getString(R.string.due),
modifier = GlanceModifier.size(imageSize).padding(end = 4.dp),
colorFilter = ColorFilter.tint(metaBarColor)
colorFilter = ColorFilter.tint(textStyleMetaInfo.color)
)
Text(
text = ICalObject.getDueTextInfo(
Expand All @@ -149,7 +149,7 @@ fun ListEntry(
provider = ImageProvider(R.drawable.ic_priority),
contentDescription = context.getString(R.string.priority),
modifier = GlanceModifier.size(imageSize).padding(end = 4.dp),
colorFilter = ColorFilter.tint(metaBarColor)
colorFilter = ColorFilter.tint(textStyleMetaInfo.color)
)
Text(
text = obj.priority.toString(),
Expand All @@ -164,7 +164,7 @@ fun ListEntry(
provider = ImageProvider(R.drawable.ic_status),
contentDescription = context.getString(R.string.status),
modifier = GlanceModifier.size(imageSize).padding(end = 4.dp),
colorFilter = ColorFilter.tint(metaBarColor)
colorFilter = ColorFilter.tint(textStyleMetaInfo.color)
)
Text(
text = obj.xstatus
Expand All @@ -181,7 +181,7 @@ fun ListEntry(
provider = ImageProvider(R.drawable.ic_classification),
contentDescription = context.getString(R.string.classification),
modifier = GlanceModifier.size(imageSize).padding(end = 4.dp),
colorFilter = ColorFilter.tint(metaBarColor)
colorFilter = ColorFilter.tint(textStyleMetaInfo.color)
)
Text(
text = Classification.getClassificationFromString(obj.classification)?.let { context.getString(it.stringResource) } ?: "",
Expand Down

0 comments on commit 02151ae

Please sign in to comment.