From 24d0efad1e1fba70db59f642ac4ecbb4096aa96f Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Mon, 23 Nov 2015 21:28:15 +0100 Subject: [PATCH 1/3] Restore scroll position (don't forget it) --- .../java/de/danoeh/antennapod/fragment/QueueFragment.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index bfac7a347..8eab1ef9e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -211,11 +211,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(); } } From f12362c776826bf27347ed968de8087fc7733811 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Mon, 23 Nov 2015 21:29:02 +0100 Subject: [PATCH 2/3] We do all the moving ourselves, no need to react on it --- .../antennapod/fragment/QueueFragment.java | 29 ++++++++++--------- .../menuhandler/FeedItemMenuHandler.java | 5 ---- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 8eab1ef9e..802802ec9 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -162,14 +162,6 @@ 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; } onFragmentLoaded(); @@ -331,12 +323,21 @@ public class QueueFragment extends Fragment { return super.onContextItemSelected(item); } - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); - } catch (DownloadRequestException e) { - e.printStackTrace(); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); - return true; + switch(item.getItemId()) { + 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); + return true; + default: + try { + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); + } catch (DownloadRequestException e) { + e.printStackTrace(); + Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); + return true; + } } } diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index 3fa1048c0..0197cc88c 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -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; From 58813db55300ad742e5fe91be180d7ca80d55af0 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Mon, 23 Nov 2015 23:31:38 +0100 Subject: [PATCH 3/3] Save position before refreshing, handle top/bottom moving and notify adapter --- .../de/danoeh/antennapod/fragment/QueueFragment.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 802802ec9..433e72778 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -162,8 +162,9 @@ public class QueueFragment extends Fragment { recyclerAdapter.notifyDataSetChanged(); break; case MOVED: - break; + return; } + saveScrollPosition(); onFragmentLoaded(); } @@ -325,9 +326,15 @@ public class QueueFragment extends Fragment { 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: