mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-18 06:57:28 +01:00
Use sqldelight for direct db calls in MangaPresenter (#7366)
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package eu.kanade.domain.track.interactor
|
||||
|
||||
import eu.kanade.domain.track.repository.TrackRepository
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import logcat.LogPriority
|
||||
|
||||
class DeleteTrack(
|
||||
private val trackRepository: TrackRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(mangaId: Long, syncId: Long) {
|
||||
try {
|
||||
trackRepository.delete(mangaId, syncId)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package eu.kanade.domain.track.interactor
|
||||
import eu.kanade.domain.track.model.Track
|
||||
import eu.kanade.domain.track.repository.TrackRepository
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import logcat.LogPriority
|
||||
|
||||
class GetTracks(
|
||||
@@ -17,4 +18,8 @@ class GetTracks(
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun subscribe(mangaId: Long): Flow<List<Track>> {
|
||||
return trackRepository.subscribeTracksByMangaId(mangaId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,14 @@ class InsertTrack(
|
||||
private val trackRepository: TrackRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(track: Track) {
|
||||
try {
|
||||
trackRepository.insert(track)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun awaitAll(tracks: List<Track>) {
|
||||
try {
|
||||
trackRepository.insertAll(tracks)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package eu.kanade.domain.track.model
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Track as DbTrack
|
||||
|
||||
data class Track(
|
||||
val id: Long,
|
||||
val mangaId: Long,
|
||||
@@ -25,3 +27,37 @@ data class Track(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun Track.toDbTrack(): DbTrack = DbTrack.create(syncId.toInt()).also {
|
||||
it.id = id
|
||||
it.manga_id = mangaId
|
||||
it.media_id = remoteId
|
||||
it.library_id = libraryId
|
||||
it.title = title
|
||||
it.last_chapter_read = lastChapterRead.toFloat()
|
||||
it.total_chapters = totalChapters.toInt()
|
||||
it.status = status.toInt()
|
||||
it.score = score
|
||||
it.tracking_url = remoteUrl
|
||||
it.started_reading_date = startDate
|
||||
it.finished_reading_date = finishDate
|
||||
}
|
||||
|
||||
fun DbTrack.toDomainTrack(idRequired: Boolean = true): Track? {
|
||||
val trackId = id ?: if (idRequired.not()) -1 else return null
|
||||
return Track(
|
||||
id = trackId,
|
||||
mangaId = manga_id,
|
||||
syncId = sync_id.toLong(),
|
||||
remoteId = media_id,
|
||||
libraryId = library_id,
|
||||
title = title,
|
||||
lastChapterRead = last_chapter_read.toDouble(),
|
||||
totalChapters = total_chapters.toLong(),
|
||||
status = status.toLong(),
|
||||
score = score,
|
||||
remoteUrl = tracking_url,
|
||||
startDate = started_reading_date,
|
||||
finishDate = finished_reading_date,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package eu.kanade.domain.track.repository
|
||||
|
||||
import eu.kanade.domain.track.model.Track
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface TrackRepository {
|
||||
|
||||
suspend fun getTracksByMangaId(mangaId: Long): List<Track>
|
||||
|
||||
suspend fun subscribeTracksByMangaId(mangaId: Long): Flow<List<Track>>
|
||||
|
||||
suspend fun delete(mangaId: Long, syncId: Long)
|
||||
|
||||
suspend fun insert(track: Track)
|
||||
|
||||
suspend fun insertAll(tracks: List<Track>)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user