switched to snackbar
This commit is contained in:
parent
358a96ef6e
commit
910363c3e4
|
@ -1,255 +0,0 @@
|
|||
package de.danoeh.antennapod.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget;
|
||||
import com.joanzapata.iconify.Iconify;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
|
||||
/**
|
||||
* List adapter for the list of new episodes
|
||||
*/
|
||||
public class AllEpisodesListAdapter extends BaseAdapter {
|
||||
|
||||
private static final String TAG = AllEpisodesListAdapter.class.getSimpleName();
|
||||
|
||||
private final Context context;
|
||||
private final ItemAccess itemAccess;
|
||||
private final ActionButtonCallback actionButtonCallback;
|
||||
private final ActionButtonUtils actionButtonUtils;
|
||||
private final boolean showOnlyNewEpisodes;
|
||||
|
||||
public AllEpisodesListAdapter(Context context, ItemAccess itemAccess, ActionButtonCallback actionButtonCallback,
|
||||
boolean showOnlyNewEpisodes) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.itemAccess = itemAccess;
|
||||
this.actionButtonUtils = new ActionButtonUtils(context);
|
||||
this.actionButtonCallback = actionButtonCallback;
|
||||
this.showOnlyNewEpisodes = showOnlyNewEpisodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return itemAccess.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return itemAccess.getItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Holder holder;
|
||||
final FeedItem item = (FeedItem) getItem(position);
|
||||
if (item == null) return null;
|
||||
|
||||
if (convertView == null) {
|
||||
holder = new Holder();
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.new_episodes_listitem,
|
||||
parent, false);
|
||||
holder.placeholder = (TextView) convertView.findViewById(R.id.txtvPlaceholder);
|
||||
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
|
||||
holder.pubDate = (TextView) convertView
|
||||
.findViewById(R.id.txtvPublished);
|
||||
holder.statusUnread = convertView.findViewById(R.id.statusUnread);
|
||||
holder.butSecondary = (ImageButton) convertView
|
||||
.findViewById(R.id.butSecondaryAction);
|
||||
holder.queueStatus = (ImageView) convertView
|
||||
.findViewById(R.id.imgvInPlaylist);
|
||||
holder.progress = (ProgressBar) convertView
|
||||
.findViewById(R.id.pbar_progress);
|
||||
holder.cover = (ImageView) convertView.findViewById(R.id.imgvCover);
|
||||
holder.txtvDuration = (TextView) convertView.findViewById(R.id.txtvDuration);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.placeholder.setVisibility(View.VISIBLE);
|
||||
holder.placeholder.setText(item.getFeed().getTitle());
|
||||
holder.title.setText(item.getTitle());
|
||||
holder.pubDate.setText(DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL));
|
||||
if (showOnlyNewEpisodes || false == item.isNew()) {
|
||||
holder.statusUnread.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
holder.statusUnread.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
FeedMedia media = item.getMedia();
|
||||
if (media != null) {
|
||||
final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media);
|
||||
|
||||
if (media.getDuration() > 0) {
|
||||
holder.txtvDuration.setText(Converter.getDurationStringLong(media.getDuration()));
|
||||
} else if (media.getSize() > 0) {
|
||||
holder.txtvDuration.setText(Converter.byteToString(media.getSize()));
|
||||
} else if(false == media.checkedOnSizeButUnknown()) {
|
||||
holder.txtvDuration.setText("{fa-spinner}");
|
||||
Iconify.addIcons(holder.txtvDuration);
|
||||
NetworkUtils.getFeedMediaSizeObservable(media)
|
||||
.subscribe(
|
||||
size -> {
|
||||
if (size > 0) {
|
||||
holder.txtvDuration.setText(Converter.byteToString(size));
|
||||
} else {
|
||||
holder.txtvDuration.setText("");
|
||||
}
|
||||
}, error -> {
|
||||
holder.txtvDuration.setText("");
|
||||
Log.e(TAG, Log.getStackTraceString(error));
|
||||
});
|
||||
} else {
|
||||
holder.txtvDuration.setText("");
|
||||
}
|
||||
|
||||
FeedItem.State state = item.getState();
|
||||
if (isDownloadingMedia) {
|
||||
holder.progress.setVisibility(View.VISIBLE);
|
||||
// item is being downloaded
|
||||
holder.progress.setProgress(itemAccess.getItemDownloadProgressPercent(item));
|
||||
} else if (state == FeedItem.State.PLAYING
|
||||
|| state == FeedItem.State.IN_PROGRESS) {
|
||||
if (media.getDuration() > 0) {
|
||||
int progress = (int) (100.0 * media.getPosition() / media.getDuration());
|
||||
holder.progress.setProgress(progress);
|
||||
holder.progress.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
holder.progress.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
} else {
|
||||
holder.progress.setVisibility(View.GONE);
|
||||
holder.txtvDuration.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (itemAccess.isInQueue(item)) {
|
||||
holder.queueStatus.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.queueStatus.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
actionButtonUtils.configureActionButton(holder.butSecondary, item);
|
||||
holder.butSecondary.setFocusable(false);
|
||||
holder.butSecondary.setTag(item);
|
||||
holder.butSecondary.setOnClickListener(secondaryActionListener);
|
||||
|
||||
Glide.with(context)
|
||||
.load(item.getImageUri())
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.fitCenter()
|
||||
.dontAnimate()
|
||||
.into(new CoverTarget(item.getFeed().getImageUri(), holder.placeholder, holder.cover));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class CoverTarget extends GlideDrawableImageViewTarget {
|
||||
|
||||
private final WeakReference<Uri> fallback;
|
||||
private final WeakReference<TextView> placeholder;
|
||||
private final WeakReference<ImageView> cover;
|
||||
|
||||
public CoverTarget(Uri fallbackUri, TextView txtvPlaceholder, ImageView imgvCover) {
|
||||
super(imgvCover);
|
||||
fallback = new WeakReference<>(fallbackUri);
|
||||
placeholder = new WeakReference<>(txtvPlaceholder);
|
||||
cover = new WeakReference<>(imgvCover);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
Uri fallbackUri = fallback.get();
|
||||
TextView txtvPlaceholder = placeholder.get();
|
||||
ImageView imgvCover = cover.get();
|
||||
if(fallbackUri != null && txtvPlaceholder != null && imgvCover != null) {
|
||||
Glide.with(context)
|
||||
.load(fallbackUri)
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.fitCenter()
|
||||
.dontAnimate()
|
||||
.into(new CoverTarget(null, txtvPlaceholder, imgvCover));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
|
||||
super.onResourceReady(drawable, anim);
|
||||
TextView txtvPlaceholder = placeholder.get();
|
||||
if(txtvPlaceholder != null) {
|
||||
txtvPlaceholder.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private View.OnClickListener secondaryActionListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FeedItem item = (FeedItem) v.getTag();
|
||||
actionButtonCallback.onActionButtonPressed(item);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static class Holder {
|
||||
TextView placeholder;
|
||||
TextView title;
|
||||
TextView pubDate;
|
||||
View statusUnread;
|
||||
ImageView queueStatus;
|
||||
ImageView cover;
|
||||
ProgressBar progress;
|
||||
TextView txtvDuration;
|
||||
ImageButton butSecondary;
|
||||
}
|
||||
|
||||
public interface ItemAccess {
|
||||
|
||||
int getCount();
|
||||
|
||||
FeedItem getItem(int position);
|
||||
|
||||
int getItemDownloadProgressPercent(FeedItem item);
|
||||
|
||||
boolean isInQueue(FeedItem item);
|
||||
|
||||
}
|
||||
}
|
|
@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.adapter.AllEpisodesListAdapter;
|
||||
import de.danoeh.antennapod.adapter.AllEpisodesRecycleAdapter;
|
||||
import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
|
||||
import de.danoeh.antennapod.core.asynctask.DownloadObserver;
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.danoeh.antennapod.fragment;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
|
@ -35,8 +36,6 @@ public class FavoriteEpisodesFragment extends AllEpisodesFragment {
|
|||
|
||||
private static final String PREF_NAME = "PrefFavoriteEpisodesFragment";
|
||||
|
||||
private UndoBarController undoBarController;
|
||||
|
||||
public FavoriteEpisodesFragment() {
|
||||
super(false, PREF_NAME);
|
||||
}
|
||||
|
@ -61,13 +60,12 @@ public class FavoriteEpisodesFragment extends AllEpisodesFragment {
|
|||
@Override
|
||||
protected void resetViewState() {
|
||||
super.resetViewState();
|
||||
undoBarController = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = super.onCreateViewHelper(inflater, container, savedInstanceState,
|
||||
R.layout.episodes_fragment_with_undo);
|
||||
R.layout.all_episodes_fragment);
|
||||
|
||||
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
|
||||
@Override
|
||||
|
@ -87,34 +85,18 @@ public class FavoriteEpisodesFragment extends AllEpisodesFragment {
|
|||
if (item != null) {
|
||||
DBWriter.removeFavoriteItem(item);
|
||||
|
||||
undoBarController.showUndoBar(false,
|
||||
getString(R.string.removed_item), new FeedItemUndoToken(item,
|
||||
holder.getItemPosition())
|
||||
);
|
||||
Snackbar snackbar = Snackbar.make(root, getString(R.string.removed_item),
|
||||
Snackbar.LENGTH_LONG);
|
||||
snackbar.setAction(getString(R.string.undo), v -> {
|
||||
DBWriter.addFavoriteItem(item);
|
||||
});
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
@Override
|
||||
public void onUndo(FeedItemUndoToken token) {
|
||||
if (token != null) {
|
||||
long itemId = token.getFeedItemId();
|
||||
DBWriter.addFavoriteItemById(itemId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHide(FeedItemUndoToken token) {
|
||||
// nothing to do
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ package de.danoeh.antennapod.fragment;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
|
@ -19,6 +21,7 @@ import de.danoeh.antennapod.adapter.AllEpisodesRecycleAdapter;
|
|||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.event.QueueEvent;
|
||||
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.core.util.LongList;
|
||||
|
@ -38,8 +41,6 @@ public class NewEpisodesFragment extends AllEpisodesFragment {
|
|||
|
||||
private static final String PREF_NAME = "PrefNewEpisodesFragment";
|
||||
|
||||
private UndoBarController undoBarController;
|
||||
|
||||
public NewEpisodesFragment() {
|
||||
super(true, PREF_NAME);
|
||||
}
|
||||
|
@ -64,13 +65,12 @@ public class NewEpisodesFragment extends AllEpisodesFragment {
|
|||
@Override
|
||||
protected void resetViewState() {
|
||||
super.resetViewState();
|
||||
undoBarController = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = super.onCreateViewHelper(inflater, container, savedInstanceState,
|
||||
R.layout.episodes_fragment_with_undo);
|
||||
R.layout.all_episodes_fragment);
|
||||
|
||||
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
|
||||
@Override
|
||||
|
@ -81,6 +81,7 @@ public class NewEpisodesFragment extends AllEpisodesFragment {
|
|||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
|
||||
AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder)viewHolder;
|
||||
|
||||
Log.d(TAG, "remove(" + holder.getItemId() + ")");
|
||||
if (subscription != null) {
|
||||
subscription.unsubscribe();
|
||||
|
@ -89,38 +90,28 @@ public class NewEpisodesFragment extends AllEpisodesFragment {
|
|||
// we're marking it as unplayed since the user didn't actually play it
|
||||
// but they don't want it considered 'NEW' anymore
|
||||
DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
|
||||
undoBarController.showUndoBar(false,
|
||||
getString(R.string.marked_as_read_label), new FeedItemUndoToken(item,
|
||||
holder.getItemPosition()));
|
||||
|
||||
final Handler h = new Handler(getActivity().getMainLooper());
|
||||
final Runnable r = () -> {
|
||||
FeedMedia media = item.getMedia();
|
||||
if (media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) {
|
||||
DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId());
|
||||
}
|
||||
};
|
||||
|
||||
Snackbar snackbar = Snackbar.make(root, getString(R.string.marked_as_read_label),
|
||||
Snackbar.LENGTH_LONG);
|
||||
snackbar.setAction(getString(R.string.undo), v -> {
|
||||
DBWriter.markItemPlayed(FeedItem.NEW, item.getId());
|
||||
});
|
||||
snackbar.show();
|
||||
h.postDelayed(r, (int)Math.ceil(snackbar.getDuration() * 1.05f));
|
||||
}
|
||||
};
|
||||
|
||||
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
|
||||
itemTouchHelper.attachToRecyclerView(listView);
|
||||
|
||||
undoBarController = new UndoBarController<FeedItemUndoToken>(root.findViewById(R.id.undobar), new UndoBarController.UndoListener<FeedItemUndoToken>() {
|
||||
|
||||
private final Context context = getActivity();
|
||||
|
||||
@Override
|
||||
public void onUndo(FeedItemUndoToken token) {
|
||||
if (token != null) {
|
||||
long itemId = token.getFeedItemId();
|
||||
DBWriter.markItemPlayed(FeedItem.NEW, itemId);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onHide(FeedItemUndoToken token) {
|
||||
if (token != null && context != null) {
|
||||
long itemId = token.getFeedItemId();
|
||||
FeedItem item = DBReader.getFeedItem(itemId);
|
||||
FeedMedia media = item.getMedia();
|
||||
if(media != null && media.hasAlmostEnded() && item.getFeed().getPreferences().getCurrentAutoDelete()) {
|
||||
DBWriter.deleteFeedMediaOfItem(context, media.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dslv="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
android:paddingTop="@dimen/list_vertical_padding"
|
||||
android:paddingBottom="@dimen/list_vertical_padding"
|
||||
android:clipToPadding="false"/>
|
||||
<!--
|
||||
<com.mobeta.android.dslv.DragSortListView
|
||||
android:id="@android:id/list"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="@dimen/list_vertical_padding"
|
||||
android:paddingBottom="@dimen/list_vertical_padding"
|
||||
android:clipToPadding="false"
|
||||
dslv:collapsed_height="2dp"
|
||||
dslv:drag_enabled="true"
|
||||
dslv:drag_handle_id="@id/drag_handle"
|
||||
dslv:drag_scroll_start="0.33"
|
||||
dslv:float_alpha="0.6"
|
||||
dslv:max_drag_scroll_speed="0.5"
|
||||
dslv:remove_enabled="true"
|
||||
dslv:remove_mode="flingRemove"
|
||||
dslv:slide_shuffle_speed="0.3"
|
||||
dslv:sort_enabled="false"
|
||||
dslv:track_drag_sort="false"
|
||||
dslv:float_background_color="?attr/dragview_float_background"
|
||||
dslv:use_default_controller="true"
|
||||
tools:background="@android:color/holo_green_dark"/>
|
||||
-->
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progLoading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:indeterminateOnly="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:layout_width="match_parent"
|
||||
tools:layout_height="64dp"
|
||||
tools:background="@android:color/holo_red_light"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/undobar"
|
||||
style="@style/UndoBar">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/undobar_message"
|
||||
style="@style/UndoBarMessage"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/undobar_button"
|
||||
style="@style/UndoBarButton"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue