This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add switch preference and make thumbnail color fallback opt…
…ional
- Loading branch information
Showing
8 changed files
with
140 additions
and
3 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
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
44 changes: 44 additions & 0 deletions
44
app/src/main/java/app/suhasdissa/vibeyou/ui/screens/settings/AppearanceSettingsScreen.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,44 @@ | ||
package app.suhasdissa.vibeyou.ui.screens.settings | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.LargeTopAppBar | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.nestedscroll.nestedScroll | ||
import androidx.compose.ui.res.stringResource | ||
import app.suhasdissa.vibeyou.R | ||
import app.suhasdissa.vibeyou.utils.Pref | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun AppearanceSettingsScreen() { | ||
val topBarBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior() | ||
|
||
Scaffold(modifier = Modifier.fillMaxSize(), topBar = { | ||
LargeTopAppBar( | ||
title = { Text(stringResource(R.string.appearance_settings)) }, | ||
scrollBehavior = topBarBehavior | ||
) | ||
}) { innerPadding -> | ||
LazyColumn( | ||
Modifier | ||
.fillMaxSize() | ||
.padding(innerPadding) | ||
.nestedScroll(topBarBehavior.nestedScrollConnection) | ||
) { | ||
item { | ||
SwitchPref( | ||
prefKey = Pref.thumbnailColorFallbackKey, | ||
title = stringResource(R.string.fallback_thumnail_accent), | ||
summary = stringResource(R.string.fallback_thumnail_accent_description) | ||
) | ||
} | ||
} | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
app/src/main/java/app/suhasdissa/vibeyou/ui/screens/settings/SwitchPref.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,66 @@ | ||
package app.suhasdissa.vibeyou.ui.screens.settings | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.Switch | ||
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.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import app.suhasdissa.vibeyou.utils.rememberPreference | ||
|
||
@Composable | ||
fun SwitchPref( | ||
prefKey: String, | ||
title: String, | ||
summary: String? = null, | ||
defaultValue: Boolean = false, | ||
onCheckedChange: (Boolean) -> Unit = {} | ||
) { | ||
var checked by rememberPreference(key = prefKey, defaultValue = defaultValue) | ||
val interactionSource = remember { MutableInteractionSource() } | ||
|
||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 12.dp) | ||
.clickable( | ||
interactionSource = interactionSource, | ||
indication = null | ||
) { | ||
checked = !checked | ||
}, | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Column( | ||
modifier = Modifier.weight(1f), | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
Text(fontSize = 18.sp, text = title) | ||
if (summary != null) { | ||
Text(modifier = Modifier.padding(top = 6.dp), text = summary) | ||
} | ||
} | ||
Spacer(modifier = Modifier.width(6.dp)) | ||
Switch( | ||
checked = checked, | ||
onCheckedChange = { | ||
checked = it | ||
onCheckedChange.invoke(it) | ||
} | ||
) | ||
} | ||
} |
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