Inject Glide

This commit is contained in:
Shinokuni 2020-10-20 22:04:00 +02:00
parent f3330ba07d
commit aa59f890bb
6 changed files with 23 additions and 12 deletions

View File

@ -3,6 +3,7 @@ package com.readrops.app
import com.readrops.app.repositories.FreshRSSRepository
import com.readrops.app.repositories.LocalFeedRepository
import com.readrops.app.repositories.NextNewsRepository
import com.readrops.app.utils.GlideApp
import com.readrops.app.viewmodels.*
import com.readrops.db.entities.account.Account
import com.readrops.db.entities.account.AccountType
@ -46,4 +47,5 @@ val appModule = module {
AccountViewModel(get())
}
single { GlideApp.with(androidApplication()) }
}

View File

@ -33,7 +33,7 @@ import com.bumptech.glide.request.transition.Transition;
import com.readrops.api.utils.DateUtils;
import com.readrops.app.R;
import com.readrops.app.databinding.ActivityItemBinding;
import com.readrops.app.utils.GlideApp;
import com.readrops.app.utils.GlideRequests;
import com.readrops.app.utils.PermissionManager;
import com.readrops.app.utils.SharedPreferencesManager;
import com.readrops.app.utils.Utils;
@ -42,6 +42,7 @@ import com.readrops.db.entities.Item;
import com.readrops.db.pojo.ItemWithFeed;
import org.koin.androidx.viewmodel.compat.ViewModelCompat;
import org.koin.java.KoinJavaComponent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -93,7 +94,7 @@ public class ItemActivity extends AppCompatActivity {
binding.appBarLayout.setExpanded(true);
binding.collapsingLayout.setTitleEnabled(true);
GlideApp.with(this)
KoinJavaComponent.get(GlideRequests.class)
.load(imageUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(binding.collapsingLayoutImage);
@ -358,7 +359,7 @@ public class ItemActivity extends AppCompatActivity {
}
private void shareImage(String url) {
GlideApp.with(this)
KoinJavaComponent.get(GlideRequests.class)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.load(url)

View File

@ -37,7 +37,7 @@ import com.readrops.app.R;
import com.readrops.app.adapters.MainItemListAdapter;
import com.readrops.app.databinding.ActivityMainBinding;
import com.readrops.app.utils.DrawerManager;
import com.readrops.app.utils.GlideApp;
import com.readrops.app.utils.GlideRequests;
import com.readrops.app.utils.ReadropsItemTouchCallback;
import com.readrops.app.utils.SharedPreferencesManager;
import com.readrops.app.utils.Utils;
@ -51,6 +51,7 @@ import com.readrops.db.pojo.ItemWithFeed;
import org.jetbrains.annotations.NotNull;
import org.koin.androidx.viewmodel.compat.ViewModelCompat;
import org.koin.java.KoinJavaComponent;
import java.lang.ref.WeakReference;
import java.util.Collections;
@ -300,7 +301,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
private void initRecyclerView() {
ViewPreloadSizeProvider preloadSizeProvider = new ViewPreloadSizeProvider();
adapter = new MainItemListAdapter(GlideApp.with(this), preloadSizeProvider);
adapter = new MainItemListAdapter(KoinJavaComponent.get(GlideRequests.class), preloadSizeProvider);
adapter.setOnItemClickListener(new MainItemListAdapter.OnItemClickListener() {
@Override
public void onItemClick(ItemWithFeed itemWithFeed, int position) {
@ -349,7 +350,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
binding.itemsRecyclerView.setRecyclerListener(viewHolder -> {
MainItemListAdapter.ItemViewHolder vh = (MainItemListAdapter.ItemViewHolder) viewHolder;
GlideApp.with(this).clear(vh.getItemImage());
KoinJavaComponent.get(GlideRequests.class).clear(vh.getItemImage());
});
LinearLayoutManager layoutManager = new LinearLayoutManager(this);

View File

@ -13,9 +13,11 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.readrops.app.R;
import com.readrops.app.databinding.FeedLayoutBinding;
import com.readrops.app.utils.GlideApp;
import com.readrops.app.utils.GlideRequests;
import com.readrops.db.pojo.FeedWithFolder;
import org.koin.java.KoinJavaComponent;
import java.util.List;
public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.FeedViewHolder> {
@ -64,7 +66,7 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.FeedV
FeedWithFolder feedWithFolder = getItem(i);
if (feedWithFolder.getFeed().getIconUrl() != null) {
GlideApp.with(viewHolder.itemView.getContext())
KoinJavaComponent.get(GlideRequests.class)
.load(feedWithFolder.getFeed().getIconUrl())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.ic_rss_feed_grey)

View File

@ -9,10 +9,13 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.readrops.app.R
import com.readrops.app.databinding.NotificationPermissionLayoutBinding
import com.readrops.app.utils.GlideApp
import com.readrops.app.utils.GlideRequests
import com.readrops.db.entities.Feed
import org.koin.core.KoinComponent
import org.koin.core.get
class NotificationPermissionListAdapter(var enableAll: Boolean, val listener: (feed: Feed) -> Unit) :
ListAdapter<Feed, NotificationPermissionListAdapter.NotificationPermissionViewHolder>(DIFF_CALLBACK) {
ListAdapter<Feed, NotificationPermissionListAdapter.NotificationPermissionViewHolder>(DIFF_CALLBACK), KoinComponent {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotificationPermissionViewHolder {
val binding = NotificationPermissionLayoutBinding.inflate(LayoutInflater.from(parent.context))
@ -30,7 +33,7 @@ class NotificationPermissionListAdapter(var enableAll: Boolean, val listener: (f
holder.itemView.setOnClickListener { if (enableAll) listener(getItem(position)) }
GlideApp.with(holder.itemView.context)
get<GlideRequests>()
.load(feed.iconUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.ic_rss_feed_grey)

View File

@ -9,11 +9,13 @@ import com.readrops.db.entities.Feed
import com.readrops.db.entities.Item
import com.readrops.db.entities.account.Account
import com.readrops.api.services.SyncResult
import org.koin.core.KoinComponent
import org.koin.core.get
/**
* Simple class to get synchro notification content (title, content and largeIcon) according to some rules
*/
class SyncResultAnalyser(val context: Context, private val syncResults: Map<Account, SyncResult>, val database: Database) {
class SyncResultAnalyser(val context: Context, private val syncResults: Map<Account, SyncResult>, val database: Database) : KoinComponent {
private val notifContent = SyncResultNotifContent()
@ -66,7 +68,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map<Acco
notifContent.title = feed?.name
feed?.iconUrl?.let {
val target = GlideApp.with(context)
val target = get<GlideRequests>()
.asBitmap()
.load(it)
.diskCacheStrategy(DiskCacheStrategy.ALL)