-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from apeun-gidaechi/feature/368-chatting-emoji
Feature/Chatting Emoji
- Loading branch information
Showing
19 changed files
with
1,155 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 40 additions & 1 deletion
41
data/message/src/main/java/com/seugi/data/message/model/MessageEmojiModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,47 @@ | ||
package com.seugi.data.message.model | ||
|
||
import kotlinx.collections.immutable.ImmutableList | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlinx.collections.immutable.toImmutableList | ||
|
||
data class MessageEmojiModel( | ||
val emojiId: Int, | ||
val userId: ImmutableList<Int>, | ||
val userId: ImmutableList<Long>, | ||
) | ||
|
||
fun List<MessageEmojiModel>.addEmoji(userId: Long, emojiId: Int): List<MessageEmojiModel> { | ||
val emojiItems = this.toMutableList() | ||
emojiItems.forEachIndexed { index, messageEmojiModel -> | ||
if (messageEmojiModel.emojiId != emojiId) return@forEachIndexed | ||
emojiItems[index] = messageEmojiModel.copy( | ||
userId = messageEmojiModel.userId.toMutableList().apply { | ||
add(userId) | ||
}.toSet().toImmutableList(), | ||
) | ||
return emojiItems | ||
} | ||
emojiItems.add( | ||
MessageEmojiModel( | ||
emojiId = emojiId, | ||
userId = persistentListOf(userId), | ||
), | ||
) | ||
return emojiItems | ||
} | ||
|
||
fun List<MessageEmojiModel>.minusEmoji(userId: Long, emojiId: Int): List<MessageEmojiModel> { | ||
val emojiItems = this.toMutableList() | ||
|
||
emojiItems.forEachIndexed { index, messageEmojiModel -> | ||
if (messageEmojiModel.emojiId != emojiId) return@forEachIndexed | ||
|
||
val userIds = messageEmojiModel.userId.minus(userId) | ||
if (userIds.isEmpty()) { | ||
emojiItems.removeAt(index) | ||
return emojiItems | ||
} | ||
emojiItems[index] = messageEmojiModel.copy(userId = userIds.toImmutableList()) | ||
return emojiItems | ||
} | ||
return emojiItems | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
designsystem/src/main/java/com/seugi/designsystem/component/Emoji.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.seugi.designsystem.component | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.seugi.designsystem.animation.bounceClick | ||
import com.seugi.designsystem.theme.SeugiTheme | ||
|
||
@Composable | ||
fun SeugiEmoji(modifier: Modifier = Modifier, emoji: String, count: Int, isChecked: Boolean, onClick: () -> Unit) { | ||
Box( | ||
modifier = Modifier.bounceClick(onClick), | ||
) { | ||
Row( | ||
modifier = modifier | ||
.background( | ||
color = if (isChecked) SeugiTheme.colors.primary100 else SeugiTheme.colors.gray100, | ||
shape = RoundedCornerShape(8.dp), | ||
) | ||
.border( | ||
width = 1.dp, | ||
color = if (isChecked) SeugiTheme.colors.primary300 else SeugiTheme.colors.gray200, | ||
shape = RoundedCornerShape(8.dp), | ||
), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Spacer(modifier = Modifier.width(8.dp)) | ||
Text( | ||
modifier = Modifier.padding( | ||
vertical = 4.dp, | ||
), | ||
text = emoji, | ||
color = SeugiTheme.colors.black, | ||
style = SeugiTheme.typography.subtitle2, | ||
) | ||
Spacer(modifier = Modifier.width(4.dp)) | ||
Text( | ||
text = count.toString(), | ||
color = SeugiTheme.colors.gray600, | ||
style = SeugiTheme.typography.body1, | ||
) | ||
Spacer(modifier = Modifier.width(8.dp)) | ||
} | ||
} | ||
} |
Oops, something went wrong.