Commit a3f7898b authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Merge branch 'beta' of github.com:RocketChat/Rocket.Chat.Android into improvement/image-compression

parents 4c8e492a 041a0f0d
...@@ -8,6 +8,7 @@ import android.view.View ...@@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.analytics.AnalyticsManager import chat.rocket.android.analytics.AnalyticsManager
...@@ -16,7 +17,6 @@ import chat.rocket.android.authentication.registerusername.presentation.Register ...@@ -16,7 +17,6 @@ import chat.rocket.android.authentication.registerusername.presentation.Register
import chat.rocket.android.authentication.registerusername.presentation.RegisterUsernameView import chat.rocket.android.authentication.registerusername.presentation.RegisterUsernameView
import chat.rocket.android.util.extension.asObservable import chat.rocket.android.util.extension.asObservable
import chat.rocket.android.util.extensions.inflate import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.setVisible
import chat.rocket.android.util.extensions.showKeyboard import chat.rocket.android.util.extensions.showKeyboard
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.textContent import chat.rocket.android.util.extensions.textContent
...@@ -113,13 +113,13 @@ class RegisterUsernameFragment : Fragment(), RegisterUsernameView { ...@@ -113,13 +113,13 @@ class RegisterUsernameFragment : Fragment(), RegisterUsernameView {
override fun showLoading() { override fun showLoading() {
ui { ui {
disableUserInput() disableUserInput()
view_loading.setVisible(true) view_loading.isVisible = true
} }
} }
override fun hideLoading() { override fun hideLoading() {
ui { ui {
view_loading.setVisible(false) view_loading.isVisible = false
enableUserInput() enableUserInput()
} }
} }
......
...@@ -6,6 +6,7 @@ import android.view.View ...@@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.analytics.AnalyticsManager import chat.rocket.android.analytics.AnalyticsManager
...@@ -15,7 +16,6 @@ import chat.rocket.android.authentication.resetpassword.presentation.ResetPasswo ...@@ -15,7 +16,6 @@ import chat.rocket.android.authentication.resetpassword.presentation.ResetPasswo
import chat.rocket.android.util.extension.asObservable import chat.rocket.android.util.extension.asObservable
import chat.rocket.android.util.extensions.inflate import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.isEmail import chat.rocket.android.util.extensions.isEmail
import chat.rocket.android.util.extensions.setVisible
import chat.rocket.android.util.extensions.showKeyboard import chat.rocket.android.util.extensions.showKeyboard
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.textContent import chat.rocket.android.util.extensions.textContent
...@@ -93,13 +93,13 @@ class ResetPasswordFragment : Fragment(), ResetPasswordView { ...@@ -93,13 +93,13 @@ class ResetPasswordFragment : Fragment(), ResetPasswordView {
override fun showLoading() { override fun showLoading() {
ui { ui {
disableUserInput() disableUserInput()
view_loading.setVisible(true) view_loading.isVisible = true
} }
} }
override fun hideLoading() { override fun hideLoading() {
ui { ui {
view_loading.setVisible(false) view_loading.isVisible = false
enableUserInput() enableUserInput()
} }
} }
......
...@@ -4,6 +4,7 @@ import android.os.Bundle ...@@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
...@@ -15,7 +16,6 @@ import chat.rocket.android.chatinformation.adapter.ReadReceiptAdapter ...@@ -15,7 +16,6 @@ import chat.rocket.android.chatinformation.adapter.ReadReceiptAdapter
import chat.rocket.android.chatinformation.presentation.MessageInfoPresenter import chat.rocket.android.chatinformation.presentation.MessageInfoPresenter
import chat.rocket.android.chatinformation.presentation.MessageInfoView import chat.rocket.android.chatinformation.presentation.MessageInfoView
import chat.rocket.android.chatinformation.viewmodel.ReadReceiptViewModel import chat.rocket.android.chatinformation.viewmodel.ReadReceiptViewModel
import chat.rocket.android.util.extensions.setVisible
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.ui import chat.rocket.android.util.extensions.ui
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
...@@ -86,15 +86,15 @@ class MessageInfoFragment : Fragment(), MessageInfoView { ...@@ -86,15 +86,15 @@ class MessageInfoFragment : Fragment(), MessageInfoView {
override fun showLoading() { override fun showLoading() {
ui { ui {
view_loading.setVisible(true) view_loading.isVisible = true
view_loading.show() view_loading.show()
} }
} }
override fun hideLoading() { override fun hideLoading() {
ui { ui {
view_loading.isVisible = false
view_loading.hide() view_loading.hide()
view_loading.setVisible(false)
} }
} }
...@@ -103,4 +103,4 @@ class MessageInfoFragment : Fragment(), MessageInfoView { ...@@ -103,4 +103,4 @@ class MessageInfoFragment : Fragment(), MessageInfoView {
adapter.addAll(messageReceipts) adapter.addAll(messageReceipts)
} }
} }
} }
\ No newline at end of file
...@@ -7,10 +7,10 @@ import android.view.View ...@@ -7,10 +7,10 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.core.view.isVisible
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.chatroom.adapter.PeopleSuggestionsAdapter.PeopleSuggestionViewHolder import chat.rocket.android.chatroom.adapter.PeopleSuggestionsAdapter.PeopleSuggestionViewHolder
import chat.rocket.android.chatroom.uimodel.suggestion.PeopleSuggestionUiModel import chat.rocket.android.chatroom.uimodel.suggestion.PeopleSuggestionUiModel
import chat.rocket.android.util.extensions.setVisible
import chat.rocket.android.suggestions.model.SuggestionModel import chat.rocket.android.suggestions.model.SuggestionModel
import chat.rocket.android.suggestions.ui.BaseSuggestionViewHolder import chat.rocket.android.suggestions.ui.BaseSuggestionViewHolder
import chat.rocket.android.suggestions.ui.SuggestionsAdapter import chat.rocket.android.suggestions.ui.SuggestionsAdapter
...@@ -58,9 +58,9 @@ class PeopleSuggestionsAdapter(context: Context) : SuggestionsAdapter<PeopleSugg ...@@ -58,9 +58,9 @@ class PeopleSuggestionsAdapter(context: Context) : SuggestionsAdapter<PeopleSugg
username.text = item.username username.text = item.username
name.text = item.name name.text = item.name
if (item.imageUri?.isEmpty() != false) { if (item.imageUri?.isEmpty() != false) {
avatar.setVisible(false) avatar.isVisible = false
} else { } else {
avatar.setVisible(true) avatar.isVisible = true
avatar.setImageURI(item.imageUri) avatar.setImageURI(item.imageUri)
} }
val status = item.status val status = item.status
...@@ -68,7 +68,7 @@ class PeopleSuggestionsAdapter(context: Context) : SuggestionsAdapter<PeopleSugg ...@@ -68,7 +68,7 @@ class PeopleSuggestionsAdapter(context: Context) : SuggestionsAdapter<PeopleSugg
val statusDrawable = DrawableHelper.getUserStatusDrawable(status, itemView.context) val statusDrawable = DrawableHelper.getUserStatusDrawable(status, itemView.context)
statusView.setImageDrawable(statusDrawable) statusView.setImageDrawable(statusDrawable)
} else { } else {
statusView.setVisible(false) statusView.isVisible = false
} }
setOnClickListener { setOnClickListener {
itemClickListener?.onClick(item) itemClickListener?.onClick(item)
......
...@@ -266,16 +266,16 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -266,16 +266,16 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
setReactionButtonIcon(R.drawable.ic_reaction_24dp)
dismissEmojiKeyboard() dismissEmojiKeyboard()
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
} }
private fun dismissEmojiKeyboard() { fun dismissEmojiKeyboard() {
// Check if the keyboard was ever initialized. // Check if the keyboard was ever initialized.
// It may be the case when you are looking a not joined room // It may be the case when you are looking a not joined room
if (::emojiKeyboardPopup.isInitialized) { if (::emojiKeyboardPopup.isInitialized) {
emojiKeyboardPopup.dismiss() emojiKeyboardPopup.dismiss()
setReactionButtonIcon(R.drawable.ic_reaction_24dp)
} }
} }
...@@ -784,8 +784,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -784,8 +784,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
context: Context context: Context
) { ) {
if (f is MessageActionsBottomSheet) { if (f is MessageActionsBottomSheet) {
setReactionButtonIcon(R.drawable.ic_reaction_24dp) dismissEmojiKeyboard()
emojiKeyboardPopup.dismiss()
} }
} }
}, },
...@@ -805,9 +804,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -805,9 +804,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
it.onBackPressed() it.onBackPressed()
} }
KeyboardHelper.hideSoftKeyboard(it) KeyboardHelper.hideSoftKeyboard(it)
emojiKeyboardPopup.dismiss() dismissEmojiKeyboard()
} }
setReactionButtonIcon(R.drawable.ic_reaction_24dp)
} }
} }
...@@ -917,8 +915,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -917,8 +915,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
setReactionButtonIcon(R.drawable.ic_keyboard_black_24dp) setReactionButtonIcon(R.drawable.ic_keyboard_black_24dp)
} else { } else {
// If popup is showing, simply dismiss it to show the underlying text keyboard // If popup is showing, simply dismiss it to show the underlying text keyboard
emojiKeyboardPopup.dismiss() dismissEmojiKeyboard()
setReactionButtonIcon(R.drawable.ic_reaction_24dp)
} }
} }
......
...@@ -24,21 +24,30 @@ fun ChatRoomFragment.showFileAttachmentDialog(uri: Uri) { ...@@ -24,21 +24,30 @@ fun ChatRoomFragment.showFileAttachmentDialog(uri: Uri) {
description.text.clear() description.text.clear()
when { when {
mimeType.startsWith("image") -> { mimeType.startsWith("image") -> {
GlideApp if (mimeType.contains("gif")) {
.with(context) GlideApp
.asBitmap() .with(context)
.load(uri) .asGif()
.fitCenter() .load(uri)
.into(object : SimpleTarget<Bitmap>() { .fitCenter()
override fun onResourceReady( .into(imagePreview)
resource: Bitmap, } else {
transition: Transition<in Bitmap>? GlideApp
) { .with(context)
bitmap = resource .asBitmap()
imagePreview.setImageBitmap(resource) .load(uri)
imagePreview.isVisible = true .fitCenter()
} .into(object : SimpleTarget<Bitmap>() {
}) override fun onResourceReady(
resource: Bitmap,
transition: Transition<in Bitmap>?
) {
bitmap = resource
imagePreview.setImageBitmap(resource)
}
})
}
imagePreview.isVisible = true
} }
mimeType.startsWith("video") -> audioVideoAttachment.isVisible = true mimeType.startsWith("video") -> audioVideoAttachment.isVisible = true
else -> { else -> {
......
...@@ -79,6 +79,17 @@ private fun ChatRoomFragment.setupSearchMessageMenuItem(menu: Menu, context: Con ...@@ -79,6 +79,17 @@ private fun ChatRoomFragment.setupSearchMessageMenuItem(menu: Menu, context: Con
.setShowAsActionFlags( .setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_IF_ROOM or MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW MenuItem.SHOW_AS_ACTION_IF_ROOM or MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
) )
.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
dismissEmojiKeyboard()
return true
}
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
dismissEmojiKeyboard()
return true
}
})
(searchItem?.actionView as? SearchView)?.let { (searchItem?.actionView as? SearchView)?.let {
// TODO: Check why we need to stylize the search text programmatically instead of by defining it in the styles.xml (ChatRoom.SearchView) // TODO: Check why we need to stylize the search text programmatically instead of by defining it in the styles.xml (ChatRoom.SearchView)
......
...@@ -42,27 +42,28 @@ class RoomUiModelMapper( ...@@ -42,27 +42,28 @@ class RoomUiModelMapper(
userInteractor.get() userInteractor.get()
} }
fun map(rooms: List<ChatRoom>, grouped: Boolean = false): List<ItemHolder<*>> { fun map(rooms: List<ChatRoom>, grouped: Boolean = false, showLastMessage: Boolean = true): List<ItemHolder<*>> {
val list = ArrayList<ItemHolder<*>>(rooms.size + 4) val list = ArrayList<ItemHolder<*>>(rooms.size + 4)
var lastType: String? = null var lastType: String? = null
rooms.forEach { room -> rooms.forEach { room ->
if (grouped && lastType != room.chatRoom.type) { if (grouped && lastType != room.chatRoom.type) {
list.add(HeaderItemHolder(roomType(room.chatRoom.type))) list.add(HeaderItemHolder(roomType(room.chatRoom.type)))
} }
list.add(RoomItemHolder(map(room))) list.add(RoomItemHolder(map(room, showLastMessage)))
lastType = room.chatRoom.type lastType = room.chatRoom.type
} }
return list return list
} }
fun map(spotlight: SpotlightResult): List<ItemHolder<*>> { fun map(spotlight: SpotlightResult, showLastMessage: Boolean = true): List<ItemHolder<*>> {
val list = ArrayList<ItemHolder<*>>(spotlight.users.size + spotlight.rooms.size) val list = ArrayList<ItemHolder<*>>(spotlight.users.size + spotlight.rooms.size)
spotlight.users.filterNot { it.username.isNullOrEmpty() }.forEach { user -> spotlight.users.filterNot { it.username.isNullOrEmpty() }.forEach { user ->
list.add(RoomItemHolder(mapUser(user))) list.add(RoomItemHolder(mapUser(user)))
} }
spotlight.rooms.filterNot { it.name.isNullOrEmpty() }.forEach { room -> spotlight.rooms.filterNot { it.name.isNullOrEmpty() }.forEach { room ->
list.add(RoomItemHolder(mapRoom(room))) list.add(RoomItemHolder(mapRoom(room, showLastMessage)))
} }
return list return list
...@@ -86,21 +87,21 @@ class RoomUiModelMapper( ...@@ -86,21 +87,21 @@ class RoomUiModelMapper(
} }
} }
private fun mapRoom(room: Room): RoomUiModel { private fun mapRoom(room: Room, showLastMessage:Boolean = true): RoomUiModel {
return with(room) { return with(room) {
RoomUiModel( RoomUiModel(
id = id, id = id,
name = name!!, name = name!!,
type = type, type = type,
avatar = serverUrl.avatarUrl(name!!, isGroupOrChannel = true), avatar = serverUrl.avatarUrl(name!!, isGroupOrChannel = true),
lastMessage = mapLastMessage(lastMessage?.sender?.id, lastMessage?.sender?.username, lastMessage = if(showLastMessage) { mapLastMessage(lastMessage?.sender?.id, lastMessage?.sender?.username,
lastMessage?.sender?.name, lastMessage?.message, lastMessage?.sender?.name, lastMessage?.message,
isDirectMessage = type is RoomType.DirectMessage) isDirectMessage = type is RoomType.DirectMessage)} else { null }
) )
} }
} }
fun map(chatRoom: ChatRoom): RoomUiModel { fun map(chatRoom: ChatRoom, showLastMessage:Boolean = true): RoomUiModel {
return with(chatRoom.chatRoom) { return with(chatRoom.chatRoom) {
val isUnread = alert || unread > 0 val isUnread = alert || unread > 0
val type = roomTypeOf(type) val type = roomTypeOf(type)
...@@ -113,9 +114,9 @@ class RoomUiModelMapper( ...@@ -113,9 +114,9 @@ class RoomUiModelMapper(
serverUrl.avatarUrl(name, isGroupOrChannel = true) serverUrl.avatarUrl(name, isGroupOrChannel = true)
} }
val unread = mapUnread(unread) val unread = mapUnread(unread)
val lastMessage = mapLastMessage(lastMessageUserId, chatRoom.lastMessageUserName, val lastMessage = if(showLastMessage) { mapLastMessage(lastMessageUserId, chatRoom.lastMessageUserName,
chatRoom.lastMessageUserFullName, lastMessageText, isUnread, chatRoom.lastMessageUserFullName, lastMessageText, isUnread,
type is RoomType.DirectMessage) type is RoomType.DirectMessage) } else { null }
val open = open val open = open
RoomUiModel( RoomUiModel(
...@@ -148,6 +149,7 @@ class RoomUiModelMapper( ...@@ -148,6 +149,7 @@ class RoomUiModelMapper(
private fun mapLastMessage(userId: String?, name: String?, fullName: String?, text: String?, private fun mapLastMessage(userId: String?, name: String?, fullName: String?, text: String?,
unread: Boolean = false, unread: Boolean = false,
isDirectMessage: Boolean = false): CharSequence? { isDirectMessage: Boolean = false): CharSequence? {
return if (!settings.showLastMessage()) { return if (!settings.showLastMessage()) {
null null
} else if (name != null && text != null) { } else if (name != null && text != null) {
......
...@@ -12,6 +12,7 @@ import android.view.View ...@@ -12,6 +12,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.core.view.isVisible
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.infrastructure.checkIfMyself import chat.rocket.android.infrastructure.checkIfMyself
...@@ -53,13 +54,13 @@ class ChatRoomsAdapter( ...@@ -53,13 +54,13 @@ class ChatRoomsAdapter(
bindName(chatRoom, text_chat_name) bindName(chatRoom, text_chat_name)
bindIcon(chatRoom, image_chat_icon) bindIcon(chatRoom, image_chat_icon)
if (settings.showLastMessage()) { if (settings.showLastMessage()) {
text_last_message.setVisible(true) text_last_message.isVisible = true
text_last_message_date_time.setVisible(true) text_last_message_date_time.isVisible = true
bindLastMessageDateTime(chatRoom, text_last_message_date_time) bindLastMessageDateTime(chatRoom, text_last_message_date_time)
bindLastMessage(chatRoom, text_last_message) bindLastMessage(chatRoom, text_last_message)
} else { } else {
text_last_message.setVisible(false) text_last_message.isVisible = false
text_last_message_date_time.setVisible(false) text_last_message_date_time.isVisible = false
} }
bindUnreadMessages(chatRoom, text_total_unread_messages) bindUnreadMessages(chatRoom, text_total_unread_messages)
...@@ -178,13 +179,13 @@ class ChatRoomsAdapter( ...@@ -178,13 +179,13 @@ class ChatRoomsAdapter(
when { when {
totalUnreadMessage in 1..99 -> { totalUnreadMessage in 1..99 -> {
textView.textContent = totalUnreadMessage.toString() textView.textContent = totalUnreadMessage.toString()
textView.setVisible(true) textView.isVisible = true
} }
totalUnreadMessage > 99 -> { totalUnreadMessage > 99 -> {
textView.textContent = context.getString(R.string.msg_more_than_ninety_nine_unread_messages) textView.textContent = context.getString(R.string.msg_more_than_ninety_nine_unread_messages)
textView.setVisible(true) textView.isVisible = true
} }
else -> textView.setVisible(false) else -> textView.isVisible = false
} }
} }
} }
......
...@@ -178,11 +178,14 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -178,11 +178,14 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override fun onMenuItemActionCollapse(item: MenuItem): Boolean { override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
// Simply setting sortView to visible won't work, so we invalidate the options // Simply setting sortView to visible won't work, so we invalidate the options
// to recreate the entire menu... // to recreate the entire menu...
viewModel.showLastMessage = true
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
queryChatRoomsByName(null)
return true return true
} }
override fun onMenuItemActionExpand(item: MenuItem): Boolean { override fun onMenuItemActionExpand(item: MenuItem): Boolean {
viewModel.showLastMessage = false
sortView?.isVisible = false sortView?.isVisible = false
return true return true
} }
......
...@@ -30,6 +30,7 @@ import timber.log.Timber ...@@ -30,6 +30,7 @@ import timber.log.Timber
import java.security.InvalidParameterException import java.security.InvalidParameterException
import kotlin.coroutines.experimental.coroutineContext import kotlin.coroutines.experimental.coroutineContext
class ChatRoomsViewModel( class ChatRoomsViewModel(
private val connectionManager: ConnectionManager, private val connectionManager: ConnectionManager,
private val interactor: FetchChatRoomsInteractor, private val interactor: FetchChatRoomsInteractor,
...@@ -41,9 +42,11 @@ class ChatRoomsViewModel( ...@@ -41,9 +42,11 @@ class ChatRoomsViewModel(
private val runContext = newSingleThreadContext("chat-rooms-view-model") private val runContext = newSingleThreadContext("chat-rooms-view-model")
private val client = connectionManager.client private val client = connectionManager.client
private var loaded = false private var loaded = false
var showLastMessage = true
fun getChatRooms(): LiveData<RoomsModel> { fun getChatRooms(): LiveData<RoomsModel> {
return Transformations.switchMap(query) { query -> return Transformations.switchMap(query) { query ->
return@switchMap if (query.isSearch()) { return@switchMap if (query.isSearch()) {
this@ChatRoomsViewModel.query.wrap(runContext) { _, data: MutableLiveData<RoomsModel> -> this@ChatRoomsViewModel.query.wrap(runContext) { _, data: MutableLiveData<RoomsModel> ->
val string = (query as Query.Search).query val string = (query as Query.Search).query
...@@ -53,11 +56,13 @@ class ChatRoomsViewModel( ...@@ -53,11 +56,13 @@ class ChatRoomsViewModel(
// TODO - find a better way for cancellation checking // TODO - find a better way for cancellation checking
if (!coroutineContext.isActive) return@wrap if (!coroutineContext.isActive) return@wrap
val rooms = repository.search(string).let { mapper.map(it) } val rooms = repository.search(string).let { mapper.map(it, showLastMessage = this.showLastMessage) }
data.postValue(rooms.toMutableList() + LoadingItemHolder()) data.postValue(rooms.toMutableList() + LoadingItemHolder())
if (!coroutineContext.isActive) return@wrap if (!coroutineContext.isActive) return@wrap
val spotlight = spotlight(query.query)?.let { mapper.map(it) } val spotlight = spotlight(query.query)?.let { mapper.map(it, showLastMessage = this.showLastMessage) }
if (!coroutineContext.isActive) return@wrap if (!coroutineContext.isActive) return@wrap
spotlight?.let { spotlight?.let {
...@@ -72,7 +77,7 @@ class ChatRoomsViewModel( ...@@ -72,7 +77,7 @@ class ChatRoomsViewModel(
.distinct() .distinct()
.transform(runContext) { rooms -> .transform(runContext) { rooms ->
val mappedRooms = rooms?.let { val mappedRooms = rooms?.let {
mapper.map(rooms, query.isGrouped()) mapper.map(rooms, query.isGrouped(), this.showLastMessage)
} }
if (loaded && mappedRooms?.isEmpty() == true) { if (loaded && mappedRooms?.isEmpty() == true) {
loadingState.postValue(LoadingState.Loaded(0)) loadingState.postValue(LoadingState.Loaded(0))
......
...@@ -13,7 +13,6 @@ import android.text.style.ReplacementSpan ...@@ -13,7 +13,6 @@ import android.text.style.ReplacementSpan
import android.view.View import android.view.View
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.util.PatternsCompat import androidx.core.util.PatternsCompat
import chat.rocket.android.R
import chat.rocket.android.chatroom.ui.StrikethroughDelimiterProcessor import chat.rocket.android.chatroom.ui.StrikethroughDelimiterProcessor
import chat.rocket.android.emoji.EmojiParser import chat.rocket.android.emoji.EmojiParser
import chat.rocket.android.emoji.EmojiRepository import chat.rocket.android.emoji.EmojiRepository
...@@ -32,6 +31,7 @@ import org.commonmark.node.Emphasis ...@@ -32,6 +31,7 @@ import org.commonmark.node.Emphasis
import org.commonmark.node.ListItem import org.commonmark.node.ListItem
import org.commonmark.node.Node import org.commonmark.node.Node
import org.commonmark.node.OrderedList import org.commonmark.node.OrderedList
import org.commonmark.node.SoftLineBreak
import org.commonmark.node.StrongEmphasis import org.commonmark.node.StrongEmphasis
import org.commonmark.parser.Parser import org.commonmark.parser.Parser
import ru.noties.markwon.SpannableBuilder import ru.noties.markwon.SpannableBuilder
...@@ -219,6 +219,11 @@ class MessageParser @Inject constructor( ...@@ -219,6 +219,11 @@ class MessageParser @Inject constructor(
builder.append('\n') builder.append('\n')
} }
} }
override fun visit(softLineBreak: SoftLineBreak) {
super.visit(softLineBreak)
builder.append("\n")
}
} }
class LinkVisitor(private val builder: SpannableBuilder) : AbstractVisitor() { class LinkVisitor(private val builder: SpannableBuilder) : AbstractVisitor() {
......
...@@ -43,6 +43,7 @@ class MembersAdapter(private val listener: (MemberUiModel) -> Unit) : ...@@ -43,6 +43,7 @@ class MembersAdapter(private val listener: (MemberUiModel) -> Unit) :
fun bind(memberUiModel: MemberUiModel, listener: (MemberUiModel) -> Unit) = with(itemView) { fun bind(memberUiModel: MemberUiModel, listener: (MemberUiModel) -> Unit) = with(itemView) {
image_avatar.setImageURI(memberUiModel.avatarUri) image_avatar.setImageURI(memberUiModel.avatarUri)
text_member.content = memberUiModel.displayName text_member.content = memberUiModel.displayName
text_member.setCompoundDrawablesRelativeWithIntrinsicBounds(DrawableHelper.getUserStatusDrawable(memberUiModel.status, context), null, null, null)
setOnClickListener { listener(memberUiModel) } setOnClickListener { listener(memberUiModel) }
} }
} }
......
...@@ -3,6 +3,7 @@ package chat.rocket.android.members.uimodel ...@@ -3,6 +3,7 @@ package chat.rocket.android.members.uimodel
import chat.rocket.android.server.domain.useRealName import chat.rocket.android.server.domain.useRealName
import chat.rocket.android.util.extensions.avatarUrl import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.common.model.User import chat.rocket.common.model.User
import chat.rocket.common.model.UserStatus
import chat.rocket.core.model.Value import chat.rocket.core.model.Value
class MemberUiModel( class MemberUiModel(
...@@ -16,6 +17,7 @@ class MemberUiModel( ...@@ -16,6 +17,7 @@ class MemberUiModel(
val username: String? val username: String?
val email: String? val email: String?
val utcOffset: Float? val utcOffset: Float?
val status: UserStatus?
init { init {
avatarUri = getUserAvatar() avatarUri = getUserAvatar()
...@@ -24,6 +26,7 @@ class MemberUiModel( ...@@ -24,6 +26,7 @@ class MemberUiModel(
username = getUserUsername() username = getUserUsername()
email = getUserEmail() email = getUserEmail()
utcOffset = getUserUtcOffset() utcOffset = getUserUtcOffset()
status = getUserStatus()
} }
private fun getUserAvatar(): String? { private fun getUserAvatar(): String? {
...@@ -47,4 +50,6 @@ class MemberUiModel( ...@@ -47,4 +50,6 @@ class MemberUiModel(
private fun getUserEmail(): String? = member.emails?.get(0)?.address private fun getUserEmail(): String? = member.emails?.get(0)?.address
private fun getUserUtcOffset(): Float? = member.utcOffset private fun getUserUtcOffset(): Float? = member.utcOffset
private fun getUserStatus(): UserStatus? = member.status
} }
\ No newline at end of file
...@@ -37,19 +37,6 @@ fun FragmentActivity.clearLightStatusBar() { ...@@ -37,19 +37,6 @@ fun FragmentActivity.clearLightStatusBar() {
} }
} }
// TODO: Remove. Use KTX instead.
fun View.setVisible(visible: Boolean) {
visibility = if (visible) {
View.VISIBLE
} else {
View.GONE
}
}
fun View.isVisible(): Boolean {
return visibility == View.VISIBLE
}
fun ViewGroup.inflate(@LayoutRes resource: Int, attachToRoot: Boolean = false): View = fun ViewGroup.inflate(@LayoutRes resource: Int, attachToRoot: Boolean = false): View =
LayoutInflater.from(context).inflate(resource, this, attachToRoot) LayoutInflater.from(context).inflate(resource, this, attachToRoot)
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:paddingBottom="@dimen/member_item_top_and_bottom_padding"
android:paddingEnd="@dimen/screen_edge_left_and_right_padding"
android:paddingStart="@dimen/screen_edge_left_and_right_padding" android:paddingStart="@dimen/screen_edge_left_and_right_padding"
android:paddingTop="@dimen/member_item_top_and_bottom_padding"> android:paddingTop="@dimen/member_item_top_and_bottom_padding"
android:paddingEnd="@dimen/screen_edge_left_and_right_padding"
android:paddingBottom="@dimen/member_item_top_and_bottom_padding">
<include <include
android:id="@+id/layout_avatar" android:id="@+id/layout_avatar"
...@@ -24,9 +24,11 @@ ...@@ -24,9 +24,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:drawablePadding="@dimen/text_view_drawable_padding"
app:layout_constraintBottom_toBottomOf="@+id/layout_avatar" app:layout_constraintBottom_toBottomOf="@+id/layout_avatar"
app:layout_constraintLeft_toRightOf="@+id/layout_avatar" app:layout_constraintLeft_toRightOf="@+id/layout_avatar"
app:layout_constraintTop_toTopOf="@+id/layout_avatar" app:layout_constraintTop_toTopOf="@+id/layout_avatar"
tools:drawableStart="@drawable/ic_status_invisible_12dp"
tools:text="Ronald Perkins" /> tools:text="Ronald Perkins" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment