Commit 29a51143 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Fixing things.

parent f00301c0
package chat.rocket.android.chatroom.presentation
import chat.rocket.android.chatroom.viewmodel.MessageViewModelMapper
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.launchUI
import chat.rocket.common.model.roomTypeOf
......@@ -13,6 +15,7 @@ import chat.rocket.core.internal.realtime.unsubscibre
import chat.rocket.core.internal.rest.messages
import chat.rocket.core.internal.rest.sendMessage
import chat.rocket.core.model.Message
import chat.rocket.core.model.Value
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.launch
......@@ -21,12 +24,18 @@ import javax.inject.Inject
class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
private val strategy: CancelStrategy,
getSettingsInteractor: GetSettingsInteractor,
private val serverInteractor: GetCurrentServerInteractor,
factory: RocketChatClientFactory,
private val mapper: MessageViewModelMapper) {
private val client = factory.create(serverInteractor.get()!!)
private val roomMessages = ArrayList<Message>()
private var subId: String? = null
private var settings: Map<String, Value<Any>>? = null
init {
settings = getSettingsInteractor.get(serverInteractor.get()!!)
}
private val stateChannel = Channel<State>()
......@@ -51,8 +60,8 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
ex.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
view.showGenericErrorMessage()
}
} finally {
view.hideLoading()
}
......@@ -71,8 +80,8 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
ex.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
view.showGenericErrorMessage()
}
view.enableMessageInput()
}
......
package chat.rocket.android.chatroom.presentation
import chat.rocket.android.chatroom.viewmodel.MessageViewModel
import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView
import chat.rocket.core.model.Message
interface ChatRoomView : LoadingView, MessageView {
......@@ -12,7 +12,7 @@ interface ChatRoomView : LoadingView, MessageView {
* @param dataSet The data set to show.
* @param serverUrl The server URL.
*/
fun showMessages(dataSet: List<Message>, serverUrl: String)
fun showMessages(dataSet: List<MessageViewModel>, serverUrl: String)
/**
* Send a message to a chat room.
......@@ -26,14 +26,14 @@ interface ChatRoomView : LoadingView, MessageView {
*
* @param message The (recent) message sent to a chat room.
*/
fun showNewMessage(message: Message)
fun showNewMessage(message: MessageViewModel)
/**
* Dispatch a update to the recycler views adapter about a changed message.
*
* @param index The index of the changed message
*/
fun dispatchUpdateMessage(index: Int, message: Message)
fun dispatchUpdateMessage(index: Int, message: MessageViewModel)
fun disableMessageInput()
......
......@@ -119,8 +119,8 @@ class ChatRoomAdapter(private val serverUrl: String) : RecyclerView.Adapter<Chat
drawee.setVisible(true)
imageUnknownAvatar.setVisible(false)
}.ifNull {
drawee.setVisible(false)
imageUnknownAvatar.setVisible(true)
}
drawee.setVisible(false)
imageUnknownAvatar.setVisible(true)
}
}
}
\ No newline at end of file
......@@ -12,11 +12,11 @@ import android.widget.Toast
import chat.rocket.android.R
import chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import chat.rocket.android.chatroom.presentation.ChatRoomView
import chat.rocket.android.chatroom.viewmodel.MessageViewModel
import chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import chat.rocket.android.util.inflate
import chat.rocket.android.util.setVisible
import chat.rocket.android.util.textContent
import chat.rocket.core.model.Message
import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_chat_room.*
import kotlinx.android.synthetic.main.message_composer.*
......@@ -75,10 +75,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
super.onDestroyView()
}
override fun showMessages(dataSet: List<Message>, serverUrl: String) {
override fun showMessages(dataSet: List<MessageViewModel>, serverUrl: String) {
activity?.apply {
if (recycler_view.adapter == null) {
adapter = ChatRoomAdapter(this, serverUrl)
adapter = ChatRoomAdapter(serverUrl)
recycler_view.adapter = adapter
val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
recycler_view.layoutManager = linearLayoutManager
......@@ -102,7 +102,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
}
}
override fun showNewMessage(message: Message) {
override fun showNewMessage(message: MessageViewModel) {
text_message.textContent = ""
adapter.addItem(message)
recycler_view.smoothScrollToPosition(0)
......@@ -119,7 +119,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
if (clear) text_message.textContent = ""
}
override fun dispatchUpdateMessage(index: Int, message: Message) {
override fun dispatchUpdateMessage(index: Int, message: MessageViewModel) {
adapter.updateItem(index, message)
}
......
......@@ -13,7 +13,7 @@ import chat.rocket.android.profile.presentation.ProfilePresenter
import chat.rocket.android.profile.presentation.ProfileView
import chat.rocket.android.util.getObservable
import chat.rocket.android.util.inflate
import chat.rocket.android.util.setVisibility
import chat.rocket.android.util.setVisible
import chat.rocket.android.util.textContent
import dagger.android.support.AndroidSupportInjection
import io.reactivex.rxkotlin.Observables
......@@ -62,7 +62,7 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
currentUsername = username
currentEmail = email
profile_container.setVisibility(true)
profile_container.setVisible(true)
listenToChanges()
}
......@@ -71,11 +71,11 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
override fun showLoading() {
enableUserInput(false)
view_loading.setVisibility(true)
view_loading.setVisible(true)
}
override fun hideLoading() {
view_loading.setVisibility(false)
view_loading.setVisible(false)
enableUserInput(true)
}
......
......@@ -47,4 +47,13 @@
<string name="msg_you">Você</string>
<string name="msg_unknown">Desconhecido</string>
<!-- System messages -->
<string name="message_room_name_changed">Nome da sala alterado para: %1$s por %2$s</string>
<string name="message_user_added_by">Usuário %1$s adicionado por %2$s</string>
<string name="message_user_removed_by">Usuário %1$s removido por %2$s</string>
<string name="message_user_left">Saiu da sala.</string>
<string name="message_user_joined_channel">Entrou no sala.</string>
<string name="message_welcome">Bem-vindo, %s</string>
<string name="message_removed">Mensagem removida</string>
</resources>
\ No newline at end of file
......@@ -49,4 +49,13 @@
<string name="msg_you">You</string>
<string name="msg_unknown">Unknown</string>
<!-- System messages -->
<string name="message_room_name_changed">Room name changed to: %1$s by %2$s</string>
<string name="message_user_added_by">User %1$s added by %2$s</string>
<string name="message_user_removed_by">User %1$s removed by %2$s</string>
<string name="message_user_left">Has left the channel.</string>
<string name="message_user_joined_channel">Has joined the channel.</string>
<string name="message_welcome">Welcome %s</string>
<string name="message_removed">Message removed</string>
</resources>
\ 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