All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.sceyt.chatuikit.presentation.components.role.viewmodel.RoleViewModel.kt Maven / Gradle / Ivy

package com.sceyt.chatuikit.presentation.components.role.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.sceyt.chat.models.role.Role
import com.sceyt.chatuikit.presentation.components.role.adapter.RoleItem
import com.sceyt.chat.wrapper.ClientWrapper
import com.sceyt.chatuikit.data.models.SceytResponse
import com.sceyt.chatuikit.presentation.root.BaseViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class RoleViewModel : BaseViewModel() {
    private val _rolesLiveData = MutableLiveData>()
    val rolesLiveData: LiveData> = _rolesLiveData

    fun getRoles() {
        viewModelScope.launch(Dispatchers.IO) {
            ClientWrapper.getRoles { roles, status ->
                if (status == null || status.isOk) {
                    _rolesLiveData.postValue(roles.map { RoleItem(it) })
                } else
                    notifyPageStateWithResponse(SceytResponse.Error>(status.error))
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy