From 7fdbf40cd23132915bd90cf623e4a69fb560dd26 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 4 Jun 2022 16:01:49 -0400 Subject: [PATCH] Minor cleanups Pulling out some of the smaller changes that aren't related to the manga controller changes in #7244 --- .../data/chapter/NoChaptersException.kt | 3 ++ .../browse/components/BrowseIcons.kt | 4 +-- .../presentation/components/MangaCover.kt | 4 +-- .../presentation/components/SwipeRefresh.kt | 10 ++++-- .../kanade/presentation/util/PaddingValues.kt | 2 ++ .../eu/kanade/presentation/util/Resources.kt | 14 +++++--- .../data/backup/AbstractBackupRestore.kt | 2 +- .../data/backup/full/FullBackupManager.kt | 4 +-- .../kanade/tachiyomi/data/cache/CoverCache.kt | 24 ++++++------- .../tachiyomi/data/coil/MangaCoverFetcher.kt | 4 +-- .../data/database/queries/TrackQueries.kt | 4 +-- .../data/download/DownloadManager.kt | 5 +-- .../tachiyomi/data/download/model/Download.kt | 9 +++-- .../data/library/LibraryUpdateService.kt | 4 +-- .../track/job/DelayedTrackingUpdateJob.kt | 2 +- .../ui/browse/migration/MigrationFlags.kt | 36 +++++++++---------- .../migration/search/SearchPresenter.kt | 4 +-- .../tachiyomi/ui/library/LibraryController.kt | 4 +-- .../tachiyomi/ui/manga/MangaController.kt | 3 +- .../tachiyomi/ui/manga/MangaPresenter.kt | 8 ++--- .../ui/manga/chapter/ChaptersSettingsSheet.kt | 12 +++---- .../tachiyomi/ui/reader/ReaderPresenter.kt | 4 +-- .../ui/recent/updates/UpdatesPresenter.kt | 2 +- .../kanade/tachiyomi/util/MangaExtensions.kt | 2 +- .../util/chapter/ChapterSourceSync.kt | 3 +- 25 files changed, 94 insertions(+), 79 deletions(-) create mode 100644 app/src/main/java/eu/kanade/data/chapter/NoChaptersException.kt diff --git a/app/src/main/java/eu/kanade/data/chapter/NoChaptersException.kt b/app/src/main/java/eu/kanade/data/chapter/NoChaptersException.kt new file mode 100644 index 0000000000..f532f650a7 --- /dev/null +++ b/app/src/main/java/eu/kanade/data/chapter/NoChaptersException.kt @@ -0,0 +1,3 @@ +package eu.kanade.data.chapter + +class NoChaptersException : Exception() diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt index bd333228b6..59457aaddf 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt @@ -24,7 +24,7 @@ import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap import coil.compose.AsyncImage import eu.kanade.domain.source.model.Source -import eu.kanade.presentation.util.bitmapPainterResource +import eu.kanade.presentation.util.rememberResourceBitmapPainter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.util.lang.withIOContext @@ -67,7 +67,7 @@ fun ExtensionIcon( model = extension.iconUrl, contentDescription = "", placeholder = ColorPainter(Color(0x1F888888)), - error = bitmapPainterResource(id = R.drawable.cover_error), + error = rememberResourceBitmapPainter(id = R.drawable.cover_error), modifier = modifier .clip(RoundedCornerShape(4.dp)) .then(defaultModifier), diff --git a/app/src/main/java/eu/kanade/presentation/components/MangaCover.kt b/app/src/main/java/eu/kanade/presentation/components/MangaCover.kt index 3b2504d99f..2d47b9a9c6 100644 --- a/app/src/main/java/eu/kanade/presentation/components/MangaCover.kt +++ b/app/src/main/java/eu/kanade/presentation/components/MangaCover.kt @@ -11,7 +11,7 @@ import androidx.compose.ui.graphics.painter.ColorPainter import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp import coil.compose.AsyncImage -import eu.kanade.presentation.util.bitmapPainterResource +import eu.kanade.presentation.util.rememberResourceBitmapPainter import eu.kanade.tachiyomi.R enum class MangaCover(private val ratio: Float) { @@ -28,7 +28,7 @@ enum class MangaCover(private val ratio: Float) { AsyncImage( model = data, placeholder = ColorPainter(CoverPlaceholderColor), - error = bitmapPainterResource(id = R.drawable.cover_error), + error = rememberResourceBitmapPainter(id = R.drawable.cover_error), contentDescription = contentDescription, modifier = modifier .aspectRatio(ratio) diff --git a/app/src/main/java/eu/kanade/presentation/components/SwipeRefresh.kt b/app/src/main/java/eu/kanade/presentation/components/SwipeRefresh.kt index b9a1bc2a9a..6767835b63 100644 --- a/app/src/main/java/eu/kanade/presentation/components/SwipeRefresh.kt +++ b/app/src/main/java/eu/kanade/presentation/components/SwipeRefresh.kt @@ -3,15 +3,21 @@ package eu.kanade.presentation.components import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp import com.google.accompanist.swiperefresh.SwipeRefreshState import com.google.accompanist.swiperefresh.SwipeRefreshIndicator as AccompanistSwipeRefreshIndicator @Composable -fun SwipeRefreshIndicator(state: SwipeRefreshState, refreshTrigger: Dp) { +fun SwipeRefreshIndicator( + state: SwipeRefreshState, + refreshTriggerDistance: Dp, + refreshingOffset: Dp = 16.dp, +) { AccompanistSwipeRefreshIndicator( state = state, - refreshTriggerDistance = refreshTrigger, + refreshTriggerDistance = refreshTriggerDistance, backgroundColor = MaterialTheme.colorScheme.primary, contentColor = MaterialTheme.colorScheme.onPrimary, + refreshingOffset = refreshingOffset, ) } diff --git a/app/src/main/java/eu/kanade/presentation/util/PaddingValues.kt b/app/src/main/java/eu/kanade/presentation/util/PaddingValues.kt index b1a2a97846..039883ce8c 100644 --- a/app/src/main/java/eu/kanade/presentation/util/PaddingValues.kt +++ b/app/src/main/java/eu/kanade/presentation/util/PaddingValues.kt @@ -4,9 +4,11 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.calculateEndPadding import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.ui.platform.LocalLayoutDirection @Composable +@ReadOnlyComposable operator fun PaddingValues.plus(other: PaddingValues): PaddingValues { val layoutDirection = LocalLayoutDirection.current return PaddingValues( diff --git a/app/src/main/java/eu/kanade/presentation/util/Resources.kt b/app/src/main/java/eu/kanade/presentation/util/Resources.kt index b22e6d02bb..6f3f11a394 100644 --- a/app/src/main/java/eu/kanade/presentation/util/Resources.kt +++ b/app/src/main/java/eu/kanade/presentation/util/Resources.kt @@ -4,6 +4,8 @@ import android.content.res.Resources import androidx.annotation.DrawableRes import androidx.annotation.PluralsRes import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.runtime.remember import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.platform.LocalContext @@ -18,6 +20,7 @@ import androidx.core.graphics.drawable.toBitmap * @return the string data associated with the resource */ @Composable +@ReadOnlyComposable fun quantityStringResource(@PluralsRes id: Int, quantity: Int): String { val context = LocalContext.current return context.resources.getQuantityString(id, quantity, quantity) @@ -32,6 +35,7 @@ fun quantityStringResource(@PluralsRes id: Int, quantity: Int): String { * @return the string data associated with the resource */ @Composable +@ReadOnlyComposable fun quantityStringResource(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any): String { val context = LocalContext.current return context.resources.getQuantityString(id, quantity, *formatArgs) @@ -46,9 +50,11 @@ fun quantityStringResource(@PluralsRes id: Int, quantity: Int, vararg formatArgs * @return the bitmap associated with the resource */ @Composable -fun bitmapPainterResource(@DrawableRes id: Int): BitmapPainter { +fun rememberResourceBitmapPainter(@DrawableRes id: Int): BitmapPainter { val context = LocalContext.current - val drawable = ContextCompat.getDrawable(context, id) - ?: throw Resources.NotFoundException() - return BitmapPainter(drawable.toBitmap().asImageBitmap()) + return remember(id) { + val drawable = ContextCompat.getDrawable(context, id) + ?: throw Resources.NotFoundException() + BitmapPainter(drawable.toBitmap().asImageBitmap()) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt index a648df8cb6..f10856ede5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.backup import android.content.Context import android.net.Uri +import eu.kanade.data.chapter.NoChaptersException import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter @@ -9,7 +10,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.source.Source -import eu.kanade.tachiyomi.util.chapter.NoChaptersException import eu.kanade.tachiyomi.util.system.createFileInCacheDir import kotlinx.coroutines.Job import uy.kohesive.injekt.injectLazy diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt index cb84c66ab2..6e0ed654fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt @@ -175,7 +175,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { // Check if user wants track information in backup if (options and BACKUP_TRACK_MASK == BACKUP_TRACK) { - val tracks = db.getTracks(manga).executeAsBlocking() + val tracks = db.getTracks(manga.id).executeAsBlocking() if (tracks.isNotEmpty()) { mangaObject.tracking = tracks.map { BackupTracking.copyFrom(it) } } @@ -318,7 +318,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { tracks.map { it.manga_id = manga.id!! } // Get tracks from database - val dbTracks = db.getTracks(manga).executeAsBlocking() + val dbTracks = db.getTracks(manga.id).executeAsBlocking() val trackToUpdate = mutableListOf() tracks.forEach { track -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt index 123d697a7b..0788ef37d6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt @@ -34,11 +34,11 @@ class CoverCache(private val context: Context) { /** * Returns the cover from cache. * - * @param manga the manga. + * @param mangaThumbnailUrl thumbnail url for the manga. * @return cover image. */ - fun getCoverFile(manga: Manga): File? { - return manga.thumbnail_url?.let { + fun getCoverFile(mangaThumbnailUrl: String?): File? { + return mangaThumbnailUrl?.let { File(cacheDir, DiskUtil.hashKeyForDisk(it)) } } @@ -46,11 +46,11 @@ class CoverCache(private val context: Context) { /** * Returns the custom cover from cache. * - * @param manga the manga. + * @param mangaId the manga id. * @return cover image. */ - fun getCustomCoverFile(manga: Manga): File { - return File(customCoverCacheDir, DiskUtil.hashKeyForDisk(manga.id.toString())) + fun getCustomCoverFile(mangaId: Long?): File { + return File(customCoverCacheDir, DiskUtil.hashKeyForDisk(mangaId.toString())) } /** @@ -62,7 +62,7 @@ class CoverCache(private val context: Context) { */ @Throws(IOException::class) fun setCustomCoverToCache(manga: Manga, inputStream: InputStream) { - getCustomCoverFile(manga).outputStream().use { + getCustomCoverFile(manga.id).outputStream().use { inputStream.copyTo(it) } } @@ -77,12 +77,12 @@ class CoverCache(private val context: Context) { fun deleteFromCache(manga: Manga, deleteCustomCover: Boolean = false): Int { var deleted = 0 - getCoverFile(manga)?.let { + getCoverFile(manga.thumbnail_url)?.let { if (it.exists() && it.delete()) ++deleted } if (deleteCustomCover) { - if (deleteCustomCover(manga)) ++deleted + if (deleteCustomCover(manga.id)) ++deleted } return deleted @@ -91,11 +91,11 @@ class CoverCache(private val context: Context) { /** * Delete custom cover of the manga from the cache * - * @param manga the manga. + * @param mangaId the manga id. * @return whether the cover was deleted. */ - fun deleteCustomCover(manga: Manga): Boolean { - return getCustomCoverFile(manga).let { + fun deleteCustomCover(mangaId: Long?): Boolean { + return getCustomCoverFile(mangaId).let { it.exists() && it.delete() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt b/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt index 978765c43b..870ced03eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt @@ -57,7 +57,7 @@ class MangaCoverFetcher( override suspend fun fetch(): FetchResult { // Use custom cover if exists val useCustomCover = options.parameters.value(USE_CUSTOM_COVER) ?: true - val customCoverFile = coverCache.getCustomCoverFile(manga) + val customCoverFile = coverCache.getCustomCoverFile(manga.id) if (useCustomCover && customCoverFile.exists()) { return fileLoader(customCoverFile) } @@ -82,7 +82,7 @@ class MangaCoverFetcher( private suspend fun httpLoader(): FetchResult { // Only cache separately if it's a library item val libraryCoverCacheFile = if (manga.favorite) { - coverCache.getCoverFile(manga) ?: error("No cover specified") + coverCache.getCoverFile(manga.thumbnail_url) ?: error("No cover specified") } else { null } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt index cd1fe85823..bb692d3874 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt @@ -19,13 +19,13 @@ interface TrackQueries : DbProvider { ) .prepare() - fun getTracks(manga: Manga) = db.get() + fun getTracks(mangaId: Long?) = db.get() .listOfObjects(Track::class.java) .withQuery( Query.builder() .table(TrackTable.TABLE) .where("${TrackTable.COL_MANGA_ID} = ?") - .whereArgs(manga.id) + .whereArgs(mangaId) .build(), ) .prepare() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index cb025e7dc7..4ecdc039f3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -102,8 +102,9 @@ class DownloadManager( downloader.clearQueue(isNotification) } - fun startDownloadNow(chapter: Chapter) { - val download = downloader.queue.find { it.chapter.id == chapter.id } ?: return + fun startDownloadNow(chapterId: Long?) { + if (chapterId == null) return + val download = downloader.queue.find { it.chapter.id == chapterId } ?: return val queue = downloader.queue.toMutableList() queue.remove(download) queue.add(0, download) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt index 7ebd7a9a5d..a1438b9949 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt @@ -6,9 +6,12 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource import rx.subjects.PublishSubject -class Download(val source: HttpSource, val manga: Manga, val chapter: Chapter) { - - var pages: List? = null +data class Download( + val source: HttpSource, + val manga: Manga, + val chapter: Chapter, + var pages: List? = null, +) { @Volatile @Transient 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 796ca31bd2..3989ed8cf6 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 @@ -6,6 +6,7 @@ import android.content.Intent import android.os.IBinder import android.os.PowerManager import androidx.core.content.ContextCompat +import eu.kanade.data.chapter.NoChaptersException import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -31,7 +32,6 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.toMangaInfo import eu.kanade.tachiyomi.source.model.toSChapter import eu.kanade.tachiyomi.source.model.toSManga -import eu.kanade.tachiyomi.util.chapter.NoChaptersException import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay import eu.kanade.tachiyomi.util.lang.withIOContext @@ -500,7 +500,7 @@ class LibraryUpdateService( } private suspend fun updateTrackings(manga: LibraryManga, loggedServices: List) { - db.getTracks(manga).executeAsBlocking() + db.getTracks(manga.id).executeAsBlocking() .map { track -> supervisorScope { async { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt index 65531d0139..e47961eefc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt @@ -30,7 +30,7 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters) withContext(Dispatchers.IO) { val tracks = delayedTrackingStore.getItems().mapNotNull { val manga = db.getManga(it.mangaId).executeAsBlocking() ?: return@withContext - db.getTracks(manga).executeAsBlocking() + db.getTracks(manga.id).executeAsBlocking() .find { track -> track.id == it.trackId } ?.also { track -> track.last_chapter_read = it.lastChapterRead diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt index a6307bcf2d..f72a096dac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt @@ -16,12 +16,8 @@ object MigrationFlags { private const val TRACK = 0b0100 private const val CUSTOM_COVER = 0b1000 - private const val CHAPTERS2 = 0x1 - private const val CATEGORIES2 = 0x2 - private const val TRACK2 = 0x4 - - private val coverCache: CoverCache by injectLazy() - private val db: DatabaseHelper = Injekt.get() + private val coverCache: CoverCache by injectLazy() + private val db: DatabaseHelper = Injekt.get() val flags get() = arrayOf(CHAPTERS, CATEGORIES, TRACK, CUSTOM_COVER) @@ -49,19 +45,19 @@ object MigrationFlags { return positions.fold(0) { accumulated, position -> accumulated or (1 shl position) } } - fun titles(manga: Manga?): Array { - val titles = arrayOf(R.string.chapters, R.string.categories).toMutableList() - if (manga != null) { - db.inTransaction { - if (db.getTracks(manga).executeAsBlocking().isNotEmpty()) { - titles.add(R.string.track) - } + fun titles(manga: Manga?): Array { + val titles = arrayOf(R.string.chapters, R.string.categories).toMutableList() + if (manga != null) { + db.inTransaction { + if (db.getTracks(manga.id).executeAsBlocking().isNotEmpty()) { + titles.add(R.string.track) + } - if (manga.hasCustomCover(coverCache)) { - titles.add(R.string.custom_cover) - } - } - } - return titles.toTypedArray() - } + if (manga.hasCustomCover(coverCache)) { + titles.add(R.string.custom_cover) + } + } + } + return titles.toTypedArray() + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt index 6f17a92e7a..45ff3e341b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt @@ -150,7 +150,7 @@ class SearchPresenter( // Update track if (migrateTracks) { - val tracksToUpdate = db.getTracks(prevManga).executeAsBlocking().mapNotNull { track -> + val tracksToUpdate = db.getTracks(prevManga.id).executeAsBlocking().mapNotNull { track -> track.id = null track.manga_id = manga.id!! @@ -183,7 +183,7 @@ class SearchPresenter( // Update custom cover if (migrateCustomCover) { - coverCache.setCustomCoverToCache(manga, coverCache.getCustomCoverFile(prevManga).inputStream()) + coverCache.setCustomCoverToCache(manga, coverCache.getCustomCoverFile(prevManga.id).inputStream()) } // SearchPresenter#networkToLocalManga may have updated the manga title, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 902f7b5cb4..1aaf592015 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -467,7 +467,7 @@ class LibraryController( override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { - R.id.action_move_to_category -> showChangeMangaCategoriesDialog() + R.id.action_move_to_category -> showMangaCategoriesDialog() R.id.action_download_unread -> downloadUnreadChapters() R.id.action_mark_as_read -> markReadStatus(true) R.id.action_mark_as_unread -> markReadStatus(false) @@ -540,7 +540,7 @@ class LibraryController( /** * Move the selected manga to a list of categories. */ - private fun showChangeMangaCategoriesDialog() { + private fun showMangaCategoriesDialog() { // Create a copy of selected manga val mangas = selectedMangas.toList() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 961356cabb..37bf74ffe6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -34,6 +34,7 @@ import com.google.android.material.snackbar.Snackbar import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter +import eu.kanade.data.chapter.NoChaptersException import eu.kanade.domain.history.model.HistoryWithRelations import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache @@ -84,7 +85,6 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.recent.history.HistoryController import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.ui.webview.WebViewActivity -import eu.kanade.tachiyomi.util.chapter.NoChaptersException import eu.kanade.tachiyomi.util.hasCustomCover import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchUI @@ -149,7 +149,6 @@ class MangaController : private val preferences: PreferencesHelper by injectLazy() private val coverCache: CoverCache by injectLazy() - private val sourceManager: SourceManager by injectLazy() private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index e65a18311c..7f8e94a2b8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -185,7 +185,7 @@ class MangaPresenter( return Observable.just(0) } - return db.getTracks(manga).asRxObservable() + return db.getTracks(manga.id).asRxObservable() .map { tracks -> val loggedServices = trackManager.services.filter { it.isLogged }.map { it.id } tracks.filter { it.sync_id in loggedServices } @@ -335,7 +335,7 @@ class MangaPresenter( fun deleteCustomCover(manga: Manga) { Observable .fromCallable { - coverCache.deleteCustomCover(manga) + coverCache.deleteCustomCover(manga.id) manga.updateCoverLastModified(db) coverCache.clearMemoryCache() } @@ -514,7 +514,7 @@ class MangaPresenter( } fun startDownloadingNow(chapter: Chapter) { - downloadManager.startDownloadNow(chapter) + downloadManager.startDownloadNow(chapter.id) } /** @@ -720,7 +720,7 @@ class MangaPresenter( private fun fetchTrackers() { trackSubscription?.let { remove(it) } - trackSubscription = db.getTracks(manga) + trackSubscription = db.getTracks(manga.id) .asRxObservable() .map { tracks -> loggedServices.map { service -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSettingsSheet.kt index 9c04ba10d1..a8d04394d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSettingsSheet.kt @@ -85,9 +85,9 @@ class ChaptersSettingsSheet( private val unread = Item.TriStateGroup(R.string.action_filter_unread, this) private val bookmarked = Item.TriStateGroup(R.string.action_filter_bookmarked, this) - override val header = null + override val header: Item? = null override val items = listOf(downloaded, unread, bookmarked) - override val footer = null + override val footer: Item? = null override fun initModels() { if (presenter.forceDownloaded()) { @@ -138,9 +138,9 @@ class ChaptersSettingsSheet( private val chapterNum = Item.MultiSort(R.string.sort_by_number, this) private val uploadDate = Item.MultiSort(R.string.sort_by_upload_date, this) - override val header = null + override val header: Item? = null override val items = listOf(source, uploadDate, chapterNum) - override val footer = null + override val footer: Item? = null override fun initModels() { val sorting = presenter.manga.sorting @@ -200,9 +200,9 @@ class ChaptersSettingsSheet( private val displayTitle = Item.Radio(R.string.show_title, this) private val displayChapterNum = Item.Radio(R.string.show_chapter_number, this) - override val header = null + override val header: Item? = null override val items = listOf(displayTitle, displayChapterNum) - override val footer = null + override val footer: Item? = null override fun initModels() { val mode = presenter.manga.displayMode 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 9a1e5c1bf7..14d0b4943f 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 @@ -151,7 +151,7 @@ class ReaderPresenter( private var hasTrackers: Boolean = false private val checkTrackers: (Manga) -> Unit = { manga -> - val tracks = db.getTracks(manga).executeAsBlocking() + val tracks = db.getTracks(manga.id).executeAsBlocking() hasTrackers = tracks.size > 0 } @@ -755,7 +755,7 @@ class ReaderPresenter( val context = Injekt.get() launchIO { - db.getTracks(manga).executeAsBlocking() + db.getTracks(manga.id).executeAsBlocking() .mapNotNull { track -> val service = trackManager.getService(track.sync_id) if (service != null && service.isLogged && chapterRead > track.last_chapter_read) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt index 3fa69379ea..60567d7858 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt @@ -143,7 +143,7 @@ class UpdatesPresenter : BasePresenter() { } fun startDownloadingNow(chapter: Chapter) { - downloadManager.startDownloadNow(chapter) + downloadManager.startDownloadNow(chapter.id) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt index adc3b2c7d8..321e96c7e1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt @@ -37,7 +37,7 @@ fun Manga.prepUpdateCover(coverCache: CoverCache, remoteManga: SManga, refreshSa } fun Manga.hasCustomCover(coverCache: CoverCache): Boolean { - return coverCache.getCustomCoverFile(this).exists() + return coverCache.getCustomCoverFile(id).exists() } fun Manga.removeCovers(coverCache: CoverCache) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt index 519b4574ae..d5c6b8c6a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.util.chapter +import eu.kanade.data.chapter.NoChaptersException import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga @@ -171,5 +172,3 @@ private fun shouldUpdateDbChapter(dbChapter: Chapter, sourceChapter: Chapter): B dbChapter.chapter_number != sourceChapter.chapter_number || dbChapter.source_order != sourceChapter.source_order } - -class NoChaptersException : Exception()