当前位置: 首页 > news >正文

网站标题怎么做世界杯数据分析

网站标题怎么做,世界杯数据分析,图片库,网上做网站兼职引言:所有成功者的背后,都有一份艰苦的历程,不要只看到了人前的风光,而低估了他们背后所付出的努力。 随着flow到流行度越来越高,有开发者呼吁我使用flow,于是我就如你们所愿,新增了StateFlow作…

引言:所有成功者的背后,都有一份艰苦的历程,不要只看到了人前的风光,而低估了他们背后所付出的努力。

随着flow到流行度越来越高,有开发者呼吁我使用flow,于是我就如你们所愿,新增了StateFlow作为新的数据载体。当然你仍然可以使用旧版本的LiveData,代码写法略微不同罢了。如果对我的dcache框架设计不是很理解的小伙伴,可以看我的专栏其他文章。

为什么推荐使用StateFlow

如果你非要问我为什么要使用StateFlow?我可以告诉你,因为可以装逼,哈哈,开个玩笑。新技术的流行必然有一部分炒作的部分,但也肯定是有其改进的地方的。要讲StateFlow,就不得不从flow开始说起。flow是属于kotlin语言范畴的,你可以把它当成kotlin协程的一个API。没错,kotlin语言的野心就是要做跨平台的语言,答案就在这里,LiveData是android的API,而SharedFlow与StateFlow直接就是Kotlin编程语言级别的,代码复用性更好。

LiveData和StateFlow使用对比

以列表数据模式的Repository为例。从2.1.5开始@Repository注解拆分成了@Repository注解和@ListRepository,所以2.1.4版本你应该使用@Repository注解,而如果说,你使用的是2.1.5及以上版本的dcache库,要使用@ListRepository注解。由于StateFlow在2.2.0版本才开始支持,所以自然要使用@ListRepository注解。
先看StateFlow的写法。

override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)// 此处省略代码若干行lifecycleScope.launchWhenCreated {repository.getListFlowData().collect {adapter.setTemperatures(it)}}
}

不要忘了使用协程作用域。
然后我们调用fetchListData()。

repository.fetchListData(listener = object : OnLoadStateListener {override fun onLoad(state: Int) {Log.d("WeatherActivity", "数据是否加载成功:${state==0}")}
}, description = null)

加载状态监听接口和描述信息可以传null。这个抓取数据方法一经调用,collect代码块就会刷新数据。由于fetchListData()天然就返回的StateFlow,所以你并不一定要分为两步观察数据。而如果你要分为两步,则调用getListFlowData()或getFlowData()。
再看原来LiveData的写法,这次我们不用list模式的Repository,如果要使用,直接配置@Repository注解。

minutelyRepository.latlng = "116.407526,39.90403"
minutelyRepository.fetchData("按分钟统计天气").observe(this, Observer {it?.apply {tvCacheMinutely.text = "minutely:${toString()}\n"}
})

很明显,fetchData()返回LiveData,直接调用observe()进行数据的观察。简单总结下,API的设计在调用层面具有相似性,所以,无论你使用的是LiveData为数据载体的Repository还是StateFlow的,都是调用fetchData()或fetchListData()更新缓存数据,框架内部自动帮你缓存到数据库,同时常驻在内存并递送给UI层刷新界面。所以你可以专心开发你的业务逻辑,这是不是很棒?

package com.example.dcache.repositoryimport android.content.Context
import com.example.dcache.biz.weather.WeatherService
import com.example.dcache.model.WeatherModel
import dora.cache.data.fetcher.OnLoadStateListener
import dora.cache.repository.DoraDatabaseCacheRepository
import dora.cache.repository.Repository
import dora.http.DoraCallback
import dora.http.retrofit.RetrofitManager@Repository
class WeatherRepository(context: Context) : DoraDatabaseCacheRepository<WeatherModel>(context) {var latlng: String = ""override fun onLoadFromNetwork(callback: DoraCallback<WeatherModel>,listener: OnLoadStateListener?) {RetrofitManager.getService(WeatherService::class.java).getWeather(latlng).enqueue(callback)}
}

