Last active
December 18, 2020 12:48
-
-
Save pranay1494/f742f6b454cf41501c54e420485d882d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NestedFilterViewAdapterWrapper { | |
private val mainAdapter = ConcatAdapter() | |
fun getMainAdapter() = mainAdapter | |
fun refreshAdapters() = getMainAdapter().adapters.map { it.notifyDataSetChanged() } | |
fun swapAdapter() = getMainAdapter().removeAllAdapters() | |
fun addAdapterAt(position: Int, adapter: Adapter<out ViewHolder>) = getMainAdapter().addAdapter(position, adapter) | |
fun addAdapter(adapter: Adapter<out ViewHolder>) = getMainAdapter().addAdapter(adapter) | |
} | |
private fun ConcatAdapter.removeAllAdapters() { | |
val listOfAdapters = this.adapters | |
listOfAdapters.forEach { adapter -> | |
this.removeAdapter(adapter) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment