mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Minor tracking cleanups
This commit is contained in:
parent
6d74a86711
commit
6887d98f15
24 changed files with 64 additions and 69 deletions
|
@ -25,7 +25,7 @@ class RefreshTracks(
|
|||
suspend fun await(mangaId: Long): List<Pair<Tracker?, Throwable>> {
|
||||
return supervisorScope {
|
||||
return@supervisorScope getTracks.await(mangaId)
|
||||
.map { it to trackerManager.get(it.syncId) }
|
||||
.map { it to trackerManager.get(it.trackerId) }
|
||||
.filter { (_, service) -> service?.isLoggedIn == true }
|
||||
.map { (track, service) ->
|
||||
async {
|
||||
|
|
|
@ -27,7 +27,7 @@ class TrackChapter(
|
|||
if (tracks.isEmpty()) return@withNonCancellableContext
|
||||
|
||||
tracks.mapNotNull { track ->
|
||||
val service = trackerManager.get(track.syncId)
|
||||
val service = trackerManager.get(track.trackerId)
|
||||
if (service == null || !service.isLoggedIn || chapterNumber <= track.lastChapterRead) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ fun Track.copyPersonalFrom(other: Track): Track {
|
|||
)
|
||||
}
|
||||
|
||||
fun Track.toDbTrack(): DbTrack = DbTrack.create(syncId).also {
|
||||
fun Track.toDbTrack(): DbTrack = DbTrack.create(trackerId).also {
|
||||
it.id = id
|
||||
it.manga_id = mangaId
|
||||
it.remote_id = remoteId
|
||||
|
@ -33,7 +33,7 @@ fun DbTrack.toDomainTrack(idRequired: Boolean = true): Track? {
|
|||
return Track(
|
||||
id = trackId,
|
||||
mangaId = manga_id,
|
||||
syncId = sync_id.toLong(),
|
||||
trackerId = tracker_id.toLong(),
|
||||
remoteId = remote_id,
|
||||
libraryId = library_id,
|
||||
title = title,
|
||||
|
|
|
@ -9,26 +9,24 @@ class TrackPreferences(
|
|||
private val preferenceStore: PreferenceStore,
|
||||
) {
|
||||
|
||||
fun trackUsername(sync: Tracker) = preferenceStore.getString(trackUsername(sync.id), "")
|
||||
fun trackUsername(tracker: Tracker) = preferenceStore.getString(
|
||||
Preference.privateKey("pref_mangasync_username_${tracker.id}"),
|
||||
"",
|
||||
)
|
||||
|
||||
fun trackPassword(sync: Tracker) = preferenceStore.getString(trackPassword(sync.id), "")
|
||||
fun trackPassword(tracker: Tracker) = preferenceStore.getString(
|
||||
Preference.privateKey("pref_mangasync_password_${tracker.id}"),
|
||||
"",
|
||||
)
|
||||
|
||||
fun setCredentials(sync: Tracker, username: String, password: String) {
|
||||
trackUsername(sync).set(username)
|
||||
trackPassword(sync).set(password)
|
||||
fun setCredentials(tracker: Tracker, username: String, password: String) {
|
||||
trackUsername(tracker).set(username)
|
||||
trackPassword(tracker).set(password)
|
||||
}
|
||||
|
||||
fun trackToken(sync: Tracker) = preferenceStore.getString(trackToken(sync.id), "")
|
||||
fun trackToken(tracker: Tracker) = preferenceStore.getString(Preference.privateKey("track_token_${tracker.id}"), "")
|
||||
|
||||
fun anilistScoreType() = preferenceStore.getString("anilist_score_type", Anilist.POINT_10)
|
||||
|
||||
fun autoUpdateTrack() = preferenceStore.getBoolean("pref_auto_update_manga_sync_key", true)
|
||||
|
||||
companion object {
|
||||
fun trackUsername(syncId: Long) = Preference.privateKey("pref_mangasync_username_$syncId")
|
||||
|
||||
private fun trackPassword(syncId: Long) = Preference.privateKey("pref_mangasync_password_$syncId")
|
||||
|
||||
private fun trackToken(syncId: Long) = Preference.privateKey("track_token_$syncId")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import eu.kanade.presentation.more.settings.widget.SwitchPreferenceWidget
|
|||
import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget
|
||||
import eu.kanade.presentation.more.settings.widget.TrackingPreferenceWidget
|
||||
import kotlinx.coroutines.launch
|
||||
import tachiyomi.core.preference.PreferenceStore
|
||||
import tachiyomi.presentation.core.components.SliderItem
|
||||
import tachiyomi.presentation.core.util.collectAsState
|
||||
import uy.kohesive.injekt.Injekt
|
||||
|
@ -157,8 +156,8 @@ internal fun PreferenceItem(
|
|||
)
|
||||
}
|
||||
is Preference.PreferenceItem.TrackerPreference -> {
|
||||
val uName by Injekt.get<PreferenceStore>()
|
||||
.getString(TrackPreferences.trackUsername(item.tracker.id))
|
||||
val uName by Injekt.get<TrackPreferences>()
|
||||
.trackUsername(item.tracker)
|
||||
.collectAsState()
|
||||
item.tracker.run {
|
||||
TrackingPreferenceWidget(
|
||||
|
|
|
@ -34,11 +34,10 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark
|
|||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import eu.kanade.presentation.theme.TachiyomiTheme
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.ChapterImpl
|
||||
import eu.kanade.tachiyomi.data.database.models.toDomainChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.chapter.service.calculateChapterGap
|
||||
import tachiyomi.i18n.MR
|
||||
import tachiyomi.presentation.core.i18n.pluralStringResource
|
||||
|
@ -51,8 +50,8 @@ fun ChapterTransition(
|
|||
currChapterDownloaded: Boolean,
|
||||
goingToChapterDownloaded: Boolean,
|
||||
) {
|
||||
val currChapter = transition.from.chapter
|
||||
val goingToChapter = transition.to?.chapter
|
||||
val currChapter = transition.from.chapter.toDomainChapter()
|
||||
val goingToChapter = transition.to?.chapter?.toDomainChapter()
|
||||
|
||||
ProvideTextStyle(MaterialTheme.typography.bodyMedium) {
|
||||
when (transition) {
|
||||
|
@ -65,7 +64,7 @@ fun ChapterTransition(
|
|||
bottomChapter = currChapter,
|
||||
bottomChapterDownloaded = currChapterDownloaded,
|
||||
fallbackLabel = stringResource(MR.strings.transition_no_previous),
|
||||
chapterGap = calculateChapterGap(currChapter.toDomainChapter(), goingToChapter?.toDomainChapter()),
|
||||
chapterGap = calculateChapterGap(currChapter, goingToChapter),
|
||||
)
|
||||
}
|
||||
is ChapterTransition.Next -> {
|
||||
|
@ -77,7 +76,7 @@ fun ChapterTransition(
|
|||
bottomChapter = goingToChapter,
|
||||
bottomChapterDownloaded = goingToChapterDownloaded,
|
||||
fallbackLabel = stringResource(MR.strings.transition_no_next),
|
||||
chapterGap = calculateChapterGap(goingToChapter?.toDomainChapter(), currChapter.toDomainChapter()),
|
||||
chapterGap = calculateChapterGap(goingToChapter, currChapter),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -275,24 +274,23 @@ private val CardColor: CardColors
|
|||
private val VerticalSpacerSize = 24.dp
|
||||
private const val DownloadedIconContentId = "downloaded"
|
||||
|
||||
private fun previewChapter(name: String, scanlator: String, chapterNumber: Float) = ChapterImpl().apply {
|
||||
this.name = name
|
||||
this.scanlator = scanlator
|
||||
this.chapter_number = chapterNumber
|
||||
|
||||
this.id = 0
|
||||
this.manga_id = 0
|
||||
this.url = ""
|
||||
}
|
||||
private fun previewChapter(name: String, scanlator: String, chapterNumber: Double) = Chapter.create().copy(
|
||||
id = 0L,
|
||||
mangaId = 0L,
|
||||
url = "",
|
||||
name = name,
|
||||
scanlator = scanlator,
|
||||
chapterNumber = chapterNumber,
|
||||
)
|
||||
private val FakeChapter = previewChapter(
|
||||
name = "Vol.1, Ch.1 - Fake Chapter Title",
|
||||
scanlator = "Scanlator Name",
|
||||
chapterNumber = 1f,
|
||||
chapterNumber = 1.0,
|
||||
)
|
||||
private val FakeGapChapter = previewChapter(
|
||||
name = "Vol.5, Ch.44 - Fake Gap Chapter Title",
|
||||
scanlator = "Scanlator Name",
|
||||
chapterNumber = 44f,
|
||||
chapterNumber = 44.0,
|
||||
)
|
||||
private val FakeChapterLongTitle = previewChapter(
|
||||
name = "Vol.1, Ch.0 - The Mundane Musings of a Metafictional Manga: A Chapter About a Chapter, Featuring" +
|
||||
|
@ -301,7 +299,7 @@ private val FakeChapterLongTitle = previewChapter(
|
|||
"Fictional Realities and Reality-Bending Fiction, Where the Fourth Wall is Always in Danger of Being Broken " +
|
||||
"and the Line Between Author and Character is Forever Blurred.",
|
||||
scanlator = "Long Long Funny Scanlator Sniper Group Name Reborn",
|
||||
chapterNumber = 1f,
|
||||
chapterNumber = 1.0,
|
||||
)
|
||||
|
||||
@PreviewLightDark
|
||||
|
|
|
@ -13,7 +13,7 @@ internal class TrackInfoDialogHomePreviewProvider :
|
|||
private val aTrack = Track(
|
||||
id = 1L,
|
||||
mangaId = 2L,
|
||||
syncId = 3L,
|
||||
trackerId = 3L,
|
||||
remoteId = 4L,
|
||||
libraryId = null,
|
||||
title = "Manage Name On Tracker Site",
|
||||
|
|
|
@ -62,7 +62,7 @@ internal class TrackerSearchPreviewProvider : PreviewParameterProvider<@Composab
|
|||
private fun randTrackSearch() = TrackSearch().let {
|
||||
it.id = Random.nextLong()
|
||||
it.manga_id = Random.nextLong()
|
||||
it.sync_id = Random.nextInt()
|
||||
it.tracker_id = Random.nextInt()
|
||||
it.remote_id = Random.nextLong()
|
||||
it.library_id = Random.nextLong()
|
||||
it.title = lorem((1..10).random()).joinToString()
|
||||
|
|
|
@ -346,12 +346,12 @@ class MangaRestorer(
|
|||
}
|
||||
|
||||
private suspend fun restoreTracking(manga: Manga, backupTracks: List<BackupTracking>) {
|
||||
val dbTrackBySyncId = getTracks.await(manga.id).associateBy { it.syncId }
|
||||
val dbTrackByTrackerId = getTracks.await(manga.id).associateBy { it.trackerId }
|
||||
|
||||
val (existingTracks, newTracks) = backupTracks
|
||||
.mapNotNull {
|
||||
val track = it.getTrackImpl()
|
||||
val dbTrack = dbTrackBySyncId[track.syncId]
|
||||
val dbTrack = dbTrackByTrackerId[track.trackerId]
|
||||
?: // New track
|
||||
return@mapNotNull track.copy(
|
||||
id = 0, // Let DB assign new ID
|
||||
|
@ -380,7 +380,7 @@ class MangaRestorer(
|
|||
existingTracks.forEach { track ->
|
||||
manga_syncQueries.update(
|
||||
track.mangaId,
|
||||
track.syncId,
|
||||
track.trackerId,
|
||||
track.remoteId,
|
||||
track.libraryId,
|
||||
track.title,
|
||||
|
|
|
@ -8,7 +8,7 @@ interface Track : Serializable {
|
|||
|
||||
var manga_id: Long
|
||||
|
||||
var sync_id: Int
|
||||
var tracker_id: Int
|
||||
|
||||
var remote_id: Long
|
||||
|
||||
|
@ -40,7 +40,7 @@ interface Track : Serializable {
|
|||
|
||||
companion object {
|
||||
fun create(serviceId: Long): Track = TrackImpl().apply {
|
||||
sync_id = serviceId.toInt()
|
||||
tracker_id = serviceId.toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ class TrackImpl : Track {
|
|||
|
||||
override var manga_id: Long = 0
|
||||
|
||||
override var sync_id: Int = 0
|
||||
override var tracker_id: Int = 0
|
||||
|
||||
override var remote_id: Long = 0
|
||||
|
||||
|
|
|
@ -33,6 +33,4 @@ class TrackerManager {
|
|||
fun loggedInTrackers() = trackers.filter { it.isLoggedIn }
|
||||
|
||||
fun get(id: Long) = trackers.find { it.id == id }
|
||||
|
||||
fun hasLoggedIn() = trackers.any { it.isLoggedIn }
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ class TrackSearch : Track {
|
|||
|
||||
override var manga_id: Long = 0
|
||||
|
||||
override var sync_id: Int = 0
|
||||
override var tracker_id: Int = 0
|
||||
|
||||
override var remote_id: Long = 0
|
||||
|
||||
|
@ -47,7 +47,7 @@ class TrackSearch : Track {
|
|||
other as TrackSearch
|
||||
|
||||
if (manga_id != other.manga_id) return false
|
||||
if (sync_id != other.sync_id) return false
|
||||
if (tracker_id != other.tracker_id) return false
|
||||
if (remote_id != other.remote_id) return false
|
||||
|
||||
return true
|
||||
|
@ -55,14 +55,14 @@ class TrackSearch : Track {
|
|||
|
||||
override fun hashCode(): Int {
|
||||
var result = manga_id.hashCode()
|
||||
result = 31 * result + sync_id
|
||||
result = 31 * result + tracker_id
|
||||
result = 31 * result + remote_id.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create(serviceId: Long): TrackSearch = TrackSearch().apply {
|
||||
sync_id = serviceId.toInt()
|
||||
tracker_id = serviceId.toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ class LibraryScreenModel(
|
|||
if (isNotLoggedInAnyTrack || trackFiltersIsIgnored) return@tracking true
|
||||
|
||||
val mangaTracks = trackMap
|
||||
.mapValues { entry -> entry.value.map { it.syncId } }[item.libraryManga.id]
|
||||
.mapValues { entry -> entry.value.map { it.trackerId } }[item.libraryManga.id]
|
||||
.orEmpty()
|
||||
|
||||
val isExcluded = excludedTracks.isNotEmpty() && mangaTracks.fastAny { it in excludedTracks }
|
||||
|
@ -257,7 +257,7 @@ class LibraryScreenModel(
|
|||
entry.value.isEmpty() -> null
|
||||
else ->
|
||||
entry.value
|
||||
.mapNotNull { trackerMap[it.syncId]?.get10PointScore(it) }
|
||||
.mapNotNull { trackerMap[it.trackerId]?.get10PointScore(it) }
|
||||
.average()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -983,7 +983,7 @@ class MangaScreenModel(
|
|||
.map { tracks ->
|
||||
loggedInTrackers
|
||||
// Map to TrackItem
|
||||
.map { service -> TrackItem(tracks.find { it.syncId == service.id }, service) }
|
||||
.map { service -> TrackItem(tracks.find { it.trackerId == service.id }, service) }
|
||||
// Show only if the service supports this manga's source
|
||||
.filter { (it.tracker as? EnhancedTracker)?.accept(source!!) ?: true }
|
||||
}
|
||||
|
|
|
@ -244,7 +244,7 @@ data class TrackInfoDialogHomeScreen(
|
|||
val source = Injekt.get<SourceManager>().getOrStub(sourceId)
|
||||
return loggedInTrackers
|
||||
// Map to TrackItem
|
||||
.map { service -> TrackItem(find { it.syncId == service.id }, service) }
|
||||
.map { service -> TrackItem(find { it.trackerId == service.id }, service) }
|
||||
// Show only if the service supports this manga's source
|
||||
.filter { (it.tracker as? EnhancedTracker)?.accept(source) ?: true }
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.kanade.tachiyomi.ui.reader.model
|
||||
|
||||
import eu.kanade.domain.chapter.model.toDbChapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.ui.reader.loader.PageLoader
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
@ -23,6 +24,8 @@ data class ReaderChapter(val chapter: Chapter) {
|
|||
|
||||
private var references = 0
|
||||
|
||||
constructor(chapter: tachiyomi.domain.chapter.model.Chapter) : this(chapter.toDbChapter())
|
||||
|
||||
fun ref() {
|
||||
references++
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ class StatsScreenModel(
|
|||
val loggedInTrackerIds = loggedInTrackers.map { it.id }.toHashSet()
|
||||
return libraryManga.associate { manga ->
|
||||
val tracks = getTracks.await(manga.id)
|
||||
.fastFilter { it.syncId in loggedInTrackerIds }
|
||||
.fastFilter { it.trackerId in loggedInTrackerIds }
|
||||
|
||||
manga.id to tracks
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ class StatsScreenModel(
|
|||
}
|
||||
|
||||
private fun get10PointScore(track: Track): Double {
|
||||
val service = trackerManager.get(track.syncId)!!
|
||||
val service = trackerManager.get(track.trackerId)!!
|
||||
return service.get10PointScore(track)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ object TrackMapper {
|
|||
): Track = Track(
|
||||
id = id,
|
||||
mangaId = mangaId,
|
||||
syncId = syncId,
|
||||
trackerId = syncId,
|
||||
remoteId = remoteId,
|
||||
libraryId = libraryId,
|
||||
title = title,
|
||||
|
|
|
@ -31,11 +31,11 @@ class TrackRepositoryImpl(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun delete(mangaId: Long, syncId: Long) {
|
||||
override suspend fun delete(mangaId: Long, trackerId: Long) {
|
||||
handler.await {
|
||||
manga_syncQueries.delete(
|
||||
mangaId = mangaId,
|
||||
syncId = syncId,
|
||||
syncId = trackerId,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class TrackRepositoryImpl(
|
|||
tracks.forEach { mangaTrack ->
|
||||
manga_syncQueries.insert(
|
||||
mangaId = mangaTrack.mangaId,
|
||||
syncId = mangaTrack.syncId,
|
||||
syncId = mangaTrack.trackerId,
|
||||
remoteId = mangaTrack.remoteId,
|
||||
libraryId = mangaTrack.libraryId,
|
||||
title = mangaTrack.title,
|
||||
|
|
|
@ -7,7 +7,6 @@ import tachiyomi.domain.track.model.Track
|
|||
@Serializable
|
||||
data class BackupTracking(
|
||||
// in 1.x some of these values have different types or names
|
||||
// syncId is called siteId in 1,x
|
||||
@ProtoNumber(1) var syncId: Int,
|
||||
// LibraryId is not null in 1.x
|
||||
@ProtoNumber(2) var libraryId: Long,
|
||||
|
@ -34,7 +33,7 @@ data class BackupTracking(
|
|||
return Track(
|
||||
id = -1,
|
||||
mangaId = -1,
|
||||
syncId = this@BackupTracking.syncId.toLong(),
|
||||
trackerId = this@BackupTracking.syncId.toLong(),
|
||||
remoteId = if (this@BackupTracking.mediaIdInt != 0) {
|
||||
this@BackupTracking.mediaIdInt.toLong()
|
||||
} else {
|
||||
|
|
|
@ -8,9 +8,9 @@ class DeleteTrack(
|
|||
private val trackRepository: TrackRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(mangaId: Long, syncId: Long) {
|
||||
suspend fun await(mangaId: Long, trackerId: Long) {
|
||||
try {
|
||||
trackRepository.delete(mangaId, syncId)
|
||||
trackRepository.delete(mangaId, trackerId)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package tachiyomi.domain.track.model
|
|||
data class Track(
|
||||
val id: Long,
|
||||
val mangaId: Long,
|
||||
val syncId: Long,
|
||||
val trackerId: Long,
|
||||
val remoteId: Long,
|
||||
val libraryId: Long?,
|
||||
val title: String,
|
||||
|
|
|
@ -13,7 +13,7 @@ interface TrackRepository {
|
|||
|
||||
fun getTracksByMangaIdAsFlow(mangaId: Long): Flow<List<Track>>
|
||||
|
||||
suspend fun delete(mangaId: Long, syncId: Long)
|
||||
suspend fun delete(mangaId: Long, trackerId: Long)
|
||||
|
||||
suspend fun insert(track: Track)
|
||||
|
||||
|
|
Loading…
Reference in a new issue