Modify ViewModel

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-11-27 18:23:14 +01:00 committed by Marcel Hibbe
parent 5fd8541ddc
commit b769a024c4
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -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)
} }
} }