mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 04:58:56 +01:00
Refactor some tracking-related logic
This commit is contained in:
@@ -45,7 +45,6 @@ import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.category.interactor.GetCategories
|
||||
import tachiyomi.domain.category.interactor.SetMangaCategories
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
|
||||
import tachiyomi.domain.chapter.interactor.SetMangaDefaultChapterFlags
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
import tachiyomi.domain.manga.interactor.GetDuplicateLibraryManga
|
||||
@@ -72,7 +71,6 @@ class BrowseSourceScreenModel(
|
||||
private val getRemoteManga: GetRemoteManga = Injekt.get(),
|
||||
private val getDuplicateLibraryManga: GetDuplicateLibraryManga = Injekt.get(),
|
||||
private val getCategories: GetCategories = Injekt.get(),
|
||||
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
|
||||
private val setMangaCategories: SetMangaCategories = Injekt.get(),
|
||||
private val setMangaDefaultChapterFlags: SetMangaDefaultChapterFlags = Injekt.get(),
|
||||
private val getManga: GetManga = Injekt.get(),
|
||||
@@ -82,7 +80,7 @@ class BrowseSourceScreenModel(
|
||||
private val syncChaptersWithTrackServiceTwoWay: SyncChaptersWithTrackServiceTwoWay = Injekt.get(),
|
||||
) : StateScreenModel<BrowseSourceScreenModel.State>(State(Listing.valueOf(listingQuery))) {
|
||||
|
||||
private val loggedServices by lazy { Injekt.get<TrackManager>().services.filter { it.isLogged } }
|
||||
private val loggedServices by lazy { Injekt.get<TrackManager>().services.filter { it.isLoggedIn } }
|
||||
|
||||
var displayMode by sourcePreferences.sourceDisplayMode().asState(coroutineScope)
|
||||
|
||||
@@ -299,8 +297,7 @@ class BrowseSourceScreenModel(
|
||||
(service as TrackService).bind(track)
|
||||
insertTrack.await(track.toDomainTrack()!!)
|
||||
|
||||
val chapters = getChapterByMangaId.await(manga.id)
|
||||
syncChaptersWithTrackServiceTwoWay.await(chapters, track.toDomainTrack()!!, service)
|
||||
syncChaptersWithTrackServiceTwoWay.await(manga.id, track.toDomainTrack()!!, service)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.WARN, e) { "Could not match manga: ${manga.title} with service $service" }
|
||||
|
||||
@@ -366,7 +366,7 @@ class LibraryScreenModel(
|
||||
* @return map of track id with the filter value
|
||||
*/
|
||||
private fun getTrackingFilterFlow(): Flow<Map<Long, TriState>> {
|
||||
val loggedServices = trackManager.services.filter { it.isLogged }
|
||||
val loggedServices = trackManager.services.filter { it.isLoggedIn }
|
||||
return if (loggedServices.isNotEmpty()) {
|
||||
val prefFlows = loggedServices
|
||||
.map { libraryPreferences.filterTracking(it.id.toInt()).changes() }
|
||||
|
||||
@@ -26,7 +26,7 @@ class LibrarySettingsScreenModel(
|
||||
) : ScreenModel {
|
||||
|
||||
val trackServices
|
||||
get() = trackManager.services.filter { it.isLogged }
|
||||
get() = trackManager.services.filter { it.isLoggedIn }
|
||||
|
||||
fun toggleFilter(preference: (LibraryPreferences) -> Preference<TriState>) {
|
||||
preference(libraryPreferences).getAndSet {
|
||||
|
||||
@@ -105,7 +105,7 @@ class MangaScreenModel(
|
||||
private val successState: State.Success?
|
||||
get() = state.value as? State.Success
|
||||
|
||||
private val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
|
||||
private val loggedServices by lazy { trackManager.services.filter { it.isLoggedIn } }
|
||||
|
||||
val manga: Manga?
|
||||
get() = successState?.manga
|
||||
|
||||
@@ -71,7 +71,6 @@ import tachiyomi.core.util.lang.withIOContext
|
||||
import tachiyomi.core.util.lang.withUIContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.manga.interactor.GetManga
|
||||
import tachiyomi.domain.manga.interactor.GetMangaWithChapters
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
import tachiyomi.domain.track.interactor.DeleteTrack
|
||||
import tachiyomi.domain.track.interactor.GetTracks
|
||||
@@ -218,8 +217,7 @@ data class TrackInfoDialogHomeScreen(
|
||||
|
||||
private suspend fun refreshTrackers() {
|
||||
val insertTrack = Injekt.get<InsertTrack>()
|
||||
val getMangaWithChapters = Injekt.get<GetMangaWithChapters>()
|
||||
val syncTwoWayService = Injekt.get<SyncChaptersWithTrackServiceTwoWay>()
|
||||
val syncChaptersWithTrackServiceTwoWay = Injekt.get<SyncChaptersWithTrackServiceTwoWay>()
|
||||
val context = Injekt.get<Application>()
|
||||
|
||||
try {
|
||||
@@ -229,11 +227,7 @@ data class TrackInfoDialogHomeScreen(
|
||||
val track = trackItem.track ?: continue
|
||||
val domainTrack = trackItem.service.refresh(track.toDbTrack()).toDomainTrack() ?: continue
|
||||
insertTrack.await(domainTrack)
|
||||
|
||||
if (trackItem.service is EnhancedTrackService) {
|
||||
val allChapters = getMangaWithChapters.awaitChapters(mangaId)
|
||||
syncTwoWayService.await(allChapters, domainTrack, trackItem.service)
|
||||
}
|
||||
syncChaptersWithTrackServiceTwoWay.await(mangaId, domainTrack, trackItem.service)
|
||||
} catch (e: Exception) {
|
||||
logcat(
|
||||
LogPriority.ERROR,
|
||||
@@ -257,7 +251,7 @@ data class TrackInfoDialogHomeScreen(
|
||||
}
|
||||
|
||||
private fun List<Track>.mapToTrackItem(): List<TrackItem> {
|
||||
val loggedServices = Injekt.get<TrackManager>().services.filter { it.isLogged }
|
||||
val loggedServices = Injekt.get<TrackManager>().services.filter { it.isLoggedIn }
|
||||
val source = Injekt.get<SourceManager>().getOrStub(sourceId)
|
||||
return loggedServices
|
||||
// Map to TrackItem
|
||||
|
||||
@@ -36,7 +36,7 @@ class StatsScreenModel(
|
||||
private val trackManager: TrackManager = Injekt.get(),
|
||||
) : StateScreenModel<StatsScreenState>(StatsScreenState.Loading) {
|
||||
|
||||
private val loggedServices by lazy { trackManager.services.fastFilter { it.isLogged } }
|
||||
private val loggedServices by lazy { trackManager.services.fastFilter { it.isLoggedIn } }
|
||||
|
||||
init {
|
||||
coroutineScope.launchIO {
|
||||
|
||||
Reference in New Issue
Block a user