Skip to content

Instantly share code, notes, and snippets.

@maxlord
Created August 19, 2019 15:19
Show Gist options
  • Save maxlord/293ad1fc4ae5ac63e151b86363b594e4 to your computer and use it in GitHub Desktop.
Save maxlord/293ad1fc4ae5ac63e151b86363b594e4 to your computer and use it in GitHub Desktop.
class IntroDelegate(
) : BaseAdapterDelegate<TrackItemUiModel.Intro, IntroDelegate.IntroViewHolder>() {
private val actionRelay = PublishRelay.create<TrackItemUiModel>()
val actionObservable: Observable<TrackItemUiModel> = actionRelay
override fun isForViewType(item: Item): Boolean = item is TrackItemUiModel.Intro
override val layoutId: Int = R.layout.view_track_intro
override fun createViewHolder(view: View): IntroViewHolder =
IntroViewHolder(view).apply {
itemView.btnAction
.clicks()
.subscribe { item?.let(actionRelay::accept) }
}
inner class IntroViewHolder(itemView: View) :
ItemViewHolder<TrackItemUiModel.Intro>(itemView) {
override fun onBindItem(item: TrackItemUiModel.Intro) = with(itemView) {
...
}
}
}
class TestFragment() : Fragment() {
private val delegate = IntroDelegate()
private val adapter = DefaultAdapter().addDelegate(delegate)
fun onCreateView() {
delegate.actionObservable
.subscribe {
// TODO тут ловишь клики из конкретного делегата
}
adapter.setItems(listOf())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment