Skip to content

Commit

Permalink
make it possible to create colorless tags
Browse files Browse the repository at this point in the history
and solve the bug with "Cancel" on the color picker dialog
  • Loading branch information
AkesiSeli committed Jan 5, 2025
1 parent d85ff06 commit c56e38b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.RemoveCircle
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.CornerSize
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.Spacing
import com.livefast.eattrash.raccoonforlemmy.core.l10n.LocalStrings
import com.livefast.eattrash.raccoonforlemmy.core.utils.compose.onClick

@Composable
Expand All @@ -27,6 +35,7 @@ fun SettingsColorRow(
modifier: Modifier = Modifier,
subtitle: String? = null,
onTap: (() -> Unit)? = null,
onClear: (() -> Unit)? = null,
) {
Row(
modifier =
Expand Down Expand Up @@ -55,12 +64,36 @@ fun SettingsColorRow(
)
}
}
Spacer(modifier = Modifier.weight(1f))
if (onClear != null && value != Color.Transparent) {
IconButton(
onClick = {
onClear()
},
) {
Icon(
imageVector = Icons.Default.RemoveCircle,
contentDescription = LocalStrings.current.actionClear,
)
}
}
Box(
modifier =
Modifier
.padding(start = Spacing.xs)
.size(36.dp)
.background(color = value, shape = CircleShape),
.background(color = value, shape = CircleShape)
.then(
if (value == Color.Transparent) {
Modifier.border(
color = MaterialTheme.colorScheme.onBackground,
width = Dp.Hairline,
shape = CircleShape,
)
} else {
Modifier
},
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ fun EditUserTagDialog(
onTap = {
selectCustomColorDialogOpen = true
},
onClear = {
selectedColor = Color.Transparent
},
)
TextField(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -114,9 +117,11 @@ fun EditUserTagDialog(
if (selectCustomColorDialogOpen) {
CustomColorPickerDialog(
initialValue = color,
onClose = {
onClose = { newColor ->
selectCustomColorDialogOpen = false
selectedColor = it ?: Color.Transparent
if (newColor != null) {
selectedColor = newColor
}
},
)
}
Expand Down

0 comments on commit c56e38b

Please sign in to comment.