Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.example.dialogflowapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import com.example.dialogflowapplication.databinding.ActivityChannelBinding;
import com.getstream.sdk.chat.StreamChat;
import com.getstream.sdk.chat.model.Channel;
import com.getstream.sdk.chat.rest.core.Client;
import com.getstream.sdk.chat.utils.PermissionChecker;
import com.getstream.sdk.chat.view.MessageInputView;
import com.getstream.sdk.chat.viewmodel.ChannelViewModel;
import com.getstream.sdk.chat.viewmodel.ChannelViewModelFactory;
/**
* Show the messages for a channel
*/
public class ChannelActivity extends AppCompatActivity
implements MessageInputView.PermissionRequestListener {
private ChannelViewModel viewModel;
private ActivityChannelBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// receive the intent and create a channel object
Intent intent = getIntent();
String channelType = intent.getStringExtra(MainActivity.EXTRA_CHANNEL_TYPE);
String channelID = intent.getStringExtra(MainActivity.EXTRA_CHANNEL_ID);
Client client = StreamChat.getInstance(getApplication());
// we're using data binding in this example
binding = DataBindingUtil.setContentView(this, R.layout.activity_channel);
// most the business logic of the chat is handled in the ChannelViewModel view model
binding.setLifecycleOwner(this);
Channel channel = client.channel(channelType, channelID);
ChannelViewModelFactory viewModelFactory = new ChannelViewModelFactory(this.getApplication(), channel);
viewModel = new ViewModelProvider(this, viewModelFactory).get(ChannelViewModel.class);
// connect the view model
binding.setViewModel(viewModel);
binding.channelHeader.setViewModel(viewModel, this);
binding.messageList.setViewModel(viewModel, this);
binding.messageInput.setViewModel(viewModel, this);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// If you are using own MessageInputView please comment this line.
binding.messageInput.captureMedia(requestCode, resultCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
// If you are using own MessageInputView please comment this line.
binding.messageInput.permissionResult(requestCode, permissions, grantResults);
}
@Override
public void openPermissionRequest() {
PermissionChecker.permissionCheck(this, null);
}
}
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.