From 73d1b6ac2798f34c52881f9f2b327faf5ab4edee Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 11 Jan 2020 14:27:36 -0800 Subject: [PATCH] Covers now update automatcally with library, local covers instant change now --- .../tachiyomi/data/database/models/MangaImpl.kt | 2 ++ .../tachiyomi/data/library/LibraryUpdateService.kt | 12 +++++++++++- .../tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../tachiyomi/data/preference/PreferencesHelper.kt | 2 ++ .../kanade/tachiyomi/ui/library/LibraryGridHolder.kt | 6 ++++-- .../kanade/tachiyomi/ui/library/LibraryListHolder.kt | 2 ++ .../kanade/tachiyomi/ui/library/LibraryPresenter.kt | 3 +++ .../tachiyomi/ui/manga/info/MangaInfoController.kt | 8 +++++++- .../tachiyomi/ui/manga/info/MangaInfoPresenter.kt | 3 +++ .../eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 2 ++ .../ui/setting/SettingsLibraryController.kt | 6 ++++++ app/src/main/res/values/strings.xml | 3 +++ 12 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt index b5a4754486..a34429b398 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt @@ -36,6 +36,8 @@ open class MangaImpl : Manga { override var hide_title: Boolean = false + var last_cover_fetch: Long = 0 + override fun copyFrom(other: SManga) { if (other is MangaImpl && (other as MangaImpl)::title.isInitialized && other.title != title) title = other.title diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 00e9cdf5a0..58041d69eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -14,6 +14,7 @@ import androidx.core.app.NotificationCompat.GROUP_ALERT_SUMMARY import androidx.core.app.NotificationManagerCompat import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Chapter @@ -48,7 +49,9 @@ import rx.schedulers.Schedulers import timber.log.Timber import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import uy.kohesive.injekt.injectLazy import java.util.ArrayList +import java.util.Date import java.util.concurrent.atomic.AtomicInteger /** @@ -292,7 +295,7 @@ class LibraryUpdateService( // Initialize the variables holding the progress of the updates. val count = AtomicInteger(0) // List containing new updates - val newUpdates = ArrayList>>() + val newUpdates = ArrayList>>() // list containing failed updates val failedUpdates = ArrayList() // List containing categories that get included in downloads. @@ -340,6 +343,10 @@ class LibraryUpdateService( if (downloadNew && hasDownloads) { DownloadService.start(this) } + if (preferences.refreshCoversToo().getOrDefault()) { + updateDetails(newUpdates.map { it.first }).observeOn(Schedulers.io()) + .subscribeOn(Schedulers.io()).subscribe {} + } } if (failedUpdates.isNotEmpty()) { @@ -393,6 +400,7 @@ class LibraryUpdateService( fun updateDetails(mangaToUpdate: List): Observable { // Initialize the variables holding the progress of the updates. val count = AtomicInteger(0) + val coverCache by injectLazy() // Emit each manga and update it sequentially. return Observable.from(mangaToUpdate) @@ -407,6 +415,8 @@ class LibraryUpdateService( .map { networkManga -> manga.copyFrom(networkManga) db.insertManga(manga).executeAsBlocking() + coverCache.deleteFromCache(manga.thumbnail_url) + manga.last_cover_fetch = Date().time manga } .onErrorReturn { manga } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index a66fa234fa..d84968cd70 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -129,6 +129,8 @@ object PreferenceKeys { const val skipPreMigration = "skip_pre_migration" + const val refreshCoversToo = "refresh_covers_too" + @Deprecated("Use the preferences of the source") fun sourceUsername(sourceId: Long) = "pref_source_username_$sourceId" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 50324f0ada..0162865846 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -199,6 +199,8 @@ class PreferencesHelper(val context: Context) { fun defaultMangaOrder() = rxPrefs.getString("default_manga_order", "") + fun refreshCoversToo() = rxPrefs.getBoolean(Keys.refreshCoversToo, true) + fun upgradeFilters() { val filterDl = rxPrefs.getBoolean(Keys.filterDownloaded, false).getOrDefault() val filterUn = rxPrefs.getBoolean(Keys.filterUnread, false).getOrDefault() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 1be2e10e4f..6edbf424f7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -1,13 +1,14 @@ package eu.kanade.tachiyomi.ui.library import android.view.View +import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.signature.ObjectKey import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource import kotlinx.android.synthetic.main.catalogue_grid_item.* -import androidx.recyclerview.widget.RecyclerView -import eu.davidea.flexibleadapter.items.IFlexible /** * Class used to hold the displayed data of a manga in the library, like the cover or the title. @@ -56,6 +57,7 @@ class LibraryGridHolder( GlideApp.with(view.context) .load(item.manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey(item.manga.last_cover_fetch.toString())) .centerCrop() .into(thumbnail) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 8783da5b96..21e2f75d45 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource import kotlinx.android.synthetic.main.catalogue_list_item.* import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.signature.ObjectKey import eu.davidea.flexibleadapter.items.IFlexible /** @@ -58,6 +59,7 @@ class LibraryListHolder( GlideApp.with(itemView.context) .load(item.manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey(item.manga.last_cover_fetch.toString())) .centerCrop() .circleCrop() .dontAnimate() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 68862af5de..9e78ab0f98 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory +import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault @@ -36,6 +37,7 @@ import java.io.InputStream import java.util.ArrayList import java.util.Collections import java.util.Comparator +import java.util.Date /** * Class containing library information. @@ -464,6 +466,7 @@ class LibraryPresenter( if (manga.thumbnail_url != null && manga.favorite) { coverCache.copyToCache(manga.thumbnail_url!!, inputStream) + (manga as? MangaImpl)?.last_cover_fetch = Date().time return true } return false diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index a2b009ab33..cdef034626 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -28,6 +28,7 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition +import com.bumptech.glide.signature.ObjectKey import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar import com.jakewharton.rxbinding.support.v4.widget.refreshes @@ -36,6 +37,7 @@ import com.jakewharton.rxbinding.view.longClicks import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -60,6 +62,7 @@ import eu.kanade.tachiyomi.util.updateLayoutParams import eu.kanade.tachiyomi.util.updatePaddingRelative import jp.wasabeef.glide.transformations.CropSquareTransformation import jp.wasabeef.glide.transformations.MaskTransformation +import kotlinx.android.synthetic.main.catalogue_list_item.* import kotlinx.android.synthetic.main.manga_info_controller.* import uy.kohesive.injekt.injectLazy import java.io.File @@ -269,17 +272,20 @@ class MangaInfoController : NucleusController(), setFavoriteDrawable(manga.favorite) // Set cover if it wasn't already. - if (manga_cover.drawable == null && !manga.thumbnail_url.isNullOrEmpty()) { + if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(view.context) .load(manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey((manga as MangaImpl).last_cover_fetch.toString())) .centerCrop() .into(manga_cover) if (backdrop != null) { + //GlideApp.with(view.context).clear(backdrop) GlideApp.with(view.context) .load(manga) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey((manga as MangaImpl).last_cover_fetch.toString())) .centerCrop() .into(backdrop) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt index 03ba4a025a..f96d0459a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory +import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter @@ -92,6 +93,8 @@ class MangaInfoPresenter( manga.copyFrom(networkManga) manga.initialized = true db.insertManga(manga).executeAsBlocking() + coverCache.deleteFromCache(manga.thumbnail_url) + (manga as? MangaImpl)?.last_cover_fetch = Date().time manga } .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index c6d138881b..8e94968cc3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager @@ -530,6 +531,7 @@ class ReaderPresenter( val thumbUrl = manga.thumbnail_url ?: throw Exception("Image url not found") if (manga.favorite) { coverCache.copyToCache(thumbUrl, stream()) + (manga as? MangaImpl)?.last_cover_fetch = Date().time SetAsCoverResult.Success } else { SetAsCoverResult.AddToLibraryFirst diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 0b4b9f1574..21f2433119 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -170,6 +170,12 @@ class SettingsLibraryController : SettingsController() { summaryRes = R.string.pref_remove_articles_summary defaultValue = false } + switchPreference { + key = Keys.refreshCoversToo + titleRes = R.string.pref_refresh_covers_too + summaryRes = R.string.pref_refresh_covers_too_summary + defaultValue = true + } } class LibraryColumnsDialog : DialogController() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ae56c91bdc..069da382b5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -190,6 +190,9 @@ Never After %1$s minutes Search title, tags, source + Automatically refresh covers + Refresh covers in library as well + when updating library (overwrites local covers) All