Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: implement user tags • part 2 #197

Merged
merged 9 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ sealed class OptionId(
data object PurgeCreator : OptionId(29)

data object Restore : OptionId(30)

data object ManageTags : OptionId(31)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.livefast.eattrash.raccoonforlemmy.feature.settings.ui.components
package com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
Expand All @@ -21,7 +21,7 @@ import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.Spacing
import com.livefast.eattrash.raccoonforlemmy.core.utils.compose.onClick

@Composable
internal fun SettingsColorRow(
fun SettingsColorRow(
title: String,
value: Color,
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.livefast.eattrash.raccoonforlemmy.feature.settings.ui.components
package com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -19,7 +19,7 @@ import com.livefast.eattrash.raccoonforlemmy.core.commonui.components.MultiColor
import com.livefast.eattrash.raccoonforlemmy.core.utils.compose.onClick

@Composable
internal fun SettingsMultiColorRow(
fun SettingsMultiColorRow(
title: String,
values: List<Color>,
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui

import androidx.compose.foundation.background
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.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.Checkbox
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInParent
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.DpOffset
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.IconSize
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.Spacing
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.ancillaryTextAlpha
import com.livefast.eattrash.raccoonforlemmy.core.commonui.components.CustomDropDown
import com.livefast.eattrash.raccoonforlemmy.core.persistence.data.UserTagModel
import com.livefast.eattrash.raccoonforlemmy.core.utils.toLocalDp

@Composable
fun UserTagItem(
tag: UserTagModel,
modifier: Modifier = Modifier,
checked: Boolean? = null,
onCheckedChange: ((Boolean) -> Unit)? = null,
options: List<Option> = emptyList(),
onOptionSelected: ((OptionId) -> Unit)? = null,
) {
val title = tag.name
val color = tag.color?.let { Color(it) } ?: Color.Transparent
val fullColor = MaterialTheme.colorScheme.onBackground
val ancillaryColor = MaterialTheme.colorScheme.onBackground.copy(alpha = ancillaryTextAlpha)
var optionsOffset by remember { mutableStateOf(Offset.Zero) }
var optionsMenuOpen by remember { mutableStateOf(false) }

Row(
modifier = modifier.padding(Spacing.s),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Spacing.xs),
) {
Box(
modifier =
Modifier
.size(IconSize.m)
.background(
color = color,
shape = CircleShape,
),
)
Column(
modifier = Modifier.weight(1f).padding(start = Spacing.xs),
) {
Text(
text = title,
style = MaterialTheme.typography.bodyLarge,
color = fullColor,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}

if (checked != null) {
Checkbox(
checked = checked,
onCheckedChange = onCheckedChange,
)
}

if (options.isNotEmpty()) {
Box {
IconButton(
modifier =
Modifier
.size(IconSize.m)
.padding(Spacing.xs)
.onGloballyPositioned {
optionsOffset = it.positionInParent()
},
onClick = {
optionsMenuOpen = true
},
) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = null,
tint = ancillaryColor,
)
}

CustomDropDown(
expanded = optionsMenuOpen,
onDismiss = {
optionsMenuOpen = false
},
offset =
DpOffset(
x = optionsOffset.x.toLocalDp(),
y = optionsOffset.y.toLocalDp(),
),
) {
options.forEach { option ->
DropdownMenuItem(
text = {
Text(option.text)
},
onClick = {
optionsMenuOpen = false
onOptionSelected?.invoke(option.id)
},
)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui

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.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInParent
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.DpOffset
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.IconSize
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.Spacing
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.ancillaryTextAlpha
import com.livefast.eattrash.raccoonforlemmy.core.commonui.components.CustomDropDown
import com.livefast.eattrash.raccoonforlemmy.core.persistence.data.UserTagMemberModel
import com.livefast.eattrash.raccoonforlemmy.core.utils.toLocalDp

@Composable
fun UserTagMemberItem(
member: UserTagMemberModel,
modifier: Modifier = Modifier,
options: List<Option> = emptyList(),
onOptionSelected: ((OptionId) -> Unit)? = null,
) {
val title = member.username
val fullColor = MaterialTheme.colorScheme.onBackground
val ancillaryColor = MaterialTheme.colorScheme.onBackground.copy(alpha = ancillaryTextAlpha)
var optionsOffset by remember { mutableStateOf(Offset.Zero) }
var optionsMenuOpen by remember { mutableStateOf(false) }

Row(
modifier = modifier.padding(Spacing.s),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Spacing.xs),
) {
Column(
modifier = Modifier.weight(1f).padding(start = Spacing.xs),
) {
Text(
text = title,
style = MaterialTheme.typography.bodyLarge,
color = fullColor,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}

if (options.isNotEmpty()) {
Box {
IconButton(
modifier =
Modifier
.size(IconSize.m)
.padding(Spacing.xs)
.onGloballyPositioned {
optionsOffset = it.positionInParent()
},
onClick = {
optionsMenuOpen = true
},
) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = null,
tint = ancillaryColor,
)
}

CustomDropDown(
expanded = optionsMenuOpen,
onDismiss = {
optionsMenuOpen = false
},
offset =
DpOffset(
x = optionsOffset.x.toLocalDp(),
y = optionsOffset.y.toLocalDp(),
),
) {
options.forEach { option ->
DropdownMenuItem(
text = {
Text(option.text)
},
onClick = {
optionsMenuOpen = false
onOptionSelected?.invoke(option.id)
},
)
}
}
}
}
}
}
1 change: 1 addition & 0 deletions core/commonui/modals/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.compose.colorpicker)
implementation(libs.voyager.navigator)
implementation(libs.voyager.bottomsheet)

Expand Down
Loading
Loading