-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ab13cd
commit 1213344
Showing
13 changed files
with
221 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/kotlin/cn/super12138/todo/logic/model/ContrastLevel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.super12138.todo.logic.model | ||
|
||
import android.content.Context | ||
import cn.super12138.todo.R | ||
|
||
enum class ContrastLevel(val value: Float) { | ||
VeryLow(-1f), | ||
Low(-0.5f), | ||
Default(0f), | ||
Medium(0.5f), | ||
High(1f); | ||
|
||
fun getDisplayName(context: Context): String { | ||
val resId = when (this) { | ||
VeryLow -> R.string.contrast_very_low | ||
Low -> R.string.contrast_low | ||
Default -> R.string.contrast_default | ||
Medium -> R.string.contrast_medium | ||
High -> R.string.contrast_high | ||
} | ||
return context.getString(resId) | ||
} | ||
|
||
companion object { | ||
fun fromFloat(float: Float): ContrastLevel { | ||
return ContrastLevel.entries.find { it.value == float } ?: Default | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...rc/main/kotlin/cn/super12138/todo/ui/pages/settings/components/contrast/ContrastPicker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package cn.super12138.todo.ui.pages.settings.components.contrast | ||
|
||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.sizeIn | ||
import androidx.compose.foundation.layout.wrapContentWidth | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Label | ||
import androidx.compose.material3.PlainTooltip | ||
import androidx.compose.material3.Slider | ||
import androidx.compose.material3.SliderDefaults | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.semantics.contentDescription | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.unit.dp | ||
import cn.super12138.todo.R | ||
import cn.super12138.todo.constants.Constants | ||
import cn.super12138.todo.logic.model.ContrastLevel | ||
import cn.super12138.todo.ui.pages.settings.components.MoreContentSettingsItem | ||
import cn.super12138.todo.ui.pages.settings.state.rememberPrefFloatState | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun ContrastPicker( | ||
onContrastChange: (ContrastLevel) -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
val context = LocalContext.current | ||
MoreContentSettingsItem( | ||
title = stringResource(R.string.pref_contrast_level), | ||
description = stringResource(R.string.pref_contrast_level_desc) | ||
) { | ||
var contrastState by rememberPrefFloatState( | ||
Constants.PREF_CONTRAST_LEVEL, | ||
Constants.PREF_CONTRAST_LEVEL_DEFAULT | ||
) | ||
val interactionSource = remember { MutableInteractionSource() } | ||
|
||
Slider( | ||
modifier = Modifier.semantics { | ||
contentDescription = context.getString(R.string.tip_change_contrast_level) | ||
}, | ||
value = contrastState, | ||
onValueChange = { | ||
contrastState = it | ||
onContrastChange(ContrastLevel.fromFloat(it)) | ||
}, | ||
valueRange = -1f..1f, | ||
steps = 3, | ||
interactionSource = interactionSource, | ||
thumb = { | ||
Label( | ||
label = { | ||
PlainTooltip( | ||
modifier = Modifier | ||
.sizeIn(45.dp, 25.dp) | ||
.wrapContentWidth() | ||
) { | ||
Text(ContrastLevel.fromFloat(contrastState).getDisplayName(context)) | ||
} | ||
}, | ||
interactionSource = interactionSource | ||
) { | ||
SliderDefaults.Thumb(interactionSource) | ||
} | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.