|
1 | 1 | package com.mikepenz.aboutlibraries.sample |
2 | 2 |
|
| 3 | +import androidx.compose.foundation.background |
| 4 | +import androidx.compose.foundation.clickable |
| 5 | +import androidx.compose.foundation.interaction.MutableInteractionSource |
| 6 | +import androidx.compose.foundation.isSystemInDarkTheme |
| 7 | +import androidx.compose.foundation.layout.Arrangement |
| 8 | +import androidx.compose.foundation.layout.Column |
| 9 | +import androidx.compose.foundation.layout.Row |
| 10 | +import androidx.compose.foundation.layout.WindowInsets |
| 11 | +import androidx.compose.foundation.layout.WindowInsetsSides |
3 | 12 | import androidx.compose.foundation.layout.fillMaxSize |
| 13 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 14 | +import androidx.compose.foundation.layout.only |
| 15 | +import androidx.compose.foundation.layout.padding |
| 16 | +import androidx.compose.foundation.layout.systemBars |
| 17 | +import androidx.compose.foundation.layout.windowInsetsPadding |
| 18 | +import androidx.compose.material.BottomDrawer |
| 19 | +import androidx.compose.material.BottomDrawerValue |
| 20 | +import androidx.compose.material.icons.Icons |
| 21 | +import androidx.compose.material.icons.automirrored.filled.List |
| 22 | +import androidx.compose.material.icons.filled.Build |
| 23 | +import androidx.compose.material.icons.filled.Info |
| 24 | +import androidx.compose.material.icons.filled.Person |
| 25 | +import androidx.compose.material.rememberBottomDrawerState |
| 26 | +import androidx.compose.material.ripple |
4 | 27 | import androidx.compose.material3.ExperimentalMaterial3Api |
| 28 | +import androidx.compose.material3.Icon |
| 29 | +import androidx.compose.material3.MaterialTheme |
5 | 30 | import androidx.compose.material3.Scaffold |
| 31 | +import androidx.compose.material3.Switch |
6 | 32 | import androidx.compose.material3.Text |
7 | | -import androidx.compose.material3.TopAppBar |
8 | 33 | import androidx.compose.runtime.Composable |
| 34 | +import androidx.compose.runtime.getValue |
| 35 | +import androidx.compose.runtime.mutableStateOf |
| 36 | +import androidx.compose.runtime.remember |
| 37 | +import androidx.compose.runtime.rememberCoroutineScope |
| 38 | +import androidx.compose.runtime.setValue |
| 39 | +import androidx.compose.ui.Alignment |
9 | 40 | import androidx.compose.ui.Modifier |
| 41 | +import androidx.compose.ui.graphics.vector.ImageVector |
| 42 | +import androidx.compose.ui.unit.dp |
10 | 43 | import com.mikepenz.aboutlibraries.Libs |
11 | | -import com.mikepenz.aboutlibraries.sample.m3.AppTheme |
12 | 44 | import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer |
| 45 | +import kotlinx.coroutines.launch |
13 | 46 |
|
14 | 47 | @OptIn(ExperimentalMaterial3Api::class) |
15 | 48 | @Composable |
16 | 49 | fun App(libs: Libs?) { |
17 | | - AppTheme { |
18 | | - Scaffold( |
19 | | - topBar = { |
20 | | - TopAppBar(title = { |
21 | | - Text("AboutLibraries Compose Desktop Sample", maxLines = 1) |
22 | | - }) |
| 50 | + val isSystemInDarkMode = isSystemInDarkTheme() |
| 51 | + var darkMode by remember { mutableStateOf(isSystemInDarkMode) } |
| 52 | + var v3Theme by remember { mutableStateOf(true) } |
| 53 | + var showAuthor by remember { mutableStateOf(true) } |
| 54 | + var showDescription by remember { mutableStateOf(false) } |
| 55 | + var showVersion by remember { mutableStateOf(true) } |
| 56 | + var showLicenseBadges by remember { mutableStateOf(true) } |
| 57 | + var showHeader by remember { mutableStateOf(false) } |
| 58 | + val bottomDrawerState = rememberBottomDrawerState(BottomDrawerValue.Closed) |
| 59 | + |
| 60 | + val scope = rememberCoroutineScope() |
| 61 | + |
| 62 | + |
| 63 | + AppTheme(useV3 = v3Theme, useDarkTheme = darkMode) { |
| 64 | + BottomDrawer( |
| 65 | + gesturesEnabled = bottomDrawerState.isOpen, |
| 66 | + drawerState = bottomDrawerState, |
| 67 | + drawerContent = { |
| 68 | + Column( |
| 69 | + modifier = Modifier.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)) |
| 70 | + ) { |
| 71 | + ToggleableSetting( |
| 72 | + title = "Show Author", |
| 73 | + icon = Icons.Default.Person, |
| 74 | + enabled = showAuthor, |
| 75 | + onToggled = { showAuthor = it }, |
| 76 | + ) |
| 77 | + ToggleableSetting( |
| 78 | + title = "Show Description", |
| 79 | + icon = Icons.Default.Person, |
| 80 | + enabled = showDescription, |
| 81 | + onToggled = { showDescription = it }, |
| 82 | + ) |
| 83 | + ToggleableSetting( |
| 84 | + title = "Show Version", |
| 85 | + icon = Icons.Default.Build, |
| 86 | + enabled = showVersion, |
| 87 | + onToggled = { showVersion = it }, |
| 88 | + ) |
| 89 | + ToggleableSetting( |
| 90 | + title = "Show License Badges", |
| 91 | + icon = Icons.AutoMirrored.Filled.List, |
| 92 | + enabled = showLicenseBadges, |
| 93 | + onToggled = { showLicenseBadges = it }, |
| 94 | + ) |
| 95 | + ToggleableSetting( |
| 96 | + title = "Show Header", |
| 97 | + icon = Icons.Default.Info, |
| 98 | + enabled = showHeader, |
| 99 | + onToggled = { showHeader = it }, |
| 100 | + ) |
| 101 | + } |
| 102 | + }, content = { |
| 103 | + Scaffold( |
| 104 | + topBar = { |
| 105 | + TopAppBar( |
| 106 | + useDarkTheme = darkMode, |
| 107 | + onThemeToggle = { darkMode = it }, |
| 108 | + isV3 = v3Theme, |
| 109 | + onV3Toggle = { v3Theme = it }, |
| 110 | + onSettingsClick = { scope.launch { bottomDrawerState.open() } }, |
| 111 | + ) |
| 112 | + } |
| 113 | + ) { |
| 114 | + if (v3Theme) { |
| 115 | + LibrariesContainer( |
| 116 | + libraries = libs, |
| 117 | + modifier = Modifier.fillMaxSize(), |
| 118 | + contentPadding = it, |
| 119 | + showAuthor = showAuthor, |
| 120 | + showDescription = showDescription, |
| 121 | + showVersion = showVersion, |
| 122 | + showLicenseBadges = showLicenseBadges, |
| 123 | + header = { |
| 124 | + if (showHeader) { |
| 125 | + stickyHeader { |
| 126 | + Column( |
| 127 | + modifier = Modifier |
| 128 | + .fillMaxWidth() |
| 129 | + .background(MaterialTheme.colorScheme.surface) |
| 130 | + .padding(vertical = 25.dp), |
| 131 | + horizontalAlignment = Alignment.CenterHorizontally, |
| 132 | + ) { |
| 133 | + Text("ExampleHeader") |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + ) |
| 139 | + } else { |
| 140 | + com.mikepenz.aboutlibraries.ui.compose.LibrariesContainer( |
| 141 | + libraries = libs, |
| 142 | + modifier = Modifier.fillMaxSize(), |
| 143 | + contentPadding = it, |
| 144 | + showAuthor = showAuthor, |
| 145 | + showDescription = showDescription, |
| 146 | + showVersion = showVersion, |
| 147 | + showLicenseBadges = showLicenseBadges, |
| 148 | + header = { |
| 149 | + if (showHeader) { |
| 150 | + stickyHeader { |
| 151 | + Column( |
| 152 | + modifier = Modifier |
| 153 | + .fillMaxWidth() |
| 154 | + .background(MaterialTheme.colorScheme.surface) |
| 155 | + .padding(vertical = 25.dp), |
| 156 | + horizontalAlignment = Alignment.CenterHorizontally, |
| 157 | + ) { |
| 158 | + Text("ExampleHeader") |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + ) |
| 164 | + } |
| 165 | + } |
23 | 166 | } |
24 | | - ) { |
25 | | - LibrariesContainer( |
26 | | - libraries = libs, |
27 | | - modifier = Modifier.fillMaxSize(), |
28 | | - contentPadding = it, |
29 | | - showFundingBadges = false, |
30 | | - // divider = { Divider(modifier = Modifier.fillMaxWidth()) } |
31 | | - ) |
32 | | - } |
| 167 | + ) |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +@Composable |
| 172 | +fun ToggleableSetting(title: String, icon: ImageVector, enabled: Boolean, onToggled: (Boolean) -> Unit) { |
| 173 | + val interactionSource = remember { MutableInteractionSource() } |
| 174 | + Row( |
| 175 | + verticalAlignment = Alignment.CenterVertically, |
| 176 | + modifier = Modifier |
| 177 | + .clickable(interactionSource = interactionSource, onClick = { onToggled(!enabled) }, indication = ripple()) |
| 178 | + .fillMaxWidth() |
| 179 | + .padding(horizontal = 16.dp, vertical = 12.dp), |
| 180 | + horizontalArrangement = Arrangement.spacedBy(30.dp) |
| 181 | + ) { |
| 182 | + Icon(icon, contentDescription = title) |
| 183 | + Text(text = title, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.weight(1f)) |
| 184 | + Switch(interactionSource = interactionSource, checked = enabled, onCheckedChange = { |
| 185 | + onToggled(!enabled) |
| 186 | + }) |
33 | 187 | } |
34 | 188 | } |