Add dot to make the user aware of battery restrictions

This commit is contained in:
vfsfitvnm 2022-07-11 20:25:40 +02:00
parent 742e8702e5
commit 10b8c66887
3 changed files with 62 additions and 4 deletions

View file

@ -22,11 +22,13 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
@ -196,6 +198,26 @@ fun HomeScreen() {
settingsRoute()
}
.padding(horizontal = 16.dp, vertical = 8.dp)
.run {
if (preferences.isFirstLaunch) {
drawBehind {
drawCircle(
color = colorPalette.red,
center = Offset(
x = size.width,
y = 0.dp.toPx()
),
radius = 4.dp.toPx(),
shadow = Shadow(
color = colorPalette.red,
blurRadius = 4.dp.toPx()
)
)
}
} else {
this
}
}
.size(24.dp)
)

View file

@ -12,6 +12,7 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.geometry.center
import androidx.compose.ui.graphics.*
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
@ -26,6 +27,7 @@ import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
import it.vfsfitvnm.vimusic.utils.*
@ExperimentalAnimationApi
@Composable
fun SettingsScreen() {
@ -92,6 +94,7 @@ fun SettingsScreen() {
host {
val colorPalette = LocalColorPalette.current
val typography = LocalTypography.current
val preferences = LocalPreferences.current
Column(
modifier = Modifier
@ -132,7 +135,9 @@ fun SettingsScreen() {
color: Color,
title: String,
description: String,
route: Route0
route: Route0,
withAlert: Boolean = false,
onClick: (() -> Unit)? = null
) {
Row(
verticalAlignment = Alignment.CenterVertically,
@ -143,6 +148,7 @@ fun SettingsScreen() {
interactionSource = remember { MutableInteractionSource() },
onClick = {
route()
onClick?.invoke()
}
)
.padding(horizontal = 16.dp, vertical = 12.dp)
@ -163,7 +169,10 @@ fun SettingsScreen() {
)
}
Column {
Column(
modifier = Modifier
.weight(1f)
) {
BasicText(
text = title,
style = typography.s.semiBold,
@ -175,6 +184,23 @@ fun SettingsScreen() {
maxLines = 1
)
}
if (withAlert) {
Canvas(
modifier = Modifier
.size(8.dp)
) {
drawCircle(
color = colorPalette.red,
center = size.center.copy(x = size.width),
radius = 4.dp.toPx(),
shadow = Shadow(
color = colorPalette.red,
blurRadius = 4.dp.toPx()
)
)
}
}
}
}
@ -215,7 +241,11 @@ fun SettingsScreen() {
icon = R.drawable.shapes,
title = "Other",
description = "Advanced settings",
route = otherSettingsRoute
route = otherSettingsRoute,
withAlert = LocalPreferences.current.isFirstLaunch,
onClick = {
preferences.isFirstLaunch = false
}
)
Entry(

View file

@ -13,6 +13,7 @@ import it.vfsfitvnm.youtubemusic.YouTube
@Stable
class Preferences(
private val edit: (action: SharedPreferences.Editor.() -> Unit) -> Unit,
initialIsFirstLaunch: Boolean,
initialSongSortBy: SongSortBy,
initialSongSortOrder: SortOrder,
initialColorPaletteMode: ColorPaletteMode,
@ -30,6 +31,7 @@ class Preferences(
edit = { action: SharedPreferences.Editor.() -> Unit ->
preferences.edit(action = action)
},
initialIsFirstLaunch = preferences.getBoolean(Keys.isFirstLaunch, true),
initialSongSortBy = preferences.getEnum(Keys.songSortBy, SongSortBy.DateAdded),
initialSongSortOrder = preferences.getEnum(Keys.songSortOrder, SortOrder.Descending),
initialColorPaletteMode = preferences.getEnum(Keys.colorPaletteMode, ColorPaletteMode.System),
@ -44,6 +46,9 @@ class Preferences(
initialIsInvincibilityEnabled = preferences.getBoolean(Keys.isInvincibilityEnabled, false),
)
var isFirstLaunch = initialIsFirstLaunch
set(value) = edit { putBoolean(Keys.isFirstLaunch, value) }
var songSortBy = initialSongSortBy
set(value) = edit { putEnum(Keys.songSortBy, value) }
@ -81,6 +86,7 @@ class Preferences(
set(value) = edit { putBoolean(Keys.isInvincibilityEnabled, value) }
object Keys {
const val isFirstLaunch = "isFirstLaunch"
const val songSortOrder = "songSortOrder"
const val songSortBy = "songSortBy"
const val colorPaletteMode = "colorPaletteMode"