|
@@ -34,6 +34,7 @@ import dev.chrisbanes.insetter.applyInsetter
|
|
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
|
import eu.davidea.flexibleadapter.SelectableAdapter
|
|
|
import eu.kanade.data.chapter.NoChaptersException
|
|
|
+import eu.kanade.domain.category.model.toDbCategory
|
|
|
import eu.kanade.domain.history.model.HistoryWithRelations
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.data.cache.CoverCache
|
|
@@ -97,6 +98,7 @@ import eu.kanade.tachiyomi.widget.ActionModeWithToolbar
|
|
|
import eu.kanade.tachiyomi.widget.materialdialogs.QuadStateTextView
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
+import kotlinx.coroutines.runBlocking
|
|
|
import logcat.LogPriority
|
|
|
import reactivecircus.flowbinding.recyclerview.scrollStateChanges
|
|
|
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
|
@@ -397,13 +399,16 @@ class MangaController :
|
|
|
}
|
|
|
|
|
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
|
|
- // Hide options for local manga
|
|
|
- menu.findItem(R.id.action_share).isVisible = !isLocalSource
|
|
|
- menu.findItem(R.id.download_group).isVisible = !isLocalSource
|
|
|
-
|
|
|
- // Hide options for non-library manga
|
|
|
- menu.findItem(R.id.action_edit_categories).isVisible = presenter.manga.favorite && presenter.getCategories().isNotEmpty()
|
|
|
- menu.findItem(R.id.action_migrate).isVisible = presenter.manga.favorite
|
|
|
+ runBlocking {
|
|
|
+ // Hide options for local manga
|
|
|
+ menu.findItem(R.id.action_share).isVisible = !isLocalSource
|
|
|
+ menu.findItem(R.id.download_group).isVisible = !isLocalSource
|
|
|
+
|
|
|
+ // Hide options for non-library manga
|
|
|
+ menu.findItem(R.id.action_edit_categories).isVisible =
|
|
|
+ presenter.manga.favorite && presenter.getCategories().isNotEmpty()
|
|
|
+ menu.findItem(R.id.action_migrate).isVisible = presenter.manga.favorite
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
@@ -533,39 +538,47 @@ class MangaController :
|
|
|
}
|
|
|
|
|
|
private fun addToLibrary(newManga: Manga) {
|
|
|
- val categories = presenter.getCategories()
|
|
|
- val defaultCategoryId = preferences.defaultCategory()
|
|
|
- val defaultCategory = categories.find { it.id == defaultCategoryId }
|
|
|
+ launchIO {
|
|
|
+ val categories = presenter.getCategories()
|
|
|
+ val defaultCategoryId = preferences.defaultCategory()
|
|
|
+ val defaultCategory = categories.find { it.id == defaultCategoryId.toLong() }
|
|
|
+
|
|
|
+ withUIContext {
|
|
|
+ when {
|
|
|
+ // Default category set
|
|
|
+ defaultCategory != null -> {
|
|
|
+ toggleFavorite()
|
|
|
+ presenter.moveMangaToCategory(newManga, defaultCategory.toDbCategory())
|
|
|
+ activity?.toast(activity?.getString(R.string.manga_added_library))
|
|
|
+ activity?.invalidateOptionsMenu()
|
|
|
+ }
|
|
|
|
|
|
- when {
|
|
|
- // Default category set
|
|
|
- defaultCategory != null -> {
|
|
|
- toggleFavorite()
|
|
|
- presenter.moveMangaToCategory(newManga, defaultCategory)
|
|
|
- activity?.toast(activity?.getString(R.string.manga_added_library))
|
|
|
- activity?.invalidateOptionsMenu()
|
|
|
- }
|
|
|
+ // Automatic 'Default' or no categories
|
|
|
+ defaultCategoryId == 0 || categories.isEmpty() -> {
|
|
|
+ toggleFavorite()
|
|
|
+ presenter.moveMangaToCategory(newManga, null)
|
|
|
+ activity?.toast(activity?.getString(R.string.manga_added_library))
|
|
|
+ activity?.invalidateOptionsMenu()
|
|
|
+ }
|
|
|
|
|
|
- // Automatic 'Default' or no categories
|
|
|
- defaultCategoryId == 0 || categories.isEmpty() -> {
|
|
|
- toggleFavorite()
|
|
|
- presenter.moveMangaToCategory(newManga, null)
|
|
|
- activity?.toast(activity?.getString(R.string.manga_added_library))
|
|
|
- activity?.invalidateOptionsMenu()
|
|
|
- }
|
|
|
+ // Choose a category
|
|
|
+ else -> {
|
|
|
+ val ids = presenter.getMangaCategoryIds(newManga)
|
|
|
+ val preselected = categories.map {
|
|
|
+ if (it.id in ids) {
|
|
|
+ QuadStateTextView.State.CHECKED.ordinal
|
|
|
+ } else {
|
|
|
+ QuadStateTextView.State.UNCHECKED.ordinal
|
|
|
+ }
|
|
|
+ }.toTypedArray()
|
|
|
|
|
|
- // Choose a category
|
|
|
- else -> {
|
|
|
- val ids = presenter.getMangaCategoryIds(newManga)
|
|
|
- val preselected = categories.map {
|
|
|
- if (it.id in ids) {
|
|
|
- QuadStateTextView.State.CHECKED.ordinal
|
|
|
- } else {
|
|
|
- QuadStateTextView.State.UNCHECKED.ordinal
|
|
|
+ showChangeCategoryDialog(
|
|
|
+ newManga,
|
|
|
+ categories.map { it.toDbCategory() },
|
|
|
+ preselected,
|
|
|
+ )
|
|
|
}
|
|
|
- }.toTypedArray()
|
|
|
-
|
|
|
- showChangeCategoryDialog(newManga, categories, preselected)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -609,18 +622,27 @@ class MangaController :
|
|
|
}
|
|
|
|
|
|
fun onCategoriesClick() {
|
|
|
- val manga = presenter.manga
|
|
|
- val categories = presenter.getCategories()
|
|
|
+ launchIO {
|
|
|
+ val manga = presenter.manga
|
|
|
+ val categories = presenter.getCategories()
|
|
|
|
|
|
- val ids = presenter.getMangaCategoryIds(manga)
|
|
|
- val preselected = categories.map {
|
|
|
- if (it.id in ids) {
|
|
|
- QuadStateTextView.State.CHECKED.ordinal
|
|
|
- } else {
|
|
|
- QuadStateTextView.State.UNCHECKED.ordinal
|
|
|
+ if (categories.isEmpty()) {
|
|
|
+ return@launchIO
|
|
|
}
|
|
|
- }.toTypedArray()
|
|
|
- showChangeCategoryDialog(manga, categories, preselected)
|
|
|
+
|
|
|
+ val ids = presenter.getMangaCategoryIds(manga)
|
|
|
+ val preselected = categories.map {
|
|
|
+ if (it.id in ids) {
|
|
|
+ QuadStateTextView.State.CHECKED.ordinal
|
|
|
+ } else {
|
|
|
+ QuadStateTextView.State.UNCHECKED.ordinal
|
|
|
+ }
|
|
|
+ }.toTypedArray()
|
|
|
+
|
|
|
+ withUIContext {
|
|
|
+ showChangeCategoryDialog(manga, categories.map { it.toDbCategory() }, preselected)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private fun showChangeCategoryDialog(manga: Manga, categories: List<Category>, preselected: Array<Int>) {
|