Salimov Azimjon 316-18 guruh Mavzu: Android dasturlarida xabarlarni yuborish va almashtirish uchun foydalanuvchi interfeysini yaratish


}.flow } override fun searchStock(query: String) = flow {



Download 24,18 Kb.
bet3/5
Sana31.12.2021
Hajmi24,18 Kb.
#238279
1   2   3   4   5
Bog'liq
3-TOPSHIRIQ MI

}.flow
}

override fun searchStock(query: String) = flow>> {


searchService.searchStock(query)
.collect {
when (it) {
is Resource.InitialState ->{
emit(Resource.InitialState())
}
is Resource.Loading -> {
emit(Resource.Loading())
}
is Resource.Error -> {
emit(Resource.Error(it.message.toString()))
}
is Resource.Success -> {
it.data?.let { response ->
emit(Resource.Success(response.result))
}
}
}
}
}
}

package uz.azim.stocks.ui.fragment.stocks.vm

import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import androidx.paging.map
import com.google.gson.Gson
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import okhttp3.*
import uz.azim.stocks.data.repo.stock.StocksRepository
import uz.azim.stocks.model.Quote
import uz.azim.stocks.model.StockUpdate
import uz.azim.stocks.ui.BaseViewModel
import uz.azim.stocks.util.Resource
import uz.azim.stocks.util.log
import javax.inject.Inject

@HiltViewModel


class StocksVM
@Inject constructor(
private val stocksRepository: StocksRepository
) : BaseViewModel() {

private val _quotes = MutableStateFlow
>>(Resource.InitialState())
val quotes = _quotes.asStateFlow()

private val _stockUpdate = MutableStateFlow>(Resource.InitialState())


val stockUpdate = _stockUpdate.asStateFlow()

private val stocks = arrayListOf()


lateinit var ws: WebSocket

init {
getStocks()


}

fun getStocks() = viewModelScope.launch(exceptionHandler) {


stocksRepository.getStocks()
.cachedIn(viewModelScope)
.collectLatest {
log("collect")
_quotes.value = Resource.Success(it)

Download 24,18 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish