Skip to content

Instantly share code, notes, and snippets.

@hXtreme
Last active July 10, 2019 10:12
Show Gist options
  • Save hXtreme/4636273cf29693239261751eb96f224f to your computer and use it in GitHub Desktop.
Save hXtreme/4636273cf29693239261751eb96f224f to your computer and use it in GitHub Desktop.
Template for when I try to implement filters for categories in Tachiyomi.
inner class CategoryGroup : Group {
private val categories = List<Category>(0)
override val items = categories.map { category -> Item.TriStateGroup( category.id, this) }
override val header = Item.Header(R.string.categories)
override val footer = Item.Separator()
override fun initModels() {
items.forEach{ it.state = STATE_IGNORE }
}
override fun onItemClicked(item: Item) {
item as Item.TriStateGroup
val prevState = item.state
item.state = when (prevState) {
STATE_IGNORE -> STATE_INCLUDE
STATE_INCLUDE -> STATE_EXCLUDE
STATE_EXCLUDE -> STATE_IGNORE
else -> throw Exception("Unknown state")
}
adapter.notifyItemChanged(item)
}
}
@hXtreme
Copy link
Author

hXtreme commented Jul 10, 2019

This doesn't work for the following major reasons:

  1. Line 3: I don't know how to get a list of all categories.
  2. Line 5: Item.TriStateGroup(.) requires a resource ID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment