在使用 Concat*Adapter 实现 header 或 footer 时,有时候需要一个只有一条数据的 Adapter 来作为 header 或 footer,这时候 AssemblySingleData*Adapter 就派上用场了,如下:
val appsOverviewAdapter =
AssemblySingleDataRecyclerAdapter(AppsOverviewItemFactory(requireActivity()))
val recyclerAdapter = AssemblyRecyclerAdapter<Any>(
listOf(
AppItemFactory(requireActivity()),
ListSeparatorItemFactory(requireActivity())
)
)
val footerLoadStateAdapter =
AssemblySingleDataRecyclerAdapter(LoadStateItemFactory(requireActivity()))
binding.recyclerRecycler.apply {
adapter = ConcatAdapter(appsOverviewAdapter, recyclerAdapter, footerLoadStateAdapter)
}
// 数据加载成功后更新数据
appsOverviewAdapter.data = AppsOverview()
footerLoadStateAdapter.data = LoadState.NotLoading(true)