package Ġru . i andre ys he v . android architecture components app . application Ċ Ċ import Ġandroid . app . Application Ċ import Ġru . i andre ys he v . android architecture components app . presenter . Player Presenter Ċ import Ġru . i andre ys he v . android architecture components app . presenter . Playlist Presenter Ċ import Ġru . i andre ys he v . android architecture components app . viewModel . Playlist ViewModel Ċ import Ġru . i andre ys he v . model . player . IP layer Presenter Ċ import Ġru . i andre ys he v . model . player . Player Ċ import Ġru . i andre ys he v . model . playlist . IP lay list Presenter Ċ import Ġru . i andre ys he v . model . playlist . Playlist Ċ import Ġru . i andre ys he v . model . repository . Repository Ċ Ċ class ĠMusic Application Ġ: ĠApplication () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġm Repository Ġ= ĠRepository () ĊĠĠĠ Ġprivate Ġval Ġm Playlist Ġ= ĠPlaylist ( m Repository . getAll S ongs (), Ġ:: on Select Song ) ĊĠĠĠ Ġprivate Ġval Ġm Player Ġ= ĠPlayer ( this ) ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġm Player Presenter : ĠPlayer Presenter ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate () ĊĊĠĠĠĠĠĠĠ Ġinstance Ġ= Ġthis ĊĠĠĠĠĠĠĠ Ġm Player Presenter Ġ= ĠPlayer Presenter ( instance . m Player ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠonSelect Song ( song Id : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsong To Play Ġ= Ġm Repository . getS ong ById ( song Id ) Ġ?: Ġreturn ĊĠĠĠĠĠĠĠ Ġval ĠimageUrl Ġ= Ġm Repository . get Picture Url ( song Id ) Ġ?: Ġ"" ĊĠĠĠĠĠĠĠ Ġm Player Presenter . imageUrl Ġ= ĠimageUrl ĊĠĠĠĠĠĠĠ Ġm Player . set Song ( song To Play ) ĊĠĠĠĠĠĠĠ Ġm Player . on Play () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġlateinit Ġvar Ġinstance : ĠMusic Application ĊĊĠĠĠĠĠĠĠ Ġfun Ġsubscribe To Playlist Change ( viewModel : ĠIP lay list Presenter ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinstance . m Playlist . subscribe ( viewModel ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfun Ġget Player Presenter ( viewModel : ĠI Player Presenter ): ĠPlayer Presenter Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinstance . m Player . subscribe ( viewModel ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġurl Ġ= Ġinstance . m Player Presenter . imageUrl ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( url Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . update Image ( url ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġinstance . m Player Presenter ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ Ċ }