diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt index 5d267927f..395a6e63e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt @@ -14,9 +14,7 @@ class ChangeMangaCategoriesDialog(bundle: Bundle? = null) : DialogController(bundle) where T : Controller, T : ChangeMangaCategoriesDialog.Listener { private var mangas = emptyList() - private var categories = emptyList() - private var preselected = emptyArray() constructor( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 97f53244c..1f2a9ea7e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -7,6 +7,7 @@ import android.view.View import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.customview.customView +import com.afollestad.materialdialogs.list.listItemsMultiChoice import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category @@ -166,11 +167,13 @@ class SettingsLibraryController : SettingsController() { titleRes = R.string.pref_update_only_non_completed defaultValue = false } - multiSelectListPreference { + preference { key = Keys.libraryUpdateCategories titleRes = R.string.pref_library_update_categories - entries = categories.map { it.name }.toTypedArray() - entryValues = categories.map { it.id.toString() }.toTypedArray() + onClick { + LibraryGlobalUpdateCategoriesDialog().showDialog(router) + } + preferences.libraryUpdateCategories().asFlow() .onEach { mutableSet -> val selectedCategories = mutableSet @@ -266,4 +269,34 @@ class SettingsLibraryController : SettingsController() { } } } + + class LibraryGlobalUpdateCategoriesDialog : DialogController() { + + private val preferences: PreferencesHelper = Injekt.get() + private val db: DatabaseHelper = Injekt.get() + + override fun onCreateDialog(savedViewState: Bundle?): Dialog { + val dbCategories = db.getCategories().executeAsBlocking() + val categories = listOf(Category.createDefault()) + dbCategories + + val items = categories.map { it.name } + val preselected = categories + .filter { it.id.toString() in preferences.libraryUpdateCategories().get() } + .map { categories.indexOf(it) } + .toIntArray() + + return MaterialDialog(activity!!) + .title(R.string.pref_library_update_categories) + .listItemsMultiChoice( + items = items, + initialSelection = preselected, + allowEmptySelection = true + ) { _, selections, _ -> + val newCategories = selections.map { categories[it] } + preferences.libraryUpdateCategories().set(newCategories.map { it.id.toString() }.toSet()) + } + .positiveButton(android.R.string.ok) + .negativeButton(android.R.string.cancel) + } + } }