From 28fd22dfe055224e807400e8a4a9e51cdd83d88e Mon Sep 17 00:00:00 2001 From: NoodleMage Date: Sat, 30 Jan 2016 13:15:28 +0100 Subject: [PATCH] Manga initialized check. Now takes network cover image if something went wrong --- .../eu/kanade/tachiyomi/data/cache/CoverCache.java | 2 +- .../tachiyomi/ui/manga/info/MangaInfoFragment.java | 10 +++++----- .../tachiyomi/ui/manga/info/MangaInfoPresenter.java | 9 +++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.java b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.java index 90fc07862..17ede8122 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.java @@ -201,7 +201,7 @@ public class CoverCache { * @param imageView imageView where picture should be displayed. * @param file file to load. Must exist!. */ - public void loadFromCache(ImageView imageView, File file) { + private void loadFromCache(ImageView imageView, File file) { Glide.with(context) .load(file) .diskCacheStrategy(DiskCacheStrategy.RESULT) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.java index 3d2eaa133..532692c6b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.java @@ -26,8 +26,8 @@ import butterknife.ButterKnife; import eu.kanade.tachiyomi.R; import eu.kanade.tachiyomi.data.cache.CoverCache; import eu.kanade.tachiyomi.data.database.models.Manga; -import eu.kanade.tachiyomi.data.source.base.Source; import eu.kanade.tachiyomi.data.io.IOHandler; +import eu.kanade.tachiyomi.data.source.base.Source; import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment; import eu.kanade.tachiyomi.util.ToastUtil; import nucleus.factory.RequiresPresenter; @@ -35,6 +35,7 @@ import nucleus.factory.RequiresPresenter; @RequiresPresenter(MangaInfoPresenter.class) public class MangaInfoFragment extends BaseRxFragment { + private static final int REQUEST_IMAGE_OPEN = 101; @Bind(R.id.swipe_refresh) SwipeRefreshLayout swipeRefresh; @Bind(R.id.manga_artist) TextView artist; @Bind(R.id.manga_author) TextView author; @@ -47,8 +48,6 @@ public class MangaInfoFragment extends BaseRxFragment { @Bind(R.id.action_favorite) Button favoriteBtn; @Bind(R.id.fab_edit) FloatingActionButton fabEdit; - private static final int REQUEST_IMAGE_OPEN = 101; - public static MangaInfoFragment newInstance() { return new MangaInfoFragment(); } @@ -165,8 +164,9 @@ public class MangaInfoFragment extends BaseRxFragment { File picture = new File(result != null ? result : ""); try { - // Update cover to selected file - getPresenter().editCoverWithLocalFile(picture, cover); + // Update cover to selected file, show error if something went wrong + if (!getPresenter().editCoverWithLocalFile(picture, cover)) + ToastUtil.showShort(getContext(), R.string.notification_manga_update_failed); } catch (IOException e) { e.printStackTrace(); diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.java index a947279d6..2820ef62d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.java @@ -149,11 +149,16 @@ public class MangaInfoPresenter extends BasePresenter { /** * Update cover with local file */ - public void editCoverWithLocalFile(File file, ImageView imageView) throws IOException { + public boolean editCoverWithLocalFile(File file, ImageView imageView) throws IOException { + if (!manga.initialized) + return false; + if (manga.favorite) { coverCache.copyToLocalCache(manga.thumbnail_url, file); - coverCache.loadFromCache(imageView, file); + coverCache.saveOrLoadFromCache(imageView, manga.thumbnail_url, source.getGlideHeaders()); + return true; } + return false; } private void onMangaFavoriteChange(boolean isFavorite) {