mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Use Material Dialogs for global update categories preference
To allow for negative selections in the future.
This commit is contained in:
		| @@ -14,9 +14,7 @@ class ChangeMangaCategoriesDialog<T>(bundle: Bundle? = null) : | ||||
|     DialogController(bundle) where T : Controller, T : ChangeMangaCategoriesDialog.Listener { | ||||
|  | ||||
|     private var mangas = emptyList<Manga>() | ||||
|  | ||||
|     private var categories = emptyList<Category>() | ||||
|  | ||||
|     private var preselected = emptyArray<Int>() | ||||
|  | ||||
|     constructor( | ||||
|   | ||||
| @@ -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) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user