1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-2966 Chats | Fix | Misc. fixes (#2454)

This commit is contained in:
Evgenii Kozlov 2025-05-24 15:42:38 +02:00 committed by GitHub
parent 10939ff549
commit 1319a78cdb
Signed by: github
GPG key ID: B5690EEEBB952194
6 changed files with 72 additions and 34 deletions

View file

@ -501,7 +501,10 @@ private fun WidgetList(
mode = mode,
unReadMentionCount = item.unreadMentionCount,
unReadMessageCount = item.unreadMessageCount,
onWidgetClicked = { onWidgetSourceClicked(item.id, item.source) }
onWidgetClicked = { onWidgetSourceClicked(item.id, item.source) },
onDropDownMenuAction = { action ->
onWidgetMenuAction(item.id, action)
}
)
}
is WidgetView.Action.EditWidgets -> {

View file

@ -1,10 +1,10 @@
package com.anytypeio.anytype.ui.widgets.types
import android.content.res.Configuration.UI_MODE_NIGHT_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@ -18,28 +18,40 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.anytypeio.anytype.R
import com.anytypeio.anytype.core_ui.common.DefaultPreviews
import com.anytypeio.anytype.core_ui.views.Caption1Regular
import com.anytypeio.anytype.core_ui.views.HeadlineSubheading
import com.anytypeio.anytype.presentation.home.InteractionMode
import com.anytypeio.anytype.presentation.widgets.DropDownMenuAction
import com.anytypeio.anytype.ui.widgets.menu.WidgetMenu
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun SpaceChatWidgetCard(
mode: InteractionMode,
onWidgetClicked: () -> Unit = {},
onDropDownMenuAction: (DropDownMenuAction) -> Unit = {},
unReadMessageCount: Int = 0,
unReadMentionCount: Int = 0
) {
val isCardMenuExpanded = remember {
mutableStateOf(false)
}
val haptic = LocalHapticFeedback.current
Row(
modifier = Modifier
.padding(start = 20.dp, end = 20.dp, top = 6.dp, bottom = 6.dp)
@ -52,13 +64,21 @@ fun SpaceChatWidgetCard(
.clip(RoundedCornerShape(16.dp))
.then(
if (mode !is InteractionMode.Edit) {
Modifier.clickable {
onWidgetClicked()
}
Modifier.combinedClickable(
onClick = onWidgetClicked,
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
isCardMenuExpanded.value = true
}
)
} else {
Modifier
}
),
)
.alpha(
if (isCardMenuExpanded.value) 0.8f else 1f
)
,
verticalAlignment = Alignment.CenterVertically
) {
Image(
@ -79,27 +99,32 @@ fun SpaceChatWidgetCard(
color = colorResource(id = R.color.text_primary),
)
if (unReadMentionCount > 0) {
Box(
modifier = Modifier
.background(
color = colorResource(R.color.transparent_active),
shape = CircleShape
)
.size(20.dp),
contentAlignment = Alignment.Center
) {
Image(
painter = painterResource(R.drawable.ic_chat_widget_mention),
contentDescription = null
)
}
}
// Uncomment when go-to-bottom is ready
// if (unReadMentionCount > 0) {
// Box(
// modifier = Modifier
// .background(
// color = colorResource(R.color.transparent_active),
// shape = CircleShape
// )
// .size(20.dp),
// contentAlignment = Alignment.Center
// ) {
// Image(
// painter = painterResource(R.drawable.ic_chat_widget_mention),
// contentDescription = null
// )
// }
// if (unReadMessageCount == 0) {
// Spacer(modifier = Modifier.width(16.dp))
// }
// }
if (unReadMessageCount > 0) {
if (unReadMentionCount > 0) {
Spacer(modifier = Modifier.width(8.dp))
}
// Uncomment when go-to-bottom is ready
// if (unReadMentionCount > 0) {
// Spacer(modifier = Modifier.width(8.dp))
// }
Box(
modifier = Modifier
.height(20.dp)
@ -119,6 +144,12 @@ fun SpaceChatWidgetCard(
}
Spacer(modifier = Modifier.width(16.dp))
}
WidgetMenu(
isExpanded = isCardMenuExpanded,
onDropDownMenuAction = onDropDownMenuAction,
canEditWidgets = mode !is InteractionMode.Edit,
canChangeType = false
)
}
}

View file

@ -213,10 +213,7 @@ class ChatContainer @Inject constructor(
val target = messages.find { it.order == oldestReadOrderId }
ChatStreamState(
messages = messages,
intent = if (target != null)
Intent.ScrollToMessage(target.id, smooth = true)
else
Intent.ScrollToBottom,
intent = Intent.ScrollToBottom,
state = state.state
)
} else {

View file

@ -392,9 +392,8 @@ class ChatContainerTest {
}
}
@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun `should scroll to the first unread message when scroll-to-bottom is clicked when subscribing chat`() = runTest {
fun `should scroll to bottom when scroll-to-bottom is clicked when subscribing chat`() = runTest {
val container = ChatContainer(
repo = repo,
@ -482,6 +481,13 @@ class ChatContainerTest {
msg = "80"
)
val next = awaitItem()
assertEquals(
expected = ChatContainer.Intent.ScrollToBottom,
actual = next.intent,
)
// New state is not emitted, since it does not change.
}
}

View file

@ -336,7 +336,7 @@ fun Bubble(
DropdownMenuItem(
text = {
Text(
text = stringResource(R.string.copy),
text = stringResource(R.string.copy_text),
color = colorResource(id = R.color.text_primary),
modifier = Modifier.padding(end = 64.dp)
)

View file

@ -1855,6 +1855,7 @@ Please provide specific details of your needs here.</string>
<string name="chat">Chat</string>
<string name="copy">Copy</string>
<string name="copy_text">Copy Text</string>
<string name="chats_edit_message">Edit message</string>
<string name="chats_message_edited">edited</string>
<string name="chat_empty_state_message">There is no messages yet.\nBe the first to start a discussion.</string>