Address minor build warnings

This commit is contained in:
arkon 2023-05-06 23:11:14 -04:00
parent 44383ff950
commit b051e37ab7
4 changed files with 46 additions and 70 deletions

View File

@ -70,7 +70,6 @@ class BackupManager(
* @param uri path of Uri * @param uri path of Uri
* @param isAutoBackup backup called from scheduled backup job * @param isAutoBackup backup called from scheduled backup job
*/ */
@Suppress("BlockingMethodInNonBlockingContext")
suspend fun createBackup(uri: Uri, flags: Int, isAutoBackup: Boolean): String { suspend fun createBackup(uri: Uri, flags: Int, isAutoBackup: Boolean): String {
if (!context.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { if (!context.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
throw IllegalStateException(context.getString(R.string.missing_storage_permission)) throw IllegalStateException(context.getString(R.string.missing_storage_permission))
@ -222,10 +221,10 @@ class BackupManager(
} }
internal suspend fun restoreExistingManga(manga: Manga, dbManga: Mangas): Manga { internal suspend fun restoreExistingManga(manga: Manga, dbManga: Mangas): Manga {
var manga = manga.copy(id = dbManga._id) var updatedManga = manga.copy(id = dbManga._id)
manga = manga.copyFrom(dbManga) updatedManga = updatedManga.copyFrom(dbManga)
updateManga(manga) updateManga(updatedManga)
return manga return updatedManga
} }
/** /**
@ -298,7 +297,7 @@ class BackupManager(
dbCategories.firstOrNull { dbCategory -> dbCategories.firstOrNull { dbCategory ->
dbCategory.name == backupCategory.name dbCategory.name == backupCategory.name
}?.let { dbCategory -> }?.let { dbCategory ->
mangaCategoriesToUpdate.add(Pair(manga.id!!, dbCategory.id)) mangaCategoriesToUpdate.add(Pair(manga.id, dbCategory.id))
} }
} }
} }
@ -306,7 +305,7 @@ class BackupManager(
// Update database // Update database
if (mangaCategoriesToUpdate.isNotEmpty()) { if (mangaCategoriesToUpdate.isNotEmpty()) {
handler.await(true) { handler.await(true) {
mangas_categoriesQueries.deleteMangaCategoryByMangaId(manga.id!!) mangas_categoriesQueries.deleteMangaCategoryByMangaId(manga.id)
mangaCategoriesToUpdate.forEach { (mangaId, categoryId) -> mangaCategoriesToUpdate.forEach { (mangaId, categoryId) ->
mangas_categoriesQueries.insert(mangaId, categoryId) mangas_categoriesQueries.insert(mangaId, categoryId)
} }
@ -370,15 +369,15 @@ class BackupManager(
* @param tracks the track list to restore. * @param tracks the track list to restore.
*/ */
internal suspend fun restoreTracking(manga: Manga, tracks: List<tachiyomi.domain.track.model.Track>) { internal suspend fun restoreTracking(manga: Manga, tracks: List<tachiyomi.domain.track.model.Track>) {
// Fix foreign keys with the current manga id
val tracks = tracks.map { it.copy(mangaId = manga.id!!) }
// Get tracks from database // Get tracks from database
val dbTracks = handler.awaitList { manga_syncQueries.getTracksByMangaId(manga.id!!) } val dbTracks = handler.awaitList { manga_syncQueries.getTracksByMangaId(manga.id) }
val toUpdate = mutableListOf<Manga_sync>() val toUpdate = mutableListOf<Manga_sync>()
val toInsert = mutableListOf<tachiyomi.domain.track.model.Track>() val toInsert = mutableListOf<tachiyomi.domain.track.model.Track>()
tracks.forEach { track -> tracks
// Fix foreign keys with the current manga id
.map { it.copy(mangaId = manga.id) }
.forEach { track ->
var isInDatabase = false var isInDatabase = false
for (dbTrack in dbTracks) { for (dbTrack in dbTracks) {
if (track.syncId == dbTrack.sync_id) { if (track.syncId == dbTrack.sync_id) {
@ -401,6 +400,7 @@ class BackupManager(
toInsert.add(track.copy(id = 0)) toInsert.add(track.copy(id = 0))
} }
} }
// Update database // Update database
if (toUpdate.isNotEmpty()) { if (toUpdate.isNotEmpty()) {
handler.await(true) { handler.await(true) {
@ -446,25 +446,25 @@ class BackupManager(
} }
internal suspend fun restoreChapters(manga: Manga, chapters: List<tachiyomi.domain.chapter.model.Chapter>) { internal suspend fun restoreChapters(manga: Manga, chapters: List<tachiyomi.domain.chapter.model.Chapter>) {
val dbChapters = handler.awaitList { chaptersQueries.getChaptersByMangaId(manga.id!!) } val dbChapters = handler.awaitList { chaptersQueries.getChaptersByMangaId(manga.id) }
val processed = chapters.map { chapter -> val processed = chapters.map { chapter ->
var chapter = chapter var updatedChapter = chapter
val dbChapter = dbChapters.find { it.url == chapter.url } val dbChapter = dbChapters.find { it.url == updatedChapter.url }
if (dbChapter != null) { if (dbChapter != null) {
chapter = chapter.copy(id = dbChapter._id) updatedChapter = updatedChapter.copy(id = dbChapter._id)
chapter = chapter.copyFrom(dbChapter) updatedChapter = updatedChapter.copyFrom(dbChapter)
if (dbChapter.read && !chapter.read) { if (dbChapter.read && !updatedChapter.read) {
chapter = chapter.copy(read = dbChapter.read, lastPageRead = dbChapter.last_page_read) updatedChapter = updatedChapter.copy(read = true, lastPageRead = dbChapter.last_page_read)
} else if (chapter.lastPageRead == 0L && dbChapter.last_page_read != 0L) { } else if (updatedChapter.lastPageRead == 0L && dbChapter.last_page_read != 0L) {
chapter = chapter.copy(lastPageRead = dbChapter.last_page_read) updatedChapter = updatedChapter.copy(lastPageRead = dbChapter.last_page_read)
} }
if (!chapter.bookmark && dbChapter.bookmark) { if (!updatedChapter.bookmark && dbChapter.bookmark) {
chapter = chapter.copy(bookmark = dbChapter.bookmark) updatedChapter = updatedChapter.copy(bookmark = true)
} }
} }
chapter.copy(mangaId = manga.id ?: -1) updatedChapter.copy(mangaId = manga.id)
} }
val newChapters = processed.groupBy { it.id > 0 } val newChapters = processed.groupBy { it.id > 0 }
@ -564,30 +564,6 @@ class BackupManager(
} }
} }
/**
* Updates a list of chapters
*/
private suspend fun updateChapters(chapters: List<tachiyomi.domain.chapter.model.Chapter>) {
handler.await(true) {
chapters.forEach { chapter ->
chaptersQueries.update(
chapter.mangaId,
chapter.url,
chapter.name,
chapter.scanlator,
chapter.read.toLong(),
chapter.bookmark.toLong(),
chapter.lastPageRead,
chapter.chapterNumber.toDouble(),
chapter.sourceOrder,
chapter.dateFetch,
chapter.dateUpload,
chapter.id,
)
}
}
}
/** /**
* Updates a list of chapters with known database ids * Updates a list of chapters with known database ids
*/ */

View File

@ -29,6 +29,7 @@ data class BackupTracking(
@ProtoNumber(100) var mediaId: Long = 0, @ProtoNumber(100) var mediaId: Long = 0,
) { ) {
@Suppress("DEPRECATION")
fun getTrackingImpl(): Track { fun getTrackingImpl(): Track {
return Track( return Track(
id = -1, id = -1,

View File

@ -118,7 +118,6 @@ class MangaCoverScreenModel(
fun editCover(context: Context, data: Uri) { fun editCover(context: Context, data: Uri) {
val manga = state.value ?: return val manga = state.value ?: return
coroutineScope.launchIO { coroutineScope.launchIO {
@Suppress("BlockingMethodInNonBlockingContext")
context.contentResolver.openInputStream(data)?.use { context.contentResolver.openInputStream(data)?.use {
try { try {
manga.editCover(Injekt.get(), it, updateManga, coverCache) manga.editCover(Injekt.get(), it, updateManga, coverCache)

View File

@ -605,8 +605,8 @@ class MangaInfoScreenModel(
} }
if (!isFavorited && !successState.hasPromptedToAddBefore) { if (!isFavorited && !successState.hasPromptedToAddBefore) {
updateSuccessState { successState -> updateSuccessState { state ->
successState.copy(hasPromptedToAddBefore = true) state.copy(hasPromptedToAddBefore = true)
} }
coroutineScope.launch { coroutineScope.launch {
val result = snackbarHostState.showSnackbar( val result = snackbarHostState.showSnackbar(