mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Use Material Dialogs for global update categories preference
To allow for negative selections in the future.
This commit is contained in:
parent
3257cbe21f
commit
e15d7cb548
2 changed files with 36 additions and 5 deletions
|
@ -14,9 +14,7 @@ class ChangeMangaCategoriesDialog<T>(bundle: Bundle? = null) :
|
||||||
DialogController(bundle) where T : Controller, T : ChangeMangaCategoriesDialog.Listener {
|
DialogController(bundle) where T : Controller, T : ChangeMangaCategoriesDialog.Listener {
|
||||||
|
|
||||||
private var mangas = emptyList<Manga>()
|
private var mangas = emptyList<Manga>()
|
||||||
|
|
||||||
private var categories = emptyList<Category>()
|
private var categories = emptyList<Category>()
|
||||||
|
|
||||||
private var preselected = emptyArray<Int>()
|
private var preselected = emptyArray<Int>()
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.view.View
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.afollestad.materialdialogs.customview.customView
|
import com.afollestad.materialdialogs.customview.customView
|
||||||
|
import com.afollestad.materialdialogs.list.listItemsMultiChoice
|
||||||
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.database.models.Category
|
||||||
|
@ -166,11 +167,13 @@ class SettingsLibraryController : SettingsController() {
|
||||||
titleRes = R.string.pref_update_only_non_completed
|
titleRes = R.string.pref_update_only_non_completed
|
||||||
defaultValue = false
|
defaultValue = false
|
||||||
}
|
}
|
||||||
multiSelectListPreference {
|
preference {
|
||||||
key = Keys.libraryUpdateCategories
|
key = Keys.libraryUpdateCategories
|
||||||
titleRes = R.string.pref_library_update_categories
|
titleRes = R.string.pref_library_update_categories
|
||||||
entries = categories.map { it.name }.toTypedArray()
|
onClick {
|
||||||
entryValues = categories.map { it.id.toString() }.toTypedArray()
|
LibraryGlobalUpdateCategoriesDialog().showDialog(router)
|
||||||
|
}
|
||||||
|
|
||||||
preferences.libraryUpdateCategories().asFlow()
|
preferences.libraryUpdateCategories().asFlow()
|
||||||
.onEach { mutableSet ->
|
.onEach { mutableSet ->
|
||||||
val selectedCategories = 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue