GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add full theme switch to the sample app for v2/v3 material, light and… · Goooler/AboutLibraries@1a7a69e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • sample/shared
    • build.gradle.kts
    • src/commonMain/kotlin/com/mikepenz/aboutlibraries/sample
      • App.kt
      • Theme.kt
      • TopAppBar.kt
      • icon
        • Debug.kt
        • Github.kt
        • OpenSourceInitiative.kt
      • m2
        • Theme.kt
      • m3
        • Theme.kt
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎sample/shared/build.gradle.kts‎

Copy file name to clipboardExpand all lines: sample/shared/build.gradle.kts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ kotlin {
4747
implementation(compose.components.resources)
4848
implementation(compose.material)
4949
implementation(compose.material3)
50+
51+
implementation("org.jetbrains.compose.material:material-icons-extended:1.7.3")
5052
}
5153
}
5254
}
Collapse file

‎sample/shared/src/commonMain/kotlin/com/mikepenz/aboutlibraries/sample/App.kt‎

Copy file name to clipboard
+171-17Lines changed: 171 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,188 @@
11
package com.mikepenz.aboutlibraries.sample
22

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
312
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
427
import androidx.compose.material3.ExperimentalMaterial3Api
28+
import androidx.compose.material3.Icon
29+
import androidx.compose.material3.MaterialTheme
530
import androidx.compose.material3.Scaffold
31+
import androidx.compose.material3.Switch
632
import androidx.compose.material3.Text
7-
import androidx.compose.material3.TopAppBar
833
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
940
import androidx.compose.ui.Modifier
41+
import androidx.compose.ui.graphics.vector.ImageVector
42+
import androidx.compose.ui.unit.dp
1043
import com.mikepenz.aboutlibraries.Libs
11-
import com.mikepenz.aboutlibraries.sample.m3.AppTheme
1244
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
45+
import kotlinx.coroutines.launch
1346

1447
@OptIn(ExperimentalMaterial3Api::class)
1548
@Composable
1649
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+
}
23166
}
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+
})
33187
}
34188
}
Collapse file

‎sample/shared/src/commonMain/kotlin/com/mikepenz/aboutlibraries/sample/Theme.kt‎

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.mikepenz.aboutlibraries.sample
2+
3+
import androidx.compose.foundation.isSystemInDarkTheme
4+
import androidx.compose.runtime.Composable
5+
import com.mikepenz.aboutlibraries.sample.m2.M2AppTheme
6+
import com.mikepenz.aboutlibraries.sample.m3.M3AppTheme
7+
8+
@Composable
9+
fun AppTheme(
10+
useV3: Boolean,
11+
useDarkTheme: Boolean = isSystemInDarkTheme(),
12+
content: @Composable () -> Unit,
13+
) {
14+
if (useV3) {
15+
M3AppTheme(useDarkTheme, content)
16+
} else {
17+
M2AppTheme(useDarkTheme, content)
18+
}
19+
}
Collapse file

‎sample/shared/src/commonMain/kotlin/com/mikepenz/aboutlibraries/sample/TopAppBar.kt‎

Copy file name to clipboard
+95Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.mikepenz.aboutlibraries.sample
2+
3+
import androidx.compose.foundation.layout.WindowInsets
4+
import androidx.compose.foundation.layout.WindowInsetsSides
5+
import androidx.compose.foundation.layout.only
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.foundation.layout.safeContent
8+
import androidx.compose.material.icons.Icons
9+
import androidx.compose.material.icons.filled.Settings
10+
import androidx.compose.material3.ExperimentalMaterial3Api
11+
import androidx.compose.material3.Icon
12+
import androidx.compose.material3.IconButton
13+
import androidx.compose.material3.Switch
14+
import androidx.compose.material3.Text
15+
import androidx.compose.material3.TopAppBar
16+
import androidx.compose.runtime.Composable
17+
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.platform.LocalUriHandler
19+
import androidx.compose.ui.unit.dp
20+
import com.mikepenz.markdown.sample.icon.Github
21+
22+
@OptIn(ExperimentalMaterial3Api::class)
23+
@Composable
24+
internal fun TopAppBar(
25+
useDarkTheme: Boolean,
26+
onThemeToggle: (Boolean) -> Unit,
27+
isV3: Boolean,
28+
onV3Toggle: (Boolean) -> Unit,
29+
onSettingsClick: () -> Unit,
30+
) {
31+
val uriHandler = LocalUriHandler.current
32+
33+
if (isV3) {
34+
TopAppBar(
35+
title = { Text("AboutLibraries Compose Sample", maxLines = 1) },
36+
actions = {
37+
Switch(
38+
checked = useDarkTheme,
39+
onCheckedChange = onThemeToggle,
40+
modifier = Modifier.padding(end = 16.dp)
41+
)
42+
Switch(
43+
checked = isV3,
44+
onCheckedChange = onV3Toggle,
45+
modifier = Modifier.padding(end = 16.dp)
46+
)
47+
IconButton(onClick = { uriHandler.openUri("https://github.com/mikepenz/AboutLibraries") }) {
48+
Icon(
49+
imageVector = Github,
50+
contentDescription = "GitHub"
51+
)
52+
}
53+
IconButton(onClick = onSettingsClick) {
54+
Icon(
55+
imageVector = Icons.Default.Settings,
56+
contentDescription = "Settings"
57+
)
58+
}
59+
}
60+
)
61+
} else {
62+
androidx.compose.material.TopAppBar(
63+
title = {
64+
androidx.compose.material.Text("AboutLibraries Compose Sample", maxLines = 1)
65+
},
66+
windowInsets = WindowInsets.safeContent.only(
67+
WindowInsetsSides.Horizontal + WindowInsetsSides.Top
68+
),
69+
actions = {
70+
androidx.compose.material.Switch(
71+
checked = useDarkTheme,
72+
onCheckedChange = onThemeToggle,
73+
modifier = Modifier.padding(end = 16.dp)
74+
)
75+
androidx.compose.material.Switch(
76+
checked = isV3,
77+
onCheckedChange = onV3Toggle,
78+
modifier = Modifier.padding(end = 16.dp)
79+
)
80+
androidx.compose.material.IconButton(onClick = { uriHandler.openUri("https://github.com/mikepenz/AboutLibraries") }) {
81+
androidx.compose.material.Icon(
82+
imageVector = Github,
83+
contentDescription = "GitHub"
84+
)
85+
}
86+
androidx.compose.material.IconButton(onClick = onSettingsClick) {
87+
androidx.compose.material.Icon(
88+
imageVector = Icons.Default.Settings,
89+
contentDescription = "Settings"
90+
)
91+
}
92+
}
93+
)
94+
}
95+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.