diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt index 1f97a7854d4a..f125fd7c7e95 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt @@ -176,6 +176,18 @@ class ChapterCache(private val context: Context) { } } + fun removePageListFromCache( + chapter: Chapter + ) { + try { + val key = DiskUtil.hashKeyForDisk(getKey(chapter)) + diskCache.remove(key) + diskCache.flush() + } catch (e: Exception) { + // Ignore. + } + } + /** * Returns true if image is in cache. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 7bb6d95f0fab..11a7f48d16a2 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -472,6 +472,7 @@ class ChaptersController : menu.findItem(R.id.action_remove_bookmark)?.isVisible = chapters.all { it.chapter.bookmark } menu.findItem(R.id.action_mark_as_read)?.isVisible = chapters.any { !it.chapter.read } menu.findItem(R.id.action_mark_as_unread)?.isVisible = chapters.all { it.chapter.read } + menu.findItem(R.id.action_remove_page_cache)?.isVisible = true // Hide FAB to avoid interfering with the bottom action toolbar binding.fab.hide() @@ -497,7 +498,7 @@ class ChaptersController : R.id.action_mark_as_read -> markAsRead(getSelectedChapters()) R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters()) R.id.action_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters()[0]) - + R.id.action_remove_page_cache -> removePageCache(getSelectedChapters()) else -> return false } return true @@ -525,6 +526,7 @@ class ChaptersController : R.id.action_mark_as_read -> markAsRead(chapters) R.id.action_mark_as_unread -> markAsUnread(chapters) R.id.action_mark_previous_as_read -> markPreviousAsRead(chapter) + R.id.action_remove_page_cache -> removePageCache(chapters) } } @@ -588,6 +590,14 @@ class ChaptersController : destroyActionModeIfNeeded() } + private fun removePageCache( + chapters: List + ) { + destroyActionModeIfNeeded() + presenter.removePageCache(chapters) + destroyActionModeIfNeeded() + } + private fun bookmarkChapters( chapters: List, bookmarked: Boolean diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index 905a4fe82502..14ddc717ba88 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.os.Bundle import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.PublishRelay +import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga @@ -45,7 +46,8 @@ class ChaptersPresenter( private val mangaFavoriteRelay: PublishRelay, val preferences: PreferencesHelper = Injekt.get(), private val db: DatabaseHelper = Injekt.get(), - private val downloadManager: DownloadManager = Injekt.get() + private val downloadManager: DownloadManager = Injekt.get(), + private val chapterCache: ChapterCache = Injekt.get() ) : BasePresenter() { /** * List of chapters of the manga. It's always unfiltered and unsorted. @@ -336,6 +338,18 @@ class ChaptersPresenter( downloadManager.downloadChapters(manga, chapters) } + /** + * Removes the page cache for the given list of chapters. + * @param chapters the list of chapters from which to purge the page cache + */ + fun removePageCache( + chapters: List + ) { + chapters.forEach { + chapterCache.removePageListFromCache(it.chapter) + } + } + /** * Bookmarks the given list of chapters. * @param selectedChapters the list of chapters to bookmark. diff --git a/app/src/main/res/menu/chapter_selection.xml b/app/src/main/res/menu/chapter_selection.xml index 4bf88b2e47e1..f01043275877 100755 --- a/app/src/main/res/menu/chapter_selection.xml +++ b/app/src/main/res/menu/chapter_selection.xml @@ -58,4 +58,9 @@ app:iconTint="?attr/colorOnPrimary" app:showAsAction="always" /> + diff --git a/app/src/main/res/menu/chapter_single.xml b/app/src/main/res/menu/chapter_single.xml index 0f1f14e1d7ca..acc5550a58ca 100755 --- a/app/src/main/res/menu/chapter_single.xml +++ b/app/src/main/res/menu/chapter_single.xml @@ -34,4 +34,8 @@ android:id="@+id/action_mark_previous_as_read" android:title="@string/action_mark_previous_as_read" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6346d105f41f..e03cc0e1a53d 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -127,6 +127,7 @@ Search manually Migrate now Copy now + Clear page cache Loading…