package Ġme . h uf man . android aut oid rive . phone ui . fragments Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Attribute Set Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroid . widget . ScrollView Ċ import Ġandroidx . core . view . post Delayed Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġandroidx . view pager 2 . widget . ViewPager 2 Ċ import Ġcom . google . android . material . tabs . Tab Layout Ċ import Ġcom . google . android . material . tabs . Tab Layout Mediator Ċ import Ġme . h uf man . android aut oid rive . R Ċ import Ġme . h uf man . android aut oid rive . phone ui . View Helpers . find Parent Ċ import Ġme . h uf man . android aut oid rive . phone ui . View Helpers . scrollTop Ċ import Ġme . h uf man . android aut oid rive . phone ui . View Helpers . visible Ċ import Ġme . h uf man . android aut oid rive . phone ui . adapters . Data Bound ListAdapter Ċ import Ġme . h uf man . android aut oid rive . phone ui . view models . Capabilities Tips Model Ċ import Ġme . h uf man . android aut oid rive . phone ui . view models . Connection Tips Model Ċ import Ġme . h uf man . android aut oid rive . phone ui . view models . Tips Model Ċ import Ġme . h uf man . android aut oid rive . phone ui . view models . view Models Ċ Ċ class ĠT ips List Fragment : ĠFragment () Ġ{ Ċ ĉ var Ġmode Ġ= Ġ" UNKNOWN " Ċ ĉ val ĠviewModel Ġby Ġview Models < Tips Model > Ċ ĉ { Ċĉ ĉ if Ġ( mode Ġ== Ġ" connection ") Ġ{ Ċĉĉ ĉ Connection Tips Model . Factory ( require Context (). application Context ) Ċĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ Capabilities Tips Model . Factory () Ċĉ ĉ } Ċ ĉ } Ċ ĉ val Ġadapter Ġby Ġlazy Ġ{ ĠData Bound ListAdapter ( viewModel . current Tips , ĠR . layout . fragment _ tip , Ġnull ) Ġ} ĊĊ ĉ override Ġfun Ġon Inf late ( context : ĠContext , Ġattrs : ĠAttributeSet , ĠsavedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . on Inf late ( context , Ġattrs , ĠsavedInstanceState ) Ċĉ ĉ val Ġta Ġ= Ġcontext . obtain Styled Attributes ( attrs , ĠR . style able . Tips List Fragment _ Members Injector ) Ċĉ ĉ if Ġ( ta . hasValue ( R . style able . Tips List Fragment _ Members Injector _ tips Mode )) Ġ{ Ċĉĉ ĉ mode Ġ= Ġta . getString ( R . style able . Tips List Fragment _ Members Injector _ tips Mode ) Ġ?: Ġ"" Ċĉ ĉ } Ċĉ ĉ ta . recycle () Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView Ġ{ Ċĉ ĉ val Ġview Ġ= Ġinflater . inflate ( R . layout . fragment _ tips list , Ġcontainer , Ġfalse ) Ċĉ ĉ val Ġpane Ġ= Ġview . findViewById < ViewPager 2 >( R . id . p gr Tips List ) Ċĉ ĉ pane . adapter Ġ= Ġadapter ĊĊĉ ĉ // Ġshow Ġthe Ġoff screen Ġpages Ċĉ ĉ pane . off screen Page Limit Ġ= Ġ 2 Ċĉ ĉ ( pane . getChild At ( 0 ) Ġas ? ĠRecyclerView )?. apply Ġ{ Ċĉĉ ĉ clip To Padding Ġ= Ġfalse Ċĉ ĉ } ĊĊĉ ĉ // Ġset Ġup Ġthe Ġtab Ġbar Ċĉ ĉ val Ġtab Layout Ġ= Ġview . findViewById < Tab Layout >( R . id . p gr Tips List Tabs ) Ċĉ ĉ Tab Layout Mediator ( tab Layout , Ġpane ) Ġ{ Ġ_, Ġ_ Ġ-> Ġ}. attach () ĊĊĉ ĉ // Ġautomatic Ġpager Ġheight Ġmeasurement Ġhttps :// stackoverflow . com / a / 6 7 1 0 4 2 7 0 / 1 6 9 0 3 5 Ċĉ ĉ val Ġpage Callback Ġ= Ġobject : ĠView Pager 2 . On Page Change Callback () Ġ{ Ċĉĉ ĉ override Ġfun Ġon Page Selected ( position : ĠInt ) Ġ{ Ċĉĉĉ ĉ super . on Page Selected ( position ) ĊĊĉĉĉ ĉ val Ġre cyclerView Ġ= Ġ( pane . getChild At ( 0 ) Ġas ? ĠRecyclerView ) Ċĉĉĉ ĉ re cyclerView ?. getChild At ( position )?. let Ġ{ Ċĉĉĉĉ ĉ update Pager Height For Child ( it , Ġpane ) Ċĉĉĉ ĉ } Ċĉĉ ĉ } ĊĊĉĉ ĉ fun Ġupdate Pager Height For Child ( view : ĠView , Ġpager : ĠView Pager 2 ) Ġ{ Ċĉĉĉ ĉ view . post Ġ{ Ċĉĉĉĉ ĉ val Ġwidth Measure Spec Ġ= ĠView . Measure Spec . make Measure Spec ( Ċĉĉĉĉĉĉ ĉ view . width , ĠView . Measure Spec . EX ACT LY Ċĉĉĉĉ ĉ ) Ċĉĉĉĉ ĉ val Ġheight Measure Spec Ġ= ĠView . Measure Spec . make Measure Spec ( Ċĉĉĉĉĉĉĉ 0 , ĠView . Measure Spec . UNSPECIFIED Ċĉĉĉĉ ĉ ) Ċĉĉĉĉ ĉ view . measure ( width Measure Spec , Ġheight Measure Spec ) Ċĉĉĉĉ ĉ if Ġ( pager . layout Params . height Ġ< Ġview . meas ured Height ) Ġ{ Ċĉĉĉĉĉ ĉ pager . layout Params Ġ= Ġ( pager . layout Params ). also Ġ{ Ċĉĉĉĉĉĉ ĉ it . height Ġ= Ġview . meas ured Height Ċĉĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ pane . register On Page Change Callback ( page Callback ) Ċĉ ĉ page Callback . on Page Selected ( 0 ) ĊĊĉ ĉ // Ġsupport Ġto g gling Ċĉ ĉ view . findViewById < View >( R . id . pane _ tip list _ expand ). setOnClickListener Ġ{ Ċĉĉ ĉ val Ġvisible Ġ= Ġ! pane . visible Ċĉĉ ĉ pane . visible Ġ= Ġvisible Ċĉĉ ĉ tab Layout . visible Ġ= Ġvisible Ċĉĉ ĉ update () Ċĉĉ ĉ pane . post Delayed ( 2 0 0 ) Ġ{ Ċĉĉĉ ĉ if Ġ( visible ) Ġ{ Ċĉĉĉĉ ĉ val Ġposition Ġ= Ġpane . scrollTop Ċĉĉĉĉ ĉ ( pane . find Parent Ġ{ Ġit Ġis ĠScroll View Ġ} Ġas ĠScroll View ). smooth Scroll To ( 0 , Ġposition ) Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ return Ġview Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Resume () Ġ{ Ċĉ ĉ super . on Resume () ĊĊĉ ĉ update () Ċ ĉ } ĊĊ ĉ fun Ġupdate () Ġ{ Ċĉ ĉ viewModel . mode Ġ= Ġmode Ċĉ ĉ viewModel . update () Ċĉ ĉ view ?. visible Ġ= ĠviewModel . current Tips . isNotEmpty () Ċĉ ĉ adapter . notify DataSet Changed () Ċĉ ĉ view ?. invalidate () Ċ ĉ } Ċ }