Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Jul 6, 2023
2 parents 576df9d + af4cc87 commit aa32597
Show file tree
Hide file tree
Showing 25 changed files with 1,597 additions and 151 deletions.
2 changes: 1 addition & 1 deletion jchucomponents-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ afterEvaluate {
from components.release
groupId = "com.github.jeluchu"
artifactId = "jchucomponents-core"
version = "1.5.3"
version = "1.6.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion jchucomponents-ktx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ afterEvaluate {
from components.release
groupId = "com.github.jeluchu"
artifactId = "jchucomponents-ktx"
version = "1.5.3"
version = "1.6.0"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.jeluchu.jchucomponents.ktx.compose

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.jeluchu.jchucomponents.ktx.R
import com.jeluchu.jchucomponents.ktx.constants.GIGA_BYTES
import com.jeluchu.jchucomponents.ktx.constants.MEGA_BYTES

@Composable
fun Long.toFileSizeText() = this.toFloat().run {
if (this > GIGA_BYTES)
stringResource(R.string.filesize_gb).format(this / GIGA_BYTES)
else stringResource(R.string.filesize_mb).format(this / MEGA_BYTES)
}
R.string.filesize_gb.toStringRes().format(this / GIGA_BYTES)
else R.string.filesize_mb.toStringRes().format(this / MEGA_BYTES)
}
2 changes: 1 addition & 1 deletion jchucomponents-qr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ afterEvaluate {
from components.release
groupId = "com.github.jeluchu"
artifactId = "jchucomponents-qr"
version = "1.5.3"
version = "1.6.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion jchucomponents-ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ afterEvaluate {
from components.release
groupId = "com.github.jeluchu"
artifactId = "jchucomponents-ui"
version = "1.5.3"
version = "1.6.0"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
fun SystemStatusBarColors(
statusBarColor: Color,
systemBarsColor: Color,
isNavigationBarContrastEnforced: Boolean = true,
useDarkIcons: Boolean = !isSystemInDarkTheme()
) = with(rememberSystemUiController()) {
SideEffect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,177 @@ import androidx.compose.animation.ExitTransition
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.FloatingActionButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.jeluchu.jchucomponents.ktx.strings.empty
import com.jeluchu.jchucomponents.ui.R
import com.jeluchu.jchucomponents.ui.animations.navigation.enterTransition
import com.jeluchu.jchucomponents.ui.animations.navigation.exitTransition
import com.jeluchu.jchucomponents.ui.themes.artichoke
import com.jeluchu.jchucomponents.ui.themes.cosmicLatte

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun FloatingButton(
isVisible: Boolean,
enter: EnterTransition = scaleIn(),
enabled: Boolean = true,
isVisible: Boolean = true,
exit: ExitTransition = scaleOut(),
floatButton: FloatingButtonSettings = FloatingButtonSettings()
enter: EnterTransition = scaleIn(),
size: FloatingButtonSize = FloatingButtonSize.Medium,
floatButton: FloatingButtonSettings = FloatingButtonSettings(),
onClick: () -> Unit = {}
) = AnimatedVisibility(
visible = isVisible,
enter = enter,
exit = exit
) {
FloatingActionButton(
containerColor = floatButton.background,
modifier = Modifier.size(size.buttonSize),
containerColor = if (enabled) floatButton.background else floatButton.disabledBackground,
elevation = FloatingActionButtonDefaults.elevation(
defaultElevation = 0.dp,
pressedElevation = 0.dp
),
onClick = floatButton.onClick
shape = RoundedCornerShape(size.shape),
onClick = onClick
) {
Icon(
modifier = Modifier.size(floatButton.size),
modifier = Modifier.size(size.iconSize),
imageVector = ImageVector.vectorResource(id = floatButton.icon),
contentDescription = String.empty(),
tint = floatButton.tint
tint = if (enabled) floatButton.tint else floatButton.disabledTint
)
}
}

@Immutable
class FloatingButtonSettings constructor(
@DrawableRes val icon: Int = R.drawable.ic_btn_share,
val size: Dp = 40.dp,
val tint: Color = cosmicLatte,
val background: Color = artichoke,
val onClick: () -> Unit = {}
)
val disabledBackground: Color = Color.LightGray,
val disabledTint: Color = Color.Gray,
)

@Immutable sealed class FloatingButtonSize(val buttonSize: Dp, val iconSize: Dp, val shape: Dp) {
@Immutable object Large : FloatingButtonSize(buttonSize = 64.dp, iconSize = 30.dp, shape = 15.dp)
@Immutable object Medium : FloatingButtonSize(buttonSize = 48.dp, iconSize = 24.dp, shape = 12.dp)
@Immutable object Small : FloatingButtonSize(buttonSize = 32.dp, iconSize = 16.dp, shape = 8.dp)
@Immutable object Border : FloatingButtonSize(buttonSize = 32.dp, iconSize = 24.dp, shape = 8.dp)
@Immutable class Custom(buttonSize: Dp, iconSize: Dp, shape: Dp) : FloatingButtonSize(buttonSize, iconSize, shape)
}

@Preview(showBackground = true)
@Composable
fun FloatingButtonPreview() {
Column {
Row(
Modifier
.padding(16.dp)
.fillMaxWidth()
) {
Box(Modifier.weight(1f)) {}
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
Text("Large")
}
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
Text("Medium")
}
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
Text("Small")
}
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
Text("Border")
}
}
Row(
Modifier
.padding(16.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Text("Enabled", Modifier.weight(1f))
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
FloatingButton(size = FloatingButtonSize.Large)
}
Box(
modifier = Modifier
.weight(1f)
.padding(start = 16.dp), contentAlignment = Alignment.Center
) {
FloatingButton(size = FloatingButtonSize.Medium)
}
Box(
modifier = Modifier
.weight(1f)
.padding(start = 8.dp), contentAlignment = Alignment.Center
) {
FloatingButton(size = FloatingButtonSize.Small)
}
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
FloatingButton(size = FloatingButtonSize.Border)
}
}
Row(
Modifier
.padding(16.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Text("Disable", Modifier.weight(1f))
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
FloatingButton(
enabled = false,
size = FloatingButtonSize.Large,
)
}
Box(
modifier = Modifier
.weight(1f)
.padding(start = 16.dp), contentAlignment = Alignment.Center
) {
FloatingButton(
enabled = false,
size = FloatingButtonSize.Medium
)
}
Box(
modifier = Modifier
.weight(1f)
.padding(start = 8.dp), contentAlignment = Alignment.Center
) {
FloatingButton(
enabled = false,
size = FloatingButtonSize.Small
)
}
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
FloatingButton(
enabled = false,
size = FloatingButtonSize.Border
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -42,6 +40,7 @@ import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.jeluchu.jchucomponents.ktx.compose.toImageVector
import com.jeluchu.jchucomponents.ktx.strings.empty
import com.jeluchu.jchucomponents.ui.R

Expand All @@ -53,16 +52,14 @@ fun DropdownItem(
contentPadding: PaddingValues = MenuDefaults.DropdownMenuItemContentPadding,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable RowScope.() -> Unit
) {
DropdownMenuItemContent(
onClick = onClick,
modifier = modifier,
enabled = enabled,
contentPadding = contentPadding,
interactionSource = interactionSource,
content = content
)
}
) = DropdownMenuItemContent(
onClick = onClick,
modifier = modifier,
enabled = enabled,
contentPadding = contentPadding,
interactionSource = interactionSource,
content = content
)

@Composable
fun DropdownItemOption(
Expand All @@ -73,9 +70,9 @@ fun DropdownItemOption(
) {
with(dropdownItemIcon) {
Icon(
modifier = modifier,
imageVector = ImageVector.vectorResource(id = icon),
tint = tint,
modifier = modifier,
imageVector = icon.toImageVector(),
contentDescription = String.empty()
)
}
Expand Down Expand Up @@ -139,30 +136,28 @@ internal fun DropdownMenuItemContent(
contentPadding: PaddingValues = MenuDefaults.DropdownMenuItemContentPadding,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable RowScope.() -> Unit
) = Row(
modifier = modifier
.clickable(
enabled = enabled,
onClick = onClick,
interactionSource = interactionSource,
indication = null
)
.fillMaxWidth()
.sizeIn(
minWidth = DropdownMenuItemDefaultMinWidth,
maxWidth = DropdownMenuItemDefaultMaxWidth,
minHeight = DropdownMenuItemDefaultMinHeight
)
.padding(contentPadding),
verticalAlignment = Alignment.CenterVertically
) {
Row(
modifier = modifier
.clickable(
enabled = enabled,
onClick = onClick,
interactionSource = interactionSource,
indication = null
)
.fillMaxWidth()
.sizeIn(
minWidth = DropdownMenuItemDefaultMinWidth,
maxWidth = DropdownMenuItemDefaultMaxWidth,
minHeight = DropdownMenuItemDefaultMinHeight
)
.padding(contentPadding),
verticalAlignment = Alignment.CenterVertically
) {
val typography = MaterialTheme.typography
ProvideTextStyle(typography.titleMedium) {
val contentAlpha = if (enabled) ContentAlpha.high else ContentAlpha.disabled
CompositionLocalProvider(LocalContentAlpha provides contentAlpha) {
content()
}
val typography = MaterialTheme.typography
ProvideTextStyle(typography.titleMedium) {
val contentAlpha = if (enabled) ContentAlpha.high else ContentAlpha.disabled
CompositionLocalProvider(LocalContentAlpha provides contentAlpha) {
content()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun CircularLoading(
}
}

@Preview
@Preview(showBackground = true)
@Composable
fun CircularLoadingPreview() {
CircularLoading(
Expand Down
Loading

0 comments on commit aa32597

Please sign in to comment.