mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3098 Space-level | Enhancement | Editing attachments (#2108)
This commit is contained in:
parent
d6aa3e7223
commit
8541e33aa7
3 changed files with 123 additions and 7 deletions
|
@ -4,6 +4,7 @@ import com.anytypeio.anytype.core_models.Block
|
|||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Url
|
||||
import com.anytypeio.anytype.presentation.confgs.ChatConfig
|
||||
import com.anytypeio.anytype.presentation.objects.ObjectIcon
|
||||
import com.anytypeio.anytype.presentation.search.GlobalSearchItemView
|
||||
|
@ -73,16 +74,33 @@ sealed interface ChatView {
|
|||
}
|
||||
|
||||
sealed class ChatBoxAttachment {
|
||||
|
||||
data class Media(
|
||||
val uri: String,
|
||||
val state: State = State.Idle
|
||||
): ChatBoxAttachment()
|
||||
|
||||
data class File(
|
||||
val uri: String,
|
||||
val name: String,
|
||||
val size: Int,
|
||||
val state: State = State.Idle
|
||||
): ChatBoxAttachment()
|
||||
|
||||
sealed class Existing : ChatBoxAttachment() {
|
||||
data class Image(
|
||||
val target: Id,
|
||||
val url: Url
|
||||
) : Existing()
|
||||
|
||||
data class Link(
|
||||
val target: Id,
|
||||
val name: String,
|
||||
val typeName: String,
|
||||
val icon: ObjectIcon
|
||||
) : Existing()
|
||||
}
|
||||
|
||||
data class Link(
|
||||
val target: Id,
|
||||
val wrapper: GlobalSearchItemView
|
||||
|
|
|
@ -343,7 +343,6 @@ class ChatViewModel @Inject constructor(
|
|||
Timber.d("DROID-2635 OnMessageSent, markup: $markup}")
|
||||
}
|
||||
viewModelScope.launch {
|
||||
|
||||
val urlRegex = Regex(DEFAULT_URL_REGEX)
|
||||
val parsedUrls = buildList {
|
||||
urlRegex.findAll(msg).forEach { match ->
|
||||
|
@ -380,6 +379,22 @@ class ChatViewModel @Inject constructor(
|
|||
)
|
||||
)
|
||||
}
|
||||
is ChatView.Message.ChatBoxAttachment.Existing.Link -> {
|
||||
add(
|
||||
Chat.Message.Attachment(
|
||||
target = attachment.target,
|
||||
type = Chat.Message.Attachment.Type.Link
|
||||
)
|
||||
)
|
||||
}
|
||||
is ChatView.Message.ChatBoxAttachment.Existing.Image -> {
|
||||
add(
|
||||
Chat.Message.Attachment(
|
||||
target = attachment.target,
|
||||
type = Chat.Message.Attachment.Type.Image
|
||||
)
|
||||
)
|
||||
}
|
||||
is ChatView.Message.ChatBoxAttachment.Media -> {
|
||||
chatBoxAttachments.value = currAttachments.toMutableList().apply {
|
||||
set(
|
||||
|
@ -495,16 +510,13 @@ class ChatViewModel @Inject constructor(
|
|||
chatBoxMode.value = ChatBoxMode.Default()
|
||||
}
|
||||
is ChatBoxMode.EditMessage -> {
|
||||
val editedMessage = data.value.find {
|
||||
it.id == mode.msg
|
||||
}
|
||||
editChatMessage.async(
|
||||
params = Command.ChatCommand.EditMessage(
|
||||
chat = vmParams.ctx,
|
||||
message = Chat.Message.updated(
|
||||
id = mode.msg,
|
||||
text = msg.trim(),
|
||||
attachments = editedMessage?.attachments.orEmpty(),
|
||||
attachments = attachments,
|
||||
marks = normalizedMarkup
|
||||
)
|
||||
)
|
||||
|
@ -546,6 +558,33 @@ class ChatViewModel @Inject constructor(
|
|||
fun onRequestEditMessageClicked(msg: ChatView.Message) {
|
||||
Timber.d("onRequestEditMessageClicked")
|
||||
viewModelScope.launch {
|
||||
chatBoxAttachments.value = msg.attachments.mapNotNull { a ->
|
||||
when(a) {
|
||||
is ChatView.Message.Attachment.Image -> {
|
||||
ChatView.Message.ChatBoxAttachment.Existing.Image(
|
||||
target = a.target,
|
||||
url = a.url
|
||||
)
|
||||
}
|
||||
is ChatView.Message.Attachment.Link -> {
|
||||
val wrapper = a.wrapper
|
||||
if (wrapper != null) {
|
||||
val type = wrapper.type.firstOrNull()
|
||||
ChatView.Message.ChatBoxAttachment.Existing.Link(
|
||||
target = wrapper.id,
|
||||
name = wrapper.name.orEmpty(),
|
||||
icon = wrapper.objectIcon(urlBuilder),
|
||||
typeName = if (type != null)
|
||||
storeOfObjectTypes.get(type)?.name.orEmpty()
|
||||
else
|
||||
""
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
chatBoxMode.value = ChatBoxMode.EditMessage(msg.id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,38 @@ internal fun ChatBoxAttachments(
|
|||
) {
|
||||
attachments.forEach { attachment ->
|
||||
when (attachment) {
|
||||
is ChatView.Message.ChatBoxAttachment.Existing.Link -> {
|
||||
item {
|
||||
Box {
|
||||
AttachedObject(
|
||||
modifier = Modifier
|
||||
.padding(
|
||||
top = 12.dp,
|
||||
end = 4.dp
|
||||
)
|
||||
.width(216.dp),
|
||||
title = attachment.name,
|
||||
type = attachment.typeName,
|
||||
icon = attachment.icon,
|
||||
onAttachmentClicked = {
|
||||
// TODO
|
||||
}
|
||||
)
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_clear_chatbox_attachment),
|
||||
contentDescription = "Close icon",
|
||||
modifier = Modifier
|
||||
.align(
|
||||
Alignment.TopEnd
|
||||
)
|
||||
.padding(top = 6.dp)
|
||||
.noRippleClickable {
|
||||
onClearAttachmentClicked(attachment)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is ChatView.Message.ChatBoxAttachment.Link -> {
|
||||
item {
|
||||
Box {
|
||||
|
@ -76,7 +108,6 @@ internal fun ChatBoxAttachments(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
is ChatView.Message.ChatBoxAttachment.Media -> {
|
||||
item {
|
||||
Box(modifier = Modifier.padding()) {
|
||||
|
@ -114,7 +145,35 @@ internal fun ChatBoxAttachments(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
is ChatView.Message.ChatBoxAttachment.Existing.Image -> {
|
||||
item {
|
||||
Box(modifier = Modifier.padding()) {
|
||||
Image(
|
||||
painter = rememberAsyncImagePainter(attachment.url),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.padding(
|
||||
top = 12.dp,
|
||||
end = 4.dp
|
||||
)
|
||||
.size(72.dp)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
,
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
Image(
|
||||
painter = painterResource(R.drawable.ic_clear_chatbox_attachment),
|
||||
contentDescription = "Clear attachment icon",
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(top = 6.dp)
|
||||
.noRippleClickable {
|
||||
onClearAttachmentClicked(attachment)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is ChatView.Message.ChatBoxAttachment.File -> {
|
||||
item {
|
||||
Box {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue