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.
bet1/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


O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Dasturiy injinering fakulteti

Axborot Texnologiyalarining Dasturiy Ta’minoti kafedrasi


Dasturiy injiniringga kirish




Amaliy ish №3,4
Topshirdi: Ustaboyev Abbosbek
Qabul qildi: Jabborova N.

Toshkent 2022


Mavzu: 3 - Dasturiy mahsulotning backend qismi.


Dastur kodi va screenshot:
Bu ilova MVVM arhitekturasida qili








Shopping Repository
package mobiler.abbosbek.onlineshopping.repository

import androidx.lifecycle.MutableLiveData


import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.observers.DisposableObserver
import io.reactivex.schedulers.Schedulers
import mobiler.abbosbek.onlineshopping.api.NetworkManager
import mobiler.abbosbek.onlineshopping.model.BaseResponse
import mobiler.abbosbek.onlineshopping.model.CategoryModel
import mobiler.abbosbek.onlineshopping.model.OfferModel
import mobiler.abbosbek.onlineshopping.model.ProductModel
import mobiler.abbosbek.onlineshopping.model.request.GetProductsByIdRequest
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class ShopRepository{


val compositeDisposable = CompositeDisposable()

fun getOffers(error : MutableLiveData, success : MutableLiveData>){


compositeDisposable.add(
NetworkManager.getApiService().getOffers()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver>>(){
override fun onNext(t: BaseResponse>) {
if (t.success){
success.value = t.data
}else{
error.value = t.message
}
}

override fun onError(e: Throwable) {


error.value = e.localizedMessage
}

override fun onComplete() {


}
})
)
}

fun getCategories(error : MutableLiveData,success : MutableLiveData>){


compositeDisposable.add(
NetworkManager.getApiService().getCategories()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver>>(){
override fun onNext(t: BaseResponse>) {
if (t.success){
success.value = t.data
}else{
error.value = t.message
}
}

override fun onError(e: Throwable) {


error.value = e.localizedMessage
}

override fun onComplete() {


}
})
)
}

fun getTopProducts(error : MutableLiveData,success : MutableLiveData
>){
compositeDisposable.add(
NetworkManager.getApiService().getTopProducts()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver>>(){
override fun onNext(t: BaseResponse>) {
if (t.success){
success.value = t.data
}else{
error.value = t.message
}
}

override fun onError(e: Throwable) {


error.value = e.localizedMessage
}

override fun onComplete() {


}
})
)
}

fun getProductsByCategory(id : Int,error : MutableLiveData,success : MutableLiveData
>){
compositeDisposable.add(
NetworkManager.getApiService().getCategoryProducts(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver>>(){
override fun onNext(t: BaseResponse>) {
if (t.success){
success.value = t.data
}else{
error.value = t.message
}
}

override fun onError(e: Throwable) {


error.value = e.localizedMessage
}

override fun onComplete() {


}
})
)
}

fun getProductsByIds(ids : List,error : MutableLiveData,progress: MutableLiveData,success : MutableLiveData
>){
progress.value = true
compositeDisposable.add(
NetworkManager.getApiService().getTopProductsByIds(GetProductsByIdRequest(ids))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver>>(){
override fun onNext(t: BaseResponse>) {
progress.value = false
if (t.success){
success.value = t.data
}else{
error.value = t.message
}
}

override fun onError(e: Throwable) {


progress.value = false
error.value = e.localizedMessage
}

override fun onComplete() {


}
})
)
}
}



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