Commit a8daa6c8 authored by Lucio Maciel's avatar Lucio Maciel

WIP

parent baf84e1e
...@@ -15,6 +15,10 @@ class ChatRoomsRepository @Inject constructor(val dao: ChatRoomDao){ ...@@ -15,6 +15,10 @@ class ChatRoomsRepository @Inject constructor(val dao: ChatRoomDao){
} }
} }
fun getChatRooms(query: String): List<ChatRoom> {
TODO()
}
enum class Order { enum class Order {
ACTIVITY, ACTIVITY,
GROUPED_ACTIVITY, GROUPED_ACTIVITY,
......
...@@ -9,12 +9,14 @@ import chat.rocket.android.chatrooms.adapter.RoomUiModelMapper ...@@ -9,12 +9,14 @@ import chat.rocket.android.chatrooms.adapter.RoomUiModelMapper
import chat.rocket.android.chatrooms.domain.FetchChatRoomsInteractor import chat.rocket.android.chatrooms.domain.FetchChatRoomsInteractor
import chat.rocket.android.chatrooms.infrastructure.ChatRoomsRepository import chat.rocket.android.chatrooms.infrastructure.ChatRoomsRepository
import chat.rocket.android.chatrooms.infrastructure.isGrouped import chat.rocket.android.chatrooms.infrastructure.isGrouped
import chat.rocket.android.db.model.ChatRoom
import chat.rocket.android.server.infraestructure.ConnectionManager import chat.rocket.android.server.infraestructure.ConnectionManager
import chat.rocket.android.util.livedata.transform import chat.rocket.android.util.livedata.transform
import chat.rocket.core.internal.realtime.socket.model.State import chat.rocket.core.internal.realtime.socket.model.State
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.newSingleThreadContext import kotlinx.coroutines.experimental.newSingleThreadContext
import me.henrytao.livedataktx.distinct import me.henrytao.livedataktx.distinct
import me.henrytao.livedataktx.filter
import me.henrytao.livedataktx.map import me.henrytao.livedataktx.map
import me.henrytao.livedataktx.nonNull import me.henrytao.livedataktx.nonNull
import timber.log.Timber import timber.log.Timber
...@@ -26,6 +28,7 @@ class ChatRoomsViewModel( ...@@ -26,6 +28,7 @@ class ChatRoomsViewModel(
private val mapper: RoomUiModelMapper private val mapper: RoomUiModelMapper
) : ViewModel() { ) : ViewModel() {
private val ordering: MutableLiveData<ChatRoomsRepository.Order> = MutableLiveData() private val ordering: MutableLiveData<ChatRoomsRepository.Order> = MutableLiveData()
private val query: MutableLiveData<String> = MutableLiveData()
private val runContext = newSingleThreadContext("chat-rooms-view-model") private val runContext = newSingleThreadContext("chat-rooms-view-model")
init { init {
...@@ -46,6 +49,12 @@ class ChatRoomsViewModel( ...@@ -46,6 +49,12 @@ class ChatRoomsViewModel(
} }
} }
fun spotlight(): LiveData<List<ChatRoom>> {
return query.filter { !it.isNullOrEmpty() }.distinct().nonNull().transform {
repository.getChatRooms(it!!)
}
}
fun getStatus(): MutableLiveData<State> { fun getStatus(): MutableLiveData<State> {
return connectionManager.statusLiveData.nonNull().distinct().map { state -> return connectionManager.statusLiveData.nonNull().distinct().map { state ->
if (state is State.Connected) { if (state is State.Connected) {
......
...@@ -20,6 +20,10 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> { ...@@ -20,6 +20,10 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
""") """)
abstract fun get(id: String): ChatRoom? abstract fun get(id: String): ChatRoom?
@Transaction
@Query("$BASE_QUERY")
abstract fun getAllSync(): List<ChatRoom>
@Transaction @Transaction
@Query(""" @Query("""
$BASE_QUERY $BASE_QUERY
......
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