Skip to content

Commit

Permalink
Use one Glide instance per NewsListRecyclerAdapter
Browse files Browse the repository at this point in the history
Signed-off-by: Unpublished <unpublished@gmx.net>
  • Loading branch information
Unpublished committed Apr 1, 2024
1 parent 9faaf90 commit 8d97c0a
Show file tree
Hide file tree
Showing 10 changed files with 1,206 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

Expand All @@ -32,6 +35,7 @@
import de.luhmer.owncloudnewsreader.databinding.SubscriptionDetailListItemWebLayoutBinding;
import de.luhmer.owncloudnewsreader.events.podcast.PodcastCompletedEvent;
import de.luhmer.owncloudnewsreader.helper.AsyncTaskHelper;
import de.luhmer.owncloudnewsreader.helper.FavIconHandler;
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
import de.luhmer.owncloudnewsreader.helper.StopWatch;
import de.luhmer.owncloudnewsreader.interfaces.IPlayPausePodcastClicked;
Expand All @@ -43,6 +47,8 @@ public class NewsListRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.V
@SuppressWarnings("FieldCanBeLocal")
private final int VIEW_ITEM = 1; // Item
private final int VIEW_PROG = 0; // Progress
private final FavIconHandler faviconHandler;
private final RequestManager glide;

private long idOfCurrentlyPlayedPodcast = -1;

