undo for favorites

This commit is contained in:
Tom Hennen 2015-10-10 15:38:00 -04:00
parent 8f5e0bb5e4
commit 7489046037
2 changed files with 35 additions and 18 deletions

View File

@ -79,7 +79,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
.findViewById(R.id.pbar_progress);
holder.cover = (ImageView) view.findViewById(R.id.imgvCover);
holder.txtvDuration = (TextView) view.findViewById(R.id.txtvDuration);
holder.itemId = 0;
holder.item = null;
holder.mainActivity = mainActivity;
return holder;
@ -89,7 +89,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
public void onBindViewHolder(final Holder holder, int position) {
final FeedItem item = itemAccess.getItem(position);
if (item == null) return;
holder.itemId = item.getId();
holder.item = item;
holder.placeholder.setVisibility(View.VISIBLE);
holder.placeholder.setText(item.getFeed().getTitle());
holder.title.setText(item.getTitle());
@ -239,7 +239,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
ProgressBar progress;
TextView txtvDuration;
ImageButton butSecondary;
long itemId;
FeedItem item;
MainActivity mainActivity;
public Holder(View itemView) {
@ -251,9 +251,11 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
@Override
public void onClick(View v) {
if (mainActivity != null) {
mainActivity.loadChildFragment(ItemFragment.newInstance(itemId));
mainActivity.loadChildFragment(ItemFragment.newInstance(item.getId()));
}
}
public FeedItem getFeedItem() { return item; }
}
public interface ItemAccess {

View File

@ -3,6 +3,8 @@ package de.danoeh.antennapod.fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.util.Pair;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -11,6 +13,7 @@ import android.view.ViewGroup;
import java.util.List;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.AllEpisodesRecycleAdapter;
import de.danoeh.antennapod.core.event.FavoritesEvent;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.storage.DBReader;
@ -66,24 +69,36 @@ public class FavoriteEpisodesFragment extends AllEpisodesFragment {
View root = super.onCreateViewHelper(inflater, container, savedInstanceState,
R.layout.episodes_fragment_with_undo);
/** TODO!
listView.setRemoveListener(which -> {
Log.d(TAG, "remove(" + which + ")");
if (subscription != null) {
subscription.unsubscribe();
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
FeedItem item = (FeedItem) listView.getAdapter().getItem(which);
DBWriter.removeFavoriteItem(item);
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder)viewHolder;
Log.d(TAG, "remove(" + holder.getItemId() + ")");
undoBarController.showUndoBar(false,
getString(R.string.removed_item), new FeedItemUndoToken(item,
which)
);
});
*/
if (subscription != null) {
subscription.unsubscribe();
}
FeedItem item = holder.getFeedItem();
if (item != null) {
DBWriter.removeFavoriteItem(item);
undoBarController = new UndoBarController<FeedItemUndoToken>(root.findViewById(R.id.undobar), new UndoBarController.UndoListener<FeedItemUndoToken>() {
undoBarController.showUndoBar(false,
getString(R.string.removed_item), new FeedItemUndoToken(item,
0)
);
}
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(listView);
undoBarController = new UndoBarController<>(root.findViewById(R.id.undobar), new UndoBarController.UndoListener<FeedItemUndoToken>() {
private final Context context = getActivity();