Move some ColorProvider stuff to kmp

pull/2984/head
Alex Baker 4 months ago
parent f66df67592
commit 3ab672bfbc

@ -8,7 +8,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import org.tasks.data.entity.Task import org.tasks.data.entity.Task
import org.tasks.themes.ColorProvider import org.tasks.kmp.org.tasks.themes.ColorProvider.priorityColor
import org.tasks.ui.CheckBoxProvider.Companion.getCheckboxRes import org.tasks.ui.CheckBoxProvider.Companion.getCheckboxRes
@Composable @Composable
@ -22,7 +22,7 @@ fun CheckBox(
Icon( Icon(
painter = painterResource(id = task.getCheckboxRes()), painter = painterResource(id = task.getCheckboxRes()),
tint = Color( tint = Color(
ColorProvider.priorityColor( priorityColor(
priority = task.priority, priority = task.priority,
isDarkMode = isSystemInDarkTheme(), isDarkMode = isSystemInDarkTheme(),
desaturate = desaturate, desaturate = desaturate,

@ -28,7 +28,7 @@ import androidx.compose.ui.unit.dp
import org.tasks.R import org.tasks.R
import org.tasks.compose.TaskEditRow import org.tasks.compose.TaskEditRow
import org.tasks.data.entity.Task import org.tasks.data.entity.Task
import org.tasks.themes.ColorProvider.Companion.priorityColor import org.tasks.kmp.org.tasks.themes.ColorProvider.priorityColor
import org.tasks.themes.TasksTheme import org.tasks.themes.TasksTheme
@Composable @Composable

@ -13,7 +13,7 @@ import org.tasks.compose.ChipGroup
import org.tasks.compose.DisabledText import org.tasks.compose.DisabledText
import org.tasks.compose.TaskEditRow import org.tasks.compose.TaskEditRow
import org.tasks.data.entity.TagData import org.tasks.data.entity.TagData
import org.tasks.themes.ColorProvider import org.tasks.kmp.org.tasks.themes.ColorProvider.BLUE_500
import org.tasks.themes.TasksIcons import org.tasks.themes.TasksIcons
import org.tasks.themes.TasksTheme import org.tasks.themes.TasksTheme
@ -74,7 +74,7 @@ fun SingleTag() {
TagData( TagData(
name = "Home", name = "Home",
icon = "home", icon = "home",
color = ColorProvider.BLUE_500 color = BLUE_500
) )
), ),
colorProvider = { it }, colorProvider = { it },
@ -112,7 +112,7 @@ fun TagWithReallyLongName() {
TagData( TagData(
name = "This is a tag with a really really long name", name = "This is a tag with a really really long name",
icon = "home", icon = "home",
color = ColorProvider.BLUE_500 color = BLUE_500
) )
), ),
colorProvider = { it }, colorProvider = { it },

@ -25,7 +25,7 @@ import org.tasks.data.entity.Task.Companion.NOTIFY_AFTER_DEADLINE
import org.tasks.data.entity.Task.Companion.NOTIFY_AT_DEADLINE import org.tasks.data.entity.Task.Companion.NOTIFY_AT_DEADLINE
import org.tasks.data.entity.TaskAttachment import org.tasks.data.entity.TaskAttachment
import org.tasks.extensions.Context.getResourceUri import org.tasks.extensions.Context.getResourceUri
import org.tasks.themes.ColorProvider import org.tasks.kmp.org.tasks.themes.ColorProvider.BLUE_500
import org.tasks.themes.ThemeBase import org.tasks.themes.ThemeBase
import org.tasks.time.DateTime import org.tasks.time.DateTime
import org.tasks.time.DateTimeUtils2.currentTimeMillis import org.tasks.time.DateTimeUtils2.currentTimeMillis
@ -558,7 +558,7 @@ class Preferences @JvmOverloads constructor(
} }
val defaultThemeColor: Int val defaultThemeColor: Int
get() = getInt(R.string.p_theme_color, ColorProvider.BLUE_500) get() = getInt(R.string.p_theme_color, BLUE_500)
val markdown: Boolean val markdown: Boolean
get() = getBoolean(R.string.p_markdown, false) get() = getBoolean(R.string.p_markdown, false)

@ -2,9 +2,10 @@ package org.tasks.themes
import android.content.Context import android.content.Context
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import org.tasks.data.entity.Task
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.R import org.tasks.R
import org.tasks.kmp.org.tasks.themes.ColorProvider.priorityColor
import org.tasks.kmp.org.tasks.themes.ColorProvider.saturated
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import javax.inject.Inject import javax.inject.Inject
@ -13,79 +14,6 @@ class ColorProvider @Inject constructor(
preferences: Preferences preferences: Preferences
) { ) {
companion object {
const val BLUE_500 = -14575885
private const val RED_500 = -769226
private const val AMBER_500 = -16121
private const val GREY_500 = -6381922
private const val WHITE = -1
private const val BLACK = -16777216
private val saturated: Map<Int, Int> = hashMapOf(
// 2014 material design palette
-10453621 to -7297874, // blue_grey
RED_500 to -1739917, // red
-1499549 to -1023342, // pink
-6543440 to -4560696, // purple
-10011977 to -6982195, // deep purple
// -12627531 to -8812853, // indigo
BLUE_500 to -10177034, // blue
-16537100 to -11549705, // light blue
-16728876 to -11677471, // cyan
// -16738680 to -11684180, // teal
-11751600 to -8271996, // green
-7617718 to -5319295, // light green
-3285959 to -2300043, // lime
-5317 to -3722, // yellow
AMBER_500 to -10929, // amber
-26624 to -18611, // orange
-43230 to -30107, // deep orange
// -8825528 to -6190977, // brown
GREY_500 to -2039584, // grey
WHITE to BLACK,
// 2019 google calendar
-2818048 to -3397335, // tomato
-765666 to -2136512, // tangerine
-1086464 to -2459092, // pumpkin
-1010944 to -2254804, // mango
-606426 to -2050234, // banana
-1784767 to -2769834, // citron
-4142541 to -4274613, // avocado
-8604862 to -7817131, // pistachio
-16023485 to -14116514, // basil
-16738680 to -14571622, // eucalyptus
-13388167 to -11879802, // sage
-16540699 to -13787178, // peacock
-12417548 to -10974241, // cobalt
-12627531 to -11312199, // blueberry
-8812853 to -8615738, // lavender
-5005861 to -5597744, // wisteria
-6395473 to -5934410, // amethyst
-7461718 to -6668365, // grape
-5434281 to -4967572, // radicchio
-2614432 to -3261327, // cherry blossom
-1672077 to -2654344, // flamingo
-8825528 to -6984611, // cocoa
-10395295 to -7895161, // graphite
-5792882 to -5135210 // birch
)
fun priorityColor(priority: Int, isDarkMode: Boolean = false, desaturate: Boolean = false): Int {
val color = when (priority) {
in Int.MIN_VALUE..Task.Priority.HIGH -> RED_500
Task.Priority.MEDIUM -> AMBER_500
Task.Priority.LOW -> BLUE_500
else -> GREY_500
}
return if (isDarkMode && desaturate) {
saturated[color] ?: color
} else {
color
}
}
}
private val isDark = context.resources.getBoolean(R.bool.is_dark) private val isDark = context.resources.getBoolean(R.bool.is_dark)
private val desaturate = preferences.desaturateDarkMode private val desaturate = preferences.desaturateDarkMode

@ -25,11 +25,11 @@ import org.tasks.extensions.setTextSize
import org.tasks.extensions.strikethrough import org.tasks.extensions.strikethrough
import org.tasks.filters.AstridOrderingFilter import org.tasks.filters.AstridOrderingFilter
import org.tasks.filters.Filter import org.tasks.filters.Filter
import org.tasks.kmp.org.tasks.themes.ColorProvider.priorityColor
import org.tasks.markdown.Markdown import org.tasks.markdown.Markdown
import org.tasks.tasklist.HeaderFormatter import org.tasks.tasklist.HeaderFormatter
import org.tasks.tasklist.SectionedDataSource import org.tasks.tasklist.SectionedDataSource
import org.tasks.tasklist.headerColor import org.tasks.tasklist.headerColor
import org.tasks.themes.ColorProvider.Companion.priorityColor
import org.tasks.time.DateTimeUtils2.currentTimeMillis import org.tasks.time.DateTimeUtils2.currentTimeMillis
import org.tasks.time.startOfDay import org.tasks.time.startOfDay
import org.tasks.ui.CheckBoxProvider.Companion.getCheckboxRes import org.tasks.ui.CheckBoxProvider.Companion.getCheckboxRes

@ -0,0 +1,76 @@
package org.tasks.kmp.org.tasks.themes
import org.tasks.data.entity.Task
object ColorProvider {
const val BLUE_500 = -14575885
private const val RED_500 = -769226
private const val AMBER_500 = -16121
private const val GREY_500 = -6381922
private const val WHITE = -1
private const val BLACK = -16777216
val saturated: Map<Int, Int> = hashMapOf(
// 2014 material design palette
-10453621 to -7297874, // blue_grey
RED_500 to -1739917, // red
-1499549 to -1023342, // pink
-6543440 to -4560696, // purple
-10011977 to -6982195, // deep purple
// -12627531 to -8812853, // indigo
BLUE_500 to -10177034, // blue
-16537100 to -11549705, // light blue
-16728876 to -11677471, // cyan
// -16738680 to -11684180, // teal
-11751600 to -8271996, // green
-7617718 to -5319295, // light green
-3285959 to -2300043, // lime
-5317 to -3722, // yellow
AMBER_500 to -10929, // amber
-26624 to -18611, // orange
-43230 to -30107, // deep orange
// -8825528 to -6190977, // brown
GREY_500 to -2039584, // grey
WHITE to BLACK,
// 2019 google calendar
-2818048 to -3397335, // tomato
-765666 to -2136512, // tangerine
-1086464 to -2459092, // pumpkin
-1010944 to -2254804, // mango
-606426 to -2050234, // banana
-1784767 to -2769834, // citron
-4142541 to -4274613, // avocado
-8604862 to -7817131, // pistachio
-16023485 to -14116514, // basil
-16738680 to -14571622, // eucalyptus
-13388167 to -11879802, // sage
-16540699 to -13787178, // peacock
-12417548 to -10974241, // cobalt
-12627531 to -11312199, // blueberry
-8812853 to -8615738, // lavender
-5005861 to -5597744, // wisteria
-6395473 to -5934410, // amethyst
-7461718 to -6668365, // grape
-5434281 to -4967572, // radicchio
-2614432 to -3261327, // cherry blossom
-1672077 to -2654344, // flamingo
-8825528 to -6984611, // cocoa
-10395295 to -7895161, // graphite
-5792882 to -5135210 // birch
)
fun priorityColor(priority: Int, isDarkMode: Boolean = false, desaturate: Boolean = false): Int {
val color = when (priority) {
in Int.MIN_VALUE..Task.Priority.HIGH -> RED_500
Task.Priority.MEDIUM -> AMBER_500
Task.Priority.LOW -> BLUE_500
else -> GREY_500
}
return if (isDarkMode && desaturate) {
saturated[color] ?: color
} else {
color
}
}
}
Loading…
Cancel
Save