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

Update layout and ChatRoomsPresenter.kt

parent 5232e7eb
...@@ -111,9 +111,13 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -111,9 +111,13 @@ class ChatRoomsPresenter @Inject constructor(
val chatRoomsCombined = mutableListOf<ChatRoom>() val chatRoomsCombined = mutableListOf<ChatRoom>()
chatRoomsCombined.addAll(usersToChatRooms(users)) chatRoomsCombined.addAll(usersToChatRooms(users))
chatRoomsCombined.addAll(roomsToChatRooms(rooms)) chatRoomsCombined.addAll(roomsToChatRooms(rooms))
view.updateChatRooms(getChatRoomsWithPreviews(chatRoomsCombined.toList())) val chatRoomsWithPreview = getChatRoomsWithPreviews(chatRoomsCombined)
val chatRoomsWithStatus = getChatRoomWithStatus(chatRoomsWithPreview)
view.updateChatRooms(chatRoomsWithStatus)
} else { } else {
view.updateChatRooms(getChatRoomsWithPreviews(roomList)) val chatRoomsWithPreview = getChatRoomsWithPreviews(roomList)
val chatRoomsWithStatus = getChatRoomWithStatus(chatRoomsWithPreview)
view.updateChatRooms(chatRoomsWithStatus)
} }
} catch (ex: RocketChatException) { } catch (ex: RocketChatException) {
Timber.e(ex) Timber.e(ex)
...@@ -121,6 +125,19 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -121,6 +125,19 @@ class ChatRoomsPresenter @Inject constructor(
} }
} }
// In the first time it will not come with the users status, but after called by the
// [reloadRooms] function may be with.
private suspend fun getUserChatRooms(): List<ChatRoom> {
val chatRooms = retryIO("chatRooms") { manager.chatRooms().update }
val chatRoomsWithPreview = getChatRoomsWithPreviews(chatRooms)
val chatRoomsWithUserStatus = getChatRoomWithStatus(chatRoomsWithPreview)
val sortedRooms = sortRooms(chatRoomsWithUserStatus)
Timber.d("Loaded rooms: ${sortedRooms.size}")
saveChatRoomsInteractor.save(currentServer, sortedRooms)
return sortedRooms
}
private fun usersToChatRooms(users: List<User>): List<ChatRoom> { private fun usersToChatRooms(users: List<User>): List<ChatRoom> {
return users.map { return users.map {
ChatRoom( ChatRoom(
...@@ -134,7 +151,6 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -134,7 +151,6 @@ class ChatRoomsPresenter @Inject constructor(
null null
}, },
name = it.name ?: "", name = it.name ?: "",
status = null,
fullName = it.name, fullName = it.name,
readonly = false, readonly = false,
updatedAt = null, updatedAt = null,
...@@ -168,7 +184,6 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -168,7 +184,6 @@ class ChatRoomsPresenter @Inject constructor(
null null
}, },
name = it.name ?: "", name = it.name ?: "",
status = null,
fullName = it.fullName, fullName = it.fullName,
readonly = it.readonly, readonly = it.readonly,
updatedAt = it.updatedAt, updatedAt = it.updatedAt,
...@@ -189,17 +204,7 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -189,17 +204,7 @@ class ChatRoomsPresenter @Inject constructor(
} }
} }
private suspend fun getUserChatRooms(): List<ChatRoom> {
val chatRooms = retryIO("chatRooms") { manager.chatRooms().update }
val sortedRooms = sortRooms(chatRooms)
Timber.d("Loaded rooms: ${sortedRooms.size}")
saveChatRoomsInteractor.save(currentServer, sortedRooms)
val chatRoomsWithPreview = getChatRoomsWithPreviews(sortedRooms)
return getChatRoomWithStatus(chatRoomsWithPreview)
}
fun updateSortedChatRooms() { fun updateSortedChatRooms() {
val currentServer = serverInteractor.get()!!
launchUI(strategy) { launchUI(strategy) {
val roomList = getChatRoomsInteractor.getAll(currentServer) val roomList = getChatRoomsInteractor.getAll(currentServer)
view.updateChatRooms(sortRooms(roomList)) view.updateChatRooms(sortRooms(roomList))
...@@ -401,7 +406,6 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -401,7 +406,6 @@ class ChatRoomsPresenter @Inject constructor(
room.name ?: name room.name ?: name
)?.status, )?.status,
name = room.name ?: name, name = room.name ?: name,
status = null,
fullName = room.fullName ?: fullName, fullName = room.fullName ?: fullName,
readonly = room.readonly, readonly = room.readonly,
updatedAt = room.updatedAt ?: updatedAt, updatedAt = room.updatedAt ?: updatedAt,
...@@ -441,7 +445,6 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -441,7 +445,6 @@ class ChatRoomsPresenter @Inject constructor(
subscription.name subscription.name
)?.status, )?.status,
name = subscription.name, name = subscription.name,
status = null,
fullName = subscription.fullName ?: fullName, fullName = subscription.fullName ?: fullName,
readonly = subscription.readonly ?: readonly, readonly = subscription.readonly ?: readonly,
updatedAt = subscription.updatedAt ?: updatedAt, updatedAt = subscription.updatedAt ?: updatedAt,
...@@ -505,6 +508,7 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -505,6 +508,7 @@ class ChatRoomsPresenter @Inject constructor(
} }
private fun updateChatRoomWithUserStatus(user_: User) { private fun updateChatRoomWithUserStatus(user_: User) {
Timber.d("active User: $user_")
val username = user_.username val username = user_.username
val status = user_.status val status = user_.status
if (username != null && status != null) { if (username != null && status != null) {
...@@ -546,10 +550,11 @@ class ChatRoomsPresenter @Inject constructor( ...@@ -546,10 +550,11 @@ class ChatRoomsPresenter @Inject constructor(
private fun updateChatRooms() { private fun updateChatRooms() {
Timber.i("Updating ChatRooms") Timber.i("Updating ChatRooms")
launch(strategy.jobs) { launch(strategy.jobs) {
val chatRooms = getChatRoomsWithPreviews( val chatRoomsWithPreview = getChatRoomsWithPreviews(
getChatRoomsInteractor.getAll(currentServer) getChatRoomsInteractor.getAll(currentServer)
) )
view.updateChatRooms(chatRooms) val chatRoomsWithStatus = getChatRoomWithStatus(chatRoomsWithPreview)
view.updateChatRooms(chatRoomsWithStatus)
} }
} }
......
...@@ -32,12 +32,9 @@ import dagger.android.support.AndroidSupportInjection ...@@ -32,12 +32,9 @@ import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_chat_rooms.* import kotlinx.android.synthetic.main.fragment_chat_rooms.*
import kotlinx.coroutines.experimental.Job import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.NonCancellable.isActive import kotlinx.coroutines.experimental.NonCancellable.isActive
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.launch
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class ChatRoomsFragment : Fragment(), ChatRoomsView { class ChatRoomsFragment : Fragment(), ChatRoomsView {
@Inject lateinit var presenter: ChatRoomsPresenter @Inject lateinit var presenter: ChatRoomsPresenter
@Inject lateinit var serverInteractor: GetCurrentServerInteractor @Inject lateinit var serverInteractor: GetCurrentServerInteractor
...@@ -67,7 +64,11 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -67,7 +64,11 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
super.onDestroy() super.onDestroy()
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = container?.inflate(R.layout.fragment_chat_rooms) override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = container?.inflate(R.layout.fragment_chat_rooms)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
...@@ -100,7 +101,6 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -100,7 +101,6 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
}) })
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.action_sort -> { R.id.action_sort -> {
......
...@@ -31,9 +31,9 @@ ...@@ -31,9 +31,9 @@
<ImageView <ImageView
android:id="@+id/image_chat_icon" android:id="@+id/image_chat_icon"
android:layout_width="12dp" android:layout_width="wrap_content"
android:layout_height="12dp" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center_vertical"
tools:src="@drawable/ic_lock_12_dp" /> tools:src="@drawable/ic_lock_12_dp" />
<TextView <TextView
...@@ -41,8 +41,10 @@ ...@@ -41,8 +41,10 @@
style="@style/ChatRoom.Name.TextView" style="@style/ChatRoom.Name.TextView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:ellipsize="end"
android:textDirection="locale" android:textDirection="locale"
tools:text="A very very very very big chat room name" /> tools:text="A very very very very big chat room name" />
</LinearLayout> </LinearLayout>
......
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