package Ġru . st yx heim . ws ang _ admin čĊč Ċ import Ġandroid . content . SharedPreferences č Ċ import Ġandroid . os . Bundle č Ċ import Ġandroid . view . LayoutInflater č Ċ import Ġandroid . view . View č Ċ import Ġandroid . view . ViewGroup č Ċ import Ġandroidx . fragment . app . Fragment č Ċ import Ġandroidx . navigation . fragment . find Nav Controller č Ċ import Ġandroidx . preference . Preference Manager č Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager č Ċ import Ġcom . squareup . mos hi . Json Adapter č Ċ import Ġcom . squareup . mos hi . M oshi č Ċ import Ġru . st yx heim . ws ang _ admin . databinding . Fragment Comp etition List Binding čĊč Ċ /** čĊ Ġ* ĠA Ġsimple Ġ[ Fragment ] Ġsubclass Ġas Ġthe Ġdefault Ġdestination Ġin Ġthe Ġnavigation . čĊ Ġ*/ č Ċ class ĠComp etition List Fragment Ġ: ĠFragment (), ĠSharedPreferences . On Shared Preference ChangeListener Ġ{ čĊĠ Ġprivate Ġvar Ġbinding : ĠFragment Comp etition List Binding ? Ġ= Ġnull čĊĠ Ġprivate Ġvar Ġcompetition Loaded : ĠBoolean Ġ= Ġfalse čĊĠ Ġprivate Ġvar Ġcompetition List : ĠMutable List < Admin API . Race Status > Ġ= Ġmutable ListOf () čĊĠ Ġprivate Ġvar Ġtransport : ĠTransport ? Ġ= Ġnull čĊĠ Ġprivate Ġvar Ġshared Preferences : ĠSharedPreferences ? Ġ= Ġnull čĊĠ Ġprivate Ġval Ġm oshi : ĠM oshi Ġ= ĠM oshi . Builder (). build () čĊĠ Ġprivate Ġval Ġcompetition Json Adapter : čĊĠĠĠĠĠ ĠJson Adapter < Admin API . Race Status > Ġ= Ġm oshi . adapter ( Admin API . Race Status :: class . java ) čĊĠ Ġprivate Ġvar Ġcompetition ListAdapter : ĠComp etition ListAdapter ? Ġ= Ġnull čĊčĊĠ Ġoverride Ġfun Ġon Shared Preference Changed ( shared Preferences : ĠSharedPreferences ?, Ġkey : ĠString ?) Ġ{ čĊĠĠĠ Ġwhen Ġ( key ) Ġ{ čĊĠĠĠĠĠ Ġ" server _ address " Ġ-> Ġload Comp etition List () čĊĠĠĠ Ġ} čĊĠ Ġ} čĊčĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ čĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) čĊčĊĠĠĠ Ġshared Preferences Ġ= ĠPreference Manager . getDefault SharedPreferences ( context ) čĊĠĠĠ Ġshared Preferences ?. register On Shared Preference ChangeListener ( this ) čĊčĊĠĠĠ Ġtransport Ġ= ĠTransport ( shared Preferences !! ) čĊĠ Ġ} čĊčĊĠ Ġoverride Ġfun ĠonCreate View ( čĊĠĠĠ Ġinflater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, čĊĠĠĠ ĠsavedInstanceState : ĠBundle ? čĊĠ Ġ): ĠView ? Ġ{ čĊĠĠĠ Ġbinding Ġ= ĠFragment Comp etition List Binding . inflate ( in flater , Ġcontainer , Ġfalse ) čĊĠĠĠ Ġreturn Ġbinding ?. root čĊĠ Ġ} čĊčĊĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ čĊĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) čĊčĊĠĠĠ Ġbinding !!. comp etition Add View . visibility Ġ= čĊĠĠĠĠĠ Ġif Ġ( comp etition Loaded ) ĠView . VISIBLE Ġelse ĠView . IN VISIBLE čĊĠĠĠ Ġbinding !!. comp etition Add View . setOnClickListener Ġ{ čĊĠĠĠĠĠ Ġval Ġcompetition Id Ġ= čĊĠĠĠĠĠĠĠ Ġ(( comp etition List . max By OrNull Ġ{ Ġit . Comp etition Id Ġ}) ?. Comp etition Id Ġ?: Ġ 0 L ) Ġ+ Ġ 1 čĊĠĠĠĠĠ Ġval Ġcompetition Ġ= čĊĠĠĠĠĠĠĠ ĠAdmin API . Race Status ( čĊĠĠĠĠĠĠĠĠĠ ĠComp etition Id Ġ= Ġcompetition Id , čĊĠĠĠĠĠĠĠĠĠ ĠComp etition Name Ġ= ĠgetString ( R . string . comp etition _ name _ default , Ġcompetition Id ), čĊĠĠĠĠĠĠĠĠĠ ĠTime Stamp Ġ= ĠSystem . currentTimeMillis () Ġ/ Ġ 1 0 0 0 , čĊĠĠĠĠĠĠĠĠĠ ĠSync Point Ġ= Ġ 0 čĊĠĠĠĠĠĠĠ Ġ) čĊĠĠĠĠĠ Ġnav To Comp etition ( comp etition , Ġtrue ) čĊĠĠĠ Ġ} čĊĠĠĠ Ġbinding !!. refresh List . setOnClickListener Ġ{ Ġthis . load Comp etition List () Ġ} čĊčĊčĊĠĠĠ Ġclass ĠOnClick Ġ: ĠComp etition ListAdapter . On Item Select Listener Interface Ġ{ čĊĠĠĠĠĠ Ġoverride Ġfun Ġon Item Select ( comp etition : ĠAdmin API . Race Status ) Ġ{ čĊĠĠĠĠĠĠĠ Ġnav To Comp etition ( comp etition , Ġfalse ) čĊĠĠĠĠĠ Ġ} čĊĠĠĠ Ġ} čĊčĊĠĠĠ Ġcompetition ListAdapter Ġ= ĠComp etition ListAdapter ( comp etition List , Ġrequire Context ()) čĊčĊĠĠĠ Ġcompetition ListAdapter ?. on Item Select Listener Ġ= ĠOnClick () čĊĠĠĠ Ġbinding !!. comp etition ListView . apply Ġ{ čĊĠĠĠĠĠ Ġlayout Manager Ġ= ĠLinearLayoutManager ( activity ) čĊĠĠĠĠĠ Ġadapter Ġ= Ġcompetition ListAdapter čĊĠĠĠ Ġ} čĊčĊčĊĠĠĠ Ġload Comp etition List () čĊĠ Ġ} čĊčĊĠ Ġoverride Ġfun Ġon Destroy View () Ġ{ čĊĠĠĠ Ġshared Preferences ?. unregister On Shared Preference ChangeListener ( this ) čĊĠĠĠ Ġsuper . on Destroy View () čĊĠĠĠ Ġbinding Ġ= Ġnull čĊĠ Ġ} čĊčĊĠ Ġprivate Ġfun Ġnavigate To Fail ( message : ĠString ) Ġ{ čĊĠĠĠ Ġval Ġargs Ġ= ĠBundle () čĊčĊĠĠĠ Ġargs . putString (" Message ", Ġmessage ) čĊĠĠĠ Ġargs . put Int (" From ", ĠR . id . Comp etition List Fragment ) čĊĠĠĠ Ġfind Nav Controller (). navigate ( R . id . action _ Comp etition List Fragment _ to _ Fail Fragment , Ġargs ) čĊĠ Ġ} čĊčĊĠ Ġprivate Ġfun Ġresponse Generic Error ( message : ĠString ?) Ġ{ čĊĠĠĠ Ġnavigate To Fail (" Connection Ġerror : Ġ$ message ") čĊĠ Ġ} čĊčĊĠ Ġprivate Ġfun Ġnav To Comp etition ( comp etition : ĠAdmin API . Race Status , Ġis _ new : ĠBoolean ) Ġ{ čĊĠĠĠ Ġval Ġargs Ġ= ĠBundle () čĊčĊĠĠĠ Ġargs . putString (" comp etition _ json ", Ġcompetition Json Adapter . toJson ( comp etition )) čĊĠĠĠ Ġargs . put Boolean (" is _ new _ comp etition ", Ġis _ new ) čĊĠĠĠ Ġfind Nav Controller (). navigate ( čĊĠĠĠĠĠ ĠR . id . action _ Comp t ition List Fragment _ to _ Comp etition Fragment , čĊĠĠĠĠĠ Ġargs čĊĠĠĠ Ġ) čĊĠ Ġ} čĊčĊĠ Ġprivate Ġfun Ġresponse Admin List ( response : ĠAdmin API . Response . Comp etition List ) Ġ{ čĊĠĠĠ Ġbinding !!. comp etition Add View . visibility Ġ= ĠView . VISIBLE čĊĠĠĠ Ġcompetition Loaded Ġ= Ġtrue čĊĠĠĠ Ġcompetition List . clear () čĊĠĠĠ Ġcompetition List . addAll ( response . Comp et itions ) čĊĠĠĠ Ġcompetition ListAdapter ?. notify DataSet Changed () čĊĠ Ġ} čĊčĊĠ Ġprivate Ġfun Ġload Comp etition List () Ġ{ čĊĠĠĠ Ġtransport ?. get Comp etition List ( čĊĠĠĠĠĠ Ġ{ Ġ-> Ġactivity ?. run On Ui Thread Ġ{ Ġactivity ?. title Ġ= ĠgetString ( R . string . updating ) Ġ} Ġ}, čĊĠĠĠĠĠ Ġ{ Ġ-> čĊĠĠĠĠĠĠĠ Ġactivity ?. run On Ui Thread Ġ{ čĊĠĠĠĠĠĠĠĠĠ Ġactivity ?. title Ġ= ĠgetString ( R . string . comp etition _ list _ fragment _ label ) čĊĠĠĠĠĠĠĠ Ġ} čĊĠĠĠĠĠ Ġ}, čĊĠĠĠĠĠ Ġ{ Ġmessage Ġ-> Ġactivity ?. run On Ui Thread Ġ{ Ġresponse Generic Error ( message ) Ġ} Ġ}, čĊĠĠĠĠĠ Ġ{ Ġcompetition List Ġ-> Ġactivity ?. run On Ui Thread Ġ{ Ġresponse Admin List ( comp etition List ) Ġ} Ġ}) čĊĠ Ġ} č Ċ }