Skip to content

Commit 1fc996d

Browse files
authored
feat(demo): advanced demos & enable r8 (#11)
* feat(demo): ability to demo everything & enable r8 * fix(demo): handle system bar colors * feat(demo/dialog): update text
1 parent 0fef3d9 commit 1fc996d

File tree

7 files changed

+574
-112
lines changed

7 files changed

+574
-112
lines changed

demo/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ android {
2626

2727
buildTypes {
2828
release {
29-
isMinifyEnabled = false
29+
isMinifyEnabled = true
30+
isShrinkResources = true
3031
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
3132
}
3233
}
@@ -42,6 +43,7 @@ android {
4243

4344
buildFeatures {
4445
compose = true
46+
buildConfig = true
4547
}
4648

4749
composeOptions {

demo/src/main/java/com/aliernfrog/toptoastdemo/MainActivity.kt

Lines changed: 391 additions & 107 deletions
Large diffs are not rendered by default.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.aliernfrog.toptoastdemo.enum
2+
3+
import android.widget.Toast
4+
import com.aliernfrog.toptoast.state.TopToastState
5+
6+
enum class ToastMethod(
7+
val label: String,
8+
val description: String,
9+
val defaultDuration: Int,
10+
val execute: (
11+
topToastState: TopToastState,
12+
text: Any,
13+
icon: Any?,
14+
iconTintColor: Any,
15+
duration: Int,
16+
swipeToDismiss: Boolean,
17+
dismissOnClick: Boolean,
18+
onClick: (() -> Unit)?
19+
) -> Unit
20+
) {
21+
COMPOSE(
22+
label = "showToast",
23+
description = "Shows a TopToast in the TopToastHost. "+
24+
"This cannot be shown above alert dialogs and bottom sheets due to limitations.",
25+
defaultDuration = 3,
26+
execute = { topToastState, text, icon, iconTintColor, duration, swipeToDismiss, dismissOnClick, onClick ->
27+
topToastState.showToast(
28+
text = text,
29+
icon = icon,
30+
duration = duration.toLong()*1000,
31+
iconTintColor = iconTintColor,
32+
swipeToDismiss = swipeToDismiss,
33+
dismissOnClick = if (onClick == null) null else dismissOnClick,
34+
onToastClick = onClick
35+
)
36+
}
37+
),
38+
39+
ANDROID(
40+
label = "showAndroidToast",
41+
description = "Shows a TopToast using the Android Toast API. "+
42+
"This can be shown above alert dialogs and bottom sheets, but it cannot be interacted with.",
43+
defaultDuration = Toast.LENGTH_LONG,
44+
execute = { topToastState, text, icon, iconTintColor, duration, _, _, _ ->
45+
topToastState.showAndroidToast(
46+
text = text,
47+
icon = icon,
48+
iconTintColor = iconTintColor,
49+
duration = duration
50+
)
51+
}
52+
)
53+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.aliernfrog.toptoastdemo.ui.component
2+
3+
import androidx.compose.foundation.shape.RoundedCornerShape
4+
import androidx.compose.material3.ExperimentalMaterial3Api
5+
import androidx.compose.material3.SegmentedButton
6+
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
7+
import androidx.compose.material3.Text
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.unit.dp
11+
import com.aliernfrog.toptoastdemo.ui.theme.AppRoundnessSize
12+
13+
@OptIn(ExperimentalMaterial3Api::class)
14+
@Composable
15+
fun SegmentedButtons(
16+
options: List<String>,
17+
selectedIndex: Int,
18+
modifier: Modifier = Modifier,
19+
onSelect: (Int) -> Unit
20+
) {
21+
SingleChoiceSegmentedButtonRow(
22+
modifier = modifier
23+
) {
24+
options.forEachIndexed { index, option ->
25+
val selected = selectedIndex == index
26+
val isStart = index == 0
27+
val isEnd = index+1 == options.size
28+
SegmentedButton(
29+
selected = selected,
30+
onClick = { onSelect(index) },
31+
shape = RoundedCornerShape(
32+
topStart = if (isStart) AppRoundnessSize else 0.dp,
33+
bottomStart = if (isStart) AppRoundnessSize else 0.dp,
34+
topEnd = if (isEnd) AppRoundnessSize else 0.dp,
35+
bottomEnd = if (isEnd) AppRoundnessSize else 0.dp
36+
)
37+
) {
38+
Text(option)
39+
}
40+
}
41+
}
42+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.aliernfrog.toptoastdemo.ui.component.form
2+
3+
import androidx.compose.foundation.layout.Column
4+
import androidx.compose.foundation.layout.ColumnScope
5+
import androidx.compose.foundation.layout.fillMaxWidth
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.material3.HorizontalDivider
8+
import androidx.compose.material3.MaterialTheme
9+
import androidx.compose.material3.Text
10+
import androidx.compose.material3.VerticalDivider
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.graphics.Color
14+
import androidx.compose.ui.unit.dp
15+
16+
@Composable
17+
fun FormSection(
18+
title: String?,
19+
modifier: Modifier = Modifier,
20+
topDivider: Boolean = false,
21+
bottomDivider: Boolean = true,
22+
titleColor: Color = MaterialTheme.colorScheme.primary,
23+
content: @Composable ColumnScope.() -> Unit
24+
) {
25+
Column(modifier) {
26+
if (topDivider) VerticalDivider(
27+
modifier = Modifier.fillMaxWidth().padding(16.dp),
28+
thickness = 1.dp
29+
)
30+
31+
if (title != null) Text(
32+
text = title,
33+
color = titleColor,
34+
modifier = Modifier.padding(
35+
horizontal = 16.dp,
36+
vertical = 8.dp
37+
)
38+
)
39+
content()
40+
41+
if (bottomDivider) HorizontalDivider(
42+
Modifier.fillMaxWidth().padding(
43+
horizontal = 16.dp,
44+
vertical = 12.dp
45+
)
46+
)
47+
}
48+
}

demo/src/main/java/com/aliernfrog/toptoastdemo/ui/theme/Shape.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import androidx.compose.foundation.shape.RoundedCornerShape
44
import androidx.compose.material3.Shapes
55
import androidx.compose.ui.unit.dp
66

7+
val AppRoundnessSize = 28.dp
8+
79
val Shapes = Shapes(
810
small = RoundedCornerShape(4.dp),
911
medium = RoundedCornerShape(4.dp),
Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,56 @@
11
package com.aliernfrog.toptoastdemo.ui.theme
22

3+
import android.annotation.SuppressLint
4+
import android.app.Activity
35
import android.os.Build
46
import androidx.compose.foundation.isSystemInDarkTheme
57
import androidx.compose.material3.*
68
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.SideEffect
10+
import androidx.compose.ui.graphics.Color
11+
import androidx.compose.ui.graphics.toArgb
712
import androidx.compose.ui.platform.LocalContext
13+
import androidx.compose.ui.platform.LocalView
14+
import androidx.core.view.WindowCompat
15+
import com.aliernfrog.toptoastdemo.MainActivity
816

17+
val supportsMaterialYou = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
18+
19+
@SuppressLint("NewApi")
920
@Composable
1021
fun TopToastComposeTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
11-
val dynamicColors = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
1222
val colors = when {
13-
dynamicColors && darkTheme -> dynamicDarkColorScheme(LocalContext.current)
14-
dynamicColors && !darkTheme -> dynamicLightColorScheme(LocalContext.current)
23+
supportsMaterialYou && darkTheme -> dynamicDarkColorScheme(LocalContext.current)
24+
supportsMaterialYou && !darkTheme -> dynamicLightColorScheme(LocalContext.current)
1525
darkTheme -> darkColorScheme()
1626
else -> lightColorScheme()
1727
}
1828

29+
val view = LocalView.current
30+
if (!view.isInEditMode) SideEffect {
31+
if (view.context !is MainActivity) return@SideEffect
32+
val activity = view.context as Activity
33+
val insetsController = WindowCompat.getInsetsController(activity.window, view)
34+
val transparentColor = Color.Transparent.toArgb()
35+
36+
WindowCompat.setDecorFitsSystemWindows(activity.window, false)
37+
38+
activity.window.statusBarColor = transparentColor
39+
activity.window.navigationBarColor = transparentColor
40+
41+
if (Build.VERSION.SDK_INT >= 29) {
42+
activity.window.isNavigationBarContrastEnforced = false
43+
}
44+
45+
insetsController.isAppearanceLightStatusBars = !darkTheme
46+
insetsController.isAppearanceLightNavigationBars = !darkTheme
47+
}
48+
1949
MaterialTheme(
2050
colorScheme = colors,
2151
typography = Typography,
2252
shapes = Shapes,
2353
content = content
2454
)
25-
}
55+
}
56+

0 commit comments

Comments
 (0)