diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-04-21 13:15:33 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-04-21 13:15:33 +0200 |
commit | 15c333ed39251329f3c69bfa4260239b9c733f3f (patch) | |
tree | 17f2abceac17b9c9ecf44a775f0c01accd74fe82 /src/de/danoeh/antennapod/fragment | |
parent | 3a3116fe9629b49b18c6777aba08649ab3a203b1 (diff) | |
download | AntennaPod-15c333ed39251329f3c69bfa4260239b9c733f3f.zip |
Re-implemented menus
Diffstat (limited to 'src/de/danoeh/antennapod/fragment')
3 files changed, 158 insertions, 11 deletions
diff --git a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java index 021aa974b..8a958c758 100644 --- a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -1,9 +1,8 @@ package de.danoeh.antennapod.fragment; import android.annotation.SuppressLint; -import android.app.Activity; import android.content.Context; -import android.content.Intent; +import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -12,21 +11,20 @@ import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.SearchView; import android.text.util.Linkify; import android.util.Log; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.View; +import android.view.*; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.ItemviewActivity; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter; import de.danoeh.antennapod.asynctask.DownloadObserver; +import de.danoeh.antennapod.asynctask.FeedRemover; import de.danoeh.antennapod.asynctask.ImageLoader; +import de.danoeh.antennapod.dialog.ConfirmationDialog; +import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.dialog.FeedItemDialog; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.Feed; @@ -35,12 +33,14 @@ import de.danoeh.antennapod.feed.FeedMedia; import de.danoeh.antennapod.service.download.DownloadService; import de.danoeh.antennapod.service.download.Downloader; import de.danoeh.antennapod.storage.DBReader; +import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.storage.DownloadRequester; import de.danoeh.antennapod.util.QueueAccess; +import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler; +import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler; import de.danoeh.antennapod.util.menuhandler.MenuItemUtils; import java.util.List; -import java.util.concurrent.atomic.AtomicReference; /** * Displays a list of FeedItems. @@ -146,6 +146,8 @@ public class ItemlistFragment extends ListFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); + FeedMenuHandler.onCreateOptionsMenu(inflater, menu); + final SearchView sv = new SearchView(getActivity()); MenuItemUtils.addSearchItem(menu, sv); sv.setQueryHint(getString(R.string.search_hint)); @@ -167,9 +169,60 @@ public class ItemlistFragment extends ListFragment { } @Override + public void onPrepareOptionsMenu(Menu menu) { + FeedMenuHandler.onPrepareOptionsMenu(menu, feed); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (!super.onOptionsItemSelected(item)) { + try { + if (!FeedMenuHandler.onOptionsItemClicked(getActivity(), item, feed)) { + switch (item.getItemId()) { + case R.id.remove_item: + final FeedRemover remover = new FeedRemover( + getActivity(), feed) { + @Override + protected void onPostExecute(Void result) { + super.onPostExecute(result); + ((MainActivity)getActivity()).loadNavFragment(MainActivity.POS_NEW, null); + } + }; + ConfirmationDialog conDialog = new ConfirmationDialog(getActivity(), + R.string.remove_feed_label, + R.string.feed_delete_confirmation_msg) { + + @Override + public void onConfirmButtonPressed( + DialogInterface dialog) { + dialog.dismiss(); + remover.executeAsync(); + } + }; + conDialog.createNewDialog().show(); + return true; + default: + return false; + + } + } else { + return true; + } + } catch (DownloadRequestException e) { + e.printStackTrace(); + DownloadRequestErrorDialogCreator.newRequestErrorDialog(getActivity(), e.getMessage()); + return true; + } + } else { + return true; + } + + } + + @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - ((ActionBarActivity)getActivity()).getSupportActionBar().setTitle(""); + ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(""); viewsCreated = true; if (itemsLoaded) { @@ -232,8 +285,7 @@ public class ItemlistFragment extends ListFragment { feedItemDialog.setQueue(queue); feedItemDialog.updateMenuAppearance(); } - - + getActivity().supportInvalidateOptionsMenu(); } private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() { diff --git a/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java index 95b50f62b..05ac37554 100644 --- a/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java +++ b/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java @@ -6,11 +6,13 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; +import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.SearchView; import android.view.*; import android.widget.AdapterView; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import com.mobeta.android.dslv.DragSortListView; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; @@ -19,10 +21,15 @@ import de.danoeh.antennapod.adapter.NewEpisodesListAdapter; import de.danoeh.antennapod.asynctask.DownloadObserver; import de.danoeh.antennapod.dialog.FeedItemDialog; 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.service.download.DownloadService; import de.danoeh.antennapod.service.download.Downloader; import de.danoeh.antennapod.storage.DBReader; +import de.danoeh.antennapod.storage.DBTasks; +import de.danoeh.antennapod.storage.DBWriter; +import de.danoeh.antennapod.storage.DownloadRequester; import de.danoeh.antennapod.util.QueueAccess; import de.danoeh.antennapod.util.menuhandler.MenuItemUtils; @@ -121,6 +128,8 @@ public class NewEpisodesFragment extends Fragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); + inflater.inflate(R.menu.new_episodes, menu); + final SearchView sv = new SearchView(getActivity()); MenuItemUtils.addSearchItem(menu, sv); sv.setQueryHint(getString(R.string.search_hint)); @@ -140,6 +149,35 @@ public class NewEpisodesFragment extends Fragment { } @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + menu.findItem(R.id.mark_all_read_item).setVisible(unreadItems != null && !unreadItems.isEmpty()); + } + + @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; + case R.id.mark_all_read_item: + DBWriter.markAllItemsRead(getActivity()); + Toast.makeText(getActivity(), R.string.mark_all_read_msg, Toast.LENGTH_SHORT).show(); + return true; + default: + return false; + } + } else { + return true; + } + + } + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.new_episodes_label); @@ -190,6 +228,8 @@ public class NewEpisodesFragment extends Fragment { feedItemDialog.updateMenuAppearance(); } listAdapter.notifyDataSetChanged(); + getActivity().supportInvalidateOptionsMenu(); + updateProgressBarVisibility(); } private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() { @@ -260,11 +300,25 @@ public class NewEpisodesFragment extends Fragment { }; + private void updateProgressBarVisibility() { + if (DownloadService.isRunning + && DownloadRequester.getInstance().isDownloadingFeeds()) { + ((ActionBarActivity) getActivity()) + .setSupportProgressBarIndeterminateVisibility(true); + } else { + ((ActionBarActivity) getActivity()) + .setSupportProgressBarIndeterminateVisibility(false); + } + getActivity().supportInvalidateOptionsMenu(); + + } + private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { startItemLoader(); + updateProgressBarVisibility(); } } }; diff --git a/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index c28208d37..c4e02c5f0 100644 --- a/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -2,12 +2,18 @@ package de.danoeh.antennapod.fragment; import android.app.Activity; import android.content.Context; +import android.content.res.TypedArray; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.ListFragment; +import android.support.v4.view.MenuItemCompat; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.ListView; +import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.ActionButtonCallback; import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter; @@ -18,6 +24,7 @@ import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedMedia; import de.danoeh.antennapod.service.download.Downloader; import de.danoeh.antennapod.storage.DBReader; +import de.danoeh.antennapod.storage.DBWriter; import de.danoeh.antennapod.util.QueueAccess; import java.util.List; @@ -44,6 +51,7 @@ public class PlaybackHistoryFragment extends ListFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); + setHasOptionsMenu(true); startItemLoader(); } @@ -106,12 +114,44 @@ public class PlaybackHistoryFragment extends ListFragment { } } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + MenuItem clearHistory = menu.add(Menu.NONE, R.id.clear_history_item, Menu.CATEGORY_CONTAINER, R.string.clear_history_label); + MenuItemCompat.setShowAsAction(clearHistory, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); + TypedArray drawables = getActivity().obtainStyledAttributes(new int[] {R.attr.content_discard}); + clearHistory.setIcon(drawables.getDrawable(0)); + drawables.recycle(); + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + menu.findItem(R.id.clear_history_item).setVisible(playbackHistory != null && !playbackHistory.isEmpty()); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (!super.onOptionsItemSelected(item)) { + switch(item.getItemId()) { + case R.id.clear_history_item: + DBWriter.clearPlaybackHistory(getActivity()); + return true; + default: + return false; + } + } else { + return true; + } + } + private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EventDistributor.PLAYBACK_HISTORY_UPDATE) != 0) { startItemLoader(); + getActivity().supportInvalidateOptionsMenu(); } } }; @@ -130,6 +170,7 @@ public class PlaybackHistoryFragment extends ListFragment { feedItemDialog.setQueue(queue); feedItemDialog.updateMenuAppearance(); } + getActivity().supportInvalidateOptionsMenu(); } private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() { |