mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix: Don't apply scanlator filter twice
Already handled using SQL
This commit is contained in:
parent
41622519e6
commit
44835ecb36
9 changed files with 35 additions and 22 deletions
|
@ -1,11 +1,14 @@
|
|||
package dev.yokai.domain.chapter.interactor
|
||||
|
||||
import dev.yokai.domain.chapter.ChapterRepository
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
|
||||
class GetChapters(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
) {
|
||||
suspend fun await(mangaId: Long, filterScanlators: Boolean) = chapterRepository.getChapters(mangaId, filterScanlators)
|
||||
fun subscribe(mangaId: Long, filterScanlators: Boolean) = chapterRepository.getChaptersAsFlow(mangaId, filterScanlators)
|
||||
suspend fun await(manga: Manga, filterScanlators: Boolean? = null) =
|
||||
await(manga.id!!, filterScanlators ?: (manga.filtered_scanlators?.isNotEmpty() == true))
|
||||
|
||||
fun subscribe(mangaId: Long, filterScanlators: Boolean) = chapterRepository.getChaptersAsFlow(mangaId, filterScanlators)
|
||||
}
|
||||
|
|
|
@ -1136,7 +1136,7 @@ class LibraryPresenter(
|
|||
|
||||
/** Returns first unread chapter of a manga */
|
||||
fun getFirstUnread(manga: Manga): Chapter? {
|
||||
val chapters = db.getChapters(manga).executeAsBlocking()
|
||||
val chapters = runBlocking { getChapters.await(manga) }
|
||||
return ChapterSort(manga, chapterFilter, preferences).getNextUnreadChapter(chapters, false)
|
||||
}
|
||||
|
||||
|
@ -1298,7 +1298,7 @@ class LibraryPresenter(
|
|||
presenterScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
mangaList.forEach { list ->
|
||||
val chapters = runBlocking { getChapters.await(list.id!!, true) }.filter { !it.read }
|
||||
val chapters = runBlocking { getChapters.await(list) }.filter { !it.read }
|
||||
downloadManager.downloadChapters(list, chapters)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import androidx.core.view.isVisible
|
|||
import com.bluelinelabs.conductor.Controller
|
||||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
|
||||
import dev.yokai.domain.chapter.interactor.GetChapters
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
|
@ -25,10 +26,13 @@ import eu.kanade.tachiyomi.ui.source.globalsearch.GlobalSearchController
|
|||
import eu.kanade.tachiyomi.util.chapter.ChapterSort
|
||||
import eu.kanade.tachiyomi.util.system.extensionIntentForText
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class SearchActivity : MainActivity() {
|
||||
private val getChapters: GetChapters by injectLazy()
|
||||
|
||||
private var backToMain = false
|
||||
|
||||
|
@ -151,8 +155,8 @@ class SearchActivity : MainActivity() {
|
|||
val mangaId = extras.getLong(MangaDetailsController.MANGA_EXTRA)
|
||||
if (mangaId != 0L) {
|
||||
val db = Injekt.get<DatabaseHelper>()
|
||||
val chapters = db.getChapters(mangaId).executeAsBlocking()
|
||||
db.getManga(mangaId).executeAsBlocking()?.let { manga ->
|
||||
val chapters = runBlocking { getChapters.await(manga) }
|
||||
val nextUnreadChapter = ChapterSort(manga).getNextUnreadChapter(chapters, false)
|
||||
if (nextUnreadChapter != null) {
|
||||
val activity =
|
||||
|
|
|
@ -25,6 +25,7 @@ class MangaDetailsAdapter(
|
|||
get() = preferences.shownChapterSwipeTutorial()
|
||||
|
||||
var items: List<ChapterItem> = emptyList()
|
||||
private set
|
||||
|
||||
val delegate: MangaDetailsInterface = controller
|
||||
val presenter = controller.presenter
|
||||
|
@ -54,10 +55,7 @@ class MangaDetailsAdapter(
|
|||
updateDataSet(items)
|
||||
} else {
|
||||
updateDataSet(
|
||||
items.filter {
|
||||
it.name.contains(s, true) ||
|
||||
it.scanlator?.contains(s, true) == true
|
||||
},
|
||||
items.filter { it.name.contains(s, true) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.lifecycle.SavedStateHandle
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.hippo.unifile.UniFile
|
||||
import dev.yokai.domain.chapter.interactor.GetChapters
|
||||
import dev.yokai.domain.download.DownloadPreferences
|
||||
import dev.yokai.domain.storage.StorageManager
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
@ -75,6 +76,7 @@ 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.io.File
|
||||
import java.util.Date
|
||||
import java.util.concurrent.CancellationException
|
||||
|
@ -93,6 +95,7 @@ class ReaderViewModel(
|
|||
private val storageManager: StorageManager = Injekt.get(),
|
||||
private val downloadPreferences: DownloadPreferences = Injekt.get(),
|
||||
) : ViewModel() {
|
||||
private val getChapters: GetChapters by injectLazy()
|
||||
|
||||
private val mutableState = MutableStateFlow(State())
|
||||
val state = mutableState.asStateFlow()
|
||||
|
@ -142,7 +145,7 @@ class ReaderViewModel(
|
|||
*/
|
||||
private val chapterList by lazy {
|
||||
val manga = manga!!
|
||||
val dbChapters = db.getChapters(manga).executeAsBlocking()
|
||||
val dbChapters = runBlocking { getChapters.await(manga) }
|
||||
|
||||
val selectedChapter = dbChapters.find { it.id == chapterId }
|
||||
?: error("Requested chapter of id $chapterId not found in chapter list")
|
||||
|
@ -260,7 +263,7 @@ class ReaderViewModel(
|
|||
val manga = manga ?: return emptyList()
|
||||
chapterItems = withContext(Dispatchers.IO) {
|
||||
val chapterSort = ChapterSort(manga, chapterFilter, preferences)
|
||||
val dbChapters = db.getChapters(manga).executeAsBlocking()
|
||||
val dbChapters = runBlocking { getChapters.await(manga) }
|
||||
chapterSort.getChaptersSorted(
|
||||
dbChapters,
|
||||
filterForReader = true,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.kanade.tachiyomi.ui.recents
|
||||
|
||||
import dev.yokai.domain.chapter.interactor.GetChapters
|
||||
import dev.yokai.domain.recents.RecentsPreferences
|
||||
import dev.yokai.domain.ui.UiPreferences
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
@ -32,9 +33,11 @@ import kotlinx.coroutines.flow.drop
|
|||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
|
@ -52,6 +55,7 @@ class RecentsPresenter(
|
|||
val db: DatabaseHelper = Injekt.get(),
|
||||
private val chapterFilter: ChapterFilter = Injekt.get(),
|
||||
) : BaseCoroutinePresenter<RecentsController>(), DownloadQueue.DownloadListener {
|
||||
private val getChapters: GetChapters by injectLazy()
|
||||
|
||||
private var recentsJob: Job? = null
|
||||
var recentItems = listOf<RecentMangaItem>()
|
||||
|
@ -452,14 +456,13 @@ class RecentsPresenter(
|
|||
}
|
||||
|
||||
private fun getNextChapter(manga: Manga): Chapter? {
|
||||
val chapters = db.getChapters(manga).executeAsBlocking()
|
||||
val chapters = runBlocking { getChapters.await(manga) }
|
||||
return ChapterSort(manga, chapterFilter, preferences).getNextUnreadChapter(chapters, false)
|
||||
}
|
||||
|
||||
private fun getFirstUpdatedChapter(manga: Manga, chapter: Chapter): Chapter? {
|
||||
val chapters = db.getChapters(manga).executeAsBlocking()
|
||||
val chapters = runBlocking { getChapters.await(manga) }
|
||||
return chapters
|
||||
.filterChaptersByScanlators(manga)
|
||||
.sortedWith(ChapterSort(manga, chapterFilter, preferences).sortComparator(true)).find {
|
||||
!it.read && abs(it.date_fetch - chapter.date_fetch) <= TimeUnit.HOURS.toMillis(12)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class ChapterFilter(val preferences: PreferencesHelper = Injekt.get(), val downl
|
|||
val notBookmarkEnabled = manga.bookmarkedFilter(preferences) == Manga.CHAPTER_SHOW_NOT_BOOKMARKED
|
||||
|
||||
// if none of the filters are enabled skip the filtering of them
|
||||
val filteredChapters = chapters.filterChaptersByScanlators(manga)
|
||||
val filteredChapters = chapters
|
||||
return if (readEnabled || unreadEnabled || downloadEnabled || notDownloadEnabled || bookmarkEnabled || notBookmarkEnabled) {
|
||||
filteredChapters.filter {
|
||||
if (readEnabled && it.read.not() ||
|
||||
|
@ -40,7 +40,7 @@ class ChapterFilter(val preferences: PreferencesHelper = Injekt.get(), val downl
|
|||
|
||||
/** filter chapters for the reader */
|
||||
fun <T : Chapter> filterChaptersForReader(chapters: List<T>, manga: Manga, selectedChapter: T? = null): List<T> {
|
||||
var filteredChapters = chapters.filterChaptersByScanlators(manga)
|
||||
var filteredChapters = chapters
|
||||
// if filter prefs aren't enabled don't even filter
|
||||
if (!preferences.skipRead() && !preferences.skipFiltered() && !preferences.skipDupe().get()) {
|
||||
return filteredChapters
|
||||
|
@ -84,6 +84,7 @@ class ChapterFilter(val preferences: PreferencesHelper = Injekt.get(), val downl
|
|||
|
||||
companion object {
|
||||
/** filters chapters for scanlators */
|
||||
@Deprecated("Filter it from SQL instead if possible")
|
||||
fun <T : Chapter> List<T>.filterChaptersByScanlators(manga: Manga): List<T> {
|
||||
return manga.filtered_scanlators?.let { filteredScanlatorString ->
|
||||
val filteredScanlators = ChapterUtil.getScanlators(filteredScanlatorString)
|
||||
|
|
|
@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.util.chapter
|
|||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterFilter.Companion.filterChaptersByScanlators
|
||||
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
@ -32,7 +31,7 @@ class ChapterSort(val manga: Manga, val chapterFilter: ChapterFilter = Injekt.ge
|
|||
fun <T : Chapter> getNextUnreadChapter(rawChapters: List<T>, andFiltered: Boolean = true): T? {
|
||||
val chapters = when {
|
||||
andFiltered -> chapterFilter.filterChapters(rawChapters, manga)
|
||||
else -> rawChapters.filterChaptersByScanlators(manga)
|
||||
else -> rawChapters
|
||||
}
|
||||
|
||||
return chapters.sortedWith(sortComparator(true)).find { !it.read }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.kanade.tachiyomi.util.chapter
|
||||
|
||||
import dev.yokai.domain.chapter.interactor.GetChapters
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
|
@ -8,8 +9,8 @@ import eu.kanade.tachiyomi.source.Source
|
|||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterFilter.Companion.filterChaptersByScanlators
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
import java.util.TreeSet
|
||||
|
||||
|
@ -32,9 +33,10 @@ fun syncChaptersWithSource(
|
|||
throw Exception("No chapters found")
|
||||
}
|
||||
|
||||
val downloadManager: DownloadManager = Injekt.get()
|
||||
val downloadManager: DownloadManager by injectLazy()
|
||||
val getChapters: GetChapters by injectLazy()
|
||||
// Chapters from db.
|
||||
val dbChapters = db.getChapters(manga).executeAsBlocking()
|
||||
val dbChapters = runBlocking { getChapters.await(manga, false) }
|
||||
|
||||
val sourceChapters = rawSourceChapters
|
||||
.distinctBy { it.url }
|
||||
|
@ -159,7 +161,7 @@ fun syncChaptersWithSource(
|
|||
db.fixChaptersSourceOrder(sourceChapters).executeAsBlocking()
|
||||
|
||||
// Set this manga as updated since chapters were changed
|
||||
val newestChapterDate = db.getChapters(manga).executeAsBlocking()
|
||||
val newestChapterDate = runBlocking { getChapters.await(manga, false) }
|
||||
.maxOfOrNull { it.date_upload } ?: 0L
|
||||
if (newestChapterDate == 0L) {
|
||||
if (toAdd.isNotEmpty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue