Chap 17 Challenge: Swipes

Added swipe control by creating an ItemTouchHelper in CrimeListFragment.onCreateView and attaching it to mCrimeRecyclerView. Code is below. Swipe left (delete) and swipe right (select) work great, but I can’t get Move working. When I press-drag up or down I get a “shadow” at the top or bottom of the list view, but no move decoration in the view or onMove callback.

Anyone see anything obvious? Am I doing the move correctly in the emulator?

    //set up our ItemTouchHelper
    ItemTouchHelper mIth = new ItemTouchHelper(
            new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN,
                    ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
                public boolean onMove(RecyclerView recyclerView,
                                      RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                    final int fromPos = viewHolder.getAdapterPosition();
                    final int toPos = target.getAdapterPosition();
                    Log.d("CriminalIntent", "onMove recognized from="+fromPos+" to="+toPos);
                    // move item in `fromPos` to `toPos` in adapter.
                    //call a moved method on adapter?
                    return false;// true if moved, false otherwise
                public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                    // remove from adapter
                    final int pos = viewHolder.getAdapterPosition();
                    Crime crime = mAdapter.getCrimes().get(pos);
                    Log.d("CriminalIntent", "onSwiped recognized on "+pos);
                    if (direction==ItemTouchHelper.LEFT) {      //remove
                        //call a notify method on adapter?
                        mCallbacks.onCrimeRemoved(crime);       //will call updateUI()
                    } else if (direction== ItemTouchHelper.RIGHT) { //like select
                        updateUI();                             //rewrite the list so item is visible

Got it. The gesture for move is press-hold-drag. Hold for a second or two. I guess this is so the move gesture can be differentiated from scroll in a RecyclerView.

Now I get the onMove callbacks. A lot actually. They are called during the move. Is there any way to find out when the move stops, so I can determine where to complete the move? If I move item 1 to position 2 and then back to position 1, I get lots of “move 1 to 2” callbacks but nothing when I move it back to position 1. Is the list supposed to be changed dynamically?