Advertisement
rnikander

slack question

Dec 16th, 2020
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. package co.encodia.test.hellojetpackcomp1
  2.  
  3. import android.app.NotificationManager
  4. import android.content.Context
  5. import androidx.compose.foundation.ScrollableColumn
  6. import androidx.compose.foundation.layout.*
  7. import androidx.compose.material.*
  8. import androidx.compose.material.icons.Icons
  9. import androidx.compose.material.icons.rounded.Menu
  10. import androidx.compose.runtime.Composable
  11. import androidx.compose.runtime.MutableState
  12. import androidx.compose.runtime.mutableStateOf
  13. import androidx.compose.runtime.remember
  14. import androidx.compose.ui.Alignment.Companion.CenterHorizontally
  15. import androidx.compose.ui.Modifier
  16. import androidx.compose.ui.graphics.Color
  17. import androidx.compose.ui.platform.AmbientContext
  18. import androidx.compose.ui.text.style.TextAlign
  19. import androidx.compose.ui.unit.dp
  20.  
  21. @ExperimentalMaterialApi
  22. @Composable
  23. fun SlackQuestionHomePage() {
  24. MainInterface()
  25. }
  26.  
  27. @ExperimentalMaterialApi
  28. @Composable
  29. private fun MainInterface() {
  30. val scaffoldState = rememberScaffoldState(rememberDrawerState(DrawerValue.Closed))
  31. Scaffold(
  32. scaffoldState = scaffoldState,
  33. drawerContent = {
  34. // LazyColumnForDrawer(context)
  35. },
  36.  
  37. topBar = {
  38. TopAppBar(
  39. title = { Text(text = "Easy DND") },
  40. navigationIcon = {
  41. IconButton(onClick = { scaffoldState.drawerState.open() }) {
  42. Icon(Icons.Rounded.Menu)
  43. }
  44. }
  45. )
  46. },
  47. bodyContent = {
  48. val selectedIndex = remember { mutableStateOf(0) }
  49.  
  50. ScrollableColumn(horizontalAlignment = CenterHorizontally) {
  51. Text(text = "Quick Settings")
  52. QuickOptions(selectedIndex)
  53. Text(text = "Sound Settings")
  54. SoundOptions(selectedIndex)
  55. }
  56. },
  57. )
  58. }
  59.  
  60. val buttonColors = listOf(Color(0xff81C784), Color(0xff9575CD), Color(0xffFF8A65), Color(0xff5C6BC0))
  61. val disabledColor = Color.DarkGray
  62.  
  63. @Composable
  64. fun QuickOptions(selectedIndex: MutableState<Int>) {
  65. val context = AmbientContext.current
  66. val mNotificationManager: NotificationManager =
  67. context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
  68.  
  69. Column(modifier = Modifier.padding(start = 30.dp, end = 30.dp)) {
  70. listOf(
  71. "DND OFF",
  72. "ALARMS ONLY",
  73. "PRIORITY ONLY",
  74. "FULL DND"
  75. ).forEachIndexed { index, string ->
  76.  
  77. val isSelectable = when (index) {
  78. 0 -> true
  79. 1 -> !(selectedIndex.value == 2 || selectedIndex.value == 3)
  80. 2 -> !(selectedIndex.value == 1 || selectedIndex.value == 3)
  81. 3 -> !(selectedIndex.value == 1 || selectedIndex.value == 2)
  82. else -> null
  83. }
  84.  
  85. val isEnabled = selectedIndex.value == index
  86.  
  87. Button(modifier = Modifier.padding(10.dp).height(60.dp),
  88. elevation = ButtonConstants.defaultElevation(8.dp),
  89. colors = ButtonConstants.defaultButtonColors(
  90. backgroundColor = buttonColors[index]
  91. ),
  92. onClick = {
  93. if (isSelectable == true) {
  94. selectedIndex.value = index
  95. when (index) {
  96. 0 -> {
  97. // mNotificationManager.setInterruptionFilter(
  98. // NotificationManager.INTERRUPTION_FILTER_ALL
  99. // )
  100. }
  101. 1 -> {
  102. // mNotificationManager.setInterruptionFilter(
  103. // NotificationManager.INTERRUPTION_FILTER_ALARMS
  104. // )
  105. }
  106. 2 -> {
  107. // mNotificationManager.setInterruptionFilter(
  108. // NotificationManager.INTERRUPTION_FILTER_PRIORITY
  109. // )
  110. }
  111. 3 -> {
  112. // mNotificationManager.setInterruptionFilter(
  113. // NotificationManager.INTERRUPTION_FILTER_NONE
  114. // )
  115. }
  116. }
  117. }
  118. }
  119. )
  120.  
  121. {
  122. Text(string, textAlign = TextAlign.Center,
  123. color = if (isSelectable == true) Color.White else Color.Gray
  124. )
  125. }
  126. }
  127. }
  128. }
  129.  
  130. @ExperimentalMaterialApi
  131. @Composable
  132. fun SoundOptions(selectedIndex: MutableState<Int>) {
  133. Column(modifier = Modifier.padding(start = 30.dp, end = 30.dp)) {
  134. listOf(
  135. "Alarms",
  136. "Media",
  137. "Touch",
  138. "Reminders",
  139. "Events",
  140. "Messages"
  141. ).forEachIndexed { index, string ->
  142. val isDisabled = remember { mutableStateOf(false) }
  143. Column(
  144. Modifier.fillMaxWidth().padding(20.dp),
  145. horizontalAlignment = CenterHorizontally,
  146. verticalArrangement = Arrangement.Center
  147. ) {
  148.  
  149. Switch(checked = isDisabled.value,
  150. onCheckedChange = {
  151. isDisabled.value = it
  152. },
  153. colors = object: SwitchColors {
  154. override fun thumbColor(enabled: Boolean, checked: Boolean): Color {
  155. return Color.White
  156. }
  157. override fun trackColor(enabled: Boolean, checked: Boolean): Color {
  158. return buttonColors[selectedIndex.value]
  159. }
  160. })
  161. Text(text = string)
  162. }
  163. }
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement