【发布时间】:2019-02-07 06:32:40
【问题描述】:
我正在尝试使用来自 thesportsdb 的 API 来显示特定联赛的最后一场比赛。在我的 recyclerview 中,我想显示每个团队的团队徽章,但是当我请求 lastmatch API 时,它不包括团队徽章,只有每个团队的 id,如果我想显示徽章,它需要我请求团队包含团队徽章网址的个人资料。
由于我是 rxJava 的新手,所以我仍然熟悉它。有些帖子建议使用平面地图,但对于像我这样的初学者来说实施起来有点困难。
这是改造服务:
interface FootballRest {
@GET("eventspastleague.php")
fun getLastmatch(@Query("id") id:String) : Flowable<FootballMatch>
@GET("lookupteam.php")
fun getTeam(@Query("id") id:String) : Flowable<Teams>
}
我使用了存储库模式
class MatchRepositoryImpl(private val footballRest: FootballRest) : MatchRepository {
override fun getFootballMatch(id: String): Flowable<FootballMatch> = footballRest.getLastmatch(id)
override fun getTeams(id: String): Flowable<Teams> =
footballRest.getTeam(id)
}
这是进行调用并将数据发送到视图的演示者:
class MainPresenter(val mView : MainContract.View, val matchRepositoryImpl: MatchRepositoryImpl) : MainContract.Presenter{
val compositeDisposable = CompositeDisposable()
val requestMatch = matchRepositoryImpl.getFootballMatch("4328")
val requestTeam = matchRepositoryImpl.getTeams()
override fun getFootballMatchData() {
compositeDisposable.add(matchRepositoryImpl.getFootballMatch("4328")
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe{
mView.displayFootballMatch(it.events)
})
}
到目前为止,我只显示最后一场比赛结果,但我还想在名单上显示徽章球队。
【问题讨论】:
标签: android kotlin retrofit2 rx-java2