package Ġcom . cons istence . pin yin . app . study Ċ Ċ import Ġandroid . app . Application Ċ import Ġcom . cons istence . pin yin . domain . study . Get Study Ċ import Ġcom . cons istence . pin yin . domain . study . db . Count Study Ċ import Ġcom . me mt rip . mx android . Mx ViewModel Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . Single Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠStudy ViewModel Ġ@ Inject Ġinternal Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġget Study : ĠGet Study , ĊĠĠĠ Ġprivate Ġval Ġcount Study : ĠCount Study , ĊĠĠĠ Ġapplication : ĠApplication Ċ ) Ġ: ĠM x ViewModel < Study Intent , ĠStudy Render Action , ĠStudy ViewState >( ĊĠĠĠ ĠStudy ViewState ( Study ViewState . View . Idle ), ĊĠĠĠ Ġapplication Ċ ) Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġdispatcher ( intent : ĠStudy Intent ): ĠObservable < Study Render Action > Ġ= Ġwhen Ġ( intent ) Ġ{ ĊĠĠĠĠĠĠĠ ĠStudy Intent . Init , ĠStudy Intent . Retry , ĠStudy Intent . Refresh Ġ-> Ġget Study () ĊĠĠĠĠĠĠĠ ĠStudy Intent . Idle Ġ-> ĠObservable . just ( Study Render Action . Idle ) ĊĠĠĠĠĠĠĠ Ġis ĠStudy Intent . Train Phrase Ġ-> ĠObservable . just ( Study Render Action . Navigate Train Phrase ( intent . study )) ĊĠĠĠĠĠĠĠ Ġis ĠStudy Intent . Select Study Ġ-> ĠObservable . just ( Study Render Action . Navigate To Study ( intent . study )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġreducer ( previous State : ĠStudy ViewState , Ġrender Action : ĠStudy Render Action ): ĠStudy ViewState Ġ= Ġwhen Ġ( render Action ) Ġ{ ĊĠĠĠĠĠĠĠ ĠStudy Render Action . Idle Ġ-> Ġprevious State . copy ( view Ġ= ĠStudy ViewState . View . Idle ) ĊĠĠĠĠĠĠĠ Ġis ĠStudy Render Action . Populate Ġ-> Ġprevious State . copy ( view Ġ= ĠStudy ViewState . View . Populate ( render Action . study )) ĊĠĠĠĠĠĠĠ ĠStudy Render Action . No Results Ġ-> Ġprevious State . copy ( view Ġ= ĠStudy ViewState . View . No Results ) ĊĠĠĠĠĠĠĠ ĠStudy Render Action . Error Ġ-> Ġprevious State . copy ( view Ġ= ĠStudy ViewState . View . Error ) ĊĠĠĠĠĠĠĠ Ġis ĠStudy Render Action . Navigate To Study Ġ-> Ġprevious State . copy ( view Ġ= ĠStudy ViewState . View . Navigate To Study ( render Action . study )) ĊĠĠĠĠĠĠĠ Ġis ĠStudy Render Action . Navigate Train Phrase Ġ-> Ġprevious State . copy ( view Ġ= ĠStudy ViewState . View . Navigate To Train Phrase ( render Action . study )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġfilter Intent s ( int ents : ĠObservable < Study Intent >): ĠObservable < Study Intent > Ġ= ĠObservable . merge ( ĊĠĠĠĠĠĠĠ Ġintent s . of Type ( Study Intent . Init . java Class ). take ( 1 ), ĊĠĠĠĠĠĠĠ Ġintent s . filter Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ! Study Intent . Init . java Class . is Instance ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġprivate Ġfun Ġget Study (): ĠObservable < Study Render Action > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġcount Study . count (). flatMap Ġ{ Ġcount Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( count Ġ> Ġ 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġget Study . get (). flatMap Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSingle . just ( Study Render Action . Populate ( it )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSingle . just ( Study Render Action . No Results ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}. onError Return Item ( Study Render Action . Error ). to Observable () ĊĠĠĠ Ġ} Ċ }