Amaliy ish №3,4 Topshirdi: Ustaboyev Abbosbek Qabul qildi: Jabborova N. Toshkent 022 Mavzu: Dasturiy mahsulotning backend qismi. Dastur kodi va screenshot: Bu ilova mvvm arhitekturasida qili Shopping Repository



Download 453,35 Kb.
bet3/11
Sana20.07.2022
Hajmi453,35 Kb.
#829770
1   2   3   4   5   6   7   8   9   10   11
Bog'liq
UnitTest Dik 3-4

viewModelni yaratamiz

package mobiler.abbosbek.onlineshopping.screen

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mobiler.abbosbek.onlineshopping.db.AppDataBase
import mobiler.abbosbek.onlineshopping.model.CategoryModel
import mobiler.abbosbek.onlineshopping.model.OfferModel
import mobiler.abbosbek.onlineshopping.model.ProductModel
import mobiler.abbosbek.onlineshopping.repository.ShopRepository

class MainViewModel : ViewModel() {

val repository = ShopRepository()
val error = MutableLiveData()
val offersData = MutableLiveData>()
val categoryData = MutableLiveData>()
val productData = MutableLiveData>()
val progress = MutableLiveData()

fun getOffers(){


repository.getOffers(error,offersData)
}

fun getCategories(){


repository.getCategories(error,categoryData)
}
fun getTopProducts(){
repository.getTopProducts(error,productData)
}

fun getProductsByCategory(id : Int){


repository.getProductsByCategory(id,error, productData)
}
fun getProductsByIds(ids : List){
repository.getProductsByIds(ids,error,progress, productData)
}

fun insertAllProducts2DB(items : List


){
CoroutineScope(Dispatchers.IO).launch {
AppDataBase.getDataBase().getProductDao().insertAll(items)
CoroutineScope(Dispatchers.Main).launch {
error.value = "Ma'lumotlar bazaga yuklandi!"
}
}
}

fun getAllDBProducts(){


CoroutineScope(Dispatchers.Main).launch {
productData.value = withContext(Dispatchers.IO){
AppDataBase.getDataBase().getProductDao().getAllProducts()

Download 453,35 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   11




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