Always include bound trackers when migrating/copying

This commit is contained in:
arkon 2023-08-05 11:53:45 -04:00
parent cb4b8ac0dc
commit 6259bbaa5e
3 changed files with 10 additions and 25 deletions

View File

@ -4,10 +4,7 @@ import eu.kanade.domain.manga.model.hasCustomCover
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.download.DownloadCache import eu.kanade.tachiyomi.data.download.DownloadCache
import kotlinx.coroutines.runBlocking
import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.track.interactor.GetTracks
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -31,12 +28,10 @@ object MigrationFlags {
private const val CHAPTERS = 0b00001 private const val CHAPTERS = 0b00001
private const val CATEGORIES = 0b00010 private const val CATEGORIES = 0b00010
private const val TRACK = 0b00100
private const val CUSTOM_COVER = 0b01000 private const val CUSTOM_COVER = 0b01000
private const val DELETE_DOWNLOADED = 0b10000 private const val DELETE_DOWNLOADED = 0b10000
private val coverCache: CoverCache by injectLazy() private val coverCache: CoverCache by injectLazy()
private val getTracks: GetTracks = Injekt.get()
private val downloadCache: DownloadCache by injectLazy() private val downloadCache: DownloadCache by injectLazy()
fun hasChapters(value: Int): Boolean { fun hasChapters(value: Int): Boolean {
@ -47,10 +42,6 @@ object MigrationFlags {
return value and CATEGORIES != 0 return value and CATEGORIES != 0
} }
fun hasTracks(value: Int): Boolean {
return value and TRACK != 0
}
fun hasCustomCover(value: Int): Boolean { fun hasCustomCover(value: Int): Boolean {
return value and CUSTOM_COVER != 0 return value and CUSTOM_COVER != 0
} }
@ -66,9 +57,6 @@ object MigrationFlags {
flags += MigrationFlag.create(CATEGORIES, defaultSelectedBitMap, R.string.categories) flags += MigrationFlag.create(CATEGORIES, defaultSelectedBitMap, R.string.categories)
if (manga != null) { if (manga != null) {
if (runBlocking { getTracks.await(manga.id) }.isNotEmpty()) {
flags += MigrationFlag.create(TRACK, defaultSelectedBitMap, R.string.track)
}
if (manga.hasCustomCover(coverCache)) { if (manga.hasCustomCover(coverCache)) {
flags += MigrationFlag.create(CUSTOM_COVER, defaultSelectedBitMap, R.string.custom_cover) flags += MigrationFlag.create(CUSTOM_COVER, defaultSelectedBitMap, R.string.custom_cover)
} }

View File

@ -222,7 +222,6 @@ internal class MigrateDialogScreenModel(
) { ) {
val migrateChapters = MigrationFlags.hasChapters(flags) val migrateChapters = MigrationFlags.hasChapters(flags)
val migrateCategories = MigrationFlags.hasCategories(flags) val migrateCategories = MigrationFlags.hasCategories(flags)
val migrateTracks = MigrationFlags.hasTracks(flags)
val migrateCustomCover = MigrationFlags.hasCustomCover(flags) val migrateCustomCover = MigrationFlags.hasCustomCover(flags)
val deleteDownloaded = MigrationFlags.hasDeleteDownloaded(flags) val deleteDownloaded = MigrationFlags.hasDeleteDownloaded(flags)
@ -273,21 +272,20 @@ internal class MigrateDialogScreenModel(
} }
// Update track // Update track
if (migrateTracks) { getTracks.await(oldManga.id).mapNotNull { track ->
val tracks = getTracks.await(oldManga.id).mapNotNull { track -> val updatedTrack = track.copy(mangaId = newManga.id)
val updatedTrack = track.copy(mangaId = newManga.id)
val service = enhancedServices val service = enhancedServices
.firstOrNull { it.isTrackFrom(updatedTrack, oldManga, oldSource) } .firstOrNull { it.isTrackFrom(updatedTrack, oldManga, oldSource) }
if (service != null) { if (service != null) {
service.migrateTrack(updatedTrack, newManga, newSource) service.migrateTrack(updatedTrack, newManga, newSource)
} else { } else {
updatedTrack updatedTrack
}
} }
insertTrack.awaitAll(tracks)
} }
.takeIf { it.isNotEmpty() }
?.let { insertTrack.awaitAll(it) }
// Delete downloaded // Delete downloaded
if (deleteDownloaded) { if (deleteDownloaded) {

View File

@ -1,5 +1,4 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">