package Ġcom . max im erous sy . f iz zh ub . presentation . issue list Ċ Ċ import Ġandroid . arch . lifecycle . Observer Ċ import Ġandroid . arch . lifecycle . ViewModel Providers Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 4 . view . MenuItem Compat Ċ import Ġandroid . support . v 4 . widget . Swipe Refresh Layout Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . support . v 7 . widget . RecyclerView Ċ import Ġandroid . support . v 7 . widget . Search View Ċ import Ġandroid . view . View Ċ import Ġandroid . view . input method . Input Method Manager Ċ import Ġcom . max im erous sy . f iz zh ub . Main Application Ċ import Ġcom . max im erous sy . f iz zh ub . R Ċ import Ġcom . max im erous sy . f iz zh ub . databinding . Fragment Issue List Binding Ċ import Ġcom . max im erous sy . f iz zh ub . domain . models . Github Issue Ċ import Ġcom . max im erous sy . f iz zh ub . presentation . Base Fragment Ċ import Ġcom . max im erous sy . f iz zh ub . presentation . issue detail . Issue Detail Activity Ċ import Ġcom . max im erous sy . f iz zh ub . util . ViewModel Factory Ċ import Ġjp . was ab eef . recyclerview . adapters . Alpha In Animation Adapter Ċ import Ġjp . was ab eef . recyclerview . anim ators . Scale In Animator Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠIssue List Fragment Ġ: ĠBase Fragment < Fragment Issue List Binding >( R . layout . fragment _ issue _ list ), ĠSearch View . On Query Text Listener Ġ{ ĊĠ Ġ@ Inject Ġinternal Ġlateinit Ġvar ĠviewModel Factory : ĠViewModel Factory < Issue List ViewModel > ĊĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠIssue List ViewModel ĊĠ Ġprivate Ġlateinit Ġvar Ġadapter : ĠIssue Adapter ĊĠ Ġprivate Ġlateinit Ġvar Ġswipe Refresh Layout : ĠSw ipe Refresh Layout ĊĊĠ Ġprivate Ġvar ĠisLoading Ġ= Ġfalse ĊĠ Ġprivate Ġvar Ġcurrent Query Ġ= Ġ"" ĊĊĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠ ĠviewModel Ġ= ĠViewModel Providers . of ( this , ĠviewModel Factory ). get ( Issue List ViewModel :: class . java ) ĊĠĠĠ Ġbinding . viewModel Ġ= ĠviewModel ĊĠĠĠ Ġsetup Toolbar () ĊĠĠĠ Ġsetup Observer s () ĊĠĠĠ Ġsetup RecyclerView () ĊĠĠĠ Ġsetup Swipe Refresh () ĊĠĠĠ ĠviewModel . load Issues () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Attach ( context : ĠContext ?) Ġ{ ĊĠĠĠ Ġ( context ?. application Context Ġas ĠMain Application ). component . inject ( this ) ĊĠĠĠ Ġsuper . on Attach ( context ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup Toolbar () Ġ{ ĊĠĠĠ Ġval Ġtoolbar Ġ= Ġbinding . toolbar ĊĠĠĠ Ġtoolbar . inflate Menu ( R . menu . menu _ issue _ list ) ĊĠĠĠ Ġval Ġmenu Ġ= Ġtoolbar . menu ĊĠĠĠ Ġval Ġsearch Item Ġ= Ġmenu . find Item ( R . id . action _ search ) ĊĠĠĠ Ġval Ġsearch View Ġ= ĠMenuItem Compat . getAction View ( search Item ) Ġas ĠSearch View ĊĠĠĠ Ġsearch View . setOn Query Text Listener ( this ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup Observer s () Ġ{ ĊĠĠĠ ĠviewModel . get Issue Results . observe ( this , ĠObserver Ġ{ Ġgithub Issues Ġ-> Ġgithub Issues ?. let Ġ{ ĊĠĠĠĠĠ Ġadapter . update Data ( it ) ĊĠĠĠĠĠ Ġstop Loading () ĊĠĠĠ Ġ} Ġ}) ĊĠĠĠ ĠviewModel . getNext Page Issue Results . observe ( this , ĠObserver Ġ{ Ġgithub Issues Ġ-> Ġgithub Issues ?. let Ġ{ ĊĠĠĠĠĠ Ġadapter . addData ( github Issues ) ĊĠĠĠĠĠ Ġstop Loading () ĊĠĠĠ Ġ} Ġ}) ĊĠĠĠ ĠviewModel . get Issue Load Error . observe ( this , ĠObserver Ġ{ ĊĠĠĠĠĠ Ġshow Error Dialog ( R . string . issue _ loading _ error ) ĊĠĠĠĠĠ Ġstop Loading () ĊĠĠĠ Ġ}) ĊĠĠĠ ĠviewModel . get Issue Search Error . observe ( this , ĠObserver Ġ{ ĊĠĠĠĠĠ Ġshow Error Dialog ( R . string . issue _ search _ error ) ĊĠĠĠĠĠ Ġstop Loading () ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġstop Loading () Ġ{ ĊĠĠĠ ĠisLoading Ġ= Ġfalse ĊĠĠĠ Ġswipe Refresh Layout . is Refresh ing Ġ= Ġfalse ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup RecyclerView () Ġ{ ĊĠĠĠ Ġval Ġre cyclerView Ġ= Ġbinding . re cyclerView ĊĠĠĠ Ġval Ġlayout Manager Ġ= ĠLinearLayoutManager ( activity ) ĊĠĠĠ Ġre cyclerView . layout Manager Ġ= Ġlayout Manager ĊĠĠĠ Ġre cyclerView . item Animator Ġ= ĠScale In Animator () ĊĠĠĠ Ġadapter Ġ= ĠIssue Adapter ( ArrayList ()) ĊĠĠĠ Ġadapter . setOnClickListener Ġ{ Ġgithub Issue Ġ-> Ġon Issue Clicked ( github Issue ) Ġ} ĊĠĠĠ Ġre cyclerView . adapter Ġ= ĠAlpha In Animation Adapter ( adapter ) ĊĠĠĠ Ġre cyclerView . add On Scroll Listener ( object : ĠRecyclerView . On Scroll Listener () Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġon Sc rolled ( re cyclerView : ĠRecyclerView , Ġdx : ĠInt , Ġdy : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( isLoading ) Ġreturn ĊĠĠĠĠĠĠĠ Ġval Ġvisible ItemCount Ġ= Ġlayout Manager . child Count ĊĠĠĠĠĠĠĠ Ġval Ġtotal ItemCount Ġ= Ġlayout Manager . item Count ĊĠĠĠĠĠĠĠ Ġval Ġpast Visible Items Ġ= Ġlayout Manager . findFirst Visible Item Position () ĊĠĠĠĠĠĠĠ Ġif Ġ( past Visible Items Ġ+ Ġvisible ItemCount Ġ>= Ġtotal ItemCount ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( current Query . isNotBlank ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . search More Issues ( current Query ) ĊĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . load More Issues () ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ ĠisLoading Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup Swipe Refresh () Ġ{ ĊĠĠĠ Ġswipe Refresh Layout Ġ= Ġbinding . swipe Refresh Layout ĊĠĠĠ Ġswipe Refresh Layout . setColor Scheme Resources ( R . color . color Primary , ĠR . color . color Primary Dark ) ĊĠĠĠ Ġswipe Refresh Layout . setOn Refresh Listener Ġ{ ĊĠĠĠĠĠ Ġif Ġ( current Query . isNotBlank ()) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . search Issues ( current Query ) ĊĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . load Issues () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Issue Clicked ( github Issue : ĠGithub Issue ) Ġ{ ĊĠĠĠ Ġactivity ?. let Ġ{ ĠstartActivity ( Issue Detail Activity . newInstance ( it , Ġgithub Issue )) Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Query Text Submit ( query : ĠString ): ĠBoolean Ġ{ ĊĠĠĠ Ġif Ġ( query . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠ Ġcurrent Query Ġ= Ġquery ĊĠĠĠĠĠ ĠviewModel . search Issues ( query ) ĊĠĠĠĠĠ Ġactivity ?. let Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinput Manager Ġ= Ġit . getSystem Service ( Context . INPUT _ METHOD _ SERVICE ) Ġas ĠInput Method Manager ĊĠĠĠĠĠĠĠ Ġinput Manager . hide Soft Input From Window ( it . current Focus !!. window Token , ĠInput Method Manager . HIDE _ NOT _ ALWAYS ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġtrue ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Query Text Change ( query : ĠString ): ĠBoolean Ġ{ ĊĠĠĠ Ġif Ġ( query . isEmpty ()) Ġ{ ĊĠĠĠĠĠ ĠviewModel . load Issues () ĊĠĠĠĠĠ Ġcurrent Query Ġ= Ġ"" ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġtrue ĊĠ Ġ} Ċ } Ċ