Merge remote-tracking branch 'upstream/master' into truly-to-androidx

This commit is contained in:
Jay 2019-11-05 00:22:55 -08:00
commit 4c02bbf14c
5 changed files with 33 additions and 27 deletions

View File

@ -364,7 +364,7 @@ open class BrowseCatalogueController(bundle: Bundle) :
val message = if (error is NoResultsException) "No results found" else (error.message ?: "")
snack?.dismiss()
snack = catalogue_view?.snack(message, Snackbar.LENGTH_INDEFINITE) {
snack = catalouge_layout?.snack(message, Snackbar.LENGTH_INDEFINITE) {
setAction(R.string.action_retry) {
// If not the first page, show bottom progress bar.
if (adapter.mainItemCount > 0) {
@ -524,20 +524,22 @@ open class BrowseCatalogueController(bundle: Bundle) :
adapter?.notifyItemChanged(position)
val categories = presenter.getCategories()
val defaultCategory = categories.find { it.id == preferences.defaultCategory() }
if (defaultCategory != null) {
presenter.moveMangaToCategory(manga, defaultCategory)
} else if (categories.size <= 1) { // default or the one from the user
presenter.moveMangaToCategory(manga, categories.firstOrNull())
} else {
val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
val defaultCategoryId = preferences.defaultCategory()
val defaultCategory = categories.find { it.id == defaultCategoryId }
when {
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
defaultCategoryId == 0 || categories.isEmpty() -> // 'Default' or no category
presenter.moveMangaToCategory(manga, null)
else -> {
val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected).showDialog(router)
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
.showDialog(router)
}
}
}
/**

View File

@ -319,9 +319,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> {
return db.getCategories().executeAsBlocking()

View File

@ -428,11 +428,12 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
toggleFavorite()
if (manga.favorite) {
val categories = presenter.getCategories()
val defaultCategory = categories.find { it.id == preferences.defaultCategory() }
val defaultCategoryId = preferences.defaultCategory()
val defaultCategory = categories.find { it.id == defaultCategoryId }
when {
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
categories.size <= 1 -> // default or the one from the user
presenter.moveMangaToCategory(manga, categories.firstOrNull())
defaultCategoryId == 0 || categories.isEmpty() -> // 'Default' or no category
presenter.moveMangaToCategory(manga, null)
else -> {
val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id ->
@ -477,9 +478,9 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
showAddedSnack()
}
val categories = presenter.getCategories()
if (categories.size <= 1) {
// default or the one from the user then just add to favorite.
presenter.moveMangaToCategory(manga, categories.firstOrNull())
if (categories.isEmpty()) {
// no categories exist, display a message about adding categories
activity?.toast(activity?.getString(R.string.action_add_category))
} else {
val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id ->

View File

@ -155,9 +155,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> {
return db.getCategories().executeAsBlocking()

View File

@ -10,6 +10,7 @@ import android.view.View
import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.R
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.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
@ -182,15 +183,17 @@ class SettingsGeneralController : SettingsController() {
key = Keys.defaultCategory
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)) +
dbCategories.map { it.name }.toTypedArray()
entryValues = arrayOf("-1") + dbCategories.map { it.id.toString() }.toTypedArray()
categories.map { it.name }.toTypedArray()
entryValues = arrayOf("-1") + categories.map { it.id.toString() }.toTypedArray()
defaultValue = "-1"
summary = selectedCategory?.name ?: context.getString(R.string.default_category_summary)
onChange { newValue ->
summary = dbCategories.find {
summary = categories.find {
it.id == (newValue as String).toInt()
}?.name ?: context.getString(R.string.default_category_summary)
true