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