Update priority row colors

pull/1952/head
Alex Baker 2 years ago
parent 85b8092982
commit d48d457a3d

@ -1,6 +1,7 @@
package org.tasks.compose.edit
import android.content.res.Configuration
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.RadioButton
@ -10,7 +11,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
@ -19,18 +20,21 @@ import com.google.android.material.composethemeadapter.MdcTheme
import com.todoroo.astrid.data.Task
import org.tasks.R
import org.tasks.compose.TaskEditRow
import org.tasks.themes.ColorProvider.Companion.priorityColor
@Composable
fun PriorityRow(
priority: Int,
onChangePriority: (Int) -> Unit,
desaturate: Boolean,
) {
TaskEditRow(
iconRes = R.drawable.ic_outline_flag_24px,
content = {
Priority(
selected = priority,
onClick = { onChangePriority(it) }
onClick = { onChangePriority(it) },
desaturate = desaturate,
)
},
)
@ -39,7 +43,8 @@ fun PriorityRow(
@Composable
fun Priority(
selected: Int,
onClick: (Int) -> Unit = {}
onClick: (Int) -> Unit = {},
desaturate: Boolean,
) {
Row(
modifier = Modifier
@ -58,7 +63,12 @@ fun Priority(
)
Spacer(modifier = Modifier.weight(1f))
for (i in Task.Priority.HIGH..Task.Priority.NONE) {
PriorityButton(priority = i, selected = selected, onClick = onClick)
PriorityButton(
priority = i,
selected = selected,
onClick = onClick,
desaturate = desaturate,
)
}
}
}
@ -67,14 +77,16 @@ fun Priority(
fun PriorityButton(
@Task.Priority priority: Int,
selected: Int,
desaturate: Boolean,
onClick: (Int) -> Unit,
) {
val color = when (priority) {
in Int.MIN_VALUE..Task.Priority.HIGH -> colorResource(id = R.color.red_500)
Task.Priority.MEDIUM -> colorResource(id = R.color.amber_500)
Task.Priority.LOW -> colorResource(id = R.color.blue_500)
else -> colorResource(R.color.grey_500)
}
val color = Color(
priorityColor(
priority = priority,
isDarkMode = isSystemInDarkTheme(),
desaturate = desaturate,
)
)
RadioButton(
selected = priority == selected,
onClick = { onClick(priority) },
@ -91,6 +103,23 @@ fun PriorityButton(
@Composable
fun PriorityPreview() {
MdcTheme {
PriorityRow(priority = Task.Priority.MEDIUM) {}
PriorityRow(
priority = Task.Priority.MEDIUM,
onChangePriority = {},
desaturate = true,
)
}
}
@ExperimentalComposeUiApi
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
fun PriorityPreviewNoDesaturate() {
MdcTheme {
PriorityRow(
priority = Task.Priority.MEDIUM,
onChangePriority = {},
desaturate = false,
)
}
}

@ -544,6 +544,9 @@ class Preferences @JvmOverloads constructor(
get() = getBoolean(R.string.p_shown_beast_mode_hint, false)
set(value) = setBoolean(R.string.p_shown_beast_mode_hint, value)
val desaturateDarkMode: Boolean
get() = getBoolean(R.string.p_desaturate_colors, true)
companion object {
private const val PREF_SORT_SORT = "sort_sort" // $NON-NLS-1$

@ -2,6 +2,7 @@ package org.tasks.themes
import android.content.Context
import androidx.annotation.ColorInt
import com.todoroo.astrid.data.Task
import dagger.hilt.android.qualifiers.ActivityContext
import org.tasks.R
import org.tasks.preferences.Preferences
@ -66,10 +67,24 @@ class ColorProvider @Inject constructor(@param:ActivityContext private val conte
-10395295 to -7895161, // graphite
-5792882 to -5135210 // birch
)
fun priorityColor(priority: Int, isDarkMode: Boolean, desaturate: Boolean): 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 desaturate = preferences.getBoolean(R.string.p_desaturate_colors, true)
private val desaturate = preferences.desaturateDarkMode
private fun getColor(@ColorInt color: Int, adjust: Boolean) =
if (adjust && isDark && desaturate) {
@ -81,12 +96,11 @@ class ColorProvider @Inject constructor(@param:ActivityContext private val conte
fun getThemeColor(@ColorInt color: Int, adjust: Boolean = true) =
ThemeColor(context, color, getColor(color, adjust))
fun getPriorityColor(priority: Int, adjust: Boolean = true) = when (priority) {
in Int.MIN_VALUE..0 -> getColor(RED_500, adjust)
1 -> getColor(AMBER_500, adjust)
2 -> getColor(BLUE_500, adjust)
else -> GREY_500
}
fun getPriorityColor(priority: Int, adjust: Boolean = true) = priorityColor(
priority = priority,
isDarkMode = isDark,
desaturate = adjust && desaturate,
)
fun getThemeAccent(index: Int) = ThemeAccent(context, if (isDark && desaturate) {
ThemeAccent.ACCENTS_DESATURATED[index]

@ -8,9 +8,12 @@ import dagger.hilt.android.AndroidEntryPoint
import org.tasks.R
import org.tasks.compose.collectAsStateLifecycleAware
import org.tasks.compose.edit.PriorityRow
import org.tasks.preferences.Preferences
import javax.inject.Inject
@AndroidEntryPoint
class PriorityControlSet : TaskEditControlComposeFragment() {
@Inject lateinit var preferences: Preferences
override fun bind(parent: ViewGroup?): View =
(parent as ComposeView).apply {
@ -18,7 +21,8 @@ class PriorityControlSet : TaskEditControlComposeFragment() {
MdcTheme {
PriorityRow(
priority = viewModel.priority.collectAsStateLifecycleAware().value,
onChangePriority = { viewModel.priority.value = it }
onChangePriority = { viewModel.priority.value = it },
desaturate = preferences.desaturateDarkMode,
)
}
}

@ -7,6 +7,7 @@ import android.content.Intent
import android.os.Bundle
import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
@ -51,7 +52,9 @@ import org.tasks.data.GoogleTask
import org.tasks.data.GoogleTaskDao
import org.tasks.data.TaskContainer
import org.tasks.data.TaskDao.TaskCriteria.activeAndVisible
import org.tasks.preferences.Preferences
import org.tasks.themes.ColorProvider
import org.tasks.themes.ColorProvider.Companion.priorityColor
import org.tasks.ui.CheckBoxProvider.Companion.getCheckboxRes
import javax.inject.Inject
@ -67,6 +70,7 @@ class SubtaskControlSet : TaskEditControlComposeFragment() {
@Inject lateinit var chipProvider: ChipProvider
@Inject lateinit var eventBus: MainActivityEventBus
@Inject lateinit var colorProvider: ColorProvider
@Inject lateinit var preferences: Preferences
private val listViewModel: TaskListViewModel by viewModels()
private val refreshReceiver = RefreshReceiver()
@ -289,12 +293,13 @@ class SubtaskControlSet : TaskEditControlComposeFragment() {
Icon(
painter = painterResource(id = task.getCheckboxRes()),
tint = Color(
colorProvider.getPriorityColor(
priorityColor(
priority = task.priority,
adjust = false
isDarkMode = isSystemInDarkTheme(),
desaturate = preferences.desaturateDarkMode,
)
),
contentDescription = null
contentDescription = null,
)
}
}

Loading…
Cancel
Save