Created
August 19, 2019 15:19
-
-
Save maxlord/293ad1fc4ae5ac63e151b86363b594e4 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 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