package Ġcom . example . work out buddy Ċ Ċ import Ġandroid . graphics . Color Ċ import Ġandroid . os . Build Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroid . view . WindowManager Ċ import Ġandroidx . annotation . NonNull Ċ import Ġandroidx . annotation . Requires Api Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . coordinator layout . widget . Coordinator Layout Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . recyclerview . widget . Divider Item Decoration Ċ import Ġandroidx . recyclerview . widget . Item Touch Helper Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . google . android . material . sn ackbar . Snackbar Ċ import Ġkotlinx . android . synt hetic . main . activity _ arms .* Ċ import Ġkotlinx . android . synt hetic . main . activity _ arms . re cyclerView Ċ import Ġkotlinx . android . synt hetic . main . activity _ random .* Ċ import Ġkotlinx . android . synt hetic . main . row _ card view .* Ċ import Ġjava . util .* Ċ import Ġkotlin . collections . ArrayList Ċ Ċ class ĠRandom Activity Ġ: ĠAppCompatActivity (){ ĊĠĠĠ Ġval Ġarray List Ġ= ĠArrayList < Model >() ĊĠĠĠ Ġvar Ġmodel Adapter : Model Adapter ? Ġ= Ġnull ĊĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġ@ Requires Api ( Build . VERSION _ CODES . LO L LI POP ) ĊĠĠĠĠĠĠĠ Ġfun Ġback Ground Color () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwindow . add Flags ( WindowManager . LayoutParams . FLAG _ DR AWS _ SYSTEM _ BAR _ BACK GRO UN DS ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwindow . status Bar Color Ġ= ĠContext Compat . getColor ( this , Ġandroid . R . color . transparent ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwindow . navigation Bar Color Ġ= ĠContext Compat . getColor ( this , Ġandroid . R . color . transparent ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwindow . setBackground Drawable Resource ( R . drawable . rect 2 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ random ) ĊĠĠĠĠĠĠĠ Ġvar Ġlist Ġ: Mutable List < Model >? Ġ= Ġnull ĊĊĠĠĠĠĠĠĠ Ġarray List . add ( Model (" D UM BB ELL ĠB ICE PS "," 2 ĠMIN UTES ", R . drawable . se ven , R . drawable . rect 3 , ĠColor . parse Color ("# ffffff "), ĠColor . parse Color ("# b 3 b 3 b 3 "))) ĊĠĠĠĠĠĠĠ Ġarray List . add ( Model (" ST RET CH ING "," 5 ĠMIN UTES ", R . drawable . four , R . drawable . rect 3 , ĠColor . parse Color ("# ffffff "), ĠColor . parse Color ("# b 3 b 3 b 3 "))) ĊĠĠĠĠĠĠĠ Ġarray List . add ( Model (" PUSH ĠU PS "," 6 ĠMIN UTES ", R . drawable . one , R . drawable . rect 3 , ĠColor . parse Color ("# ffffff "), ĠColor . parse Color ("# b 3 b 3 b 3 "))) ĊĠĠĠĠĠĠĠ Ġarray List . add ( Model (" SHO UL DER ĠP RESS "," 3 ĠMIN UTES ", R . drawable . th irt , R . drawable . rect 3 , ĠColor . parse Color ("# ffffff "), ĠColor . parse Color ("# b 3 b 3 b 3 "))) ĊĠĠĠĠĠĠĠ Ġarray List . add ( Model (" VERTICAL ĠLE G ĠC RUN CH ES "," 2 ĠMIN UTES ", R . drawable . five , R . drawable . rect 3 , ĠColor . parse Color ("# ffffff "), ĠColor . parse Color ("# b 3 b 3 b 3 "))) ĊĠĠĠĠĠĠĠ Ġmodel Adapter Ġ= ĠModel Adapter ( array List , this ) Ġ// Ġthis Ġmeans Ġthat Ġthe Ġthis Ġall Ġthings Ġshould Ġbe Ġimplemented Ġhere ĊĠĠĠĠĠĠĠ Ġre cyclerView . layout Manager Ġ= ĠLinearLayoutManager ( this ) Ġ// Ġhere Ġthe Ġview Ġis Ġattached Ġto Ġre cycler Ġview Ġthat Ġmeans Ġthis Ġshould Ġbe Ġimplemented Ġinside Ġthe Ġre cycler Ġview ĊĠĠĠĠĠĠĠ Ġ// ĠĠĠĠĠ ĠCreate Ġthe ĠItem Touch Helper ĊĠĠĠĠĠĠĠ Ġ// this Ġbuilds Ġthe Ġitem Ġtouch Ġhelper Ġfor Ġus Ġin Ġwhich Ġthe Ġviews Ġcan Ġbe Ġonly Ġmoved Ġup Ġor Ġdown ĊĠĠĠĠĠĠĠ Ġval Ġcallback : ĠItem Touch Helper . Callback Ġ= ĠItem Move Callback ( model Adapter !! ) ĊĠĠĠĠĠĠĠ Ġval Ġtouch Helper Ġ= ĠItem Touch Helper ( callback ) ĊĠĠĠĠĠĠĠ Ġtouch Helper . attach To RecyclerView ( re cyclerView ) ĊĠĠĠĠĠĠĠ Ġre cyclerView . adapter Ġ= Ġmodel Adapter ĊĠĠĠĠĠĠĠ Ġ// back Ground Color () ĊĠĠĠĠĠĠĠ Ġsupport ActionBar ?. set Display Home As Up Enabled ( true ) ĊĠĠĠĠĠĠĠ Ġ// set Ġback Ġbutton ĊĠĠĠĠĠĠĠ Ġenable Swipe ToDelete And Undo () ĊĠĠĠ Ġ} ĊĠĠĠ Ġprivate Ġfun Ġenable Swipe ToDelete And Undo () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġswipe ToDelete Callback Ġ= Ġobject : UI Action Class ( this ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Sw ip ed (@ NonNull ĠviewHolder : RecyclerView . ViewHolder , Ġi : Int ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġposition Ġ= ĠviewHolder . adapter Position ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġitem Ġ= Ġmodel Adapter ?. getData ()?. get ( position ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmodel Adapter ?. removeItem ( position ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsn ackbar Ġ= ĠSn ackbar ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. make ( card View nib , Ġ" Item Ġwas Ġremoved Ġfrom Ġthe Ġlist .", ĠSn ackbar . LENGTH _ LONG ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsn ackbar . setAction (" UN DO ", Ġobject : ĠView . OnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun ĠonClick ( view : View ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( item Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmodel Adapter ?. restore Item ( item , Ġposition ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġre cyclerView . scrollTo Position ( position ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsn ackbar . setAction TextColor ( Color . parse Color ("# 0 3 dac 6 ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsn ackbar . show () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġitem Touch helper Ġ= ĠItem Touch Helper ( swipe ToDelete Callback ) ĊĠĠĠĠĠĠĠ Ġitem Touch helper . attach To RecyclerView ( re cyclerView ) ĊĠĠĠ Ġ} Ċ Ċ } Ċ