diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2015-01-19 21:49:56 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2015-01-19 21:49:56 +0100 |
commit | d04aa8295426f786e9fa75f74038f170060d823d (patch) | |
tree | b53f5c4183098f3046eafe8cd4492b85ab47a84e /app/src/main/java/de | |
parent | 373f28c8aea278ae50ac6ebbdc7db5d3703dcec4 (diff) | |
parent | 86e5e9ea1373980576f76ad1abf676a4c9911fac (diff) | |
download | AntennaPod-d04aa8295426f786e9fa75f74038f170060d823d.zip |
Merge branch 'add_refresh_button_to_queue_view_595' of git://github.com/TomHennen/AntennaPod into TomHennen-add_refresh_button_to_queue_view_595
Diffstat (limited to 'app/src/main/java/de')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java | 42 |
1 files changed, 42 insertions, 0 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 ce77229d9..302739b6a 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.fragment; import android.app.Activity; import android.content.Context; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; @@ -30,11 +31,15 @@ import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.QueueListAdapter; import de.danoeh.antennapod.core.asynctask.DownloadObserver; import de.danoeh.antennapod.core.feed.EventDistributor; +import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.storage.DBReader; +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.menuhandler.MenuItemUtils; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; @@ -57,6 +62,7 @@ public class QueueFragment extends Fragment { private boolean itemsLoaded = false; private boolean viewsCreated = false; + private boolean isUpdatingFeeds = false; private AtomicReference<Activity> activity = new AtomicReference<Activity>(); @@ -125,10 +131,19 @@ public class QueueFragment extends Fragment { resetViewState(); } + private final MenuItemUtils.UpdateRefreshMenuItemChecker updateRefreshMenuItemChecker = new MenuItemUtils.UpdateRefreshMenuItemChecker() { + @Override + public boolean isRefreshing() { + return DownloadService.isRunning && DownloadRequester.getInstance().isDownloadingFeeds(); + } + }; + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); if (itemsLoaded && !MenuItemUtils.isActivityDrawerOpen((NavDrawerActivity) getActivity())) { + inflater.inflate(R.menu.queue, menu); + final SearchView sv = new SearchView(getActivity()); MenuItemUtils.addSearchItem(menu, sv); sv.setQueryHint(getString(R.string.search_hint)); @@ -145,7 +160,27 @@ public class QueueFragment extends Fragment { return false; } }); + isUpdatingFeeds = MenuItemUtils.updateRefreshMenuItem(menu, R.id.refresh_item, updateRefreshMenuItemChecker); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (!super.onOptionsItemSelected(item)) { + switch (item.getItemId()) { + case R.id.refresh_item: + List<Feed> feeds = ((MainActivity) getActivity()).getFeeds(); + if (feeds != null) { + DBTasks.refreshAllFeeds(getActivity(), feeds); + } + return true; + default: + return false; + } + } else { + return true; } + } @Override @@ -258,6 +293,10 @@ public class QueueFragment extends Fragment { downloadObserver.onResume(); } listAdapter.notifyDataSetChanged(); + + // we need to refresh the options menu because it sometimes + // needs data that may have just been loaded. + getActivity().supportInvalidateOptionsMenu(); } private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() { @@ -307,6 +346,9 @@ public class QueueFragment extends Fragment { public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { startItemLoader(); + if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) { + getActivity().supportInvalidateOptionsMenu(); + } } } }; |