From 3b11090e00cc8d5c1cea16a6b6973aad8c5adb5d Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 4 Dec 2015 12:37:58 +0100 Subject: [PATCH] Minor changes --- .../mangafeed/data/cache/CoverCache.java | 10 +++++++++ .../ui/catalogue/CatalogueAdapter.java | 22 +++++-------------- .../ui/catalogue/CatalogueFragment.java | 14 ++---------- .../ui/catalogue/CataloguePresenter.java | 2 ++ .../mangafeed/ui/library/LibraryHolder.java | 5 ++++- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/cache/CoverCache.java b/app/src/main/java/eu/kanade/mangafeed/data/cache/CoverCache.java index dfaf2a10d..c849f9c03 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/cache/CoverCache.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/cache/CoverCache.java @@ -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) { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueAdapter.java index df2adff17..74181e42e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueAdapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueAdapter.java @@ -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 { @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,21 +59,15 @@ public class CatalogueAdapter extends ArrayAdapter { 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); } - if(manga.favorite){ + if (manga.favorite) { favorite_sticker.setVisibility(View.VISIBLE); - }else{ + } else { favorite_sticker.setVisibility(View.INVISIBLE); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java index 83f4f0667..2f623f8ae 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java @@ -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 { 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); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java index 25742e865..d5e9e4586 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java @@ -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 { @Inject SourceManager sourceManager; @Inject DatabaseHelper db; + @Inject CoverCache coverCache; private Source selectedSource; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryHolder.java index 6ff27628f..6f5bf94c1 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryHolder.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryHolder.java @@ -39,8 +39,11 @@ public class LibraryHolder extends ItemViewHolder { } 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); + } } }