diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 4103be5c1..fbbc87508 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -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: diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index d141e0239..1f95b22c6 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -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 fallback; - private final WeakReference placeholder; - private final WeakReference 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) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/CoverTarget.java b/app/src/main/java/de/danoeh/antennapod/adapter/CoverTarget.java new file mode 100644 index 000000000..ed0c08086 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/adapter/CoverTarget.java @@ -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 fallback; + private final WeakReference placeholder; + private final WeakReference cover; + private final WeakReference 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); + } + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index 981d7563a..b6e3a3d82 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -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 fallback; - private final WeakReference placeholder; - private final WeakReference 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 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 d10674819..f865ae001 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -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 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() { - @Override - public boolean onException(Exception e, Uri model, Target target, boolean isFirstResource) { - return false; - } - - @Override - public boolean onResourceReady(GlideDrawable resource, Uri model, Target 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); + } } 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 b3af107c7..54b358ddd 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -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 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; + } + }; } diff --git a/app/src/main/res/layout/subscription_item.xml b/app/src/main/res/layout/subscription_item.xml index ffbcc33f1..19b9943e4 100644 --- a/app/src/main/res/layout/subscription_item.xml +++ b/app/src/main/res/layout/subscription_item.xml @@ -15,20 +15,13 @@ android:scaleType="centerCrop" tools:src="@drawable/ic_launcher" /> - diff --git a/core/src/main/res/drawable-hdpi/ic_add_grey_600_48dp.png b/core/src/main/res/drawable-hdpi/ic_add_grey_600_48dp.png deleted file mode 100644 index fdd230339..000000000 Binary files a/core/src/main/res/drawable-hdpi/ic_add_grey_600_48dp.png and /dev/null differ diff --git a/core/src/main/res/drawable-mdpi/ic_add_grey_600_48dp.png b/core/src/main/res/drawable-mdpi/ic_add_grey_600_48dp.png deleted file mode 100644 index 22cc91fd0..000000000 Binary files a/core/src/main/res/drawable-mdpi/ic_add_grey_600_48dp.png and /dev/null differ diff --git a/core/src/main/res/drawable-xhdpi/ic_add_grey_600_48dp.png b/core/src/main/res/drawable-xhdpi/ic_add_grey_600_48dp.png deleted file mode 100644 index d45901646..000000000 Binary files a/core/src/main/res/drawable-xhdpi/ic_add_grey_600_48dp.png and /dev/null differ diff --git a/core/src/main/res/drawable-xxhdpi/ic_add_grey_600_48dp.png b/core/src/main/res/drawable-xxhdpi/ic_add_grey_600_48dp.png deleted file mode 100644 index 6e83122fd..000000000 Binary files a/core/src/main/res/drawable-xxhdpi/ic_add_grey_600_48dp.png and /dev/null differ diff --git a/core/src/main/res/drawable-xxxhdpi/ic_add_grey_600_48dp.png b/core/src/main/res/drawable-xxxhdpi/ic_add_grey_600_48dp.png deleted file mode 100644 index 014ee87ca..000000000 Binary files a/core/src/main/res/drawable-xxxhdpi/ic_add_grey_600_48dp.png and /dev/null differ diff --git a/core/src/main/res/values/colors.xml b/core/src/main/res/values/colors.xml index ff061be4c..a570a3fcb 100644 --- a/core/src/main/res/values/colors.xml +++ b/core/src/main/res/values/colors.xml @@ -31,4 +31,6 @@ #DDDDDD #414141 + #147BAF +