package Ġcom . github . ht d ang k ho a . nex ter p . ui . adapters Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġandroidx . recyclerview . widget . Sort edList Ċ import Ġcom . github . ht d ang k ho a . nex ter p . data . remote . stock adjust ment . stock adjust ment . Stock Adjustment Response Ċ import Ġcom . github . ht d ang k ho a . nex ter p . databinding . Stock adjust ment Item ViewHolder Binding Ċ import Ġcom . github . ht d ang k ho a . nex ter p . ui . main . fragments . stock adjust ment . Stock Adjustment ViewModel Ċ import Ġcom . github . ht d ang k ho a . nex ter p . ui . view holders . Stock Adjustment ListView Holder ĊĊ Ċ class ĠStock Adjustment ListAdapter ( context : ĠContext ?, ĠviewModel : ĠStock Adjustment ViewModel , Ġcomparator : ĠComparator < Stock Adjustment Response . Stock Adjustment >) Ġ: ĊĠĠĠ ĠRecyclerView . Adapter < Stock Adjustment ListView Holder >() Ġ{ ĊĠĠĠ Ġprivate Ġval Ġm Sort edList : ĠSort edList < Stock Adjustment Response . Stock Adjustment > Ġ= ĊĠĠĠĠĠĠĠ ĠSort edList ( Stock Adjustment Response . Stock Adjustment :: class . java , Ġobject Ġ: ĠSort edList . Callback < Stock Adjustment Response . Stock Adjustment >() Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcompare ( a : ĠStock Adjustment Response . Stock Adjustment , Ġb : ĠStock Adjustment Response . Stock Adjustment ): ĠInt Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġm Comparator . compare ( a , Ġb ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Inserted ( position : ĠInt , Ġcount : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnotify Item Range Inserted ( position , Ġcount ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Removed ( position : ĠInt , Ġcount : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnotify Item Range Removed ( position , Ġcount ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Moved ( from Position : ĠInt , Ġto Position : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnotify Item Moved ( from Position , Ġto Position ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun ĠonChanged ( position : ĠInt , Ġcount : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnotify Item Range Changed ( position , Ġcount ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġare Contents The Same ( old Item : ĠStock Adjustment Response . Stock Adjustment , Ġnew Item : ĠStock Adjustment Response . Stock Adjustment ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġold Item Ġ== Ġnew Item ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġare Items The Same ( item 1 : ĠStock Adjustment Response . Stock Adjustment , Ġitem 2 : ĠStock Adjustment Response . Stock Adjustment ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġitem 1 . id Ġ== Ġitem 2 . id ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠ Ġprivate Ġval Ġm Inflater : ĠLayoutInflater Ġ= ĠLayoutInflater . from ( context ) ĊĠĠĠ Ġprivate Ġval Ġm ViewModel : ĠStock Adjustment ViewModel Ġ= ĠviewModel ĊĠĠĠ Ġprivate Ġval Ġm Comparator : ĠComparator < Stock Adjustment Response . Stock Adjustment > Ġ= Ġcomparator ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠStock Adjustment ListView Holder Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbinding : ĠStock adjust ment Item ViewHolder Binding Ġ= ĠStock adjust ment Item ViewHolder Binding . inflate ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġm Inflater , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġparent , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfalse ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġreturn ĠStock Adjustment ListView Holder ( binding ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠStock Adjustment ListView Holder , Ġposition : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmodel : ĠStock Adjustment Response . Stock Adjustment ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ= Ġm Sort edList [ position ] ĊĠĠĠĠĠĠĠ Ġholder . bind ( model , Ġm ViewModel ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠgetItem Count (): ĠInt Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġm Sort edList . size () ĊĠĠĠ Ġ} ĊĠĠĠ Ġfun Ġadd ( model : ĠStock Adjustment Response . Stock Adjustment ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġm Sort edList . add ( model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġremove ( model : ĠStock Adjustment Response . Stock Adjustment ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġm Sort edList . remove ( model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġadd ( models : ĠArray < Stock Adjustment Response . Stock Adjustment >) Ġ{ ĊĠĠĠĠĠĠĠ Ġmodels . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġm Sort edList . add ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġremove ( models : ĠList < Stock Adjustment Response . Stock Adjustment ?> ) Ġ{ ĊĠĠĠĠĠĠĠ Ġm Sort edList . begin B atched Updates () ĊĠĠĠĠĠĠĠ Ġfor Ġ( model Ġin Ġmodels ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġm Sort edList . remove ( model ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġm Sort edList . end B atched Updates () ĊĠĠĠ Ġ} ĊĠĠĠ Ġfun Ġreplace All ( models : ĠList < Stock Adjustment Response . Stock Adjustment ?> ) Ġ{ ĊĠĠĠĠĠĠĠ Ġm Sort edList . begin B atched Updates () ĊĠĠĠĠĠĠĠ Ġfor Ġ( i Ġin Ġm Sort edList . size () Ġ- Ġ 1 Ġdown To Ġ 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmodel : ĠStock Adjustment Response . Stock Adjustment Ġ= Ġm Sort edList [ i ] ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ(! models . contains ( model )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġm Sort edList . remove ( model ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġm Sort edList . addAll ( models ) ĊĠĠĠĠĠĠĠ Ġm Sort edList . end B atched Updates () ĊĠĠĠ Ġ} Ċ Ċ } Ċ