Skip to content

Instantly share code, notes, and snippets.

@nparsons08 nparsons08/MainActivity.kt Secret

Created Mar 10, 2020
What would you like to do?
// com/example/bubblechat/MainActivity.kt:13
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// setup the client using the example API key
// normally you would call init in your Application class and not the activity
StreamChat.init("<STREAM_API_KEY>", this.applicationContext)
val client = StreamChat.getInstance(this.application)
val extraData = HashMap<String, Any>()
extraData["name"] = "<USERNAME>"
extraData["image"] = "<PROFILE_IMAGE_URL>"
val currentUser = User("<USER_ID>", extraData)
// User token is typically provided by your server when the user authenticates
// we're using data binding in this example
val binding: ActivityMainBinding =
DataBindingUtil.setContentView(this, R.layout.activity_main)
// Specify the current activity as the lifecycle owner.
binding.lifecycleOwner = this
// most the business logic for chat is handled in the ChannelListViewModel view model
val viewModel = ViewModelProviders.of(this).get(
binding.viewModel = viewModel
binding.channelList.setViewModel(viewModel, this)
// query all channels of type messaging
val filter = and(eq("type", "messaging"), `in`("members",
// click handlers for clicking a user avatar or channel
binding.channelList.setOnChannelClickListener { channel ->
val intent = ChannelActivity.newIntent(this, channel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.