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



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

}
}
}
}

lifecycleScope.launchWhenStarted {
stocksVM.stockUpdate.collect {
log(it.data?.data.toString())
}
}
}

private fun setUpRv() {


binding.rvStocks.apply {
adapter =
quoteAdapter.withLoadStateFooter(LoadFooterAdapter { quoteAdapter.retry() })
layoutAnimation = AnimationUtils.loadLayoutAnimation(requireContext(),R.anim.item_layout_anim)
}
}

private fun setUpListeners() {


val likeAnim = LikeAnimation(requireContext())
quoteAdapter.onStockClickListener(object : OnStockClickListener {

override fun onFavoriteClick(quote: Quote, imgFav: ImageView) {


if (quote.isFavorite){
likeAnim.unlike(imgFav)
stocksVM.deleteStock(quote)
}
else{
likeAnim.like(imgFav)
stocksVM.saveStock(quote)
}
quote.isFavorite = !quote.isFavorite
}

override fun onStockClick(quote: Quote) {


val action = MainFragmentDirections.actionMainFragmentToQuoteFragment(quote.symbol)
navigate(R.id.mainFragment, action)
}
})

quoteAdapter.addLoadStateListener { loadState ->


binding.rvStocks.isVisible = loadState.source.refresh is LoadState.NotLoading
binding.progress.isVisible = loadState.source.refresh is LoadState.Loading
binding.retryBtn.isVisible = loadState.source.refresh is LoadState.Error
if (loadState.source.refresh is LoadState.Error) {
val er = loadState.source.refresh as LoadState.Error
log("${er.error}")
}
val errorState = loadState.source.append as? LoadState.Error
?: loadState.source.prepend as? LoadState.Error
?: loadState.append as? LoadState.Error
?: loadState.prepend as? LoadState.Error
errorState?.let {
Toast.makeText(
requireContext(),
"Error fetching",
Toast.LENGTH_LONG
).show()
}
}
binding.retryBtn.setOnClickListener {
quoteAdapter.refresh()
}
}

override fun beforeDestroyBinding() {


super.beforeDestroyBinding()
//To prevent memory leak
binding.rvStocks.adapter = null
}
}
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