diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java index bd07c4a45..e8e034afa 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -71,7 +71,7 @@ public class SubscriptionsAdapter extends BaseAdapter { } else { holder = (Holder) convertView.getTag(); } - + holder.feedTitle.setText(feed.getTitle()); Glide.with(context) .load(feed.getImageUri()) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index b932e1a1b..d25d7f2c3 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -1,9 +1,14 @@ package de.danoeh.antennapod.fragment; +import android.content.DialogInterface; +import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; +import android.view.ContextMenu; import android.view.LayoutInflater; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -16,8 +21,14 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.adapter.SubscriptionsAdapter; +import de.danoeh.antennapod.core.asynctask.FeedRemover; +import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.core.util.FeedItemUtil; import de.greenrobot.event.EventBus; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; @@ -36,6 +47,7 @@ public class SubscriptionFragment extends Fragment { private NavListAdapter.ItemAccess mItemAccess; private List mSubscriptionList = new ArrayList<>(); + private int mPosition = -1; public SubscriptionFragment() { @@ -57,6 +69,7 @@ public class SubscriptionFragment extends Fragment { Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_subscriptions, container, false); mSubscriptionGridLayout = (GridView) root.findViewById(R.id.subscriptions_grid); + registerForContextMenu(mSubscriptionGridLayout); return root; } @@ -67,18 +80,7 @@ public class SubscriptionFragment extends Fragment { mSubscriptionGridLayout.setAdapter(mSubscriptionAdapter); - Observable.fromCallable(() -> loadData()) - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(result -> { - mDrawerData = result; - mSubscriptionList = mDrawerData.feeds; - mSubscriptionAdapter.setItemAccess(mItemAccess); - mSubscriptionAdapter.notifyDataSetChanged(); - }, error -> { - Log.e(TAG, Log.getStackTraceString(error)); - }); - + loadSubscriptions(); mSubscriptionGridLayout.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -93,6 +95,86 @@ public class SubscriptionFragment extends Fragment { } + private void loadSubscriptions() { + Observable.fromCallable(() -> DBReader.getNavDrawerData()) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(result -> { + mDrawerData = result; + mSubscriptionList = mDrawerData.feeds; + mSubscriptionAdapter.setItemAccess(mItemAccess); + mSubscriptionAdapter.notifyDataSetChanged(); + }, error -> { + Log.e(TAG, Log.getStackTraceString(error)); + }); + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + AdapterView.AdapterContextMenuInfo adapterInfo = (AdapterView.AdapterContextMenuInfo) menuInfo; + int position = adapterInfo.position; + + MenuInflater inflater = getActivity().getMenuInflater(); + inflater.inflate(R.menu.nav_feed_context, menu); + Feed feed = (Feed)mSubscriptionAdapter.getItem(position); + menu.setHeaderTitle(feed.getTitle()); + + mPosition = position; + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + + final int position = mPosition; + mPosition = -1; // reset + if(position < 0) { + return false; + } + Feed feed = mDrawerData.feeds.get(position); + switch(item.getItemId()) { + case R.id.mark_all_seen_item: + DBWriter.markFeedSeen(feed.getId()); + return true; + case R.id.mark_all_read_item: + DBWriter.markFeedRead(feed.getId()); + return true; + case R.id.remove_item: + final FeedRemover remover = new FeedRemover(getContext(), feed) { + @Override + protected void onPostExecute(Void result) { + super.onPostExecute(result); + loadSubscriptions(); + } + }; + ConfirmationDialog conDialog = new ConfirmationDialog(getContext(), + R.string.remove_feed_label, + R.string.feed_delete_confirmation_msg) { + @Override + public void onConfirmButtonPressed( + DialogInterface dialog) { + dialog.dismiss(); + long mediaId = PlaybackPreferences.getCurrentlyPlayingFeedMediaId(); + if (mediaId > 0 && + FeedItemUtil.indexOfItemWithMediaId(feed.getItems(), mediaId) >= 0) { + Log.d(TAG, "Currently playing episode is about to be deleted, skipping"); + remover.skipOnCompletion = true; + int playerStatus = PlaybackPreferences.getCurrentPlayerStatus(); + if(playerStatus == PlaybackPreferences.PLAYER_STATUS_PLAYING) { + getActivity().sendBroadcast(new Intent( + PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)); + } + } + remover.executeAsync(); + } + }; + conDialog.createNewDialog().show(); + return true; + default: + return super.onContextItemSelected(item); + } + } + @Override public void onResume() { super.onResume(); @@ -105,9 +187,4 @@ public class SubscriptionFragment extends Fragment { feed = f; } } - - - private DBReader.NavDrawerData loadData() { - return DBReader.getNavDrawerData(); - } }