some fixes for pinned message
This commit is contained in:
+24
-8
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -13,6 +14,7 @@ import com.conena.nanokt.collections.indexOfOrNull
|
||||
import com.conena.nanokt.text.isEmptyOrBlank
|
||||
import com.conena.nanokt.text.isNotEmptyOrBlank
|
||||
import dev.meloda.fast.common.extensions.listenValue
|
||||
import dev.meloda.fast.common.extensions.orDots
|
||||
import dev.meloda.fast.common.extensions.setValue
|
||||
import dev.meloda.fast.common.provider.ResourceProvider
|
||||
import dev.meloda.fast.data.State
|
||||
@@ -44,6 +46,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.abs
|
||||
import kotlin.random.Random
|
||||
|
||||
interface MessagesHistoryViewModel {
|
||||
@@ -379,17 +382,30 @@ class MessagesHistoryViewModelImpl(
|
||||
error = ::handleError,
|
||||
success = { response ->
|
||||
val conversation = response.firstOrNull() ?: return@listenValue
|
||||
screenState.setValue { old ->
|
||||
old.copy(conversation = conversation)
|
||||
val title = conversation.extractTitle(
|
||||
useContactName = AppSettings.General.useContactNames,
|
||||
resources = resourceProvider.resources
|
||||
)
|
||||
val avatar = conversation.extractAvatar()
|
||||
val pinnedMessage = conversation.pinnedMessage
|
||||
val pinnedUser = if (pinnedMessage == null) null else
|
||||
VkMemoryCache.getUser(pinnedMessage.fromId)
|
||||
val pinnedGroup = if (pinnedMessage == null) null else
|
||||
VkMemoryCache.getGroup(abs(pinnedMessage.fromId))
|
||||
val pinnedTitle = pinnedUser?.fullName ?: pinnedGroup?.name
|
||||
|
||||
val pinnedSummary = buildAnnotatedString {
|
||||
pinnedMessage?.text?.let(::append) ?: append("...")
|
||||
}
|
||||
|
||||
screenState.setValue { old ->
|
||||
old.copy(
|
||||
title = conversation.extractTitle(
|
||||
useContactName = AppSettings.General.useContactNames,
|
||||
resources = resourceProvider.resources
|
||||
),
|
||||
avatar = conversation.extractAvatar(),
|
||||
conversation = conversation
|
||||
conversation = conversation,
|
||||
title = title,
|
||||
avatar = avatar,
|
||||
pinnedMessage = pinnedMessage,
|
||||
pinnedTitle = pinnedTitle.orDots(),
|
||||
pinnedSummary = pinnedSummary
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -1,10 +1,12 @@
|
||||
package dev.meloda.fast.messageshistory.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import dev.meloda.fast.common.model.UiImage
|
||||
import dev.meloda.fast.model.api.domain.VkAttachment
|
||||
import dev.meloda.fast.model.api.domain.VkConversation
|
||||
import dev.meloda.fast.model.api.domain.VkMessage
|
||||
|
||||
@Immutable
|
||||
data class MessagesHistoryScreenState(
|
||||
@@ -20,7 +22,10 @@ data class MessagesHistoryScreenState(
|
||||
val isPaginationExhausted: Boolean,
|
||||
val actionMode: ActionMode,
|
||||
val chatImageUrl: String?,
|
||||
val conversation: VkConversation
|
||||
val conversation: VkConversation,
|
||||
val pinnedMessage: VkMessage?,
|
||||
val pinnedTitle: String?,
|
||||
val pinnedSummary: AnnotatedString?
|
||||
) {
|
||||
|
||||
companion object {
|
||||
@@ -37,7 +42,10 @@ data class MessagesHistoryScreenState(
|
||||
isPaginationExhausted = false,
|
||||
actionMode = ActionMode.Record,
|
||||
chatImageUrl = null,
|
||||
conversation = VkConversation.EMPTY
|
||||
conversation = VkConversation.EMPTY,
|
||||
pinnedMessage = null,
|
||||
pinnedTitle = null,
|
||||
pinnedSummary = null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-9
@@ -86,6 +86,7 @@ import dev.chrisbanes.haze.HazeState
|
||||
import dev.chrisbanes.haze.hazeEffect
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import dev.chrisbanes.haze.materials.HazeMaterials
|
||||
import dev.meloda.fast.common.extensions.orDots
|
||||
import dev.meloda.fast.datastore.AppSettings
|
||||
import dev.meloda.fast.datastore.UserSettings
|
||||
import dev.meloda.fast.messageshistory.MessagesHistoryViewModel
|
||||
@@ -171,6 +172,8 @@ fun MessagesHistoryScreen(
|
||||
val view = LocalView.current
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val currentTheme = LocalThemeConfig.current
|
||||
val listState = rememberLazyListState()
|
||||
val hazeState = remember { HazeState() }
|
||||
|
||||
BackHandler(
|
||||
enabled = selectedMessages.isNotEmpty(),
|
||||
@@ -183,7 +186,6 @@ fun MessagesHistoryScreen(
|
||||
}
|
||||
}
|
||||
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
val paginationConditionMet by remember(canPaginate, listState) {
|
||||
derivedStateOf {
|
||||
@@ -203,8 +205,6 @@ fun MessagesHistoryScreen(
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
val hazeState = remember { HazeState() }
|
||||
|
||||
val topBarContainerColorAlpha by animateFloatAsState(
|
||||
targetValue = if (!currentTheme.enableBlur || !listState.canScrollBackward) 1f else 0f,
|
||||
label = "toolbarColorAlpha",
|
||||
@@ -458,14 +458,14 @@ fun MessagesHistoryScreen(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Text(
|
||||
text = pinnedMessage?.user?.toString()
|
||||
?: pinnedMessage?.group?.name
|
||||
?: "...",
|
||||
text = screenState.pinnedTitle.orDots(),
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
LocalContentAlpha(alpha = ContentAlpha.medium) {
|
||||
Text(text = pinnedMessage?.text.orEmpty())
|
||||
screenState.pinnedSummary?.let { summary ->
|
||||
LocalContentAlpha(alpha = ContentAlpha.medium) {
|
||||
Text(text = summary)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -733,4 +733,3 @@ fun MessagesHistoryScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user