diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-03-04 14:34:35 +0100 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-03-04 14:42:35 +0100 |
commit | 9444f266730b4b2b2a064a3d2557962d5db16a5f (patch) | |
tree | 8d6d52bbac86fa144c96be3067d1faf16e490e5f /app/src/main/java/de | |
parent | 6c81f6c868971fc343cfa49d54927dd845a39ede (diff) | |
download | AntennaPod-9444f266730b4b2b2a064a3d2557962d5db16a5f.zip |
Show UndoBar when dismiss-by-swipe
Diffstat (limited to 'app/src/main/java/de')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java | 30 |
1 files changed, 27 insertions, 3 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 30238ff51..62a01d0ad 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; +import android.os.Parcelable; import android.support.v4.app.Fragment; import android.support.v7.widget.SearchView; import android.util.Log; @@ -42,6 +43,8 @@ import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.QueueSorter; +import de.danoeh.antennapod.core.util.gui.FeedItemUndoToken; +import de.danoeh.antennapod.core.util.gui.UndoBarController; import de.danoeh.antennapod.menuhandler.MenuItemUtils; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; @@ -59,6 +62,8 @@ public class QueueFragment extends Fragment { private TextView txtvEmpty; private ProgressBar progLoading; + private UndoBarController undoBarController; + private List<FeedItem> queue; private List<Downloader> downloaderList; @@ -120,6 +125,7 @@ public class QueueFragment extends Fragment { unregisterForContextMenu(listView); listAdapter = null; activity.set(null); + undoBarController = null; viewsCreated = false; blockDownloadObserverUpdate = false; if (downloadObserver != null) { @@ -302,12 +308,30 @@ public class QueueFragment extends Fragment { @Override public void remove(int which) { Log.d(TAG, "remove("+which+")"); - final FeedItem item = queue.remove(which); - DBWriter.removeQueueItem(getActivity(), item.getId(), false); - listAdapter.notifyDataSetChanged(); + stopItemLoader(); + FeedItem item = (FeedItem) listView.getAdapter().getItem(which); + DBWriter.removeQueueItem(getActivity(), item.getId(), true); + undoBarController.showUndoBar(false, + getString(R.string.removed_from_queue), new FeedItemUndoToken(item, + which) + ); } }); + undoBarController = new UndoBarController(root.findViewById(R.id.undobar), new UndoBarController.UndoListener() { + @Override + public void onUndo(Parcelable token) { + // Perform the undo + FeedItemUndoToken undoToken = (FeedItemUndoToken) token; + if (token != null) { + long itemId = undoToken.getFeedItemId(); + int position = undoToken.getPosition(); + DBWriter.addQueueItemAt(getActivity(), itemId, position, false); + } + } + }); + + registerForContextMenu(listView); if (!itemsLoaded) { |