Updated QueueFragment to have a refresh button.
Issue #595 Also resolved an issue that may have been latent when 'All Episodes' was default. Namely, that the search and other option menus didn't show up until you navigated away and then back to the fragment. This was happening because the items weren't loaded yet, which prevented the options menu from being created. If we switch back to 'All Episodes' as being default, this problem may appear again.
This commit is contained in:
parent
18bc827ed2
commit
77840bea99
|
@ -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,9 +160,29 @@ 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
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
@ -258,6 +293,18 @@ public class QueueFragment extends Fragment {
|
|||
downloadObserver.onResume();
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
// we need to refresh the options menu because it sometimes
|
||||
// needs data that may have just been loaded.
|
||||
// Things will still work on APIs lower than honeycomb
|
||||
// but they may have to change away from this view
|
||||
// and then back to get the options menu.
|
||||
Activity theActivity = activity.get();
|
||||
if (theActivity != null) {
|
||||
theActivity.invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() {
|
||||
|
@ -307,6 +354,9 @@ public class QueueFragment extends Fragment {
|
|||
public void update(EventDistributor eventDistributor, Integer arg) {
|
||||
if ((arg & EVENTS) != 0) {
|
||||
startItemLoader();
|
||||
if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) {
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:custom="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/refresh_item"
|
||||
android:title="@string/refresh_label"
|
||||
android:menuCategory="container"
|
||||
custom:showAsAction="ifRoom"
|
||||
android:icon="?attr/navigation_refresh"/>
|
||||
|
||||
</menu>
|
Loading…
Reference in New Issue