diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-05-17 14:39:16 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-05-17 14:39:16 +0200 |
commit | 2186055c2d534dd6ac70a3480b64e597aee0d669 (patch) | |
tree | e4dc38bf7d43ff10eca15e29318b69eb8c338bbc /src/de/danoeh/antennapod/fragment | |
parent | 0d1803413c19ec78a0f0a79e3d6e8d07cf1b8a2a (diff) | |
download | AntennaPod-2186055c2d534dd6ac70a3480b64e597aee0d669.zip |
Added "swipe to refresh" in new episodes list
Diffstat (limited to 'src/de/danoeh/antennapod/fragment')
-rw-r--r-- | src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java index 4bf7a4b76..a420f9d26 100644 --- a/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java +++ b/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java @@ -7,6 +7,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.SearchView; import android.view.*; @@ -25,6 +26,7 @@ import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedMedia; +import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.service.download.DownloadService; import de.danoeh.antennapod.service.download.Downloader; import de.danoeh.antennapod.storage.DBReader; @@ -53,6 +55,7 @@ public class NewEpisodesFragment extends Fragment { private DragSortListView listView; + private SwipeRefreshLayout swipeRefreshLayout; private NewEpisodesListAdapter listAdapter; private TextView txtvEmpty; private ProgressBar progLoading; @@ -198,6 +201,8 @@ public class NewEpisodesFragment extends Fragment { ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.all_episodes_label); View root = inflater.inflate(R.layout.new_episodes_fragment, container, false); + + swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipeRefreshLayout); listView = (DragSortListView) root.findViewById(android.R.id.list); txtvEmpty = (TextView) root.findViewById(android.R.id.empty); progLoading = (ProgressBar) root.findViewById(R.id.progLoading); @@ -214,6 +219,18 @@ public class NewEpisodesFragment extends Fragment { } }); + final int secondColor = (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) ? R.color.swipe_refresh_secondary_color_dark : R.color.swipe_refresh_secondary_color_light; + swipeRefreshLayout.setColorScheme(R.color.bright_blue, secondColor, R.color.bright_blue, secondColor); + swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + List<Feed> feeds = ((MainActivity) getActivity()).getFeeds(); + if (feeds != null) { + DBTasks.refreshAllFeeds(getActivity(), feeds); + } + } + }); + if (!itemsLoaded) { progLoading.setVisibility(View.VISIBLE); txtvEmpty.setVisibility(View.GONE); @@ -310,16 +327,21 @@ public class NewEpisodesFragment extends Fragment { }; private void updateProgressBarVisibility() { + if (!viewsCreated) { + return; + } + if (DownloadService.isRunning && DownloadRequester.getInstance().isDownloadingFeeds()) { - ((ActionBarActivity) getActivity()) - .setSupportProgressBarIndeterminateVisibility(true); + swipeRefreshLayout.setRefreshing(true); + } else { + swipeRefreshLayout.setRefreshing(false); + + // if case other fragments have set this to true, this fragment should remove the progress indicator ((ActionBarActivity) getActivity()) .setSupportProgressBarIndeterminateVisibility(false); } - getActivity().supportInvalidateOptionsMenu(); - } private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { |