Skip to content

Commit

Permalink
Added ability to select stickers in markup layers by #1596
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jan 19, 2025
1 parent d3de80b commit b46aebd
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ru.tech.imageresizershrinker.core.resources.icons

import androidx.compose.material.icons.Icons
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp

val Icons.Outlined.StickerEmoji: ImageVector by lazy {
ImageVector.Builder(
name = "Outlined.StickerEmoji",
defaultWidth = 24.dp,
defaultHeight = 24.dp,
viewportWidth = 24f,
viewportHeight = 24f
).apply {
path(fill = SolidColor(Color(0xFF000000))) {
moveTo(5.5f, 2f)
curveTo(3.56f, 2f, 2f, 3.56f, 2f, 5.5f)
verticalLineTo(18.5f)
curveTo(2f, 20.44f, 3.56f, 22f, 5.5f, 22f)
horizontalLineTo(16f)
lineTo(22f, 16f)
verticalLineTo(5.5f)
curveTo(22f, 3.56f, 20.44f, 2f, 18.5f, 2f)
horizontalLineTo(5.5f)
moveTo(5.75f, 4f)
horizontalLineTo(18.25f)
arcTo(1.75f, 1.75f, 0f, isMoreThanHalf = false, isPositiveArc = true, 20f, 5.75f)
verticalLineTo(15f)
horizontalLineTo(18.5f)
curveTo(16.56f, 15f, 15f, 16.56f, 15f, 18.5f)
verticalLineTo(20f)
horizontalLineTo(5.75f)
arcTo(1.75f, 1.75f, 0f, isMoreThanHalf = false, isPositiveArc = true, 4f, 18.25f)
verticalLineTo(5.75f)
arcTo(1.75f, 1.75f, 0f, isMoreThanHalf = false, isPositiveArc = true, 5.75f, 4f)
moveTo(14.44f, 6.77f)
curveTo(14.28f, 6.77f, 14.12f, 6.79f, 13.97f, 6.83f)
curveTo(13.03f, 7.09f, 12.5f, 8.05f, 12.74f, 9f)
curveTo(12.79f, 9.15f, 12.86f, 9.3f, 12.95f, 9.44f)
lineTo(16.18f, 8.56f)
curveTo(16.18f, 8.39f, 16.16f, 8.22f, 16.12f, 8.05f)
curveTo(15.91f, 7.3f, 15.22f, 6.77f, 14.44f, 6.77f)
moveTo(8.17f, 8.5f)
curveTo(8f, 8.5f, 7.85f, 8.5f, 7.7f, 8.55f)
curveTo(6.77f, 8.81f, 6.22f, 9.77f, 6.47f, 10.7f)
curveTo(6.5f, 10.86f, 6.59f, 11f, 6.68f, 11.16f)
lineTo(9.91f, 10.28f)
curveTo(9.91f, 10.11f, 9.89f, 9.94f, 9.85f, 9.78f)
curveTo(9.64f, 9f, 8.95f, 8.5f, 8.17f, 8.5f)
moveTo(16.72f, 11.26f)
lineTo(7.59f, 13.77f)
curveTo(8.91f, 15.3f, 11f, 15.94f, 12.95f, 15.41f)
curveTo(14.9f, 14.87f, 16.36f, 13.25f, 16.72f, 11.26f)
close()
}
}.build()
}
1 change: 1 addition & 0 deletions core/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1563,4 +1563,5 @@
<string name="edit_exif_screen">Edit EXIF</string>
<string name="edit_exif_screen_sub">Change metadata of single image without recompression</string>
<string name="edit_exif_tag">Tap to edit available tags</string>
<string name="change_sticker">Change Sticker</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package ru.tech.imageresizershrinker.core.ui.widget.image
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.os.Build
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
Expand Down Expand Up @@ -89,7 +91,8 @@ fun Picture(
allowHardware: Boolean = true,
showTransparencyChecker: Boolean = true,
isLoadingFromDifferentPlace: Boolean = false,
enableUltraHDRSupport: Boolean = false
enableUltraHDRSupport: Boolean = false,
contentPadding: PaddingValues = PaddingValues()
) {
val context = LocalContext.current

Expand Down Expand Up @@ -155,7 +158,8 @@ fun Picture(
modifier = modifier
.clip(shape)
.then(if (showTransparencyChecker) Modifier.transparencyChecker() else Modifier)
.then(if (shimmerEnabled) Modifier.shimmer(shimmerVisible || isLoadingFromDifferentPlace) else Modifier),
.then(if (shimmerEnabled) Modifier.shimmer(shimmerVisible || isLoadingFromDifferentPlace) else Modifier)
.padding(contentPadding),
contentScale = contentScale,
loading = {
if (loading != null) loading(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ImageToolbox is an image editor for android
* Copyright (c) 2024 T8RIN (Malik Mukhametzyanov)
* Copyright (c) 2025 T8RIN (Malik Mukhametzyanov)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
*/

package ru.tech.imageresizershrinker.feature.settings.presentation.components.additional
package ru.tech.imageresizershrinker.core.ui.widget.sheets

import android.net.Uri
import androidx.compose.animation.animateColorAsState
Expand Down Expand Up @@ -67,6 +67,7 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import ru.tech.imageresizershrinker.core.resources.R
import ru.tech.imageresizershrinker.core.resources.emoji.Emoji
import ru.tech.imageresizershrinker.core.resources.emoji.EmojiData
import ru.tech.imageresizershrinker.core.ui.shapes.CloverShape
import ru.tech.imageresizershrinker.core.ui.utils.provider.SafeLocalContainerColor
Expand All @@ -85,9 +86,9 @@ import kotlin.random.Random

@Composable
fun EmojiSelectionSheet(
selectedEmojiIndex: Int,
emojiWithCategories: ImmutableList<EmojiData>,
allEmojis: ImmutableList<Uri>,
selectedEmojiIndex: Int?,
emojiWithCategories: ImmutableList<EmojiData> = Emoji.allIconsCategorized(),
allEmojis: ImmutableList<Uri> = Emoji.allIcons(),
onEmojiPicked: (Int) -> Unit,
visible: Boolean,
onDismiss: () -> Unit
Expand All @@ -96,7 +97,7 @@ fun EmojiSelectionSheet(

LaunchedEffect(visible) {
delay(600)
if (selectedEmojiIndex >= 0) {
if ((selectedEmojiIndex ?: -1) >= 0) {
var count = 0
val item = emojiWithCategories.find { (_, _, emojis) ->
count = 0
Expand Down Expand Up @@ -128,20 +129,22 @@ fun EmojiSelectionSheet(
Row(
verticalAlignment = Alignment.CenterVertically
) {
EnhancedIconButton(
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
enabled = emojiEnabled,
onClick = {
onEmojiPicked(Random.nextInt(0, allEmojis.lastIndex))
scope.launch {
state.animateScrollToItem(selectedEmojiIndex)
}
},
) {
Icon(
imageVector = Icons.Rounded.Shuffle,
contentDescription = stringResource(R.string.shuffle)
)
if (selectedEmojiIndex != null) {
EnhancedIconButton(
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
enabled = emojiEnabled,
onClick = {
onEmojiPicked(Random.nextInt(0, allEmojis.lastIndex))
scope.launch {
state.animateScrollToItem(selectedEmojiIndex)
}
},
) {
Icon(
imageVector = Icons.Rounded.Shuffle,
contentDescription = stringResource(R.string.shuffle)
)
}
}
EnhancedButton(
containerColor = MaterialTheme.colorScheme.secondaryContainer,
Expand Down Expand Up @@ -185,7 +188,7 @@ fun EmojiSelectionSheet(
}
var expandedCategories by rememberSaveable(visible) {
mutableStateOf(
if (selectedEmojiIndex >= 0) {
if ((selectedEmojiIndex ?: -1) >= 0) {
emojiWithCategories.find { (_, _, emojis) ->
emojis.forEach { emoji ->
val index = allEmojis.indexOf(emoji)
Expand Down Expand Up @@ -323,38 +326,44 @@ fun EmojiSelectionSheet(
}
}

Column(
modifier = Modifier.onGloballyPositioned {
topPadding = with(density) {
it.size.height.toDp()
if (selectedEmojiIndex != null) {
Column(
modifier = Modifier.onGloballyPositioned {
topPadding = with(density) {
it.size.height.toDp()
}
}
) {
PreferenceRowSwitch(
title = stringResource(R.string.enable_emoji),
color = animateColorAsState(
if (emojiEnabled) MaterialTheme.colorScheme.primaryContainer
else MaterialTheme.colorScheme.surfaceContainer
).value,
modifier = Modifier
.fillMaxWidth()
.background(EnhancedBottomSheetDefaults.containerColor)
.padding(start = 16.dp, top = 20.dp, bottom = 8.dp, end = 16.dp),
shape = RoundedCornerShape(28.dp),
checked = emojiEnabled,
startIcon = Icons.Outlined.Face6,
onClick = {
if (!emojiEnabled) onEmojiPicked(Random.nextInt(0, allEmojis.lastIndex))
else onEmojiPicked(-1)
}
)
GradientEdge(
modifier = Modifier
.fillMaxWidth()
.height(16.dp),
startColor = EnhancedBottomSheetDefaults.containerColor,
endColor = Color.Transparent
)
}
} else {
LaunchedEffect(Unit) {
topPadding = 16.dp
}
) {
PreferenceRowSwitch(
title = stringResource(R.string.enable_emoji),
color = animateColorAsState(
if (emojiEnabled) MaterialTheme.colorScheme.primaryContainer
else MaterialTheme.colorScheme.surfaceContainer
).value,
modifier = Modifier
.fillMaxWidth()
.background(EnhancedBottomSheetDefaults.containerColor)
.padding(start = 16.dp, top = 20.dp, bottom = 8.dp, end = 16.dp),
shape = RoundedCornerShape(28.dp),
checked = emojiEnabled,
startIcon = Icons.Outlined.Face6,
onClick = {
if (!emojiEnabled) onEmojiPicked(Random.nextInt(0, allEmojis.lastIndex))
else onEmojiPicked(-1)
}
)
GradientEdge(
modifier = Modifier
.fillMaxWidth()
.height(16.dp),
startColor = EnhancedBottomSheetDefaults.containerColor,
endColor = Color.Transparent
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ sealed interface LayerType {
}
}

data class Image(
val imageData: Any
sealed class Picture(
open val imageData: Any
) : LayerType {
data class Image(override val imageData: Any) : Picture(imageData)
data class Sticker(override val imageData: Any) : Picture(imageData)

companion object {
val Default by lazy {
Image(
Expand Down
Loading

0 comments on commit b46aebd

Please sign in to comment.