mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-12-21 08:02:28 +03:00
Modify ViewModel
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
5fd8541ddc
commit
b769a024c4
1 changed files with 6 additions and 7 deletions
|
@ -10,8 +10,7 @@ import android.util.Log
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import com.nextcloud.talk.openconversations.data.OpenConversation
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||||
import com.nextcloud.talk.openconversations.data.OpenConversationsModel
|
|
||||||
import com.nextcloud.talk.openconversations.data.OpenConversationsRepository
|
import com.nextcloud.talk.openconversations.data.OpenConversationsRepository
|
||||||
import io.reactivex.Observer
|
import io.reactivex.Observer
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
@ -27,7 +26,7 @@ class OpenConversationsViewModel @Inject constructor(private val repository: Ope
|
||||||
object FetchConversationsStartState : ViewState
|
object FetchConversationsStartState : ViewState
|
||||||
object FetchConversationsEmptyState : ViewState
|
object FetchConversationsEmptyState : ViewState
|
||||||
object FetchConversationsErrorState : ViewState
|
object FetchConversationsErrorState : ViewState
|
||||||
open class FetchConversationsSuccessState(val conversations: List<OpenConversation>) : ViewState
|
open class FetchConversationsSuccessState(val conversations: List<Conversation>) : ViewState
|
||||||
|
|
||||||
private val _viewState: MutableLiveData<ViewState> = MutableLiveData(FetchConversationsStartState)
|
private val _viewState: MutableLiveData<ViewState> = MutableLiveData(FetchConversationsStartState)
|
||||||
val viewState: LiveData<ViewState>
|
val viewState: LiveData<ViewState>
|
||||||
|
@ -41,16 +40,16 @@ class OpenConversationsViewModel @Inject constructor(private val repository: Ope
|
||||||
?.subscribe(FetchConversationsObserver())
|
?.subscribe(FetchConversationsObserver())
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class FetchConversationsObserver : Observer<OpenConversationsModel> {
|
inner class FetchConversationsObserver : Observer<List<Conversation>> {
|
||||||
override fun onSubscribe(d: Disposable) {
|
override fun onSubscribe(d: Disposable) {
|
||||||
// unused atm
|
// unused atm
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNext(model: OpenConversationsModel) {
|
override fun onNext(conversations: List<Conversation>) {
|
||||||
if (model.conversations.isEmpty()) {
|
if (conversations.isEmpty()) {
|
||||||
_viewState.value = FetchConversationsEmptyState
|
_viewState.value = FetchConversationsEmptyState
|
||||||
} else {
|
} else {
|
||||||
_viewState.value = FetchConversationsSuccessState(model.conversations)
|
_viewState.value = FetchConversationsSuccessState(conversations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue