mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-26 02:48:24 +01:00
Address minor build warnings
This commit is contained in:
parent
44383ff950
commit
b051e37ab7
@ -70,7 +70,6 @@ class BackupManager(
|
||||
* @param uri path of Uri
|
||||
* @param isAutoBackup backup called from scheduled backup job
|
||||
*/
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
suspend fun createBackup(uri: Uri, flags: Int, isAutoBackup: Boolean): String {
|
||||
if (!context.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
throw IllegalStateException(context.getString(R.string.missing_storage_permission))
|
||||
@ -222,10 +221,10 @@ class BackupManager(
|
||||
}
|
||||
|
||||
internal suspend fun restoreExistingManga(manga: Manga, dbManga: Mangas): Manga {
|
||||
var manga = manga.copy(id = dbManga._id)
|
||||
manga = manga.copyFrom(dbManga)
|
||||
updateManga(manga)
|
||||
return manga
|
||||
var updatedManga = manga.copy(id = dbManga._id)
|
||||
updatedManga = updatedManga.copyFrom(dbManga)
|
||||
updateManga(updatedManga)
|
||||
return updatedManga
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,7 +297,7 @@ class BackupManager(
|
||||
dbCategories.firstOrNull { dbCategory ->
|
||||
dbCategory.name == backupCategory.name
|
||||
}?.let { dbCategory ->
|
||||
mangaCategoriesToUpdate.add(Pair(manga.id!!, dbCategory.id))
|
||||
mangaCategoriesToUpdate.add(Pair(manga.id, dbCategory.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -306,7 +305,7 @@ class BackupManager(
|
||||
// Update database
|
||||
if (mangaCategoriesToUpdate.isNotEmpty()) {
|
||||
handler.await(true) {
|
||||
mangas_categoriesQueries.deleteMangaCategoryByMangaId(manga.id!!)
|
||||
mangas_categoriesQueries.deleteMangaCategoryByMangaId(manga.id)
|
||||
mangaCategoriesToUpdate.forEach { (mangaId, categoryId) ->
|
||||
mangas_categoriesQueries.insert(mangaId, categoryId)
|
||||
}
|
||||
@ -370,15 +369,15 @@ class BackupManager(
|
||||
* @param tracks the track list to restore.
|
||||
*/
|
||||
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
|
||||
val dbTracks = handler.awaitList { manga_syncQueries.getTracksByMangaId(manga.id!!) }
|
||||
val dbTracks = handler.awaitList { manga_syncQueries.getTracksByMangaId(manga.id) }
|
||||
val toUpdate = mutableListOf<Manga_sync>()
|
||||
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
|
||||
for (dbTrack in dbTracks) {
|
||||
if (track.syncId == dbTrack.sync_id) {
|
||||
@ -401,6 +400,7 @@ class BackupManager(
|
||||
toInsert.add(track.copy(id = 0))
|
||||
}
|
||||
}
|
||||
|
||||
// Update database
|
||||
if (toUpdate.isNotEmpty()) {
|
||||
handler.await(true) {
|
||||
@ -446,25 +446,25 @@ class BackupManager(
|
||||
}
|
||||
|
||||
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 ->
|
||||
var chapter = chapter
|
||||
val dbChapter = dbChapters.find { it.url == chapter.url }
|
||||
var updatedChapter = chapter
|
||||
val dbChapter = dbChapters.find { it.url == updatedChapter.url }
|
||||
if (dbChapter != null) {
|
||||
chapter = chapter.copy(id = dbChapter._id)
|
||||
chapter = chapter.copyFrom(dbChapter)
|
||||
if (dbChapter.read && !chapter.read) {
|
||||
chapter = chapter.copy(read = dbChapter.read, lastPageRead = dbChapter.last_page_read)
|
||||
} else if (chapter.lastPageRead == 0L && dbChapter.last_page_read != 0L) {
|
||||
chapter = chapter.copy(lastPageRead = dbChapter.last_page_read)
|
||||
updatedChapter = updatedChapter.copy(id = dbChapter._id)
|
||||
updatedChapter = updatedChapter.copyFrom(dbChapter)
|
||||
if (dbChapter.read && !updatedChapter.read) {
|
||||
updatedChapter = updatedChapter.copy(read = true, lastPageRead = dbChapter.last_page_read)
|
||||
} else if (updatedChapter.lastPageRead == 0L && dbChapter.last_page_read != 0L) {
|
||||
updatedChapter = updatedChapter.copy(lastPageRead = dbChapter.last_page_read)
|
||||
}
|
||||
if (!chapter.bookmark && dbChapter.bookmark) {
|
||||
chapter = chapter.copy(bookmark = dbChapter.bookmark)
|
||||
if (!updatedChapter.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 }
|
||||
@ -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
|
||||
*/
|
||||
|
@ -29,6 +29,7 @@ data class BackupTracking(
|
||||
@ProtoNumber(100) var mediaId: Long = 0,
|
||||
) {
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun getTrackingImpl(): Track {
|
||||
return Track(
|
||||
id = -1,
|
||||
|
@ -118,7 +118,6 @@ class MangaCoverScreenModel(
|
||||
fun editCover(context: Context, data: Uri) {
|
||||
val manga = state.value ?: return
|
||||
coroutineScope.launchIO {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
context.contentResolver.openInputStream(data)?.use {
|
||||
try {
|
||||
manga.editCover(Injekt.get(), it, updateManga, coverCache)
|
||||
|
@ -605,8 +605,8 @@ class MangaInfoScreenModel(
|
||||
}
|
||||
|
||||
if (!isFavorited && !successState.hasPromptedToAddBefore) {
|
||||
updateSuccessState { successState ->
|
||||
successState.copy(hasPromptedToAddBefore = true)
|
||||
updateSuccessState { state ->
|
||||
state.copy(hasPromptedToAddBefore = true)
|
||||
}
|
||||
coroutineScope.launch {
|
||||
val result = snackbarHostState.showSnackbar(
|
||||
|
Loading…
Reference in New Issue
Block a user