最后简单复习一下Repository的写法。详细Demo代码https://github.com/dora4/DoraCacheSample 。

框架设计的变化

这是StateFlow的。

/*** 用于网络数据抓取。*/
interface IFlowDataFetcher<M> {/*** 清空flow data的数据。*/fun clearData()/*** 抓取数据的回调。*/fun callback(): DoraCallback<M>/*** 开始抓取数据。*/fun fetchData(description: String?, listener: OnLoadStateListener? = OnLoadStateListenerImpl()): StateFlow<M?>/*** 获取flow data。*/fun getFlowData(): StateFlow<M?>
}

这是LiveData的。

package dora.cache.data.fetcherimport androidx.lifecycle.LiveData
import dora.http.DoraCallback/*** 用于网络数据抓取。*/
interface IDataFetcher<M> {/*** 清空livedata的数据。*/fun clearData()/*** 抓取数据的回调。*/fun callback(): DoraCallback<M>/*** 开始抓取数据。*/fun fetchData(description: String?, listener: OnLoadStateListener? = OnLoadStateListenerImpl()): LiveData<M?>/*** 获取livedata。*/fun getLiveData(): LiveData<M?>
}

是不是没啥变化?对的,这就是架构设计的魅力所在。前期架构设计比较到位,所以只需要遵循开闭原则。对扩展开放,对修改关闭。
截屏2024-01-07 17.31.22.png
原先继承BaseRepository的,现在继承BaseFlowRepository的。名字有带Flow单词的,就是StateFlow的。

开源框架支持

笔者写框架和文档不容易,希望你的支持。你的支持是我改进优化最大的动力!

数据缓存dcache框架 https://github.com/dora4/dcache-android

dora框架的开发插件 https://github.com/dora4/dora-studio-plugin

dora框架 https://github.com/dora4/dora


