Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package co.encodia.test.hellojetpackcomp1
- import android.app.NotificationManager
- import android.content.Context
- import androidx.compose.foundation.ScrollableColumn
- import androidx.compose.foundation.layout.*
- import androidx.compose.material.*
- import androidx.compose.material.icons.Icons
- import androidx.compose.material.icons.rounded.Menu
- import androidx.compose.runtime.Composable
- import androidx.compose.runtime.MutableState
- import androidx.compose.runtime.mutableStateOf
- import androidx.compose.runtime.remember
- import androidx.compose.ui.Alignment.Companion.CenterHorizontally
- import androidx.compose.ui.Modifier
- import androidx.compose.ui.graphics.Color
- import androidx.compose.ui.platform.AmbientContext
- import androidx.compose.ui.text.style.TextAlign
- import androidx.compose.ui.unit.dp
- @ExperimentalMaterialApi
- @Composable
- fun SlackQuestionHomePage() {
- MainInterface()
- }
- @ExperimentalMaterialApi
- @Composable
- private fun MainInterface() {
- val scaffoldState = rememberScaffoldState(rememberDrawerState(DrawerValue.Closed))
- Scaffold(
- scaffoldState = scaffoldState,
- drawerContent = {
- // LazyColumnForDrawer(context)
- },
- topBar = {
- TopAppBar(
- title = { Text(text = "Easy DND") },
- navigationIcon = {
- IconButton(onClick = { scaffoldState.drawerState.open() }) {
- Icon(Icons.Rounded.Menu)
- }
- }
- )
- },
- bodyContent = {
- val selectedIndex = remember { mutableStateOf(0) }
- ScrollableColumn(horizontalAlignment = CenterHorizontally) {
- Text(text = "Quick Settings")
- QuickOptions(selectedIndex)
- Text(text = "Sound Settings")
- SoundOptions(selectedIndex)
- }
- },
- )
- }
- val buttonColors = listOf(Color(0xff81C784), Color(0xff9575CD), Color(0xffFF8A65), Color(0xff5C6BC0))
- val disabledColor = Color.DarkGray
- @Composable
- fun QuickOptions(selectedIndex: MutableState<Int>) {
- val context = AmbientContext.current
- val mNotificationManager: NotificationManager =
- context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
- Column(modifier = Modifier.padding(start = 30.dp, end = 30.dp)) {
- listOf(
- "DND OFF",
- "ALARMS ONLY",
- "PRIORITY ONLY",
- "FULL DND"
- ).forEachIndexed { index, string ->
- val isSelectable = when (index) {
- 0 -> true
- 1 -> !(selectedIndex.value == 2 || selectedIndex.value == 3)
- 2 -> !(selectedIndex.value == 1 || selectedIndex.value == 3)
- 3 -> !(selectedIndex.value == 1 || selectedIndex.value == 2)
- else -> null
- }
- val isEnabled = selectedIndex.value == index
- Button(modifier = Modifier.padding(10.dp).height(60.dp),
- elevation = ButtonConstants.defaultElevation(8.dp),
- colors = ButtonConstants.defaultButtonColors(
- backgroundColor = buttonColors[index]
- ),
- onClick = {
- if (isSelectable == true) {
- selectedIndex.value = index
- when (index) {
- 0 -> {
- // mNotificationManager.setInterruptionFilter(
- // NotificationManager.INTERRUPTION_FILTER_ALL
- // )
- }
- 1 -> {
- // mNotificationManager.setInterruptionFilter(
- // NotificationManager.INTERRUPTION_FILTER_ALARMS
- // )
- }
- 2 -> {
- // mNotificationManager.setInterruptionFilter(
- // NotificationManager.INTERRUPTION_FILTER_PRIORITY
- // )
- }
- 3 -> {
- // mNotificationManager.setInterruptionFilter(
- // NotificationManager.INTERRUPTION_FILTER_NONE
- // )
- }
- }
- }
- }
- )
- {
- Text(string, textAlign = TextAlign.Center,
- color = if (isSelectable == true) Color.White else Color.Gray
- )
- }
- }
- }
- }
- @ExperimentalMaterialApi
- @Composable
- fun SoundOptions(selectedIndex: MutableState<Int>) {
- Column(modifier = Modifier.padding(start = 30.dp, end = 30.dp)) {
- listOf(
- "Alarms",
- "Media",
- "Touch",
- "Reminders",
- "Events",
- "Messages"
- ).forEachIndexed { index, string ->
- val isDisabled = remember { mutableStateOf(false) }
- Column(
- Modifier.fillMaxWidth().padding(20.dp),
- horizontalAlignment = CenterHorizontally,
- verticalArrangement = Arrangement.Center
- ) {
- Switch(checked = isDisabled.value,
- onCheckedChange = {
- isDisabled.value = it
- },
- colors = object: SwitchColors {
- override fun thumbColor(enabled: Boolean, checked: Boolean): Color {
- return Color.White
- }
- override fun trackColor(enabled: Boolean, checked: Boolean): Color {
- return buttonColors[selectedIndex.value]
- }
- })
- Text(text = string)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement