diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-01-31 09:27:04 -0500 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-01-31 09:27:04 -0500 |
commit | 9ca056253d72ba2326c7dd7e19ae12551f70c2b0 (patch) | |
tree | 953398f4cf9e63d7c8a74b7d528f1ceaa4a2bd3a /app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java | |
parent | c1dbe6da3572980775fd65bbce48cb9b72ffede7 (diff) | |
parent | 527ff45229dc4f9238d4eedc18753954238e1555 (diff) | |
download | AntennaPod-9ca056253d72ba2326c7dd7e19ae12551f70c2b0.zip |
Merge pull request #1619 from mfietz/issue/1222-completed-downloads-gears
Completed Downloads: Gears Dialog
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index 954c4c9e2..a53c85f1c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -1,12 +1,20 @@ package de.danoeh.antennapod.fragment; -import android.app.Activity; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.ListView; +import com.joanzapata.iconify.IconDrawable; +import com.joanzapata.iconify.fonts.FontAwesomeIcons; + import java.util.List; import de.danoeh.antennapod.R; @@ -14,8 +22,10 @@ import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment; import rx.Observable; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; @@ -28,22 +38,21 @@ public class CompletedDownloadsFragment extends ListFragment { private static final String TAG = CompletedDownloadsFragment.class.getSimpleName(); - private static final int EVENTS = - EventDistributor.DOWNLOAD_HANDLED | - EventDistributor.DOWNLOADLOG_UPDATE | - EventDistributor.UNREAD_ITEMS_UPDATE; + private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | + EventDistributor.DOWNLOADLOG_UPDATE | + EventDistributor.UNREAD_ITEMS_UPDATE; private List<FeedItem> items; private DownloadedEpisodesListAdapter listAdapter; private boolean viewCreated = false; - private boolean itemsLoaded = false; private Subscription subscription; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setHasOptionsMenu(true); loadItems(); } @@ -81,9 +90,9 @@ public class CompletedDownloadsFragment extends ListFragment { } @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - if (viewCreated && itemsLoaded) { + public void onAttach(Context context) { + super.onAttach(context); + if (viewCreated && items != null) { onFragmentLoaded(); } } @@ -99,7 +108,7 @@ public class CompletedDownloadsFragment extends ListFragment { lv.setPadding(0, vertPadding, 0, vertPadding); viewCreated = true; - if (itemsLoaded && getActivity() != null) { + if (items != null && getActivity() != null) { onFragmentLoaded(); } } @@ -111,7 +120,6 @@ public class CompletedDownloadsFragment extends ListFragment { if (item != null) { ((MainActivity) getActivity()).loadChildFragment(ItemFragment.newInstance(item.getId())); } - } private void onFragmentLoaded() { @@ -121,6 +129,43 @@ public class CompletedDownloadsFragment extends ListFragment { } setListShown(true); listAdapter.notifyDataSetChanged(); + getActivity().supportInvalidateOptionsMenu(); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if(!isAdded()) { + return; + } + super.onCreateOptionsMenu(menu, inflater); + if(items != null) { + inflater.inflate(R.menu.downloads_completed, menu); + MenuItem episodeActions = menu.findItem(R.id.episode_actions); + if(items.size() > 0) { + int[] attrs = {R.attr.action_bar_icon_color}; + TypedArray ta = getActivity().obtainStyledAttributes(UserPreferences.getTheme(), attrs); + int textColor = ta.getColor(0, Color.GRAY); + ta.recycle(); + episodeActions.setIcon(new IconDrawable(getActivity(), + FontAwesomeIcons.fa_gears).color(textColor).actionBarSize()); + episodeActions.setVisible(true); + } else { + episodeActions.setVisible(false); + } + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.episode_actions: + EpisodesApplyActionFragment fragment = EpisodesApplyActionFragment + .newInstance(items, EpisodesApplyActionFragment.ACTION_REMOVE); + ((MainActivity) getActivity()).loadChildFragment(fragment); + return true; + default: + return false; + } } private DownloadedEpisodesListAdapter.ItemAccess itemAccess = new DownloadedEpisodesListAdapter.ItemAccess() { @@ -157,7 +202,7 @@ public class CompletedDownloadsFragment extends ListFragment { if(subscription != null) { subscription.unsubscribe(); } - if (!itemsLoaded && viewCreated) { + if (items == null && viewCreated) { setListShown(false); } subscription = Observable.fromCallable(() -> DBReader.getDownloadedItems()) @@ -166,7 +211,6 @@ public class CompletedDownloadsFragment extends ListFragment { .subscribe(result -> { if (result != null) { items = result; - itemsLoaded = true; if (viewCreated && getActivity() != null) { onFragmentLoaded(); } |