Minor changes

This commit is contained in:
inorichi 2015-12-04 12:37:58 +01:00
parent 54a715640d
commit 3b11090e00
5 changed files with 24 additions and 29 deletions

View File

@ -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 // Helper method to load the cover from the cache directory into the specified image view
// The file must exist // The file must exist
private void loadFromCache(ImageView imageView, File file) { private void loadFromCache(ImageView imageView, File file) {

View File

@ -7,10 +7,6 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; 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 java.util.ArrayList;
import butterknife.Bind; import butterknife.Bind;
@ -51,11 +47,11 @@ public class CatalogueAdapter extends ArrayAdapter<Manga> {
@Bind(R.id.thumbnail) ImageView thumbnail; @Bind(R.id.thumbnail) ImageView thumbnail;
@Bind(R.id.favorite_sticker) ImageView favorite_sticker; @Bind(R.id.favorite_sticker) ImageView favorite_sticker;
CatalogueFragment fragment; CataloguePresenter presenter;
public ViewHolder(View view, CatalogueFragment fragment) { public ViewHolder(View view, CatalogueFragment fragment) {
this.fragment = fragment;
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
presenter = fragment.getPresenter();
} }
public void onSetValues(Manga manga) { public void onSetValues(Manga manga) {
@ -63,21 +59,15 @@ public class CatalogueAdapter extends ArrayAdapter<Manga> {
author.setText(manga.author); author.setText(manga.author);
if (manga.thumbnail_url != null) { if (manga.thumbnail_url != null) {
GlideUrl url = new GlideUrl(manga.thumbnail_url, presenter.coverCache.loadFromCacheOrNetwork(thumbnail, manga.thumbnail_url,
fragment.getPresenter().getSource().getGlideHeaders()); presenter.getSource().getGlideHeaders());
Glide.with(fragment)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.centerCrop()
.into(thumbnail);
} else { } else {
thumbnail.setImageResource(android.R.color.transparent); thumbnail.setImageResource(android.R.color.transparent);
} }
if(manga.favorite){ if (manga.favorite) {
favorite_sticker.setVisibility(View.VISIBLE); favorite_sticker.setVisibility(View.VISIBLE);
}else{ } else {
favorite_sticker.setVisibility(View.INVISIBLE); favorite_sticker.setVisibility(View.INVISIBLE);
} }
} }

View File

@ -13,10 +13,6 @@ import android.widget.GridView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; 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 java.util.List;
import butterknife.Bind; import butterknife.Bind;
@ -177,15 +173,9 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
public void updateImage(Manga manga) { public void updateImage(Manga manga) {
ImageView imageView = getImageView(getMangaIndex(manga)); ImageView imageView = getImageView(getMangaIndex(manga));
if (imageView != null) { if (imageView != null && manga.thumbnail_url != null) {
GlideUrl url = new GlideUrl(manga.thumbnail_url, getPresenter().coverCache.loadFromNetwork(imageView, manga.thumbnail_url,
getPresenter().getSource().getGlideHeaders()); getPresenter().getSource().getGlideHeaders());
Glide.with(this)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.centerCrop()
.into(imageView);
} }
} }

View File

@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject; import javax.inject.Inject;
import eu.kanade.mangafeed.data.cache.CoverCache;
import eu.kanade.mangafeed.data.database.DatabaseHelper; import eu.kanade.mangafeed.data.database.DatabaseHelper;
import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.database.models.Manga;
import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.source.SourceManager;
@ -29,6 +30,7 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
@Inject SourceManager sourceManager; @Inject SourceManager sourceManager;
@Inject DatabaseHelper db; @Inject DatabaseHelper db;
@Inject CoverCache coverCache;
private Source selectedSource; private Source selectedSource;

View File

@ -39,8 +39,11 @@ public class LibraryHolder extends ItemViewHolder<Manga> {
} }
public void loadCover(Manga manga, Source source, CoverCache coverCache) { 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()); coverCache.saveAndLoadFromCache(thumbnail, manga.thumbnail_url, source.getGlideHeaders());
} else {
thumbnail.setImageResource(android.R.color.transparent);
}
} }
} }