Merge pull request #1842 from TomHennen/subscriptions_fixup

Subscriptions fixup
This commit is contained in:
Tom Hennen 2016-04-01 19:34:31 -04:00
commit 4defb50557
13 changed files with 146 additions and 160 deletions

View File

@ -302,7 +302,6 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity
break;
case SubscriptionFragment.TAG:
SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
subscriptionFragment.setItemAccess(itemAccess);
fragment = subscriptionFragment;
break;
default:

View File

@ -1,7 +1,5 @@
package de.danoeh.antennapod.adapter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
@ -19,9 +17,6 @@ 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 com.nineoldandroids.view.ViewHelper;
@ -197,7 +192,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
.fitCenter()
.dontAnimate()
.into(new CoverTarget(item.getFeed().getImageUri(), holder.placeholder, holder.cover));
.into(new CoverTarget(item.getFeed().getImageUri(), holder.placeholder, holder.cover, mainActivityRef.get()));
}
@Override
@ -221,44 +216,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
return pos;
}
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(mainActivityRef.get())
.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) {

View File

@ -0,0 +1,58 @@
package de.danoeh.antennapod.adapter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
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 java.lang.ref.WeakReference;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.glide.ApGlideSettings;
class CoverTarget extends GlideDrawableImageViewTarget {
private final WeakReference<Uri> fallback;
private final WeakReference<TextView> placeholder;
private final WeakReference<ImageView> cover;
private final WeakReference<MainActivity> mainActivity;
public CoverTarget(Uri fallbackUri, TextView txtvPlaceholder, ImageView imgvCover, MainActivity activity) {
super(imgvCover);
fallback = new WeakReference<>(fallbackUri);
placeholder = new WeakReference<>(txtvPlaceholder);
cover = new WeakReference<>(imgvCover);
mainActivity = new WeakReference<>(activity);
}
@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) {
MainActivity activity = mainActivity.get();
Glide.with(activity)
.load(fallbackUri)
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
.fitCenter()
.dontAnimate()
.into(new CoverTarget(null, txtvPlaceholder, imgvCover, activity));
}
}
@Override
public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
super.onResourceReady(drawable, anim);
TextView txtvPlaceholder = placeholder.get();
if (txtvPlaceholder != null) {
txtvPlaceholder.setVisibility(View.INVISIBLE);
}
}
}

View File

@ -1,7 +1,5 @@
package de.danoeh.antennapod.adapter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.MotionEventCompat;
@ -23,9 +21,6 @@ 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 com.nineoldandroids.view.ViewHelper;
@ -297,49 +292,10 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
.fitCenter()
.dontAnimate()
.into(new CoverTarget(item.getFeed().getImageUri(), placeholder, cover));
.into(new CoverTarget(item.getFeed().getImageUri(), placeholder, cover, mainActivity.get()));
}
}
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(mainActivity.get())
.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

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.adapter;
import android.content.Context;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -12,9 +13,6 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import java.lang.ref.WeakReference;
@ -36,17 +34,13 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
/** the position in the view that holds the add item */
private static final int ADD_POSITION = 0;
private NavListAdapter.ItemAccess itemAccess;
private static final String TAG = "SubscriptionsAdapter";
private final WeakReference<MainActivity> mainActivityRef;
private final ItemAccess itemAccess;
public SubscriptionsAdapter(MainActivity mainActivity, NavListAdapter.ItemAccess itemAccess) {
this.itemAccess = itemAccess;
public SubscriptionsAdapter(MainActivity mainActivity, ItemAccess itemAccess) {
this.mainActivityRef = new WeakReference<>(mainActivity);
}
public void setItemAccess(NavListAdapter.ItemAccess itemAccess) {
this.itemAccess = itemAccess;
}
@ -96,41 +90,34 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
}
if (position == ADD_POSITION) {
holder.feedTitle.setText(R.string.add_feed_label);
holder.feedTitle.setText("{md-add 500%}\n\n" + mainActivityRef.get().getString(R.string.add_feed_label));
holder.feedTitle.setVisibility(View.VISIBLE);
// prevent any accidental re-use of old values (not sure how that would happen...)
holder.count.setPrimaryText("");
// make it go away, we don't need it for add feed
holder.count.setVisibility(View.INVISIBLE);
Glide.with(mainActivityRef.get())
.load(R.drawable.ic_add_grey_600_48dp)
.dontAnimate()
.into(holder.imageView);
return convertView;
}
final Feed feed = (Feed) getItem(position);
if (feed == null) return null;
holder.feedTitle.setText(feed.getTitle());
String title = feed.getTitle();
long feedId = feed.getId();
int counter = itemAccess.getFeedCounter(feedId);
Uri imageUri = feed.getImageUri();
Log.i(TAG, String.format("Title: %s id: %d counter: %d uri: %s", title, feedId, counter, imageUri.toString()));
holder.feedTitle.setText(title);
holder.feedTitle.setVisibility(View.VISIBLE);
holder.count.setPrimaryText(String.valueOf(counter));
holder.count.setVisibility(View.VISIBLE);
holder.count.setPrimaryText(String.valueOf(itemAccess.getFeedCounter(feed.getId())));
Glide.with(mainActivityRef.get())
.load(feed.getImageUri())
.placeholder(R.color.light_gray)
.load(imageUri)
.error(R.color.light_gray)
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
.fitCenter()
.dontAnimate()
.listener(new RequestListener<Uri, GlideDrawable>() {
@Override
public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
holder.feedTitle.setVisibility(View.INVISIBLE);
return false;
}
})
.into(holder.imageView);
.into(new CoverTarget(null, holder.feedTitle, holder.imageView, mainActivityRef.get()));
return convertView;
}
@ -150,4 +137,10 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
public ImageView imageView;
public TriangleLabelView count;
}
public interface ItemAccess {
int getCount();
Feed getItem(int position);
int getFeedCounter(long feedId);
}
}

