package Ġme . t ict ok . library Ċ Ċ import Ġandroid . support . v 7 . widget . RecyclerView Ċ Ċ class ĠSnap On Scroll Listener ( private Ġval Ġsnap Helper : ĠCustom Snap Helper , Ġprivate Ġvar Ġon Snap Position ChangeListener : ĠOn Snap Position ChangeListener , Ġprivate Ġvar Ġbehavior : ĠBehavior ) Ġ: ĠRecyclerView . On Scroll Listener () Ġ{ ĊĠĠĠ Ġprivate Ġvar Ġsnap Position Ġ= ĠRecyclerView . NO _ POSITION ĊĊĠĠĠ Ġenum Ġclass ĠBehavior Ġ{ ĊĠĠĠĠĠĠĠ ĠNOT IFY _ ON _ SCROLL , ĊĠĠĠĠĠĠĠ ĠNOT IFY _ ON _ SCROLL _ STATE _ IDLE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Sc rolled ( re cyclerView : ĠRecyclerView , Ġdx : ĠInt , Ġdy : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( behavior Ġ== ĠBehavior . NOTIFY _ ON _ SCROLL ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmaybe Notify Snap Position Change ( re cyclerView ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Scroll StateChanged ( re cyclerView : ĠRecyclerView , ĠnewState : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( behavior Ġ== ĠBehavior . NOTIFY _ ON _ SCROLL _ STATE _ IDLE Ġ&& ĠnewState Ġ== ĠRecyclerView . SCROLL _ STATE _ IDLE ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmaybe Notify Snap Position Change ( re cyclerView ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon Snap Position ChangeListener . on Stop Scrolling () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmaybe Notify Snap Position Change ( re cyclerView : ĠRecyclerView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsnap Position Ġ= Ġsnap Helper . getS nap Position ( re cyclerView ) ĊĠĠĠĠĠĠĠ Ġval Ġsnap Position Changed Ġ= Ġthis . snap Position Ġ!= Ġsnap Position ĊĠĠĠĠĠĠĠ Ġif Ġ( snap Position Changed ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon Snap Position ChangeListener . on Snap Position Change ( snap Position ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthis . snap Position Ġ= Ġsnap Position ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