package Ġcom . re vol gen x . an ilib . common . ui . adapter Ċ Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . fragment . app . Fragment Pager Adapter Ċ import Ġandroidx . lifecycle . Lifecycle Ċ import Ġandroidx . lifecycle . Lifecycle Observer Ċ import Ġandroidx . lifecycle . On Lifecycle Event Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġandroidx . view pager 2 . adapter . Fragment State Adapter Ċ 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 Ġcom . re vol gen x . an ilib . common . ui . fragment . Base Fragment Ċ Ċ fun ĠAppCompatActivity . make Pager Adapter ( fragments : ĠList < Base Fragment >) Ġ= ĊĠĠĠ Ġobject Ġ: ĠFragment Pager Adapter ( ĊĠĠĠĠĠĠĠ Ġthis @ make Pager Adapter . support FragmentManager , ĊĠĠĠĠĠĠĠ ĠBE HAV IOR _ RE SU ME _ ONLY _ CURRENT _ FRAGMENT ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠgetItem ( position : ĠInt ) Ġ= Ġfragments [ position ] ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Count (): ĠInt Ġ= Ġfragments . size ĊĠĠĠ Ġ} ĊĊ Ċ fun ĠFragment . make Pager Adapter ( fragments : ĠList < Base Fragment >, Ġtitles : ĠArray < String >? Ġ= Ġnull ) Ġ= ĊĠĠĠ Ġobject Ġ: ĠFragment Pager Adapter ( ĊĠĠĠĠĠĠĠ Ġthis @ make Pager Adapter . child FragmentManager , ĊĠĠĠĠĠĠĠ ĠBE HAV IOR _ RE SU ME _ ONLY _ CURRENT _ FRAGMENT ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠgetItem ( position : ĠInt ) Ġ= Ġfragments [ position ] ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Count (): ĠInt Ġ= Ġfragments . size ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Page Title ( position : ĠInt ): ĠCharSequence ? Ġ= Ġtitles ?. get ( position ) ĊĠĠĠ Ġ} Ċ Ċ fun ĠFragment . make ViewPager Adapter 2 ( fragments : ĠList < Base Fragment >) Ġ= ĊĠĠĠ Ġobject Ġ: ĠFragment State Adapter ( this ) Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠgetItem Count (): ĠInt Ġ= Ġfragments . count () ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcreate Fragment ( position : ĠInt ): ĠFragment Ġ= Ġfragments [ position ] ĊĠĠĠ Ġ} Ċ Ċ fun ĠAppCompatActivity . make ViewPager Adapter 2 ( fragments : ĠList < Base Fragment >) Ġ= ĊĠĠĠ Ġobject Ġ: ĠFragment State Adapter ( this ) Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠgetItem Count (): ĠInt Ġ= Ġfragments . count () ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcreate Fragment ( position : ĠInt ): ĠFragment Ġ= Ġfragments [ position ] ĊĠĠĠ Ġ} Ċ Ċ fun ĠFragment . setup With ViewPager 2 ( ĊĠĠĠ Ġtab Layout : ĠTab Layout , ĊĠĠĠ Ġview pager 2 : ĠView Pager 2 , ĊĠĠĠ Ġtitles : ĠArray < String > Ċ ) Ġ= ĠTab Layout Mediator ( tab Layout , Ġview pager 2 ) Ġ{ Ġtab , Ġposition Ġ-> ĊĠĠĠ Ġtab . text Ġ= Ġtitles [ position ] Ċ }. also Ġ{ Ġmedi ator Ġ-> ĊĠĠĠ Ġmedi ator . attach () ĊĠĠĠ Ġval Ġlifecycle Observer Ġ= Ġobject Ġ: ĠLifecycle Observer Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ On Lifecycle Event ( Lifecycle . Event . ON _ DESTROY ) ĊĠĠĠĠĠĠĠ Ġfun Ġon Destroy () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmedi ator . detach () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġview pager 2 . reduce Drag Sensitivity () ĊĠĠĠ Ġview Lifecycle Owner . lifecycle . add Observer ( lifecycle Observer ) Ċ } Ċ Ċ fun ĠView Pager 2 . reduce Drag Sensitivity () Ġ{ ĊĠĠĠ Ġval Ġre cyclerView Field Ġ= ĠView Pager 2 :: class . java . getDeclared Field (" m RecyclerView ") ĊĠĠĠ Ġre cyclerView Field . is Accessible Ġ= Ġtrue ĊĠĠĠ Ġval Ġre cyclerView Ġ= Ġre cyclerView Field . get ( this ) Ġas ĠRecyclerView ĊĠĠĠ Ġval Ġtouch S lop Field Ġ= ĠRecyclerView :: class . java . getDeclared Field (" m Touch S lop ") ĊĠĠĠ Ġtouch S lop Field . is Accessible Ġ= Ġtrue ĊĠĠĠ Ġval Ġtouch S lop Ġ= Ġtouch S lop Field . get ( re cyclerView ) Ġas ĠInt ĊĠĠĠ Ġtouch S lop Field . set ( re cyclerView , Ġtouch S lop Ġ* Ġ 3 ) Ċ } Ċ Ċ fun ĠFragment . setup With ViewPager 2 ( ĊĠĠĠ Ġtab Layout : ĠTab Layout , ĊĠĠĠ Ġview pager 2 : ĠView Pager 2 , ĊĠĠĠ Ġtab Meta : ĠList < Pair < Int , ĠInt >> ? Ġ= Ġnull Ċ ) Ġ= ĠTab Layout Mediator ( tab Layout , Ġview pager 2 ) Ġ{ Ġtab , Ġposition Ġ-> ĊĠĠĠ Ġval Ġitem Ġ= Ġtab Meta ?. get ( position ) Ġ?: Ġreturn @ Tab Layout Mediator ĊĠĠĠ Ġtab . setText ( item . first ) ĊĠĠĠ Ġtab . setIcon ( item . second ) Ċ }. also Ġ{ Ġmedi ator Ġ-> ĊĠĠĠ Ġmedi ator . attach () ĊĠĠĠ Ġval Ġlifecycle Observer Ġ= Ġobject Ġ: ĠLifecycle Observer Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ On Lifecycle Event ( Lifecycle . Event . ON _ DESTROY ) ĊĠĠĠĠĠĠĠ Ġfun Ġon Destroy () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmedi ator . detach () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} ĊĠĠĠ Ġview Lifecycle Owner . lifecycle . add Observer ( lifecycle Observer ) Ċ } ĊĊ Ċ fun ĠFragment . register On Page Change Callback ( ĊĠĠĠ Ġview pager 2 : ĠView Pager 2 , ĊĠĠĠ Ġcallback : ĠView Pager 2 . On Page Change Callback Ċ ) Ġ{ ĊĠĠĠ Ġview pager 2 . register On Page Change Callback ( callback ) ĊĊĠĠĠ Ġval Ġlifecycle Observer Ġ= Ġobject Ġ: ĠLifecycle Observer Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ On Lifecycle Event ( Lifecycle . Event . ON _ DESTROY ) ĊĠĠĠĠĠĠĠ Ġfun Ġon Destroy () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġview pager 2 . unregister On Page Change Callback ( callback ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} ĊĠĠĠ Ġview Lifecycle Owner . lifecycle . add Observer ( lifecycle Observer ) Ċ }