package Ġcom . f xc . p ics . pic . pic Home . fragments Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . design . widget . Snackbar Ċ import Ġandroid . support . v 4 . util . Pair Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . View Tree Observer Ċ import Ġandroid . widget . LinearLayout Ċ import Ġcom . f xc . p ics . common . base . Presenter Fragment Ċ import Ġcom . f xc . p ics . common . events . Event Util Ċ import Ġcom . f xc . p ics . pic . R Ċ import Ġcom . f xc . p ics . pic . events . Pic Events Ċ import Ġcom . f xc . p ics . pic . network . entities . Pic List Entity Ċ import Ġcom . f xc . p ics . pic . pic Detail . Pic Detail Activity Ċ import Ġcom . f xc . p ics . pic . pic Detail . Pic Detail Fragment Ċ import Ġcom . f xc . p ics . pic . pic Home . Pic Activity Ċ import Ġcom . f xc . p ics . pic . pic Home . adapter . Pic ListAdapter Ċ import Ġcom . f xc . p ics . views . images . F resco Utils Ċ import Ġcom . f xc . p ics . views . re cyclerView . item Decoration . Space Item Decoration Ċ import Ġkotlinx . android . synt hetic . main . pic _ fragment _ home . view .* Ċ import Ġkotlinx . android . synt hetic . main . pic _ fragment _ p ics _ list _ item . view .* Ċ import Ġkotlinx . android . synt hetic . main . pic _ home _ head . view .* Ċ import Ġorg . green robot . event bus . Subscribe Ċ import Ġorg . green robot . event bus . Thread Mode Ċ Ċ /** Ċ Ġ* Ċ Ġ* Ġ@ author Ġf xc Ċ Ġ* Ġ@ date Ġ 2 0 1 8 / 2 / 2 2 Ċ Ġ*/ Ċ class ĠPic Home Fragment Ġ: ĠPres enter Fragment < Pic Home Presenter Imp , ĠPic Activity >() Ġ{ ĊĊ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ fun Ġnew Instance (): ĠPic Home Fragment Ġ{ Ċĉĉ ĉ val Ġfragment Ġ= ĠPic Home Fragment () Ċĉĉ ĉ val Ġbundle Ġ= ĠBundle () Ċĉĉ ĉ fragment . arguments Ġ= Ġbundle Ċĉĉ ĉ return Ġfragment Ċĉ ĉ } ĊĊĉ ĉ const Ġval ĠKEY _ PIC _ TITLE Ġ= Ġ" key _ pic _ title " Ċĉ ĉ const Ġval ĠKEY _ PIC _ SUB TITLE Ġ= Ġ" key _ pic _ subtitle " Ċĉ ĉ const Ġval ĠKEY _ PIC _ ITEM _ IMAGE Ġ= Ġ" key _ pic _ item _ image " Ċ ĉ } ĊĊ ĉ private Ġval Ġdata Ġ= ĠArrayList < Pic List Entity >() Ċ ĉ private Ġvar Ġclick Position : ĠInt Ġ= Ġ 0 ĊĊ ĉ private Ġlateinit Ġvar Ġm Header View : ĠView ĊĊ ĉ override Ġfun Ġinit Presenter (): ĠPic Home Presenter Imp Ġ= ĠPic Home Presenter Imp ( this ) ĊĊ ĉ override Ġfun Ġget ContentView Id (): ĠInt Ġ= ĠR . layout . pic _ fragment _ home ĊĊ ĉ override Ġfun Ġerror ( fail Reason : ĠString ) Ġ{ ĊĊ ĉ } ĊĊ ĉ override Ġfun Ġinit Widget () Ġ{ Ċĉ ĉ super . init Widget () Ċĉ ĉ init RecyclerView () Ċĉ ĉ m Header View Ġ= ĠLayoutInflater . from ( context ). inflate ( R . layout . pic _ home _ head , Ġroot View . pic _ home _ recycler _ view , Ġfalse ) Ċĉ ĉ root View . pic _ home _ recycler _ view . add Header View ( m Header View ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġafter Init Widget () Ġ{ Ċĉ ĉ super . after Init Widget () Ċĉ ĉ bind Share Element ( Pair . create ( m Header View . user _ title , ĠKEY _ PIC _ TITLE ), Ċĉĉĉ ĉ Pair . create ( m Header View . pic _ subtitle , ĠKEY _ PIC _ SUB TITLE )) Ċĉ ĉ init Listener () ĊĊ ĉ } ĊĊ ĉ private Ġfun Ġinit Listener () Ġ{ Ċĉ ĉ root View . pic _ home _ recycler _ view . view Tree Observer . add On Pre Draw Listener ( object Ġ: ĠView Tree Observer . On Pre Draw Listener Ġ{ Ċĉĉ ĉ override Ġfun Ġon Pre Draw (): ĠBoolean Ġ{ Ċĉĉĉ ĉ root View . pic _ home _ recycler _ view . view Tree Observer . remove On Pre Draw Listener ( this ) Ċĉĉĉ ĉ return Ġtrue Ċĉĉ ĉ } Ċĉ ĉ }) ĊĊĉ ĉ root View . pic _ home _ recycler _ view . setOn ItemClickListener Ġ{ Ġview , Ġposition Ġ-> Ċĉĉ ĉ run Ġ{ Ċĉĉĉ ĉ F resco Utils . isIn Cache ( data [ position ]. urls . small ) Ċĉĉĉĉĉ ĉ . subscribe Ġ{ Ċĉĉĉĉĉĉ ĉ if Ġ( it ) Ġ{ Ċĉĉĉĉĉĉĉ ĉ click Position Ġ= Ġposition Ċĉĉĉĉĉĉĉ ĉ start Detail Activity ( view , Ġposition ) Ċĉĉĉĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉĉĉĉ ĉ notify Pic Not Ready () Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġnotify Pic Not Ready () Ġ{ Ċĉ ĉ Snackbar . make ( root View , ĠgetString ( R . string . pic _ not _ ready _ alter ), ĠSn ackbar . LENGTH _ SHORT ). show () Ċ ĉ } ĊĊ ĉ private Ġfun Ġstart Detail Activity ( view : ĠView , Ġposition : ĠInt ) Ġ{ Ċĉ ĉ val Ġparams Ġ= ĠHashMap < String , ĠString >() Ċĉ ĉ params [ Pic Detail Activity . KEY _ PIC _ ID ] Ġ= Ġdata [ position ]. id Ċĉ ĉ params [ Pic Detail Activity . KEY _ PIC _ URL ] Ġ= Ġdata [ position ]. urls . small Ċĉ ĉ startActivity By Shared Element ( params , ĠPic Detail Activity :: class . java , ĠPair ( view . item _ image , ĠPic Detail Fragment . KEY _ IMAGE )) Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit RecyclerView () Ġ{ Ċĉ ĉ root View . pic _ home _ recycler _ view . layout Manager Ġ= ĠLinearLayoutManager ( context , ĠLinearLayout . VERTICAL , Ġfalse ) Ċĉ ĉ root View . pic _ home _ recycler _ view . adapter Ġ= ĠPic ListAdapter ( data ) Ċĉ ĉ root View . pic _ home _ recycler _ view . addItem Decoration ( Space Item Decoration ( 4 5 , Ġ 7 0 )) Ċ ĉ } ĊĊ ĉ fun Ġdata Ar rive ( data : ĠList < Pic List Entity >) Ġ{ Ċĉ ĉ this @ Pic Home Fragment . data . addAll ( data ) Ċĉ ĉ root View . pic _ home _ recycler _ view . adapter . notify DataSet Changed () ĊĊĉ ĉ ready To Comp ete () Ċ ĉ } ĊĊ ĉ private Ġfun Ġready To Comp ete () Ġ{ Ċĉ ĉ // TODO Ġ ç©º æĮĩéĴĪ Ċĉ ĉ activity . start Post p oned Enter Transition () Ċ ĉ } ĊĊ ĉ @ Subscribe ( thread Mode Ġ= ĠThread Mode . MAIN ) Ċ ĉ fun Ġon Detail Ready ( event : ĠPic Events . Pic Detail Ready Event ) Ġ{ Ċĉ ĉ Event Util . post ( Pic Events . Pic Enter Detail Event ( data , Ġclick Position )) Ċ ĉ } Ċ Ċ }