mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 11:09:19 +01:00
Minor changes
This commit is contained in:
parent
54a715640d
commit
3b11090e00
@ -107,6 +107,16 @@ public class CoverCache {
|
||||
}
|
||||
}
|
||||
|
||||
// If the image is already in our cache, use it. If not, load it with glide
|
||||
public void loadFromCacheOrNetwork(ImageView imageView, String thumbnailUrl, LazyHeaders headers) {
|
||||
File localCover = get(thumbnailUrl);
|
||||
if (localCover.exists()) {
|
||||
loadFromCache(imageView, localCover);
|
||||
} else {
|
||||
loadFromNetwork(imageView, thumbnailUrl, headers);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to load the cover from the cache directory into the specified image view
|
||||
// The file must exist
|
||||
private void loadFromCache(ImageView imageView, File file) {
|
||||
|
@ -7,10 +7,6 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.Bind;
|
||||
@ -51,11 +47,11 @@ public class CatalogueAdapter extends ArrayAdapter<Manga> {
|
||||
@Bind(R.id.thumbnail) ImageView thumbnail;
|
||||
@Bind(R.id.favorite_sticker) ImageView favorite_sticker;
|
||||
|
||||
CatalogueFragment fragment;
|
||||
CataloguePresenter presenter;
|
||||
|
||||
public ViewHolder(View view, CatalogueFragment fragment) {
|
||||
this.fragment = fragment;
|
||||
ButterKnife.bind(this, view);
|
||||
presenter = fragment.getPresenter();
|
||||
}
|
||||
|
||||
public void onSetValues(Manga manga) {
|
||||
@ -63,14 +59,8 @@ public class CatalogueAdapter extends ArrayAdapter<Manga> {
|
||||
author.setText(manga.author);
|
||||
|
||||
if (manga.thumbnail_url != null) {
|
||||
GlideUrl url = new GlideUrl(manga.thumbnail_url,
|
||||
fragment.getPresenter().getSource().getGlideHeaders());
|
||||
|
||||
Glide.with(fragment)
|
||||
.load(url)
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.centerCrop()
|
||||
.into(thumbnail);
|
||||
presenter.coverCache.loadFromCacheOrNetwork(thumbnail, manga.thumbnail_url,
|
||||
presenter.getSource().getGlideHeaders());
|
||||
} else {
|
||||
thumbnail.setImageResource(android.R.color.transparent);
|
||||
}
|
||||
|
@ -13,10 +13,6 @@ import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
@ -177,15 +173,9 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
|
||||
|
||||
public void updateImage(Manga manga) {
|
||||
ImageView imageView = getImageView(getMangaIndex(manga));
|
||||
if (imageView != null) {
|
||||
GlideUrl url = new GlideUrl(manga.thumbnail_url,
|
||||
if (imageView != null && manga.thumbnail_url != null) {
|
||||
getPresenter().coverCache.loadFromNetwork(imageView, manga.thumbnail_url,
|
||||
getPresenter().getSource().getGlideHeaders());
|
||||
|
||||
Glide.with(this)
|
||||
.load(url)
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.centerCrop()
|
||||
.into(imageView);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import eu.kanade.mangafeed.data.cache.CoverCache;
|
||||
import eu.kanade.mangafeed.data.database.DatabaseHelper;
|
||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
||||
import eu.kanade.mangafeed.data.source.SourceManager;
|
||||
@ -29,6 +30,7 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
|
||||
|
||||
@Inject SourceManager sourceManager;
|
||||
@Inject DatabaseHelper db;
|
||||
@Inject CoverCache coverCache;
|
||||
|
||||
private Source selectedSource;
|
||||
|
||||
|
@ -39,8 +39,11 @@ public class LibraryHolder extends ItemViewHolder<Manga> {
|
||||
}
|
||||
|
||||
public void loadCover(Manga manga, Source source, CoverCache coverCache) {
|
||||
if (manga.thumbnail_url != null)
|
||||
if (manga.thumbnail_url != null) {
|
||||
coverCache.saveAndLoadFromCache(thumbnail, manga.thumbnail_url, source.getGlideHeaders());
|
||||
} else {
|
||||
thumbnail.setImageResource(android.R.color.transparent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user