Minor cleanups

Pulling out some of the smaller changes that aren't related to the manga controller changes in #7244
This commit is contained in:
arkon 2022-06-04 16:01:49 -04:00
parent 5ea03fad87
commit 7fdbf40cd2
25 changed files with 94 additions and 79 deletions

View file

@ -0,0 +1,3 @@
package eu.kanade.data.chapter
class NoChaptersException : Exception()

View file

@ -24,7 +24,7 @@ import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toBitmap import androidx.core.graphics.drawable.toBitmap
import coil.compose.AsyncImage import coil.compose.AsyncImage
import eu.kanade.domain.source.model.Source 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.R
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
import eu.kanade.tachiyomi.util.lang.withIOContext import eu.kanade.tachiyomi.util.lang.withIOContext
@ -67,7 +67,7 @@ fun ExtensionIcon(
model = extension.iconUrl, model = extension.iconUrl,
contentDescription = "", contentDescription = "",
placeholder = ColorPainter(Color(0x1F888888)), placeholder = ColorPainter(Color(0x1F888888)),
error = bitmapPainterResource(id = R.drawable.cover_error), error = rememberResourceBitmapPainter(id = R.drawable.cover_error),
modifier = modifier modifier = modifier
.clip(RoundedCornerShape(4.dp)) .clip(RoundedCornerShape(4.dp))
.then(defaultModifier), .then(defaultModifier),

View file

@ -11,7 +11,7 @@ import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage import coil.compose.AsyncImage
import eu.kanade.presentation.util.bitmapPainterResource import eu.kanade.presentation.util.rememberResourceBitmapPainter
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
enum class MangaCover(private val ratio: Float) { enum class MangaCover(private val ratio: Float) {
@ -28,7 +28,7 @@ enum class MangaCover(private val ratio: Float) {
AsyncImage( AsyncImage(
model = data, model = data,
placeholder = ColorPainter(CoverPlaceholderColor), placeholder = ColorPainter(CoverPlaceholderColor),
error = bitmapPainterResource(id = R.drawable.cover_error), error = rememberResourceBitmapPainter(id = R.drawable.cover_error),
contentDescription = contentDescription, contentDescription = contentDescription,
modifier = modifier modifier = modifier
.aspectRatio(ratio) .aspectRatio(ratio)

View file

@ -3,15 +3,21 @@ package eu.kanade.presentation.components
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.google.accompanist.swiperefresh.SwipeRefreshState import com.google.accompanist.swiperefresh.SwipeRefreshState
import com.google.accompanist.swiperefresh.SwipeRefreshIndicator as AccompanistSwipeRefreshIndicator import com.google.accompanist.swiperefresh.SwipeRefreshIndicator as AccompanistSwipeRefreshIndicator
@Composable @Composable
fun SwipeRefreshIndicator(state: SwipeRefreshState, refreshTrigger: Dp) { fun SwipeRefreshIndicator(
state: SwipeRefreshState,
refreshTriggerDistance: Dp,
refreshingOffset: Dp = 16.dp,
) {
AccompanistSwipeRefreshIndicator( AccompanistSwipeRefreshIndicator(
state = state, state = state,
refreshTriggerDistance = refreshTrigger, refreshTriggerDistance = refreshTriggerDistance,
backgroundColor = MaterialTheme.colorScheme.primary, backgroundColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary, contentColor = MaterialTheme.colorScheme.onPrimary,
refreshingOffset = refreshingOffset,
) )
} }

View file

@ -4,9 +4,11 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.calculateEndPadding import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.platform.LocalLayoutDirection
@Composable @Composable
@ReadOnlyComposable
operator fun PaddingValues.plus(other: PaddingValues): PaddingValues { operator fun PaddingValues.plus(other: PaddingValues): PaddingValues {
val layoutDirection = LocalLayoutDirection.current val layoutDirection = LocalLayoutDirection.current
return PaddingValues( return PaddingValues(

View file

@ -4,6 +4,8 @@ import android.content.res.Resources
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.PluralsRes import androidx.annotation.PluralsRes
import androidx.compose.runtime.Composable 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.asImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
@ -18,6 +20,7 @@ import androidx.core.graphics.drawable.toBitmap
* @return the string data associated with the resource * @return the string data associated with the resource
*/ */
@Composable @Composable
@ReadOnlyComposable
fun quantityStringResource(@PluralsRes id: Int, quantity: Int): String { fun quantityStringResource(@PluralsRes id: Int, quantity: Int): String {
val context = LocalContext.current val context = LocalContext.current
return context.resources.getQuantityString(id, quantity, quantity) 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 * @return the string data associated with the resource
*/ */
@Composable @Composable
@ReadOnlyComposable
fun quantityStringResource(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any): String { fun quantityStringResource(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any): String {
val context = LocalContext.current val context = LocalContext.current
return context.resources.getQuantityString(id, quantity, *formatArgs) 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 * @return the bitmap associated with the resource
*/ */
@Composable @Composable
fun bitmapPainterResource(@DrawableRes id: Int): BitmapPainter { fun rememberResourceBitmapPainter(@DrawableRes id: Int): BitmapPainter {
val context = LocalContext.current val context = LocalContext.current
val drawable = ContextCompat.getDrawable(context, id) return remember(id) {
?: throw Resources.NotFoundException() val drawable = ContextCompat.getDrawable(context, id)
return BitmapPainter(drawable.toBitmap().asImageBitmap()) ?: throw Resources.NotFoundException()
BitmapPainter(drawable.toBitmap().asImageBitmap())
}
} }

View file

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.backup
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import eu.kanade.data.chapter.NoChaptersException
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Chapter 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.database.models.Track
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.util.chapter.NoChaptersException
import eu.kanade.tachiyomi.util.system.createFileInCacheDir import eu.kanade.tachiyomi.util.system.createFileInCacheDir
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy

View file

@ -175,7 +175,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
// Check if user wants track information in backup // Check if user wants track information in backup
if (options and BACKUP_TRACK_MASK == BACKUP_TRACK) { if (options and BACKUP_TRACK_MASK == BACKUP_TRACK) {
val tracks = db.getTracks(manga).executeAsBlocking() val tracks = db.getTracks(manga.id).executeAsBlocking()
if (tracks.isNotEmpty()) { if (tracks.isNotEmpty()) {
mangaObject.tracking = tracks.map { BackupTracking.copyFrom(it) } mangaObject.tracking = tracks.map { BackupTracking.copyFrom(it) }
} }
@ -318,7 +318,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
tracks.map { it.manga_id = manga.id!! } tracks.map { it.manga_id = manga.id!! }
// Get tracks from database // Get tracks from database
val dbTracks = db.getTracks(manga).executeAsBlocking() val dbTracks = db.getTracks(manga.id).executeAsBlocking()
val trackToUpdate = mutableListOf<Track>() val trackToUpdate = mutableListOf<Track>()
tracks.forEach { track -> tracks.forEach { track ->

View file

@ -34,11 +34,11 @@ class CoverCache(private val context: Context) {
/** /**
* Returns the cover from cache. * Returns the cover from cache.
* *
* @param manga the manga. * @param mangaThumbnailUrl thumbnail url for the manga.
* @return cover image. * @return cover image.
*/ */
fun getCoverFile(manga: Manga): File? { fun getCoverFile(mangaThumbnailUrl: String?): File? {
return manga.thumbnail_url?.let { return mangaThumbnailUrl?.let {
File(cacheDir, DiskUtil.hashKeyForDisk(it)) File(cacheDir, DiskUtil.hashKeyForDisk(it))
} }
} }
@ -46,11 +46,11 @@ class CoverCache(private val context: Context) {
/** /**
* Returns the custom cover from cache. * Returns the custom cover from cache.
* *
* @param manga the manga. * @param mangaId the manga id.
* @return cover image. * @return cover image.
*/ */
fun getCustomCoverFile(manga: Manga): File { fun getCustomCoverFile(mangaId: Long?): File {
return File(customCoverCacheDir, DiskUtil.hashKeyForDisk(manga.id.toString())) return File(customCoverCacheDir, DiskUtil.hashKeyForDisk(mangaId.toString()))
} }
/** /**
@ -62,7 +62,7 @@ class CoverCache(private val context: Context) {
*/ */
@Throws(IOException::class) @Throws(IOException::class)
fun setCustomCoverToCache(manga: Manga, inputStream: InputStream) { fun setCustomCoverToCache(manga: Manga, inputStream: InputStream) {
getCustomCoverFile(manga).outputStream().use { getCustomCoverFile(manga.id).outputStream().use {
inputStream.copyTo(it) inputStream.copyTo(it)
} }
} }
@ -77,12 +77,12 @@ class CoverCache(private val context: Context) {
fun deleteFromCache(manga: Manga, deleteCustomCover: Boolean = false): Int { fun deleteFromCache(manga: Manga, deleteCustomCover: Boolean = false): Int {
var deleted = 0 var deleted = 0
getCoverFile(manga)?.let { getCoverFile(manga.thumbnail_url)?.let {
if (it.exists() && it.delete()) ++deleted if (it.exists() && it.delete()) ++deleted
} }
if (deleteCustomCover) { if (deleteCustomCover) {
if (deleteCustomCover(manga)) ++deleted if (deleteCustomCover(manga.id)) ++deleted
} }
return deleted return deleted
@ -91,11 +91,11 @@ class CoverCache(private val context: Context) {
/** /**
* Delete custom cover of the manga from the cache * Delete custom cover of the manga from the cache
* *
* @param manga the manga. * @param mangaId the manga id.
* @return whether the cover was deleted. * @return whether the cover was deleted.
*/ */
fun deleteCustomCover(manga: Manga): Boolean { fun deleteCustomCover(mangaId: Long?): Boolean {
return getCustomCoverFile(manga).let { return getCustomCoverFile(mangaId).let {
it.exists() && it.delete() it.exists() && it.delete()
} }
} }

View file

@ -57,7 +57,7 @@ class MangaCoverFetcher(
override suspend fun fetch(): FetchResult { override suspend fun fetch(): FetchResult {
// Use custom cover if exists // Use custom cover if exists
val useCustomCover = options.parameters.value(USE_CUSTOM_COVER) ?: true val useCustomCover = options.parameters.value(USE_CUSTOM_COVER) ?: true
val customCoverFile = coverCache.getCustomCoverFile(manga) val customCoverFile = coverCache.getCustomCoverFile(manga.id)
if (useCustomCover && customCoverFile.exists()) { if (useCustomCover && customCoverFile.exists()) {
return fileLoader(customCoverFile) return fileLoader(customCoverFile)
} }
@ -82,7 +82,7 @@ class MangaCoverFetcher(
private suspend fun httpLoader(): FetchResult { private suspend fun httpLoader(): FetchResult {
// Only cache separately if it's a library item // Only cache separately if it's a library item
val libraryCoverCacheFile = if (manga.favorite) { val libraryCoverCacheFile = if (manga.favorite) {
coverCache.getCoverFile(manga) ?: error("No cover specified") coverCache.getCoverFile(manga.thumbnail_url) ?: error("No cover specified")
} else { } else {
null null
} }

View file

@ -19,13 +19,13 @@ interface TrackQueries : DbProvider {
) )
.prepare() .prepare()
fun getTracks(manga: Manga) = db.get() fun getTracks(mangaId: Long?) = db.get()
.listOfObjects(Track::class.java) .listOfObjects(Track::class.java)
.withQuery( .withQuery(
Query.builder() Query.builder()
.table(TrackTable.TABLE) .table(TrackTable.TABLE)
.where("${TrackTable.COL_MANGA_ID} = ?") .where("${TrackTable.COL_MANGA_ID} = ?")
.whereArgs(manga.id) .whereArgs(mangaId)
.build(), .build(),
) )
.prepare() .prepare()

View file

@ -102,8 +102,9 @@ class DownloadManager(
downloader.clearQueue(isNotification) downloader.clearQueue(isNotification)
} }
fun startDownloadNow(chapter: Chapter) { fun startDownloadNow(chapterId: Long?) {
val download = downloader.queue.find { it.chapter.id == chapter.id } ?: return if (chapterId == null) return
val download = downloader.queue.find { it.chapter.id == chapterId } ?: return
val queue = downloader.queue.toMutableList() val queue = downloader.queue.toMutableList()
queue.remove(download) queue.remove(download)
queue.add(0, download) queue.add(0, download)

View file

@ -6,9 +6,12 @@ import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import rx.subjects.PublishSubject import rx.subjects.PublishSubject
class Download(val source: HttpSource, val manga: Manga, val chapter: Chapter) { data class Download(
val source: HttpSource,
var pages: List<Page>? = null val manga: Manga,
val chapter: Chapter,
var pages: List<Page>? = null,
) {
@Volatile @Volatile
@Transient @Transient

View file

@ -6,6 +6,7 @@ import android.content.Intent
import android.os.IBinder import android.os.IBinder
import android.os.PowerManager import android.os.PowerManager
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import eu.kanade.data.chapter.NoChaptersException
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.DatabaseHelper 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.toMangaInfo
import eu.kanade.tachiyomi.source.model.toSChapter import eu.kanade.tachiyomi.source.model.toSChapter
import eu.kanade.tachiyomi.source.model.toSManga 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.syncChaptersWithSource
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay
import eu.kanade.tachiyomi.util.lang.withIOContext import eu.kanade.tachiyomi.util.lang.withIOContext
@ -500,7 +500,7 @@ class LibraryUpdateService(
} }
private suspend fun updateTrackings(manga: LibraryManga, loggedServices: List<TrackService>) { private suspend fun updateTrackings(manga: LibraryManga, loggedServices: List<TrackService>) {
db.getTracks(manga).executeAsBlocking() db.getTracks(manga.id).executeAsBlocking()
.map { track -> .map { track ->
supervisorScope { supervisorScope {
async { async {

View file

@ -30,7 +30,7 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters)
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val tracks = delayedTrackingStore.getItems().mapNotNull { val tracks = delayedTrackingStore.getItems().mapNotNull {
val manga = db.getManga(it.mangaId).executeAsBlocking() ?: return@withContext val manga = db.getManga(it.mangaId).executeAsBlocking() ?: return@withContext
db.getTracks(manga).executeAsBlocking() db.getTracks(manga.id).executeAsBlocking()
.find { track -> track.id == it.trackId } .find { track -> track.id == it.trackId }
?.also { track -> ?.also { track ->
track.last_chapter_read = it.lastChapterRead track.last_chapter_read = it.lastChapterRead

View file

@ -16,12 +16,8 @@ object MigrationFlags {
private const val TRACK = 0b0100 private const val TRACK = 0b0100
private const val CUSTOM_COVER = 0b1000 private const val CUSTOM_COVER = 0b1000
private const val CHAPTERS2 = 0x1 private val coverCache: CoverCache by injectLazy()
private const val CATEGORIES2 = 0x2 private val db: DatabaseHelper = Injekt.get()
private const val TRACK2 = 0x4
private val coverCache: CoverCache by injectLazy()
private val db: DatabaseHelper = Injekt.get()
val flags get() = arrayOf(CHAPTERS, CATEGORIES, TRACK, CUSTOM_COVER) 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) } return positions.fold(0) { accumulated, position -> accumulated or (1 shl position) }
} }
fun titles(manga: Manga?): Array<Int> { fun titles(manga: Manga?): Array<Int> {
val titles = arrayOf(R.string.chapters, R.string.categories).toMutableList() val titles = arrayOf(R.string.chapters, R.string.categories).toMutableList()
if (manga != null) { if (manga != null) {
db.inTransaction { db.inTransaction {
if (db.getTracks(manga).executeAsBlocking().isNotEmpty()) { if (db.getTracks(manga.id).executeAsBlocking().isNotEmpty()) {
titles.add(R.string.track) titles.add(R.string.track)
} }
if (manga.hasCustomCover(coverCache)) { if (manga.hasCustomCover(coverCache)) {
titles.add(R.string.custom_cover) titles.add(R.string.custom_cover)
} }
} }
} }
return titles.toTypedArray() return titles.toTypedArray()
} }
} }

View file

@ -150,7 +150,7 @@ class SearchPresenter(
// Update track // Update track
if (migrateTracks) { if (migrateTracks) {
val tracksToUpdate = db.getTracks(prevManga).executeAsBlocking().mapNotNull { track -> val tracksToUpdate = db.getTracks(prevManga.id).executeAsBlocking().mapNotNull { track ->
track.id = null track.id = null
track.manga_id = manga.id!! track.manga_id = manga.id!!
@ -183,7 +183,7 @@ class SearchPresenter(
// Update custom cover // Update custom cover
if (migrateCustomCover) { 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, // SearchPresenter#networkToLocalManga may have updated the manga title,

View file

@ -467,7 +467,7 @@ class LibraryController(
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
when (item.itemId) { 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_download_unread -> downloadUnreadChapters()
R.id.action_mark_as_read -> markReadStatus(true) R.id.action_mark_as_read -> markReadStatus(true)
R.id.action_mark_as_unread -> markReadStatus(false) R.id.action_mark_as_unread -> markReadStatus(false)
@ -540,7 +540,7 @@ class LibraryController(
/** /**
* Move the selected manga to a list of categories. * Move the selected manga to a list of categories.
*/ */
private fun showChangeMangaCategoriesDialog() { private fun showMangaCategoriesDialog() {
// Create a copy of selected manga // Create a copy of selected manga
val mangas = selectedMangas.toList() val mangas = selectedMangas.toList()

View file

@ -34,6 +34,7 @@ import com.google.android.material.snackbar.Snackbar
import dev.chrisbanes.insetter.applyInsetter import dev.chrisbanes.insetter.applyInsetter
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.SelectableAdapter import eu.davidea.flexibleadapter.SelectableAdapter
import eu.kanade.data.chapter.NoChaptersException
import eu.kanade.domain.history.model.HistoryWithRelations import eu.kanade.domain.history.model.HistoryWithRelations
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.CoverCache 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.history.HistoryController
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
import eu.kanade.tachiyomi.ui.webview.WebViewActivity 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.hasCustomCover
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.launchUI
@ -149,7 +149,6 @@ class MangaController :
private val preferences: PreferencesHelper by injectLazy() private val preferences: PreferencesHelper by injectLazy()
private val coverCache: CoverCache by injectLazy() private val coverCache: CoverCache by injectLazy()
private val sourceManager: SourceManager by injectLazy()
private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null
private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null

View file

@ -185,7 +185,7 @@ class MangaPresenter(
return Observable.just(0) return Observable.just(0)
} }
return db.getTracks(manga).asRxObservable() return db.getTracks(manga.id).asRxObservable()
.map { tracks -> .map { tracks ->
val loggedServices = trackManager.services.filter { it.isLogged }.map { it.id } val loggedServices = trackManager.services.filter { it.isLogged }.map { it.id }
tracks.filter { it.sync_id in loggedServices } tracks.filter { it.sync_id in loggedServices }
@ -335,7 +335,7 @@ class MangaPresenter(
fun deleteCustomCover(manga: Manga) { fun deleteCustomCover(manga: Manga) {
Observable Observable
.fromCallable { .fromCallable {
coverCache.deleteCustomCover(manga) coverCache.deleteCustomCover(manga.id)
manga.updateCoverLastModified(db) manga.updateCoverLastModified(db)
coverCache.clearMemoryCache() coverCache.clearMemoryCache()
} }
@ -514,7 +514,7 @@ class MangaPresenter(
} }
fun startDownloadingNow(chapter: Chapter) { fun startDownloadingNow(chapter: Chapter) {
downloadManager.startDownloadNow(chapter) downloadManager.startDownloadNow(chapter.id)
} }
/** /**
@ -720,7 +720,7 @@ class MangaPresenter(
private fun fetchTrackers() { private fun fetchTrackers() {
trackSubscription?.let { remove(it) } trackSubscription?.let { remove(it) }
trackSubscription = db.getTracks(manga) trackSubscription = db.getTracks(manga.id)
.asRxObservable() .asRxObservable()
.map { tracks -> .map { tracks ->
loggedServices.map { service -> loggedServices.map { service ->

View file

@ -85,9 +85,9 @@ class ChaptersSettingsSheet(
private val unread = Item.TriStateGroup(R.string.action_filter_unread, this) private val unread = Item.TriStateGroup(R.string.action_filter_unread, this)
private val bookmarked = Item.TriStateGroup(R.string.action_filter_bookmarked, 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 items = listOf(downloaded, unread, bookmarked)
override val footer = null override val footer: Item? = null
override fun initModels() { override fun initModels() {
if (presenter.forceDownloaded()) { if (presenter.forceDownloaded()) {
@ -138,9 +138,9 @@ class ChaptersSettingsSheet(
private val chapterNum = Item.MultiSort(R.string.sort_by_number, this) private val chapterNum = Item.MultiSort(R.string.sort_by_number, this)
private val uploadDate = Item.MultiSort(R.string.sort_by_upload_date, 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 items = listOf(source, uploadDate, chapterNum)
override val footer = null override val footer: Item? = null
override fun initModels() { override fun initModels() {
val sorting = presenter.manga.sorting val sorting = presenter.manga.sorting
@ -200,9 +200,9 @@ class ChaptersSettingsSheet(
private val displayTitle = Item.Radio(R.string.show_title, this) private val displayTitle = Item.Radio(R.string.show_title, this)
private val displayChapterNum = Item.Radio(R.string.show_chapter_number, 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 items = listOf(displayTitle, displayChapterNum)
override val footer = null override val footer: Item? = null
override fun initModels() { override fun initModels() {
val mode = presenter.manga.displayMode val mode = presenter.manga.displayMode

View file

@ -151,7 +151,7 @@ class ReaderPresenter(
private var hasTrackers: Boolean = false private var hasTrackers: Boolean = false
private val checkTrackers: (Manga) -> Unit = { manga -> private val checkTrackers: (Manga) -> Unit = { manga ->
val tracks = db.getTracks(manga).executeAsBlocking() val tracks = db.getTracks(manga.id).executeAsBlocking()
hasTrackers = tracks.size > 0 hasTrackers = tracks.size > 0
} }
@ -755,7 +755,7 @@ class ReaderPresenter(
val context = Injekt.get<Application>() val context = Injekt.get<Application>()
launchIO { launchIO {
db.getTracks(manga).executeAsBlocking() db.getTracks(manga.id).executeAsBlocking()
.mapNotNull { track -> .mapNotNull { track ->
val service = trackManager.getService(track.sync_id) val service = trackManager.getService(track.sync_id)
if (service != null && service.isLogged && chapterRead > track.last_chapter_read) { if (service != null && service.isLogged && chapterRead > track.last_chapter_read) {

View file

@ -143,7 +143,7 @@ class UpdatesPresenter : BasePresenter<UpdatesController>() {
} }
fun startDownloadingNow(chapter: Chapter) { fun startDownloadingNow(chapter: Chapter) {
downloadManager.startDownloadNow(chapter) downloadManager.startDownloadNow(chapter.id)
} }
/** /**

View file

@ -37,7 +37,7 @@ fun Manga.prepUpdateCover(coverCache: CoverCache, remoteManga: SManga, refreshSa
} }
fun Manga.hasCustomCover(coverCache: CoverCache): Boolean { fun Manga.hasCustomCover(coverCache: CoverCache): Boolean {
return coverCache.getCustomCoverFile(this).exists() return coverCache.getCustomCoverFile(id).exists()
} }
fun Manga.removeCovers(coverCache: CoverCache) { fun Manga.removeCovers(coverCache: CoverCache) {

View file

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.util.chapter 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.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga 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.chapter_number != sourceChapter.chapter_number ||
dbChapter.source_order != sourceChapter.source_order dbChapter.source_order != sourceChapter.source_order
} }
class NoChaptersException : Exception()