Channels View Model

LAST EDIT Aug 02 2021

ChannelsViewModel is responsible for updating ChannelsView based on data received from StreamChatAndroidOffline library. It queries the channels during initialization and updates its state every time channels are updated.

The view model exposes LiveData object called state, which can be one of following:

  • LoadingNextPage

  • Loading

  • Result

  • EndPageReached

  • NoChannelsAvailable

  • NavigateToLoginScreen

You can inform the view model about new events using onEvent method. Currently, ChannelsViewModel supports the following events:

  • ReachedEndOfList

  • LogoutClicked

Creating Channels View Model

Copied!

ChannelsViewModel can be instantiated using ChannelsViewModelFactory:

Binding with ChannelsView

Copied!

ChannelsViewModel can be bound with ChannelsView using ChannelsViewModelBinding:

The bind call connects the view model with the view and from that point, different channels view states (Result, Loading, NoChannelsAvailable) will be handled automatically. Moreover, it sets view's OnEndReachedListener which is responsible for loading more channels when user reaches end of the list.