Skip to content

Commit

Permalink
Merge pull request #38 from enteraname74/develop
Browse files Browse the repository at this point in the history
v0.9.0
  • Loading branch information
enteraname74 authored Oct 23, 2024
2 parents 50df84b + d0f7387 commit 7c4ef12
Show file tree
Hide file tree
Showing 363 changed files with 6,801 additions and 4,919 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ database.db

.kotlin

desktopApp/*.log
desktopApp/*.log

features/filemanager/build
features/playback/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.enteraname74.soulsearching.coreui.ext

fun Float.coerceForProgressBar(): Float =
this.coerceIn(
minimumValue = 0f,
maximumValue = 1f,
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.github.enteraname74.soulsearching.coreui.ext

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.onClick
import androidx.compose.ui.semantics.semantics

fun Modifier.clickableWithHandCursor(onClick: () -> Unit): Modifier =
this
Expand Down Expand Up @@ -41,6 +48,18 @@ fun Modifier.optionalClickable(onClick: (() -> Unit)?, onLongClick: (() -> Unit)
)
}

/**
* Disable the focus and click action on a composable.
*/
@OptIn(ExperimentalFoundationApi::class)
fun Modifier.disableFocus(): Modifier = this
.pointerInput(Unit) { detectTapGestures { } }
.semantics(mergeDescendants = true) {
contentDescription = ""
onClick { true }
}
.onKeyEvent { true }


