New: Migrating titles maintains custom covers (#7196)

* New: Migrating titles maintains custom covers #7189

* Added Custom Covers to MigrationFlags.kt, strings.xml

* Reworded covers --> cover

* Updated logic to show/hide Migration flags titles depending on manga.

(cherry picked from commit 5ea03fad87)
This commit is contained in:
Saud-97 2022-06-04 19:52:35 +03:00 committed by arkon
parent 6db2becd30
commit f00e03e5ea
4 changed files with 50 additions and 8 deletions

View File

@ -1,20 +1,29 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.util.hasCustomCover
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
object MigrationFlags { object MigrationFlags {
private const val CHAPTERS = 0b001 private const val CHAPTERS = 0b0001
private const val CATEGORIES = 0b010 private const val CATEGORIES = 0b0010
private const val TRACK = 0b100 private const val TRACK = 0b0100
private const val CUSTOM_COVER = 0b1000
private const val CHAPTERS2 = 0x1 private const val CHAPTERS2 = 0x1
private const val CATEGORIES2 = 0x2 private const val CATEGORIES2 = 0x2
private const val TRACK2 = 0x4 private const val TRACK2 = 0x4
val titles get() = arrayOf(R.string.chapters, R.string.categories, R.string.track) private val coverCache: CoverCache by injectLazy()
private val db: DatabaseHelper = Injekt.get()
val flags get() = arrayOf(CHAPTERS, CATEGORIES, TRACK) val flags get() = arrayOf(CHAPTERS, CATEGORIES, TRACK, CUSTOM_COVER)
fun hasChapters(value: Int): Boolean { fun hasChapters(value: Int): Boolean {
return value and CHAPTERS != 0 return value and CHAPTERS != 0
@ -28,11 +37,31 @@ object MigrationFlags {
return value and TRACK != 0 return value and TRACK != 0
} }
fun hasCustomCover(value: Int): Boolean {
return value and CUSTOM_COVER != 0
}
fun getEnabledFlagsPositions(value: Int): List<Int> { fun getEnabledFlagsPositions(value: Int): List<Int> {
return flags.mapIndexedNotNull { index, flag -> if (value and flag != 0) index else null } return flags.mapIndexedNotNull { index, flag -> if (value and flag != 0) index else null }
} }
fun getFlagsFromPositions(positions: Array<Int>): Int { fun getFlagsFromPositions(positions: Array<Int>): Int {
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> {
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)
}
if (manga.hasCustomCover(coverCache)) {
titles.add(R.string.custom_cover)
}
}
}
return titles.toTypedArray()
} }
} }

View File

@ -95,7 +95,7 @@ class SearchController(
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val prefValue = preferences.migrateFlags().get() val prefValue = preferences.migrateFlags().get()
val enabledFlagsPositions = MigrationFlags.getEnabledFlagsPositions(prefValue) val enabledFlagsPositions = MigrationFlags.getEnabledFlagsPositions(prefValue)
val items = MigrationFlags.titles val items = MigrationFlags.titles(manga)
.map { resources?.getString(it) } .map { resources?.getString(it) }
.toTypedArray() .toTypedArray()
val selected = items val selected = items

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.browse.migration.search
import android.os.Bundle import android.os.Bundle
import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.BehaviorRelay
import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.database.models.MangaCategory
import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.database.models.toMangaInfo
@ -17,12 +18,14 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchCardItem
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchItem import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchItem
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
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
import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.lang.withUIContext
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.util.Date import java.util.Date
class SearchPresenter( class SearchPresenter(
@ -31,7 +34,7 @@ class SearchPresenter(
) : GlobalSearchPresenter(initialQuery) { ) : GlobalSearchPresenter(initialQuery) {
private val replacingMangaRelay = BehaviorRelay.create<Pair<Boolean, Manga?>>() private val replacingMangaRelay = BehaviorRelay.create<Pair<Boolean, Manga?>>()
private val coverCache: CoverCache by injectLazy()
private val enhancedServices by lazy { Injekt.get<TrackManager>().services.filterIsInstance<EnhancedTrackService>() } private val enhancedServices by lazy { Injekt.get<TrackManager>().services.filterIsInstance<EnhancedTrackService>() }
override fun onCreate(savedState: Bundle?) { override fun onCreate(savedState: Bundle?) {
@ -103,6 +106,10 @@ class SearchPresenter(
MigrationFlags.hasTracks( MigrationFlags.hasTracks(
flags, flags,
) )
val migrateCustomCover =
MigrationFlags.hasCustomCover(
flags,
)
db.inTransaction { db.inTransaction {
// Update chapters read // Update chapters read
@ -174,6 +181,11 @@ class SearchPresenter(
manga.date_added = Date().time manga.date_added = Date().time
} }
// Update custom cover
if (migrateCustomCover) {
coverCache.setCustomCoverToCache(manga, coverCache.getCustomCoverFile(prevManga).inputStream())
}
// SearchPresenter#networkToLocalManga may have updated the manga title, // SearchPresenter#networkToLocalManga may have updated the manga title,
// so ensure db gets updated title too // so ensure db gets updated title too
db.insertManga(manga).executeAsBlocking() db.insertManga(manga).executeAsBlocking()

View File

@ -621,6 +621,7 @@
<string name="download_custom">Custom</string> <string name="download_custom">Custom</string>
<string name="download_all">All</string> <string name="download_all">All</string>
<string name="download_unread">Unread</string> <string name="download_unread">Unread</string>
<string name="custom_cover">Custom cover</string>
<string name="manga_cover">Cover</string> <string name="manga_cover">Cover</string>
<string name="cover_saved">Cover saved</string> <string name="cover_saved">Cover saved</string>
<string name="error_saving_cover">Error saving cover</string> <string name="error_saving_cover">Error saving cover</string>