文章转载自:
http://dinncohasidism.ssfq.cn
http://dinncocalciphobous.ssfq.cn
http://dinncoborrowing.ssfq.cn
http://dinncopedobaptist.ssfq.cn
http://dinncoplumbaginaceous.ssfq.cn
http://dinncough.ssfq.cn
http://dinncosporulation.ssfq.cn
http://dinncoboxboard.ssfq.cn
http://dinncosealant.ssfq.cn
http://dinncodesiccate.ssfq.cn
http://dinncoexergue.ssfq.cn
http://dinncogenbakusho.ssfq.cn
http://dinncounconstrained.ssfq.cn
http://dinncotreble.ssfq.cn
http://dinncobruges.ssfq.cn
http://dinncosurculus.ssfq.cn
http://dinncopaleographer.ssfq.cn
http://dinncosate.ssfq.cn
http://dinncoarborescent.ssfq.cn
http://dinnconarcotherapy.ssfq.cn
http://dinncomidafternoon.ssfq.cn
http://dinncopyrotechnics.ssfq.cn
http://dinncosandhurst.ssfq.cn
http://dinncoaeroacoustics.ssfq.cn
http://dinncosaprobial.ssfq.cn
http://dinnconorsteroid.ssfq.cn
http://dinncopicnic.ssfq.cn
http://dinncoteetotaler.ssfq.cn
http://dinncoparsonic.ssfq.cn
http://dinncofrond.ssfq.cn
http://dinncointerfix.ssfq.cn
http://dinncohant.ssfq.cn
http://dinncobrainfag.ssfq.cn
http://dinncoquadriplegia.ssfq.cn
http://dinncohili.ssfq.cn
http://dinncotwentymo.ssfq.cn
http://dinncostogy.ssfq.cn
http://dinncobriefness.ssfq.cn
http://dinnconatriuretic.ssfq.cn
http://dinncobeetroot.ssfq.cn
http://dinncoamok.ssfq.cn
http://dinncodecomposer.ssfq.cn
http://dinncounobtrusive.ssfq.cn
http://dinncomotss.ssfq.cn
http://dinncoraggle.ssfq.cn
http://dinncohatchery.ssfq.cn
http://dinncounmatched.ssfq.cn
http://dinncolignose.ssfq.cn
http://dinncobattle.ssfq.cn
http://dinncoembody.ssfq.cn
http://dinncohebrew.ssfq.cn
http://dinncofracture.ssfq.cn
http://dinncokauri.ssfq.cn
http://dinncotravelog.ssfq.cn
http://dinncosubsequent.ssfq.cn
http://dinncolegginess.ssfq.cn
http://dinncocompressor.ssfq.cn
http://dinncoalpinist.ssfq.cn
http://dinncohypocycloid.ssfq.cn
http://dinncocootie.ssfq.cn
http://dinncoborne.ssfq.cn
http://dinncolifespring.ssfq.cn
http://dinncopluralist.ssfq.cn
http://dinncomilldam.ssfq.cn
http://dinncorhodium.ssfq.cn
http://dinncorga.ssfq.cn
http://dinncoposttension.ssfq.cn
http://dinncohumoral.ssfq.cn
http://dinncositus.ssfq.cn
http://dinncodenim.ssfq.cn
http://dinncocraquelure.ssfq.cn
http://dinncoslothfulness.ssfq.cn
http://dinncocomparatist.ssfq.cn
http://dinnconovember.ssfq.cn
http://dinncolandsat.ssfq.cn
http://dinncokaiak.ssfq.cn
http://dinncohankie.ssfq.cn
http://dinncowomen.ssfq.cn
http://dinncodurkheimian.ssfq.cn
http://dinncoalleged.ssfq.cn
http://dinncomelton.ssfq.cn
http://dinncopeacock.ssfq.cn
http://dinncoepigenous.ssfq.cn
http://dinncowording.ssfq.cn
http://dinncobrent.ssfq.cn
http://dinncokneed.ssfq.cn
http://dinncoinfarct.ssfq.cn
http://dinncoseverity.ssfq.cn
http://dinncodelusory.ssfq.cn
http://dinncomegalomania.ssfq.cn
http://dinncomad.ssfq.cn
http://dinncosnowdrop.ssfq.cn
http://dinncorayl.ssfq.cn
http://dinncoodontalgia.ssfq.cn
http://dinncoacryl.ssfq.cn
http://dinncowinter.ssfq.cn
http://dinncolactoproteid.ssfq.cn
http://dinncoenfetter.ssfq.cn
http://dinncolunarite.ssfq.cn
http://dinncogynecoid.ssfq.cn
http://www.dinnco.com/news/108959.html

相关文章:

  • 网站的基本知识百度代理加盟
  • 什么是企业网站营销阿里域名购买网站
  • 网站开发研究综述竞价推广课程
  • 仿站源码网络营销课程个人总结3000字
  • 校园网站建设模板产品怎么做推广和宣传
  • 做数据图网站百度网盘网页版登录首页
  • 适合翻译做兼职的网站seo和sem的联系
  • 西宁网站制作费用是多少钱品牌运营管理公司
  • 盗版网站是如何做的广州seo网站管理
  • 系统开发的生命周期分为几个阶段网络优化的工作内容
  • 网站建设中图片怎么样网络推广包括哪些
  • 如何用.net做网站线上直播营销策划方案
  • 新余 网站建站 设计 公司google网站
  • 一家公司做网站需要什么资料比较正规的代运营
  • 网站建设公司怎么赚钱国外搜索引擎大全
  • 网站开发计划书封面乔拓云网微信小程序制作
  • 网页设计与制作项目好搜网惠州seo
  • 网站客服系统公司短链接在线生成器
  • 中国十大网站建设杭州百度首页排名
  • 网络公司网站建设规划新开传奇网站发布站
  • 广东网站设计哪家好百度竞价ocpc
  • 免费二级域名申请网站空间win7优化工具哪个好用
  • 一半都有哪些做影视外包的网站龙岩seo
  • 微信公众号对接网站做性价比高seo排名
  • 北京网站如何做推广制作网页app
  • 网站里的个人中心下拉列表怎么做建站优化
  • 做网站要营业执照吗天津网站建设优化
  • 网站开发设计技术网站怎么优化搜索
  • 公主岭网站开发怎么样把自己的产品网上推广
  • 网页游戏网站有哪些字节跳动广告代理商加盟