expect fun Modifier.combinedClickableWithRightClick(
onClick: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.enteraname74.soulsearching.coreui.loading

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

class LoadingManager {
private val _state: MutableStateFlow<Boolean> = MutableStateFlow(false)
val state: StateFlow<Boolean> = _state.asStateFlow()

fun startLoading() {
_state.value = true
}

fun stopLoading() {
_state.value = false
}

suspend fun withLoading(
block: suspend () -> Unit
) {
startLoading()
block()
stopLoading()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.github.enteraname74.soulsearching.coreui.loading

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.github.enteraname74.soulsearching.coreui.SoulCircularProgressIndicator
import com.github.enteraname74.soulsearching.coreui.UiConstants
import com.github.enteraname74.soulsearching.coreui.ext.disableFocus

@Composable
fun LoadingScaffold(
loadingManager: LoadingManager,
content: @Composable (isLoading: Boolean) -> Unit,
) {
val state: Boolean by loadingManager.state.collectAsState()

Box(
modifier = Modifier
.fillMaxSize(),
) {
content(state)
AnimatedVisibility(
visible = state,
enter = fadeIn(
animationSpec = tween(
durationMillis = UiConstants.AnimationDuration.short
)
),
exit = fadeOut(
animationSpec = tween(
durationMillis = UiConstants.AnimationDuration.short
)
),
) {
LoadingView()
}
}
}

@Composable
private fun LoadingView() {
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black.copy(alpha = 0.75f))
.disableFocus(),
contentAlignment = Alignment.Center,
) {
SoulCircularProgressIndicator()
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.github.enteraname74.soulsearching.feature.settings.presentation.composable
package com.github.enteraname74.soulsearching.coreui.menu

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.RadioButton
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import com.github.enteraname74.soulsearching.coreui.UiConstants
import com.github.enteraname74.soulsearching.coreui.ext.clickableIf
import com.github.enteraname74.soulsearching.coreui.ext.clickableWithHandCursor
import com.github.enteraname74.soulsearching.coreui.theme.color.SoulSearchingColorTheme

@Composable
fun SettingsActionElement(
fun SoulMenuAction(
title: String,
subTitle: String,
clickAction: () -> Unit,
Expand All @@ -42,25 +42,12 @@ fun SettingsActionElement(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(UiConstants.Spacing.large)
) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.SpaceBetween
) {
Text(
text = title,
color = textColor,
style = UiConstants.Typography.bodyTitle,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = subTitle,
color = subTextColor,
style = UiConstants.Typography.bodySmall,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
}
SoulMenuBody(
title = title,
text = subTitle,
titleColor = textColor,
textColor = subTextColor,
)
}
RadioButton(
selected = isSelected,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.github.enteraname74.soulsearching.coreui.menu

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import com.github.enteraname74.soulsearching.coreui.UiConstants
import com.github.enteraname74.soulsearching.coreui.theme.color.SoulSearchingColorTheme

@Composable
internal fun SoulMenuBody(
title: String,
text: String?,
titleMaxLines: Int = 1,
textMaxLines: Int = 2,
titleColor: Color = SoulSearchingColorTheme.colorScheme.onPrimary,
textColor: Color = SoulSearchingColorTheme.colorScheme.subPrimaryText,
) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.SpaceBetween
) {
Text(
text = title,
color = titleColor,
style = UiConstants.Typography.bodyTitle,
maxLines = titleMaxLines,
overflow = TextOverflow.Ellipsis
)
text?.let {
Text(
text = text,
color = textColor,
style = UiConstants.Typography.bodySmall,
maxLines = textMaxLines,
overflow = TextOverflow.Ellipsis
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package com.github.enteraname74.soulsearching.feature.settings.presentation.composable
package com.github.enteraname74.soulsearching.coreui.menu

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.RadioButton
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import com.github.enteraname74.soulsearching.coreui.UiConstants
import com.github.enteraname74.soulsearching.coreui.ext.clickableIf
import com.github.enteraname74.soulsearching.coreui.ext.optionalClickable
import com.github.enteraname74.soulsearching.coreui.theme.color.SoulSearchingColorTheme

@Composable
fun SettingsElement(
fun SoulMenuElement(
title: String,
subTitle: String,
icon: ImageVector? = null,
Expand All @@ -40,24 +45,9 @@ fun SettingsElement(
colorFilter = ColorFilter.tint(SoulSearchingColorTheme.colorScheme.onPrimary)
)
}
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.SpaceBetween
) {
Text(
text = title,
color = SoulSearchingColorTheme.colorScheme.onPrimary,
style = UiConstants.Typography.bodyTitle,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = subTitle,
color = SoulSearchingColorTheme.colorScheme.subPrimaryText,
style = UiConstants.Typography.bodySmall,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
}
SoulMenuBody(
title = title,
text = subTitle,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.github.enteraname74.soulsearching.coreui.menu

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.github.enteraname74.soulsearching.coreui.UiConstants
import com.github.enteraname74.soulsearching.coreui.ext.clickableIf
import com.github.enteraname74.soulsearching.coreui.image.SoulIcon
import com.github.enteraname74.soulsearching.coreui.theme.color.SoulSearchingColorTheme

@Composable
fun SoulMenuExpand(
title: String,
subTitle: String,
clickAction: () -> Unit,
clickEnabled: Boolean = true,
isExpanded: Boolean,
padding: Dp = UiConstants.Spacing.veryLarge,
containerColor: Color = SoulSearchingColorTheme.colorScheme.secondary,
textColor: Color = SoulSearchingColorTheme.colorScheme.onSecondary,
subTextColor: Color = SoulSearchingColorTheme.colorScheme.subSecondaryText,
content: @Composable () -> Unit,
) {
val rotation by animateFloatAsState(targetValue = if (isExpanded) 180f else 0f)

Column(
modifier = Modifier
.background(
color = containerColor,
shape = RoundedCornerShape(size = RoundedCornerShapeValue)
)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.clickableIf(enabled = clickEnabled) {
clickAction()
}
.padding(padding),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Row(
modifier = Modifier
.weight(1f),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(UiConstants.Spacing.large)
) {
SoulMenuBody(
title = title,
text = subTitle,
titleColor = textColor,
textColor = subTextColor,
)
}
SoulIcon(
tint = textColor,
icon = Icons.Filled.ArrowDropDown,
contentDescription = null,
modifier = Modifier.rotate(rotation),
)
}
AnimatedVisibility(
visible = isExpanded
) {
content()
}
}
}

private val RoundedCornerShapeValue: Dp = 10.dp
Loading

0 comments on commit 7c4ef12

Please sign in to comment.