Channel Header View Model

Last Edit: Oct 28 2020

ChannelsHederViewModel is responsible for keeping ChannelHeaderView up to date using StreamChatAndroidOffline library.

The view model watches for particular channel data changes and exposes information using the following LiveData objects:

  • members

  • channelState

  • anyOtherUsersOnline

Creating Channel HeaderView Model

ChannelHeaderViewModel can be instantiated using ChannelViewModelFactory:

ChannelViewModelFactory factory = new ChannelViewModelFactory(channel.getCid());
ChannelHeaderViewModel viewModel = new ViewModelProvider(this, factory)

private val viewModel: ChannelHeaderViewModel by viewModels {

Binding with ChannelHeaderView

ChannelsViewModel can be bound with ChannelHeaderView using ChannelHeaderViewModelBinding:

ChannelHeaderViewModelBinding.bind(viewModel, channelHeaderView, lifecycle);

viewModel.bindView(channelHeaderView, viewLifecycleOwner)

From that point, the view model will make sure that ChannelHeaderView displays correct:

  • Channel title

  • Members avatars

  • Active indicator

  • Last active date