Skip to content

Instantly share code, notes, and snippets.

@AlexPrestonSB
Created June 4, 2019 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexPrestonSB/a2034a2a57f768fa05f163a9627974f7 to your computer and use it in GitHub Desktop.
Save AlexPrestonSB/a2034a2a57f768fa05f163a9627974f7 to your computer and use it in GitHub Desktop.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
mSendButton = (Button) findViewById(R.id.button_chat_send);
mMessageEditText = (EditText) findViewById(R.id.edittext_chat);
mRecyclerView = (RecyclerView) findViewById(R.id.reycler_chat);
mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setReverseLayout(true);
mRecyclerView.setLayoutManager(mLayoutManager);
OpenChannel.getChannel(mChannelUrl, new OpenChannel.OpenChannelGetHandler() {
@Override
public void onResult(final OpenChannel openChannel, SendBirdException e) {
if (e != null) {
e.printStackTrace();
return;
}
openChannel.enter(new OpenChannel.OpenChannelEnterHandler() {
@Override
public void onResult(SendBirdException e) {
if (e != null) {
e.printStackTrace();
return;
};
mChatAdapter = new ChatAdapter(openChannel);
mRecyclerView.setAdapter(mChatAdapter);
}
});
}
});
mSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mChatAdapter.sendMessage(mMessageEditText.getText().toString());
mMessageEditText.setText("");
}
});
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (mLayoutManager.findLastVisibleItemPosition() == mChatAdapter.getItemCount() - 1) {
mChatAdapter.loadPreviousMessages();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment