package Ġsan cho . gn arly music player . adapters Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . content . Context Ċ import Ġandroid . view .* Ċ import Ġandroid . widget . TextView Ċ import Ġandroidx . appcompat . widget . AppCompat ImageView Ċ import Ġandroidx . recyclerview . widget . Item Touch Helper Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġsan cho . gn arly music player . Bottom Sheet Dialog Ctx Menu Ċ import Ġsan cho . gn arly music player . Playback Queue Ċ import Ġsan cho . gn arly music player . R Ċ Ċ class ĠQueue Adapter ( Ċ ĉ private Ġval Ġ_ context : ĠContext , Ċ ĉ private Ġval Ġ_ play Track : Ġ( Int ) Ġ-> ĠUnit , Ċ ĉ private Ġval Ġ_ setup Explorer Ctx Menu : Ġ( Bottom Sheet Dialog Ctx Menu , ĠString , ĠInt ) Ġ-> ĠUnit ) Ġ: ĠRecyclerView . Adapter < Queue Adapter . Track Holder >() Ċ { Ċ ĉ var Ġtouch Helper : ĠItem Touch Helper ? Ġ= Ġnull ĊĊ ĉ override Ġfun Ġon Bind ViewHolder ( holder : ĠTrack Holder , Ġposition : ĠInt ) Ċ ĉ { Ċĉ ĉ holder . item View . findViewById < TextView >( R . id . queue _ text ). text Ġ= ĠPlay back Queue . queue [ holder . adapter Position ]. name ĊĊĉ ĉ holder . item View . isSelected Ġ= ĠPlay back Queue . current Idx Ġ== Ġholder . adapter Position ĊĊĉ ĉ holder . item View . setOnClickListener Ġ{ Ġ_ play Track ( holder . adapter Position ) Ġ} ĊĊĉ ĉ holder . item View . setOn Long ClickListener Ġ{ Ċĉĉ ĉ val Ġdialog Ġ= ĠBottom Sheet Dialog Ctx Menu (_ context , ĠR . layout . bottom _ sheet _ queue ) Ċĉĉ ĉ // Ġnote : Ġcan 't Ġsimply Ġuse Ġposition , Ġas Ġitems Ġmight Ġget Ġremoved / re arrange d Ġwithout Ġrefresh ing Ġwhole Ġdataset Ċĉĉ ĉ _ setup Explorer Ctx Menu ( dialog , ĠPlay back Queue . queue [ holder . adapter Position ]. name , Ġholder . adapter Position ) Ċĉĉ ĉ dialog . show () Ċĉĉ ĉ true Ġ// Ġconsumed Ġlong Ġpress Ċĉ ĉ } ĊĊĉ ĉ @ Suppress Lint (" Click ableView Accessibility ") Ġ// Ġwe Ġdon 't Ġwant Ġto Ġclick Ġthe Ġtrack , Ġonly Ġdrag Ċĉ ĉ if ( touch Helper Ġ!= Ġnull ) Ċĉ ĉ { Ċĉĉ ĉ holder . item View . findViewById < AppCompat ImageView >( R . id . queue _ reorder ). setOn Touch Listener Ġ{ Ġ_, Ġevent Ġ-> Ċĉĉĉ ĉ if Ġ( event . action Ġ== ĠMotion Event . ACTION _ DOWN ) Ċĉĉĉ ĉ { Ċĉĉĉĉ ĉ touch Helper ?. start Drag ( holder ) Ċĉĉĉ ĉ } Ċĉĉĉ ĉ false Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun ĠgetItem Count () Ġ= ĠPlay back Queue . queue . size ĊĊ ĉ override Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠTrack Holder Ċ ĉ { Ċĉ ĉ return ĠTrack Holder ( LayoutInflater . from (_ context ). inflate ( R . layout . queue _ item , Ġparent , Ġfalse )) Ċ ĉ } ĊĊ ĉ class ĠTrack Holder ( view : ĠView ) Ġ: ĠRecyclerView . ViewHolder ( view ) Ċ } Ċ