Remove GREY_900 theme, fix black/white theme

pull/3385/head
Alex Baker 9 months ago
parent aafe4b37b0
commit d306dda2f9

@ -12,6 +12,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -24,13 +25,22 @@ import androidx.compose.ui.unit.dp
import org.tasks.R import org.tasks.R
import org.tasks.compose.Constants import org.tasks.compose.Constants
import org.tasks.kmp.org.tasks.compose.settings.SettingRow import org.tasks.kmp.org.tasks.compose.settings.SettingRow
import org.tasks.themes.ColorProvider
import org.tasks.themes.TasksTheme import org.tasks.themes.TasksTheme
@Composable @Composable
fun SelectColorRow(color: Int, selectColor: () -> Unit, clearColor: () -> Unit) = fun SelectColorRow(
color: Int,
selectColor: () -> Unit,
clearColor: () -> Unit
) =
SettingRow( SettingRow(
modifier = Modifier.clickable(onClick = selectColor), modifier = Modifier.clickable(onClick = selectColor),
left = { left = {
val context = LocalContext.current
val adjusted = remember(color) {
ColorProvider(context).getThemeColor(color).primaryColor
}
IconButton(onClick = { selectColor() }) { IconButton(onClick = { selectColor() }) {
if (color == 0) { if (color == 0) {
Icon( Icon(
@ -45,9 +55,8 @@ fun SelectColorRow(color: Int, selectColor: () -> Unit, clearColor: () -> Unit)
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
Canvas(modifier = Modifier.size(24.dp)) { Canvas(modifier = Modifier.size(24.dp)) {
drawCircle(color = Color(color)) drawCircle(color = Color(adjusted))
drawCircle(color = borderColor, style = Stroke(width = 4.0f) drawCircle(color = borderColor, style = Stroke(width = 4.0f))
)
} }
} }
} }

@ -4,6 +4,8 @@ import android.content.Context
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
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.BLACK
import org.tasks.kmp.org.tasks.themes.ColorProvider.WHITE
import org.tasks.kmp.org.tasks.themes.ColorProvider.priorityColor import org.tasks.kmp.org.tasks.themes.ColorProvider.priorityColor
import org.tasks.kmp.org.tasks.themes.ColorProvider.saturated import org.tasks.kmp.org.tasks.themes.ColorProvider.saturated
import javax.inject.Inject import javax.inject.Inject
@ -15,10 +17,10 @@ class ColorProvider @Inject constructor(
private val isDark = context.resources.getBoolean(R.bool.is_dark) private val isDark = context.resources.getBoolean(R.bool.is_dark)
private fun getColor(@ColorInt color: Int, adjust: Boolean) = private fun getColor(@ColorInt color: Int, adjust: Boolean) =
if (adjust && isDark) { when {
saturated[color] ?: color adjust && isDark -> saturated[color] ?: color
} else { !isDark && color == WHITE -> BLACK
color else -> color
} }
fun getThemeColor(@ColorInt color: Int, adjust: Boolean = true) = fun getThemeColor(@ColorInt color: Int, adjust: Boolean = true) =

@ -1,6 +1,7 @@
package org.tasks.themes; package org.tasks.themes;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastOreo; import static com.todoroo.andlib.utility.AndroidUtilities.atLeastOreo;
import static org.tasks.kmp.org.tasks.themes.ColorProvider.WHITE;
import static org.tasks.themes.ColorUtilsKt.calculateContrast; import static org.tasks.themes.ColorUtilsKt.calculateContrast;
import android.app.Activity; import android.app.Activity;
@ -69,7 +70,6 @@ public class ThemeColor implements Pickable {
public static final int[] COLORS = public static final int[] COLORS =
new int[] { new int[] {
org.tasks.kmp.R.color.grey_900,
org.tasks.kmp.R.color.tomato, org.tasks.kmp.R.color.tomato,
org.tasks.kmp.R.color.red_500, org.tasks.kmp.R.color.red_500,
org.tasks.kmp.R.color.deep_orange_500, org.tasks.kmp.R.color.deep_orange_500,
@ -168,12 +168,12 @@ public class ThemeColor implements Pickable {
} }
colorPrimary = color; colorPrimary = color;
double contrast = calculateContrast(TasksThemeKt.WHITE, colorPrimary); double contrast = calculateContrast(WHITE, colorPrimary);
isDark = contrast < 3; isDark = contrast < 3;
if (isDark) { if (isDark) {
colorOnPrimary = context.getColor(R.color.black_87); colorOnPrimary = context.getColor(R.color.black_87);
} else { } else {
colorOnPrimary = TasksThemeKt.WHITE; colorOnPrimary = WHITE;
} }
} }

@ -7,8 +7,9 @@ object ColorProvider {
private const val RED_500 = -769226 private const val RED_500 = -769226
private const val AMBER_500 = -16121 private const val AMBER_500 = -16121
private const val GREY_500 = -6381922 private const val GREY_500 = -6381922
private const val WHITE = -1 private const val GREY_900 = -14606047
private const val BLACK = -16777216 const val WHITE = -1
const val BLACK = -16777216
val saturated: Map<Int, Int> = hashMapOf( val saturated: Map<Int, Int> = hashMapOf(
// 2014 material design palette // 2014 material design palette
@ -31,7 +32,7 @@ object ColorProvider {
-43230 to -30107, // deep orange -43230 to -30107, // deep orange
// -8825528 to -6190977, // brown // -8825528 to -6190977, // brown
GREY_500 to -2039584, // grey GREY_500 to -2039584, // grey
WHITE to BLACK, GREY_900 to WHITE, // GREY_900 removed from palette
// 2019 google calendar // 2019 google calendar
-2818048 to -3397335, // tomato -2818048 to -3397335, // tomato

@ -1,17 +1,16 @@
package org.tasks.themes package org.tasks.themes
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import org.tasks.kmp.org.tasks.themes.ColorProvider.WHITE
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.pow import kotlin.math.pow
fun contentColorFor(backgroundColor: Int): Color = fun contentColorFor(backgroundColor: Int): Color =
if (backgroundColor == 0) { when {
Color.White backgroundColor == 0 -> Color.White
} else if (calculateContrast(WHITE, backgroundColor) < 3) { calculateContrast(WHITE, backgroundColor) < 3 -> Color.Black
Color.Black else -> Color.White
} else {
Color.White
} }
fun calculateContrast(foreground: Int, background: Int): Double { fun calculateContrast(foreground: Int, background: Int): Double {

@ -8,10 +8,11 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.toArgb
import org.tasks.kmp.org.tasks.themes.ColorProvider.BLACK
import org.tasks.kmp.org.tasks.themes.ColorProvider.WHITE
import org.tasks.kmp.org.tasks.themes.ColorProvider.saturated import org.tasks.kmp.org.tasks.themes.ColorProvider.saturated
const val BLUE = -14575885 const val BLUE = -14575885
const val WHITE = -1
private val lightColorScheme = lightColorScheme( private val lightColorScheme = lightColorScheme(
surface = Color(0xFFEAEFF1), surface = Color(0xFFEAEFF1),
@ -52,10 +53,10 @@ fun TasksTheme(
3 -> wallpaperScheme 3 -> wallpaperScheme
else -> if (isSystemInDarkTheme()) darkColorScheme else lightColorScheme else -> if (isSystemInDarkTheme()) darkColorScheme else lightColorScheme
} }
val desaturated = if (isSystemInDarkTheme()) { val desaturated = when {
saturated[primary] ?: primary isSystemInDarkTheme() -> saturated[primary] ?: primary
} else { primary == WHITE -> BLACK
primary else -> primary
} }
val colorOnPrimary = colorOn(desaturated) val colorOnPrimary = colorOn(desaturated)
MaterialTheme( MaterialTheme(

Loading…
Cancel
Save