Skip to content

Commit

Permalink
Calculate contrast color for widget texts correctly
Browse files Browse the repository at this point in the history
Closes  #1311
  • Loading branch information
patrickunterwegs committed Apr 6, 2024
1 parent e0b1bbf commit 37cc37b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
13 changes: 7 additions & 6 deletions app/src/main/java/at/techbee/jtx/widgets/ListWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

const val MAX_WIDGET_ENTRIES = 50
const val MIN_ALPHA_FOR_TEXT = 0.8f

class ListWidget : GlanceAppWidget() {

Expand Down Expand Up @@ -157,10 +158,10 @@ class ListWidget : GlanceAppWidget() {
defaultTextColor
else
ColorProvider(
if(UiUtil.isDarkColor(defaultBackgroundColor.getColor(context)))
Color.White.copy(alpha = listWidgetConfig.widgetAlpha)
if(UiUtil.isDarkColor(backgorundColor.getColor(context)))
Color.White.copy(alpha = if(listWidgetConfig.widgetAlpha < MIN_ALPHA_FOR_TEXT) MIN_ALPHA_FOR_TEXT else listWidgetConfig.widgetAlpha)
else
Color.Black.copy(alpha = listWidgetConfig.widgetAlpha)
Color.Black.copy(alpha = if(listWidgetConfig.widgetAlpha < MIN_ALPHA_FOR_TEXT) MIN_ALPHA_FOR_TEXT else listWidgetConfig.widgetAlpha)
)
}

Expand All @@ -180,10 +181,10 @@ class ListWidget : GlanceAppWidget() {
defaultOnSurfaceColor
else
ColorProvider(
if(UiUtil.isDarkColor(defaultSurfaceColor.getColor(context)))
Color.White.copy(alpha = listWidgetConfig.widgetAlphaEntries)
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 = listWidgetConfig.widgetAlphaEntries)
Color.Black.copy(alpha = if(listWidgetConfig.widgetAlphaEntries < MIN_ALPHA_FOR_TEXT) MIN_ALPHA_FOR_TEXT else listWidgetConfig.widgetAlphaEntries)
)
}

Expand Down
8 changes: 2 additions & 6 deletions app/src/main/java/at/techbee/jtx/widgets/ListWidgetContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.glance.ColorFilter
import androidx.glance.GlanceModifier
import androidx.glance.GlanceTheme
import androidx.glance.Image
import androidx.glance.ImageProvider
import androidx.glance.LocalContext
Expand Down Expand Up @@ -98,7 +97,7 @@ fun ListWidgetContent(
}
},
style = TextStyle(
color = GlanceTheme.colors.onPrimaryContainer,
color = textColor,
fontSize = 16.sp,
fontWeight = FontWeight.Bold
),
Expand Down Expand Up @@ -139,7 +138,7 @@ fun ListWidgetContent(
Text(
text = key,
style = TextStyle(
color = GlanceTheme.colors.onPrimaryContainer,
color = textColor,
//fontSize = 16.sp,
fontWeight = FontWeight.Bold
),
Expand All @@ -160,7 +159,6 @@ fun ListWidgetContent(
obj = entry.iCal4List,
entryColor = entryColor,
textColor = entryTextColor,
textColorOverdue = entryOverdueTextColor,
checkboxPosition = listWidgetConfig.checkboxPosition,
showDescription = listWidgetConfig.showDescription,
onCheckedChange = onCheckedChange,
Expand Down Expand Up @@ -189,7 +187,6 @@ fun ListWidgetContent(
obj = subtask.iCal4List,
entryColor = entryColor,
textColor = entryTextColor,
textColorOverdue = entryOverdueTextColor,
checkboxPosition = listWidgetConfig.checkboxPosition,
showDescription = listWidgetConfig.showDescription,
onCheckedChange = onCheckedChange,
Expand Down Expand Up @@ -217,7 +214,6 @@ fun ListWidgetContent(
obj = subnote.iCal4List,
entryColor = entryColor,
textColor = entryTextColor,
textColorOverdue = entryOverdueTextColor,
checkboxPosition = listWidgetConfig.checkboxPosition,
showDescription = listWidgetConfig.showDescription,
onCheckedChange = onCheckedChange,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/at/techbee/jtx/widgets/ListWidgetEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package at.techbee.jtx.widgets

import android.content.Intent
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.glance.ColorFilter
Expand Down Expand Up @@ -47,7 +48,6 @@ fun ListEntry(
obj: ICal4List,
entryColor: ColorProvider,
textColor: ColorProvider,
textColorOverdue: ColorProvider,
checkboxPosition: CheckboxPosition,
showDescription: Boolean,
onCheckedChange: (iCalObjectId: Long, checked: Boolean) -> Unit,
Expand All @@ -56,7 +56,7 @@ fun ListEntry(

val context = LocalContext.current
val textStyleDate = TextStyle(fontStyle = FontStyle.Italic, fontSize = 12.sp, color = textColor)
val textStyleDateOverdue = textStyleDate.copy(color = textColorOverdue, fontWeight = FontWeight.Bold)
val textStyleDateOverdue = textStyleDate.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

0 comments on commit 37cc37b

Please sign in to comment.