View File

@ -14,15 +14,12 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import java.util.ArrayList;
import java.util.List;
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.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
@ -40,23 +37,19 @@ public class SubscriptionFragment extends Fragment {
public static final String TAG = "SubscriptionFragment";
private GridView mSubscriptionGridLayout;
private DBReader.NavDrawerData mDrawerData;
private SubscriptionsAdapter mSubscriptionAdapter;
private NavListAdapter.ItemAccess mItemAccess;
private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE
| EventDistributor.UNREAD_ITEMS_UPDATE;
private GridView subscriptionGridLayout;
private DBReader.NavDrawerData navDrawerData;
private SubscriptionsAdapter subscriptionAdapter;
private List<Feed> mSubscriptionList = new ArrayList<>();
private int mPosition = -1;
public SubscriptionFragment() {
}
public void setItemAccess(NavListAdapter.ItemAccess itemAccess) {
mItemAccess = itemAccess;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -67,26 +60,27 @@ public class SubscriptionFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_subscriptions, container, false);
mSubscriptionGridLayout = (GridView) root.findViewById(R.id.subscriptions_grid);
registerForContextMenu(mSubscriptionGridLayout);
subscriptionGridLayout = (GridView) root.findViewById(R.id.subscriptions_grid);
registerForContextMenu(subscriptionGridLayout);
return root;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mSubscriptionAdapter = new SubscriptionsAdapter((MainActivity)getActivity(), mItemAccess);
subscriptionAdapter = new SubscriptionsAdapter((MainActivity)getActivity(), itemAccess);
mSubscriptionGridLayout.setAdapter(mSubscriptionAdapter);
subscriptionGridLayout.setAdapter(subscriptionAdapter);
loadSubscriptions();
mSubscriptionGridLayout.setOnItemClickListener(mSubscriptionAdapter);
subscriptionGridLayout.setOnItemClickListener(subscriptionAdapter);
if (getActivity() instanceof MainActivity) {
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.subscriptions_label);
}
EventDistributor.getInstance().register(contentUpdate);
}
private void loadSubscriptions() {
@ -94,10 +88,8 @@ public class SubscriptionFragment extends Fragment {
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
mDrawerData = result;
mSubscriptionList = mDrawerData.feeds;
mSubscriptionAdapter.setItemAccess(mItemAccess);
mSubscriptionAdapter.notifyDataSetChanged();
navDrawerData = result;
subscriptionAdapter.notifyDataSetChanged();
}, error -> {
Log.e(TAG, Log.getStackTraceString(error));
});
@ -109,7 +101,7 @@ public class SubscriptionFragment extends Fragment {
AdapterView.AdapterContextMenuInfo adapterInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
int position = adapterInfo.position;
Object selectedObject = mSubscriptionAdapter.getItem(position);
Object selectedObject = subscriptionAdapter.getItem(position);
if (selectedObject.equals(SubscriptionsAdapter.ADD_ITEM_OBJ)) {
mPosition = position;
return;
@ -134,7 +126,7 @@ public class SubscriptionFragment extends Fragment {
return false;
}
Object selectedObject = mSubscriptionAdapter.getItem(position);
Object selectedObject = subscriptionAdapter.getItem(position);
if (selectedObject.equals(SubscriptionsAdapter.ADD_ITEM_OBJ)) {
// this is the add object, do nothing
return false;
@ -201,5 +193,41 @@ public class SubscriptionFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
loadSubscriptions();
}
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
@Override
public void update(EventDistributor eventDistributor, Integer arg) {
if ((EVENTS & arg) != 0) {
Log.d(TAG, "Received contentUpdate Intent.");
loadSubscriptions();
}
}
};
private SubscriptionsAdapter.ItemAccess itemAccess = new SubscriptionsAdapter.ItemAccess() {
@Override
public int getCount() {
if (navDrawerData != null) {
return navDrawerData.feeds.size();
} else {
return 0;
}
}
@Override
public Feed getItem(int position) {
if (navDrawerData != null && 0 <= position && position < navDrawerData.feeds.size()) {
return navDrawerData.feeds.get(position);
} else {
return null;
}
}
@Override
public int getFeedCounter(long feedId) {
return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0;
}
};
}

View File

@ -15,20 +15,13 @@
android:scaleType="centerCrop"
tools:src="@drawable/ic_launcher" />
<TextView
<com.joanzapata.iconify.widget.IconTextView
android:id="@+id/txtvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="@dimen/widget_margin"
android:layout_height="match_parent"
android:ellipsize="end"
android:padding="@dimen/widget_margin"
style="@style/AntennaPod.TextView.Heading"
android:textSize="15sp"
android:textStyle="bold"
android:layout_gravity="bottom"
android:textColor="@android:color/white"
android:background="#55000000"
android:gravity="center"
android:background="@color/light_gray"
tools:text="@string/app_name" />
<jp.shts.android.library.TriangleLabelView
@ -37,10 +30,10 @@
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
app:backgroundColor="#bbbfbfbf"
app:backgroundColor="@color/antennapod_blue"
app:corner="rightTop"
app:primaryText="Test"
app:primaryTextColor="@color/grey600"
app:primaryTextColor="@color/white"
app:primaryTextSize="12sp"
android:layout_gravity="right|top"/>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 608 B

View File

@ -31,4 +31,6 @@
<color name="highlight_light">#DDDDDD</color>
<color name="highlight_dark">#414141</color>
<color name="antennapod_blue">#147BAF</color>
</resources>