[Chat][Feature] consolidate mock preview data / HTML Support (#520)

This commit is contained in:
Adam Hammer 2022-10-19 06:49:52 -07:00 коммит произвёл GitHub
Родитель 44cf448225
Коммит 280dccd506
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 126 добавлений и 194 удалений

Просмотреть файл

@ -15,10 +15,10 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.azure.android.communication.ui.chat.models.MessageInfoModel
import com.azure.android.communication.ui.chat.presentation.ui.viewmodel.MessageViewModel
import com.azure.android.communication.ui.chat.presentation.ui.viewmodel.toViewModelList
import com.azure.android.communication.ui.chat.service.sdk.wrapper.ChatMessageType
import com.azure.android.communication.ui.chat.preview.MOCK_LOCAL_USER_ID
import com.azure.android.communication.ui.chat.preview.MOCK_MESSAGES
import com.azure.android.communication.ui.chat.utilities.outOfViewItemCount
import kotlinx.coroutines.launch
@ -54,29 +54,7 @@ internal fun MessageListView(
internal fun PreviewMessageListView() {
MessageListView(
modifier = Modifier.padding(0.dp),
messages = listOf(
MessageInfoModel(
messageType = ChatMessageType.TEXT,
content = "Test Message",
internalId = null,
id = null
),
MessageInfoModel(
messageType = ChatMessageType.TEXT,
content = "Test Message 2 ",
internalId = null,
id = null
),
MessageInfoModel(
messageType = ChatMessageType.TEXT,
content = "Test Message 3",
internalId = null,
id = null
),
).toViewModelList(""),
messages = MOCK_MESSAGES.toViewModelList(MOCK_LOCAL_USER_ID),
scrollState = LazyListState(),
)
}

Просмотреть файл

@ -3,6 +3,7 @@
package com.azure.android.communication.ui.chat.presentation.ui.chat.components
import android.widget.TextView
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@ -16,12 +17,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.azure.android.communication.ui.chat.models.MessageInfoModel
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.text.HtmlCompat
import com.azure.android.communication.ui.chat.presentation.style.ChatCompositeTheme
import com.azure.android.communication.ui.chat.presentation.ui.viewmodel.MessageViewModel
import com.azure.android.communication.ui.chat.presentation.ui.viewmodel.toViewModelList
import com.azure.android.communication.ui.chat.preview.MOCK_LOCAL_USER_ID
import com.azure.android.communication.ui.chat.preview.MOCK_MESSAGES
import com.azure.android.communication.ui.chat.service.sdk.wrapper.ChatMessageType
import com.azure.android.communication.ui.chat.service.sdk.wrapper.CommunicationIdentifier
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.format.DateTimeFormatter
val timeFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("h:m a")
@ -103,15 +106,33 @@ private fun BasicChatMessage(viewModel: MessageViewModel) {
}
}
}
BasicText(
text = viewModel.message.content ?: "Empty"
)
if (viewModel.message.messageType == ChatMessageType.HTML) {
HtmlText(html = viewModel.message.content ?: "Empty")
} else {
BasicText(
text = viewModel.message.content ?: "Empty"
)
}
}
}
}
}
}
@Composable
fun HtmlText(html: String, modifier: Modifier = Modifier) {
AndroidView(
modifier = Modifier,
factory = {
context ->
TextView(context)
},
update = {
it.text = HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_COMPACT)
}
)
}
@Preview
@Composable
internal fun PreviewChatCompositeMessage() {
@ -120,137 +141,9 @@ internal fun PreviewChatCompositeMessage() {
.width(500.dp)
.background(color = ChatCompositeTheme.colors.background)
) {
val userA_ID = CommunicationIdentifier.UnknownIdentifier("Peter")
val userA_Display = "Peter Terry"
val userB_ID = CommunicationIdentifier.UnknownIdentifier("User B")
val userB_Display = "Local User"
val userC_ID = CommunicationIdentifier.UnknownIdentifier("Carlos")
val userC_Display = "Carlos Slattery"
val userD_ID = CommunicationIdentifier.UnknownIdentifier("Johnnie")
val userD_Display = "Johnnie McConnell"
MessageView(
viewModel = MessageViewModel(
message = MessageInfoModel(
senderCommunicationIdentifier = userA_ID,
senderDisplayName = userA_Display,
content = "Hey!!",
messageType = ChatMessageType.TEXT,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
showDateHeader = true,
showUsername = true,
showTime = true,
isLocalUser = false,
)
)
MessageView(
viewModel = MessageViewModel(
message = MessageInfoModel(
senderCommunicationIdentifier = userB_ID,
senderDisplayName = userB_Display,
content = "Hi Peter, thanks for following up with me",
messageType = ChatMessageType.TEXT,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
showDateHeader = false,
showUsername = false,
showTime = true,
isLocalUser = true,
)
)
MessageView(
viewModel = MessageViewModel(
message = MessageInfoModel(
content = null,
messageType = ChatMessageType.PARTICIPANT_ADDED,
senderCommunicationIdentifier = userC_ID,
senderDisplayName = userC_Display,
id = null,
internalId = null
),
showDateHeader = false,
showUsername = false,
isLocalUser = false,
showTime = false,
)
)
MessageView(
viewModel = MessageViewModel(
message = MessageInfoModel(
senderCommunicationIdentifier = userA_ID,
senderDisplayName = userA_Display,
content = "No Problem",
messageType = ChatMessageType.TEXT,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
showDateHeader = false,
showUsername = true,
showTime = true,
isLocalUser = false,
)
)
MessageView(
viewModel = MessageViewModel(
message = MessageInfoModel(
senderCommunicationIdentifier = userA_ID,
senderDisplayName = userA_Display,
content = "Let's work through the feedback we received on our wednesday meeting",
messageType = ChatMessageType.TEXT,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
showDateHeader = false,
showUsername = false,
showTime = false,
isLocalUser = false,
)
)
MessageView(
viewModel = MessageViewModel(
message = MessageInfoModel(
content = null,
messageType = ChatMessageType.PARTICIPANT_REMOVED,
senderCommunicationIdentifier = userD_ID,
senderDisplayName = userD_Display,
id = null,
internalId = null
),
showDateHeader = false,
showUsername = false,
isLocalUser = false,
showTime = false,
)
)
MessageView(
viewModel = MessageViewModel(
message = MessageInfoModel(
content = null,
messageType = ChatMessageType.TOPIC_UPDATED,
id = null,
internalId = null,
),
showDateHeader = false,
showUsername = false,
isLocalUser = false,
showTime = false
)
)
val vms = MOCK_MESSAGES.toViewModelList(MOCK_LOCAL_USER_ID)
for (a in 0 until vms.size) {
MessageView(vms[a])
}
}
}

Просмотреть файл

@ -16,7 +16,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.viewmodel.compose.viewModel
import com.azure.android.communication.ui.chat.R
import com.azure.android.communication.ui.chat.models.MessageInfoModel
import com.azure.android.communication.ui.chat.models.RemoteParticipantInfoModel
import com.azure.android.communication.ui.chat.presentation.style.ChatCompositeTheme
import com.azure.android.communication.ui.chat.presentation.ui.chat.ChatScreenStateViewModel
@ -25,8 +24,9 @@ import com.azure.android.communication.ui.chat.presentation.ui.chat.components.B
import com.azure.android.communication.ui.chat.presentation.ui.chat.components.MessageListView
import com.azure.android.communication.ui.chat.presentation.ui.viewmodel.ChatScreenViewModel
import com.azure.android.communication.ui.chat.presentation.ui.viewmodel.toViewModelList
import com.azure.android.communication.ui.chat.preview.MOCK_LOCAL_USER_ID
import com.azure.android.communication.ui.chat.preview.MOCK_MESSAGES
import com.azure.android.communication.ui.chat.redux.state.ChatStatus
import com.azure.android.communication.ui.chat.service.sdk.wrapper.ChatMessageType
import com.azure.android.communication.ui.chat.service.sdk.wrapper.CommunicationIdentifier
@Composable
@ -79,35 +79,7 @@ internal fun ChatScreenPreview() {
ChatCompositeTheme {
ChatScreen(
viewModel = ChatScreenViewModel(
messages = listOf(
MessageInfoModel(
messageType = ChatMessageType.TEXT,
content = "Test Message",
internalId = null,
id = null,
senderDisplayName = "John Doe"
),
MessageInfoModel(
messageType = ChatMessageType.TEXT,
content = "Test Message 2 ",
internalId = null,
id = null,
senderDisplayName = "John Doe Junior"
),
MessageInfoModel(
messageType = ChatMessageType.TEXT,
content = "Test Message 3",
internalId = null,
id = null,
senderDisplayName = "Elliott Red"
),
).toViewModelList(""),
messages = MOCK_MESSAGES.toViewModelList(MOCK_LOCAL_USER_ID),
chatStatus = ChatStatus.INITIALIZED,
buildCount = 2,
typingParticipants = setOf("John Doe", "Mary Sue"),

Просмотреть файл

@ -0,0 +1,89 @@
package com.azure.android.communication.ui.chat.preview
import com.azure.android.communication.ui.chat.models.MessageInfoModel
import com.azure.android.communication.ui.chat.service.sdk.wrapper.ChatMessageType
import com.azure.android.communication.ui.chat.service.sdk.wrapper.CommunicationIdentifier
import org.threeten.bp.OffsetDateTime
internal val MOCK_LOCAL_USER_ID = "Local"
internal val MOCK_MESSAGES get(): List<MessageInfoModel> {
val userA_ID = CommunicationIdentifier.UnknownIdentifier("Peter")
val userA_Display = "Peter Terry"
val userB_ID = CommunicationIdentifier.UnknownIdentifier(MOCK_LOCAL_USER_ID)
val userB_Display = "Local User"
val userC_ID = CommunicationIdentifier.UnknownIdentifier("Carlos")
val userC_Display = "Carlos Slattery"
val userD_ID = CommunicationIdentifier.UnknownIdentifier("Johnnie")
val userD_Display = "Johnnie McConnell"
return listOf(
MessageInfoModel(
senderCommunicationIdentifier = userA_ID,
senderDisplayName = userA_Display,
content = "Hey!!",
messageType = ChatMessageType.TEXT,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
MessageInfoModel(
senderCommunicationIdentifier = userB_ID,
senderDisplayName = userB_Display,
content = "Hi Peter, thanks for following up with me",
messageType = ChatMessageType.TEXT,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
MessageInfoModel(
content = null,
messageType = ChatMessageType.PARTICIPANT_ADDED,
senderCommunicationIdentifier = userC_ID,
senderDisplayName = userC_Display,
id = null,
internalId = null
),
MessageInfoModel(
senderCommunicationIdentifier = userA_ID,
senderDisplayName = userA_Display,
content = "No Problem",
messageType = ChatMessageType.TEXT,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
MessageInfoModel(
content = null,
messageType = ChatMessageType.PARTICIPANT_REMOVED,
senderCommunicationIdentifier = userD_ID,
senderDisplayName = userD_Display,
id = null,
internalId = null
),
MessageInfoModel(
senderCommunicationIdentifier = userA_ID,
senderDisplayName = userA_Display,
content = "Let's work through the feedback we received on our wednesday meeting",
messageType = ChatMessageType.TEXT,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
MessageInfoModel(
senderCommunicationIdentifier = userA_ID,
senderDisplayName = userA_Display,
content = "<B> Hey!! </B> Check this link <A href=\"https://www.microsoft.com\">microsoft</A>",
messageType = ChatMessageType.HTML,
id = null,
internalId = null,
createdOn = OffsetDateTime.parse("2007-12-23T10:15:30+01:00")
),
)
}