Last active
June 26, 2018 08:17
-
-
Save annchar/c0204565fd2d9a527d3b82a4f3057aee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TeamDetailViewModel(private val cheerBallDataRepository: CheerBallDataRepository, | |
private val teamId: Int) : ViewModel() { | |
private val players = MutableLiveData<List<Player>>() | |
private val compositeDisposable: CompositeDisposable = CompositeDisposable() | |
val adapter = MutableLiveData<PlayerListAdapter>() | |
val layoutManager = MutableLiveData<RecyclerView.LayoutManager>() | |
fun getPlayers(): LiveData<List<Player>> { | |
return players | |
} | |
fun loadPlayerList() { | |
val playersDisposable = cheerBallDataRepository.getPlayer(teamId) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribeOn(Schedulers.io()) | |
.subscribeWith(PlayersObserver()) | |
compositeDisposable.add(playersDisposable) | |
} | |
fun disposable() { | |
compositeDisposable.dispose() | |
} | |
private inner class PlayersObserver : DefaultObserver<Players>() { | |
override fun onNext(t: Players) { | |
players.value = t.players | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment