diff --git a/app/src/main/java/eu/kanade/domain/track/model/Track.kt b/app/src/main/java/eu/kanade/domain/track/model/Track.kt index 81f629024..5fa87b16d 100644 --- a/app/src/main/java/eu/kanade/domain/track/model/Track.kt +++ b/app/src/main/java/eu/kanade/domain/track/model/Track.kt @@ -28,7 +28,7 @@ data class Track( } } -fun Track.toDbTrack(): DbTrack = DbTrack.create(syncId.toInt()).also { +fun Track.toDbTrack(): DbTrack = DbTrack.create(syncId).also { it.id = id it.manga_id = mangaId it.media_id = remoteId diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt index 779426033..bc60ffda5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt @@ -87,7 +87,7 @@ abstract class AbstractBackupRestore(protected val co */ internal suspend fun updateTracking(manga: Manga, tracks: List) { tracks.forEach { track -> - val service = trackManager.getService(track.sync_id) + val service = trackManager.getService(track.sync_id.toLong()) if (service != null && service.isLogged) { try { val updatedTrack = service.refresh(track) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt index dfe715c6e..52b4cd2fc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt @@ -56,7 +56,7 @@ class FullBackupRestoreValidator : AbstractBackupRestoreValidator() { .map { it.syncId } .distinct() val missingTrackers = trackers - .mapNotNull { trackManager.getService(it) } + .mapNotNull { trackManager.getService(it.toLong()) } .filter { !it.isLogged } .map { context.getString(it.nameRes()) } .sorted() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt index 4fb22b91a..38df114e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt @@ -39,8 +39,8 @@ interface Track : Serializable { } companion object { - fun create(serviceId: Int): Track = TrackImpl().apply { - sync_id = serviceId + fun create(serviceId: Long): Track = TrackImpl().apply { + sync_id = serviceId.toInt() } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt index 25b504d72..6663ce8d9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt @@ -7,8 +7,6 @@ import eu.kanade.tachiyomi.data.database.DbProvider import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.resolvers.LibraryMangaGetResolver -import eu.kanade.tachiyomi.data.database.resolvers.MangaCoverLastModifiedPutResolver -import eu.kanade.tachiyomi.data.database.resolvers.MangaFavoritePutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaFlagsPutResolver import eu.kanade.tachiyomi.data.database.tables.CategoryTable import eu.kanade.tachiyomi.data.database.tables.ChapterTable @@ -85,16 +83,6 @@ interface MangaQueries : DbProvider { .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags)) .prepare() - fun updateMangaFavorite(manga: Manga) = db.put() - .`object`(manga) - .withPutResolver(MangaFavoritePutResolver()) - .prepare() - - fun updateMangaCoverLastModified(manga: Manga) = db.put() - .`object`(manga) - .withPutResolver(MangaCoverLastModifiedPutResolver()) - .prepare() - fun getLastReadManga() = db.get() .listOfObjects(Manga::class.java) .withQuery( diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt index bb692d387..c6afd2977 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt @@ -1,12 +1,9 @@ package eu.kanade.tachiyomi.data.database.queries -import com.pushtorefresh.storio.sqlite.queries.DeleteQuery import com.pushtorefresh.storio.sqlite.queries.Query import eu.kanade.tachiyomi.data.database.DbProvider -import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.tables.TrackTable -import eu.kanade.tachiyomi.data.track.TrackService interface TrackQueries : DbProvider { @@ -19,28 +16,5 @@ interface TrackQueries : DbProvider { ) .prepare() - fun getTracks(mangaId: Long?) = db.get() - .listOfObjects(Track::class.java) - .withQuery( - Query.builder() - .table(TrackTable.TABLE) - .where("${TrackTable.COL_MANGA_ID} = ?") - .whereArgs(mangaId) - .build(), - ) - .prepare() - fun insertTrack(track: Track) = db.put().`object`(track).prepare() - - fun insertTracks(tracks: List) = db.put().objects(tracks).prepare() - - fun deleteTrackForManga(manga: Manga, sync: TrackService) = db.delete() - .byQuery( - DeleteQuery.builder() - .table(TrackTable.TABLE) - .where("${TrackTable.COL_MANGA_ID} = ? AND ${TrackTable.COL_SYNC_ID} = ?") - .whereArgs(manga.id, sync.id) - .build(), - ) - .prepare() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaCoverLastModifiedPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaCoverLastModifiedPutResolver.kt deleted file mode 100644 index 6ab59168f..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaCoverLastModifiedPutResolver.kt +++ /dev/null @@ -1,32 +0,0 @@ -package eu.kanade.tachiyomi.data.database.resolvers - -import androidx.core.content.contentValuesOf -import com.pushtorefresh.storio.sqlite.StorIOSQLite -import com.pushtorefresh.storio.sqlite.operations.put.PutResolver -import com.pushtorefresh.storio.sqlite.operations.put.PutResult -import com.pushtorefresh.storio.sqlite.queries.UpdateQuery -import eu.kanade.tachiyomi.data.database.inTransactionReturn -import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.database.tables.MangaTable - -class MangaCoverLastModifiedPutResolver : PutResolver() { - - override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn { - val updateQuery = mapToUpdateQuery(manga) - val contentValues = mapToContentValues(manga) - - val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues) - PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) - } - - fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder() - .table(MangaTable.TABLE) - .where("${MangaTable.COL_ID} = ?") - .whereArgs(manga.id) - .build() - - fun mapToContentValues(manga: Manga) = - contentValuesOf( - MangaTable.COL_COVER_LAST_MODIFIED to manga.cover_last_modified, - ) -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFavoritePutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFavoritePutResolver.kt deleted file mode 100644 index 42890f3d5..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFavoritePutResolver.kt +++ /dev/null @@ -1,32 +0,0 @@ -package eu.kanade.tachiyomi.data.database.resolvers - -import androidx.core.content.contentValuesOf -import com.pushtorefresh.storio.sqlite.StorIOSQLite -import com.pushtorefresh.storio.sqlite.operations.put.PutResolver -import com.pushtorefresh.storio.sqlite.operations.put.PutResult -import com.pushtorefresh.storio.sqlite.queries.UpdateQuery -import eu.kanade.tachiyomi.data.database.inTransactionReturn -import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.database.tables.MangaTable - -class MangaFavoritePutResolver : PutResolver() { - - override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn { - val updateQuery = mapToUpdateQuery(manga) - val contentValues = mapToContentValues(manga) - - val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues) - PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) - } - - fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder() - .table(MangaTable.TABLE) - .where("${MangaTable.COL_ID} = ?") - .whereArgs(manga.id) - .build() - - fun mapToContentValues(manga: Manga) = - contentValuesOf( - MangaTable.COL_FAVORITE to manga.favorite, - ) -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index f7a9277f8..7a91cf809 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -12,6 +12,10 @@ import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.interactor.GetMangaById import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.toMangaInfo +import eu.kanade.domain.track.interactor.GetTracks +import eu.kanade.domain.track.interactor.InsertTrack +import eu.kanade.domain.track.model.toDbTrack +import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -87,6 +91,8 @@ class LibraryUpdateService( private val getMangaById: GetMangaById = Injekt.get(), private val updateManga: UpdateManga = Injekt.get(), private val syncChaptersWithSource: SyncChaptersWithSource = Injekt.get(), + private val getTracks: GetTracks = Injekt.get(), + private val insertTrack: InsertTrack = Injekt.get(), ) : Service() { private lateinit var wakeLock: PowerManager.WakeLock @@ -500,18 +506,18 @@ class LibraryUpdateService( } private suspend fun updateTrackings(manga: LibraryManga, loggedServices: List) { - db.getTracks(manga.id).executeAsBlocking() + getTracks.await(manga.id!!) .map { track -> supervisorScope { async { - val service = trackManager.getService(track.sync_id) + val service = trackManager.getService(track.syncId) if (service != null && service in loggedServices) { try { - val updatedTrack = service.refresh(track) - db.insertTrack(updatedTrack).executeAsBlocking() + val updatedTrack = service.refresh(track.toDbTrack()) + insertTrack.await(updatedTrack.toDomainTrack()!!) if (service is EnhancedTrackService) { - syncChaptersWithTrackServiceTwoWay(db, db.getChapters(manga).executeAsBlocking(), track, service) + syncChaptersWithTrackServiceTwoWay(db, db.getChapters(manga).executeAsBlocking(), track.toDbTrack(), service) } } catch (e: Throwable) { // Ignore errors and continue diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index a84bfbba1..26838629d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -75,9 +75,9 @@ object PreferenceKeys { const val autoClearChapterCache = "auto_clear_chapter_cache" - fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId" + fun trackUsername(syncId: Long) = "pref_mangasync_username_$syncId" - fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId" + fun trackPassword(syncId: Long) = "pref_mangasync_password_$syncId" - fun trackToken(syncId: Int) = "track_token_$syncId" + fun trackToken(syncId: Long) = "track_token_$syncId" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt index 584136bd2..b13544d02 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt @@ -12,13 +12,13 @@ import eu.kanade.tachiyomi.data.track.shikimori.Shikimori class TrackManager(context: Context) { companion object { - const val MYANIMELIST = 1 - const val ANILIST = 2 - const val KITSU = 3 - const val SHIKIMORI = 4 - const val BANGUMI = 5 - const val KOMGA = 6 - const val MANGA_UPDATES = 7 + const val MYANIMELIST = 1L + const val ANILIST = 2L + const val KITSU = 3L + const val SHIKIMORI = 4L + const val BANGUMI = 5L + const val KOMGA = 6L + const val MANGA_UPDATES = 7L } val myAnimeList = MyAnimeList(context, MYANIMELIST) @@ -37,7 +37,7 @@ class TrackManager(context: Context) { val services = listOf(myAnimeList, aniList, kitsu, shikimori, bangumi, komga, mangaUpdates) - fun getService(id: Int) = services.find { it.id == id } + fun getService(id: Long) = services.find { it.id == id } fun hasLoggedServices() = services.any { it.isLogged } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt index 3e59201ba..4bdbfc851 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt @@ -11,7 +11,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper import okhttp3.OkHttpClient import uy.kohesive.injekt.injectLazy -abstract class TrackService(val id: Int) { +abstract class TrackService(val id: Long) { val preferences: PreferencesHelper by injectLazy() val networkService: NetworkHelper by injectLazy() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt index 1210837c0..7e8c39101 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt @@ -12,7 +12,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy -class Anilist(private val context: Context, id: Int) : TrackService(id) { +class Anilist(private val context: Context, id: Long) : TrackService(id) { companion object { const val READING = 1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt index 8189732ed..59e6fd241 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt @@ -12,7 +12,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy -class Bangumi(private val context: Context, id: Int) : TrackService(id) { +class Bangumi(private val context: Context, id: Long) : TrackService(id) { private val json: Json by injectLazy() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingStore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingStore.kt index e0c968f08..862d11e8f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingStore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingStore.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.data.track.job import android.content.Context import androidx.core.content.edit -import eu.kanade.tachiyomi.data.database.models.Track +import eu.kanade.domain.track.model.Track import eu.kanade.tachiyomi.util.system.logcat import logcat.LogPriority @@ -16,8 +16,8 @@ class DelayedTrackingStore(context: Context) { fun addItem(track: Track) { val trackId = track.id.toString() val (_, lastChapterRead) = preferences.getString(trackId, "0:0.0")!!.split(":") - if (track.last_chapter_read > lastChapterRead.toFloat()) { - val value = "${track.manga_id}:${track.last_chapter_read}" + if (track.lastChapterRead > lastChapterRead.toFloat()) { + val value = "${track.mangaId}:${track.lastChapterRead}" logcat(LogPriority.DEBUG) { "Queuing track item: $trackId, $value" } preferences.edit { putString(trackId, value) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt index e47961eef..6c5259ac7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/job/DelayedTrackingUpdateJob.kt @@ -9,7 +9,10 @@ import androidx.work.NetworkType import androidx.work.OneTimeWorkRequestBuilder import androidx.work.WorkManager import androidx.work.WorkerParameters -import eu.kanade.tachiyomi.data.database.DatabaseHelper +import eu.kanade.domain.manga.interactor.GetMangaById +import eu.kanade.domain.track.interactor.GetTracks +import eu.kanade.domain.track.interactor.InsertTrack +import eu.kanade.domain.track.model.toDbTrack import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.Dispatchers @@ -23,26 +26,27 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters) CoroutineWorker(context, workerParams) { override suspend fun doWork(): Result { - val db = Injekt.get() + val getMangaById = Injekt.get() + val getTracks = Injekt.get() + val insertTrack = Injekt.get() + val trackManager = Injekt.get() val delayedTrackingStore = Injekt.get() withContext(Dispatchers.IO) { val tracks = delayedTrackingStore.getItems().mapNotNull { - val manga = db.getManga(it.mangaId).executeAsBlocking() ?: return@withContext - db.getTracks(manga.id).executeAsBlocking() + val manga = getMangaById.await(it.mangaId) ?: return@withContext + getTracks.await(manga.id) .find { track -> track.id == it.trackId } - ?.also { track -> - track.last_chapter_read = it.lastChapterRead - } + ?.copy(lastChapterRead = it.lastChapterRead.toDouble()) } tracks.forEach { track -> try { - val service = trackManager.getService(track.sync_id) + val service = trackManager.getService(track.syncId) if (service != null && service.isLogged) { - service.update(track, true) - db.insertTrack(track).executeAsBlocking() + service.update(track.toDbTrack(), true) + insertTrack.await(track) } } catch (e: Exception) { logcat(LogPriority.ERROR, e) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt index 5cec2d634..fc4f4e57f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt @@ -13,7 +13,7 @@ import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy import java.text.DecimalFormat -class Kitsu(private val context: Context, id: Int) : TrackService(id) { +class Kitsu(private val context: Context, id: Long) : TrackService(id) { companion object { const val READING = 1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt index 409865d81..454be6d91 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt @@ -16,7 +16,7 @@ import okhttp3.OkHttpClient import eu.kanade.domain.manga.model.Manga as DomainManga import eu.kanade.domain.track.model.Track as DomainTrack -class Komga(private val context: Context, id: Int) : TrackService(id), EnhancedTrackService, NoLoginTrackService { +class Komga(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService, NoLoginTrackService { companion object { const val UNREAD = 1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt index 04c25c002..8c64ba4c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt @@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.data.track.mangaupdates.dto.copyTo import eu.kanade.tachiyomi.data.track.mangaupdates.dto.toTrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch -class MangaUpdates(private val context: Context, id: Int) : TrackService(id) { +class MangaUpdates(private val context: Context, id: Long) : TrackService(id) { companion object { const val READING_LIST = 0 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt index 60dc5f0cb..fb959a89b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt @@ -23,7 +23,7 @@ data class Record( val latestChapter: Int? = null, ) -fun Record.toTrackSearch(id: Int): TrackSearch { +fun Record.toTrackSearch(id: Long): TrackSearch { return TrackSearch.create(id).apply { media_id = this@toTrackSearch.seriesId ?: 0L title = this@toTrackSearch.title?.htmlDecode() ?: "" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt index a043610d8..2f930b50c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt @@ -61,8 +61,8 @@ class TrackSearch : Track { } companion object { - fun create(serviceId: Int): TrackSearch = TrackSearch().apply { - sync_id = serviceId + fun create(serviceId: Long): TrackSearch = TrackSearch().apply { + sync_id = serviceId.toInt() } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt index 5172b326c..0db5d8546 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt @@ -12,7 +12,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy -class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { +class MyAnimeList(private val context: Context, id: Long) : TrackService(id) { companion object { const val READING = 1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt index c0e0c3f06..8c5b757e5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt @@ -12,7 +12,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy -class Shikimori(private val context: Context, id: Int) : TrackService(id) { +class Shikimori(private val context: Context, id: Long) : TrackService(id) { companion object { const val READING = 1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt index f72a096da..ec420e631 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt @@ -1,10 +1,11 @@ package eu.kanade.tachiyomi.ui.browse.migration +import eu.kanade.domain.track.interactor.GetTracks 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 kotlinx.coroutines.runBlocking import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy @@ -17,7 +18,7 @@ object MigrationFlags { private const val CUSTOM_COVER = 0b1000 private val coverCache: CoverCache by injectLazy() - private val db: DatabaseHelper = Injekt.get() + private val getTracks: GetTracks = Injekt.get() val flags get() = arrayOf(CHAPTERS, CATEGORIES, TRACK, CUSTOM_COVER) @@ -48,14 +49,12 @@ object MigrationFlags { fun titles(manga: Manga?): Array { val titles = arrayOf(R.string.chapters, R.string.categories).toMutableList() if (manga != null) { - db.inTransaction { - if (db.getTracks(manga.id).executeAsBlocking().isNotEmpty()) { - titles.add(R.string.track) - } + if (runBlocking { getTracks.await(manga.id!!) }.isNotEmpty()) { + titles.add(R.string.track) + } - if (manga.hasCustomCover(coverCache)) { - titles.add(R.string.custom_cover) - } + if (manga.hasCustomCover(coverCache)) { + titles.add(R.string.custom_cover) } } return titles.toTypedArray() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index d087dcfbe..db91fa508 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -5,6 +5,8 @@ import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.manga.interactor.GetDuplicateLibraryManga import eu.kanade.domain.manga.model.toDbManga +import eu.kanade.domain.track.interactor.InsertTrack +import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category @@ -67,6 +69,7 @@ open class BrowseSourcePresenter( private val coverCache: CoverCache = Injekt.get(), private val getDuplicateLibraryManga: GetDuplicateLibraryManga = Injekt.get(), private val getCategories: GetCategories = Injekt.get(), + private val insertTrack: InsertTrack = Injekt.get(), ) : BasePresenter() { /** @@ -286,7 +289,7 @@ open class BrowseSourcePresenter( service.match(manga)?.let { track -> track.manga_id = manga.id!! (service as TrackService).bind(track) - db.insertTrack(track).executeAsBlocking() + insertTrack.await(track.toDomainTrack()!!) syncChaptersWithTrackServiceTwoWay(db, db.getChapters(manga).executeAsBlocking(), track, service as TrackService) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 7e3fa73c4..63d7bfc5b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -123,7 +123,7 @@ class LibraryPresenter( val filterCompleted = preferences.filterCompleted().get() val loggedInServices = trackManager.services.filter { trackService -> trackService.isLogged } .associate { trackService -> - Pair(trackService.id, preferences.filterTracking(trackService.id).get()) + Pair(trackService.id, preferences.filterTracking(trackService.id.toInt()).get()) } val isNotAnyLoggedIn = !loggedInServices.values.any() @@ -173,8 +173,8 @@ class LibraryPresenter( if (!containsExclude.any() && !containsInclude.any()) return@tracking true - val exclude = trackedManga?.filterKeys { containsExclude.containsKey(it) }?.values ?: emptyList() - val include = trackedManga?.filterKeys { containsInclude.containsKey(it) }?.values ?: emptyList() + val exclude = trackedManga?.filterKeys { containsExclude.containsKey(it.toLong()) }?.values ?: emptyList() + val include = trackedManga?.filterKeys { containsInclude.containsKey(it.toLong()) }?.values ?: emptyList() if (containsInclude.any() && containsExclude.any()) { return@tracking if (exclude.isNotEmpty()) !exclude.any() else include.any() @@ -411,7 +411,7 @@ class LibraryPresenter( .mapValues { tracksForMangaId -> // Check if any of the trackers is logged in for the current manga id tracksForMangaId.value.associate { - Pair(it.sync_id, trackManager.getService(it.sync_id)?.isLogged ?: false) + Pair(it.sync_id, trackManager.getService(it.sync_id.toLong())?.isLogged ?: false) } } }.observeOn(Schedulers.io()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 427c9bcc5..1795d31c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -91,7 +91,7 @@ class LibrarySettingsSheet( private val unread = Item.TriStateGroup(R.string.action_filter_unread, this) private val started = Item.TriStateGroup(R.string.action_filter_started, this) private val completed = Item.TriStateGroup(R.string.completed, this) - private val trackFilters: Map + private val trackFilters: Map override val header = null override val items: List @@ -127,7 +127,7 @@ class LibrarySettingsSheet( completed.state = preferences.filterCompleted().get() trackFilters.forEach { trackFilter -> - trackFilter.value.state = preferences.filterTracking(trackFilter.key).get() + trackFilter.value.state = preferences.filterTracking(trackFilter.key.toInt()).get() } } @@ -148,7 +148,7 @@ class LibrarySettingsSheet( else -> { trackFilters.forEach { trackFilter -> if (trackFilter.value == item) { - preferences.filterTracking(trackFilter.key).set(newState) + preferences.filterTracking(trackFilter.key.toInt()).set(newState) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index f3f26901f..84e50ccb0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -692,7 +692,7 @@ class MangaPresenter( .map { tracks -> val dbTracks = tracks.map { it.toDbTrack() } loggedServices.map { service -> - TrackItem(dbTracks.find { it.sync_id == service.id }, service) + TrackItem(dbTracks.find { it.sync_id.toLong() == service.id }, service) } } .collectLatest { trackItems -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt index bfd7e4837..51407cb4a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt @@ -32,7 +32,7 @@ class SetTrackChaptersDialog : DialogController @Suppress("unused") constructor(bundle: Bundle) : super(bundle) { val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track - val service = Injekt.get().getService(track.sync_id)!! + val service = Injekt.get().getService(track.sync_id.toLong())!! item = TrackItem(track, service) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt index d7732933b..cf7cf426f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt @@ -32,7 +32,7 @@ class SetTrackScoreDialog : DialogController @Suppress("unused") constructor(bundle: Bundle) : super(bundle) { val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track - val service = Injekt.get().getService(track.sync_id)!! + val service = Injekt.get().getService(track.sync_id.toLong())!! item = TrackItem(track, service) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt index 961efe6eb..128dc3b7f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt @@ -30,7 +30,7 @@ class SetTrackStatusDialog : DialogController @Suppress("unused") constructor(bundle: Bundle) : super(bundle) { val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track - val service = Injekt.get().getService(track.sync_id)!! + val service = Injekt.get().getService(track.sync_id.toLong())!! item = TrackItem(track, service) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt index f90378b53..f8f0aaf43 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt @@ -54,7 +54,7 @@ class TrackSearchDialog : DialogController { @Suppress("unused") constructor(bundle: Bundle) : super(bundle) { - service = Injekt.get().getService(bundle.getInt(KEY_SERVICE))!! + service = Injekt.get().getService(bundle.getLong(KEY_SERVICE))!! currentTrackUrl = bundle.getString(KEY_CURRENT_URL) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 1a0ac93a9..47028628c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -10,7 +10,9 @@ import eu.kanade.domain.chapter.model.ChapterUpdate import eu.kanade.domain.history.interactor.UpsertHistory import eu.kanade.domain.history.model.HistoryUpdate import eu.kanade.domain.manga.model.isLocal -import eu.kanade.tachiyomi.data.cache.CoverCache +import eu.kanade.domain.track.interactor.GetTracks +import eu.kanade.domain.track.interactor.InsertTrack +import eu.kanade.domain.track.model.toDbTrack import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toDomainManga @@ -45,6 +47,7 @@ import eu.kanade.tachiyomi.util.system.isOnline import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.runBlocking import logcat.LogPriority import rx.Observable import rx.Subscription @@ -63,9 +66,10 @@ class ReaderPresenter( private val db: DatabaseHelper = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), - private val coverCache: CoverCache = Injekt.get(), private val preferences: PreferencesHelper = Injekt.get(), private val delayedTrackingStore: DelayedTrackingStore = Injekt.get(), + private val getTracks: GetTracks = Injekt.get(), + private val insertTrack: InsertTrack = Injekt.get(), private val upsertHistory: UpsertHistory = Injekt.get(), private val updateChapter: UpdateChapter = Injekt.get(), ) : BasePresenter() { @@ -152,9 +156,8 @@ class ReaderPresenter( private var hasTrackers: Boolean = false private val checkTrackers: (Manga) -> Unit = { manga -> - val tracks = db.getTracks(manga.id).executeAsBlocking() - - hasTrackers = tracks.size > 0 + val tracks = runBlocking { getTracks.await(manga.id!!) } + hasTrackers = tracks.isNotEmpty() } private val incognitoMode = preferences.incognitoMode().get() @@ -740,27 +743,27 @@ class ReaderPresenter( if (!preferences.autoUpdateTrack()) return val manga = manga ?: return - val chapterRead = readerChapter.chapter.chapter_number + val chapterRead = readerChapter.chapter.chapter_number.toDouble() val trackManager = Injekt.get() val context = Injekt.get() launchIO { - db.getTracks(manga.id).executeAsBlocking() + getTracks.await(manga.id!!) .mapNotNull { track -> - val service = trackManager.getService(track.sync_id) - if (service != null && service.isLogged && chapterRead > track.last_chapter_read) { - track.last_chapter_read = chapterRead + val service = trackManager.getService(track.syncId) + if (service != null && service.isLogged && chapterRead > track.lastChapterRead) { + val updatedTrack = track.copy(lastChapterRead = chapterRead) // We want these to execute even if the presenter is destroyed and leaks // for a while. The view can still be garbage collected. async { runCatching { if (context.isOnline()) { - service.update(track, true) - db.insertTrack(track).executeAsBlocking() + service.update(updatedTrack.toDbTrack(), true) + insertTrack.await(updatedTrack) } else { - delayedTrackingStore.addItem(track) + delayedTrackingStore.addItem(updatedTrack) DelayedTrackingUpdateJob.setupTask(context) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt index 5c3505d9c..8950d9471 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt @@ -146,7 +146,7 @@ class SettingsTrackingController : return super.onOptionsItemSelected(item) } - private fun updatePreference(id: Int) { + private fun updatePreference(id: Long) { val pref = findPreference(Keys.trackUsername(id)) as? TrackerPreference pref?.notifyChanged() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt index 9ebe27fa6..e8cae61c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt @@ -19,7 +19,7 @@ class TrackLoginDialog( bundle: Bundle? = null, ) : LoginDialogPreference(usernameLabelRes, bundle) { - private val service = Injekt.get().getService(args.getInt("serviceId"))!! + private val service = Injekt.get().getService(args.getLong("serviceId"))!! constructor(service: TrackService) : this(service, null) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt index 0f89efdb5..78462c054 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt @@ -14,7 +14,7 @@ import uy.kohesive.injekt.api.get class TrackLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) { - private val service = Injekt.get().getService(args.getInt("serviceId"))!! + private val service = Injekt.get().getService(args.getLong("serviceId"))!! constructor(service: TrackService) : this(bundleOf("serviceId" to service.id))