Fix default category showing up in edit manga categories list

Also remove some usages of runBlocking
This commit is contained in:
arkon
2022-08-07 11:00:51 -04:00
parent 3c2e237d63
commit 3bc6b1e202
8 changed files with 36 additions and 43 deletions
@@ -61,6 +61,7 @@ import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.widget.materialdialogs.QuadStateTextView
import eu.kanade.tachiyomi.widget.materialdialogs.await
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import logcat.LogPriority
import eu.kanade.domain.chapter.model.Chapter as DomainChapter
@@ -214,7 +215,7 @@ class MangaController :
}
} else null,
onRequireCategory = { manga, categories ->
val ids = presenter.getMangaCategoryIds(manga)
val ids = runBlocking { presenter.getMangaCategoryIds(manga) }
val preselected = categories.map {
if (it.id in ids) {
QuadStateTextView.State.CHECKED.ordinal
@@ -64,7 +64,6 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.supervisorScope
import kotlinx.coroutines.withContext
import logcat.LogPriority
@@ -351,7 +350,7 @@ class MangaPresenter(
* @return List of categories, not including the default category
*/
suspend fun getCategories(): List<Category> {
return getCategories.await()
return getCategories.await().filterNot { it.isSystemCategory }
}
/**
@@ -360,8 +359,8 @@ class MangaPresenter(
* @param manga the manga to get categories from.
* @return Array of category ids the manga is in, if none returns default id
*/
fun getMangaCategoryIds(manga: DomainManga): Array<Long> {
val categories = runBlocking { getCategories.await(manga.id) }
suspend fun getMangaCategoryIds(manga: DomainManga): Array<Long> {
val categories = getCategories.await(manga.id)
return categories.map { it.id }.toTypedArray()
}