mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Allow 'Default' category as the default for adding manga (#2292)
This commit is contained in:
parent
24bb94ceac
commit
80ea9001b3
5 changed files with 32 additions and 26 deletions
|
@ -500,12 +500,13 @@ open class BrowseCatalogueController(bundle: Bundle) :
|
||||||
adapter?.notifyItemChanged(position)
|
adapter?.notifyItemChanged(position)
|
||||||
|
|
||||||
val categories = presenter.getCategories()
|
val categories = presenter.getCategories()
|
||||||
val defaultCategory = categories.find { it.id == preferences.defaultCategory() }
|
val defaultCategoryId = preferences.defaultCategory()
|
||||||
if (defaultCategory != null) {
|
val defaultCategory = categories.find { it.id == defaultCategoryId }
|
||||||
presenter.moveMangaToCategory(manga, defaultCategory)
|
when {
|
||||||
} else if (categories.size <= 1) { // default or the one from the user
|
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
|
||||||
presenter.moveMangaToCategory(manga, categories.firstOrNull())
|
defaultCategoryId == 0 || categories.isEmpty() -> // 'Default' or no category
|
||||||
} else {
|
presenter.moveMangaToCategory(manga, null)
|
||||||
|
else -> {
|
||||||
val ids = presenter.getMangaCategoryIds(manga)
|
val ids = presenter.getMangaCategoryIds(manga)
|
||||||
val preselected = ids.mapNotNull { id ->
|
val preselected = ids.mapNotNull { id ->
|
||||||
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
||||||
|
@ -514,6 +515,7 @@ open class BrowseCatalogueController(bundle: Bundle) :
|
||||||
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
|
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
|
||||||
.showDialog(router)
|
.showDialog(router)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
activity?.toast(activity?.getString(R.string.manga_added_library))
|
activity?.toast(activity?.getString(R.string.manga_added_library))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -316,9 +316,9 @@ open class BrowseCataloguePresenter(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default, and user categories.
|
* Get user categories.
|
||||||
*
|
*
|
||||||
* @return List of categories, default plus user categories
|
* @return List of categories, not including the default category
|
||||||
*/
|
*/
|
||||||
fun getCategories(): List<Category> {
|
fun getCategories(): List<Category> {
|
||||||
return db.getCategories().executeAsBlocking()
|
return db.getCategories().executeAsBlocking()
|
||||||
|
|
|
@ -382,11 +382,12 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
||||||
toggleFavorite()
|
toggleFavorite()
|
||||||
if (manga.favorite) {
|
if (manga.favorite) {
|
||||||
val categories = presenter.getCategories()
|
val categories = presenter.getCategories()
|
||||||
val defaultCategory = categories.find { it.id == preferences.defaultCategory() }
|
val defaultCategoryId = preferences.defaultCategory()
|
||||||
|
val defaultCategory = categories.find { it.id == defaultCategoryId }
|
||||||
when {
|
when {
|
||||||
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
|
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
|
||||||
categories.size <= 1 -> // default or the one from the user
|
defaultCategoryId == 0 || categories.isEmpty() -> // 'Default' or no category
|
||||||
presenter.moveMangaToCategory(manga, categories.firstOrNull())
|
presenter.moveMangaToCategory(manga, null)
|
||||||
else -> {
|
else -> {
|
||||||
val ids = presenter.getMangaCategoryIds(manga)
|
val ids = presenter.getMangaCategoryIds(manga)
|
||||||
val preselected = ids.mapNotNull { id ->
|
val preselected = ids.mapNotNull { id ->
|
||||||
|
@ -413,9 +414,9 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
||||||
activity?.toast(activity?.getString(R.string.manga_added_library))
|
activity?.toast(activity?.getString(R.string.manga_added_library))
|
||||||
}
|
}
|
||||||
val categories = presenter.getCategories()
|
val categories = presenter.getCategories()
|
||||||
if (categories.size <= 1) {
|
if (categories.isEmpty()) {
|
||||||
// default or the one from the user then just add to favorite.
|
// no categories exist, display a message about adding categories
|
||||||
presenter.moveMangaToCategory(manga, categories.firstOrNull())
|
activity?.toast(activity?.getString(R.string.action_add_category))
|
||||||
} else {
|
} else {
|
||||||
val ids = presenter.getMangaCategoryIds(manga)
|
val ids = presenter.getMangaCategoryIds(manga)
|
||||||
val preselected = ids.mapNotNull { id ->
|
val preselected = ids.mapNotNull { id ->
|
||||||
|
|
|
@ -130,9 +130,9 @@ class MangaInfoPresenter(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default, and user categories.
|
* Get user categories.
|
||||||
*
|
*
|
||||||
* @return List of categories, default plus user categories
|
* @return List of categories, not including the default category
|
||||||
*/
|
*/
|
||||||
fun getCategories(): List<Category> {
|
fun getCategories(): List<Category> {
|
||||||
return db.getCategories().executeAsBlocking()
|
return db.getCategories().executeAsBlocking()
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.view.View
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
|
import eu.kanade.tachiyomi.data.database.models.Category
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
|
@ -179,15 +180,17 @@ class SettingsGeneralController : SettingsController() {
|
||||||
key = Keys.defaultCategory
|
key = Keys.defaultCategory
|
||||||
titleRes = R.string.default_category
|
titleRes = R.string.default_category
|
||||||
|
|
||||||
val selectedCategory = dbCategories.find { it.id == preferences.defaultCategory() }
|
val categories = listOf(Category.createDefault()) + dbCategories
|
||||||
|
|
||||||
|
val selectedCategory = categories.find { it.id == preferences.defaultCategory() }
|
||||||
entries = arrayOf(context.getString(R.string.default_category_summary)) +
|
entries = arrayOf(context.getString(R.string.default_category_summary)) +
|
||||||
dbCategories.map { it.name }.toTypedArray()
|
categories.map { it.name }.toTypedArray()
|
||||||
entryValues = arrayOf("-1") + dbCategories.map { it.id.toString() }.toTypedArray()
|
entryValues = arrayOf("-1") + categories.map { it.id.toString() }.toTypedArray()
|
||||||
defaultValue = "-1"
|
defaultValue = "-1"
|
||||||
summary = selectedCategory?.name ?: context.getString(R.string.default_category_summary)
|
summary = selectedCategory?.name ?: context.getString(R.string.default_category_summary)
|
||||||
|
|
||||||
onChange { newValue ->
|
onChange { newValue ->
|
||||||
summary = dbCategories.find {
|
summary = categories.find {
|
||||||
it.id == (newValue as String).toInt()
|
it.id == (newValue as String).toInt()
|
||||||
}?.name ?: context.getString(R.string.default_category_summary)
|
}?.name ?: context.getString(R.string.default_category_summary)
|
||||||
true
|
true
|
||||||
|
|
Loading…
Reference in a new issue