Channel Header View Model

LAST EDIT Feb 16 2021

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 ModelCopied!

ChannelHeaderViewModel can be instantiated using ChannelViewModelFactory:

1
2
3
ChannelViewModelFactory factory = new ChannelViewModelFactory(channel.getCid()); 
ChannelHeaderViewModel viewModel = new ViewModelProvider(this, factory) 
        .get(ChannelHeaderViewModel.class);
1
2
3
private val viewModel: ChannelHeaderViewModel by viewModels { 
    ChannelViewModelFactory(channel.cid) 
}

Binding with ChannelHeaderViewCopied!

ChannelsViewModel can be bound with ChannelHeaderView using ChannelHeaderViewModelBinding:

1
ChannelHeaderViewModelBinding.bind(viewModel, channelHeaderView, lifecycle);
1
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