Expand Down Expand Up @@ -70,6 +76,8 @@ public NewsListRecyclerAdapter(FragmentActivity activity, RecyclerView recyclerV
pDelayHandler = postDelayHandler;

dbConn = new DatabaseConnectionOrm(activity);
faviconHandler = new FavIconHandler(activity);
glide = Glide.with(activity);
setHasStableIds(true);

EventBus.getDefault().register(this);
Expand Down Expand Up @@ -170,25 +178,60 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
RssItemViewHolder viewHolder = null;
switch (Integer.parseInt(mPrefs.getString(SettingsActivity.SP_FEED_LIST_LAYOUT, "0"))) {
case 0:
viewHolder = new RssItemThumbnailViewHolder(SubscriptionDetailListItemThumbnailBinding.inflate(LayoutInflater.from(context), parent, false), mPrefs);
viewHolder = new RssItemThumbnailViewHolder(
SubscriptionDetailListItemThumbnailBinding.inflate(LayoutInflater.from(context), parent, false),
faviconHandler,
glide,
mPrefs
);
break;
case 1:
viewHolder = new RssItemTextViewHolder(SubscriptionDetailListItemTextBinding.inflate(LayoutInflater.from(context), parent, false), mPrefs);
viewHolder = new RssItemTextViewHolder(
SubscriptionDetailListItemTextBinding.inflate(LayoutInflater.from(context), parent, false),
faviconHandler,
glide,
mPrefs
);
break;
case 3:
viewHolder = new RssItemFullTextViewHolder(SubscriptionDetailListItemTextBinding.inflate(LayoutInflater.from(context), parent, false), mPrefs);
viewHolder = new RssItemFullTextViewHolder(
SubscriptionDetailListItemTextBinding.inflate(LayoutInflater.from(context), parent, false),
faviconHandler,
glide,
mPrefs
);
break;
case 2:
viewHolder = new RssItemWebViewHolder(SubscriptionDetailListItemWebLayoutBinding.inflate(LayoutInflater.from(context), parent, false), mPrefs);
viewHolder = new RssItemWebViewHolder(
SubscriptionDetailListItemWebLayoutBinding.inflate(LayoutInflater.from(context), parent, false),
faviconHandler,
glide,
mPrefs
);
break;
case 4:
viewHolder = new RssItemCardViewHolder(SubscriptionDetailListItemCardViewBinding.inflate(LayoutInflater.from(context), parent, false), mPrefs);
viewHolder = new RssItemCardViewHolder(
SubscriptionDetailListItemCardViewBinding.inflate(LayoutInflater.from(context), parent, false),
faviconHandler,
glide,
mPrefs
);
break;
case 5:
viewHolder = new RssItemHeadlineViewHolder(SubscriptionDetailListItemHeadlineBinding.inflate(LayoutInflater.from(context), parent, false), mPrefs);
viewHolder = new RssItemHeadlineViewHolder(
SubscriptionDetailListItemHeadlineBinding.inflate(LayoutInflater.from(context), parent, false),
faviconHandler,
glide,
mPrefs
);
break;
case 6:
viewHolder = new RssItemHeadlineThumbnailViewHolder(SubscriptionDetailListItemHeadlineThumbnailBinding.inflate(LayoutInflater.from(context), parent, false), mPrefs);
viewHolder = new RssItemHeadlineThumbnailViewHolder(
SubscriptionDetailListItemHeadlineThumbnailBinding.inflate(LayoutInflater.from(context), parent, false),
faviconHandler,
glide,
mPrefs
);
break;
default:
Log.e(TAG, "Unknown layout..");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,70 @@
package de.luhmer.owncloudnewsreader.adapter;
package de.luhmer.owncloudnewsreader.adapter

import android.content.SharedPreferences;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.content.SharedPreferences
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.annotation.CallSuper
import com.bumptech.glide.RequestManager
import de.luhmer.owncloudnewsreader.database.model.RssItem
import de.luhmer.owncloudnewsreader.databinding.SubscriptionDetailListItemCardViewBinding
import de.luhmer.owncloudnewsreader.helper.FavIconHandler

import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;

import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.databinding.SubscriptionDetailListItemCardViewBinding;

public class RssItemCardViewHolder extends RssItemViewHolder<SubscriptionDetailListItemCardViewBinding> {
RssItemCardViewHolder(@NonNull SubscriptionDetailListItemCardViewBinding binding, SharedPreferences sharedPreferences) {
super(binding, sharedPreferences);
}

@Override
protected ImageView getImageViewFavIcon() {
return binding.imgViewFavIcon;
class RssItemCardViewHolder internal constructor(
binding: SubscriptionDetailListItemCardViewBinding,
faviconHandler: FavIconHandler,
glide: RequestManager,
sharedPreferences: SharedPreferences,
) : RssItemViewHolder<SubscriptionDetailListItemCardViewBinding>(
binding,
faviconHandler,
glide,
sharedPreferences,
) {
override fun getImageViewFavIcon(): ImageView {
return binding.imgViewFavIcon
}

@Override
protected ImageView getStar() {
return binding.starImageview;
override fun getStar(): ImageView {
return binding.starImageview
}

@Override
protected ImageView getPlayPausePodcastButton() {
return binding.podcastWrapper.btnPlayPausePodcast;
override fun getPlayPausePodcastButton(): ImageView {
return binding.podcastWrapper.btnPlayPausePodcast
}

@Override
protected View getColorFeed() {
return binding.colorLineFeed;
override fun getColorFeed(): View {
return binding.colorLineFeed
}

@Override
protected TextView getTextViewTitle() {
return binding.tvSubscription;
override fun getTextViewTitle(): TextView {
return binding.tvSubscription
}

@Override
protected TextView getTextViewSummary() {
return binding.summary;
override fun getTextViewSummary(): TextView {
return binding.summary
}

@Override
protected TextView getTextViewBody() {
return binding.body;
override fun getTextViewBody(): TextView {
return binding.body
}

@Override
protected TextView getTextViewItemDate() {
return binding.tvItemDate;
override fun getTextViewItemDate(): TextView {
return binding.tvItemDate
}

@Override
protected FrameLayout getPlayPausePodcastWrapper() {
return binding.podcastWrapper.flPlayPausePodcastWrapper;
override fun getPlayPausePodcastWrapper(): FrameLayout {
return binding.podcastWrapper.flPlayPausePodcastWrapper
}

@Override
protected ProgressBar getPodcastDownloadProgress() {
return binding.podcastWrapper.podcastDownloadProgress;
override fun getPodcastDownloadProgress(): ProgressBar {
return binding.podcastWrapper.podcastDownloadProgress
}

@CallSuper
public void bind(@NonNull RssItem rssItem) {
super.bind(rssItem);
override fun bind(rssItem: RssItem) {
super.bind(rssItem)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.luhmer.owncloudnewsreader.adapter;

import android.content.SharedPreferences;

import androidx.annotation.NonNull;

import de.luhmer.owncloudnewsreader.databinding.SubscriptionDetailListItemTextBinding;

public class RssItemFullTextViewHolder extends RssItemTextViewHolder {
RssItemFullTextViewHolder(@NonNull SubscriptionDetailListItemTextBinding binding, SharedPreferences sharedPreferences) {
super(binding, sharedPreferences);
}
}
package de.luhmer.owncloudnewsreader.adapter

import android.content.SharedPreferences
import com.bumptech.glide.RequestManager
import de.luhmer.owncloudnewsreader.databinding.SubscriptionDetailListItemTextBinding
import de.luhmer.owncloudnewsreader.helper.FavIconHandler

class RssItemFullTextViewHolder internal constructor(
binding: SubscriptionDetailListItemTextBinding,
faviconHandler: FavIconHandler,
glide: RequestManager,
sharedPreferences: SharedPreferences,
) : RssItemTextViewHolder(binding, faviconHandler, glide, sharedPreferences)
Loading

0 comments on commit 8d97c0a

Please sign in to comment.