Merge pull request #1410 from mfietz/issue/1409-drag-glitch

Queue: Restore scroll position, don't glitch
This commit is contained in:
Tom Hennen 2015-11-23 20:28:18 -05:00
commit 3fa38f8b1b
2 changed files with 23 additions and 25 deletions

View File

@ -162,16 +162,9 @@ public class QueueFragment extends Fragment {
recyclerAdapter.notifyDataSetChanged();
break;
case MOVED:
int from = FeedItemUtil.indexOfItemWithId(queue, event.item.getId());
int to = event.position;
if(from != to) {
queue.add(to, queue.remove(from));
recyclerAdapter.notifyItemMoved(from, to);
} else {
// QueueFragment itself sent the event and already moved the item
}
break;
return;
}
saveScrollPosition();
onFragmentLoaded();
}
@ -211,11 +204,6 @@ public class QueueFragment extends Fragment {
float offset = prefs.getFloat(PREF_SCROLL_OFFSET, 0.0f);
if (position > 0 || offset > 0) {
layoutManager.scrollToPositionWithOffset(position, (int) offset);
// restore once, then forget
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(PREF_SCROLL_POSITION, 0);
editor.putFloat(PREF_SCROLL_OFFSET, 0.0f);
editor.commit();
}
}
@ -336,6 +324,20 @@ public class QueueFragment extends Fragment {
return super.onContextItemSelected(item);
}
switch(item.getItemId()) {
case R.id.move_to_top_item:
int position = FeedItemUtil.indexOfItemWithId(queue, selectedItem.getId());
queue.add(0, queue.remove(position));
recyclerAdapter.notifyItemMoved(position, 0);
DBWriter.moveQueueItemToTop(selectedItem.getId(), true);
return true;
case R.id.move_to_bottom_item:
position = FeedItemUtil.indexOfItemWithId(queue, selectedItem.getId());
queue.add(queue.size()-1, queue.remove(position));
recyclerAdapter.notifyItemMoved(position, queue.size()-1);
DBWriter.moveQueueItemToBottom(selectedItem.getId(), true);
return true;
default:
try {
return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem);
} catch (DownloadRequestException e) {
@ -344,6 +346,7 @@ public class QueueFragment extends Fragment {
return true;
}
}
}
@Override

View File

@ -186,11 +186,6 @@ public class FeedItemMenuHandler {
GpodnetPreferences.enqueueEpisodeAction(actionNew);
}
break;
case R.id.move_to_top_item:
DBWriter.moveQueueItemToTop(selectedItem.getId(), true);
return true;
case R.id.move_to_bottom_item:
DBWriter.moveQueueItemToBottom(selectedItem.getId(), true);
case R.id.add_to_queue_item:
DBWriter.addQueueItem(context, selectedItem);
break;