Skip to content

Instantly share code, notes, and snippets.

@nparsons08 nparsons08/ChannelActivity.kt Secret

Created Mar 10, 2020
Embed
What would you like to do?
// com/example/bubblechat/ChannelActivity.kt:14
class ChannelActivity : AppCompatActivity() {
private var viewModel: ChannelViewModel? = null
private var binding: ActivityChannelBinding? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val channelType = intent.getStringExtra(EXTRA_CHANNEL_TYPE)
val channelID = intent.getStringExtra(EXTRA_CHANNEL_ID)
val client = StreamChat.getInstance(application)
binding = DataBindingUtil.setContentView(this, R.layout.activity_channel)
binding!!.lifecycleOwner = this
val channel = client.channel(channelType, channelID)
viewModel = ViewModelProviders.of(
this,
ChannelViewModelFactory(this.application, channel)
).get(ChannelViewModel::class.java)
binding!!.viewModel = viewModel
binding!!.messageList.setViewHolderFactory(BubbleMessageViewHolderFactory())
binding!!.messageList.setViewModel(viewModel!!, this)
binding!!.messageInput.setViewModel(viewModel, this)
binding!!.channelHeader.setViewModel(viewModel, this)
}
companion object {
private val EXTRA_CHANNEL_TYPE = "com.example.bubblechat.CHANNEL_TYPE"
private val EXTRA_CHANNEL_ID = "com.example.bubblechat.CHANNEL_ID"
fun newIntent(context: Context, channel: Channel): Intent {
val intent = Intent(context, ChannelActivity::class.java)
intent.putExtra(EXTRA_CHANNEL_TYPE, channel.type)
intent.putExtra(EXTRA_CHANNEL_ID, channel.id)
return intent
}
}
}
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.