use of com.codez.collar.adapter.DirectMsgConversationAdapter in project Collar by CodeZsx.
the class DirectMsgActivity method initView.
@Override
public void initView() {
EventBusUtils.register(this);
// 获取intent传递过来的uid,screen_name
mUid = getIntent().getStringExtra(INTENT_UID);
mScreenName = getIntent().getStringExtra(INTENT_SCREEN_NAME);
setToolbarTitle(mBinding.toolbar, mScreenName);
mAdapter = new DirectMsgConversationAdapter(this);
mAdapter.setUid(AccessTokenKeeper.getInstance().getUid());
mBinding.recyclerView.setAdapter(mAdapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true);
mBinding.recyclerView.setLayoutManager(linearLayoutManager);
// 设置edittext
mBinding.etContent.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if ("".equals(s.toString())) {
mBinding.ivCommit.setSelected(false);
} else {
mBinding.ivCommit.setSelected(true);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
// 设置表情界面
EmojiFragment emojiFragment = new EmojiFragment();
getSupportFragmentManager().beginTransaction().add(R.id.rl_additional, emojiFragment).show(emojiFragment).commit();
emojiFragment.addOnEmojiClickListener(new EmojiFragment.OnEmojiClickListener() {
@Override
public void onEmojiDelete() {
L.e("delete");
}
@Override
public void onEmojiClick(Emoji emoji) {
// TODO:增加表情转化功能
// mBinding.etContent.setText(EmojiUtil.transEmoji(mBinding.etContent.getText().toString() + emoji.getContent(), DirectMsgActivity.this));
mBinding.etContent.setText(mBinding.etContent.getText().toString() + emoji.getContent());
mBinding.etContent.setSelection(mBinding.etContent.getText().length());
}
});
// 当软键盘呼出时,关闭表情界面
getWindow().getDecorView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
int oldRectBottom = 0;
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
// 获取View可见区域的bottom
Rect rect = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
// 界面收缩即软键盘正在打开
if (rect.bottom - oldRectBottom < 0) {
mBinding.rlAdditional.postDelayed(new Runnable() {
@Override
public void run() {
mBinding.rlAdditional.setVisibility(View.GONE);
mBinding.ivEmoj.setSelected(false);
}
}, 10);
} else if (rect.bottom - oldRectBottom > 0) {
// 界面扩展即软键盘正在关闭
}
oldRectBottom = rect.bottom;
}
});
mBinding.ivCommit.setOnClickListener(this);
mBinding.ivEmoj.setOnClickListener(this);
// mBinding.getRoot().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
// @Override
// public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
// //获取View可见区域的bottom
// Rect rect = new Rect();
// getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
// if(bottom!=0 && oldBottom!=0 && bottom - rect.bottom <= 0){
// L.e("keboard close");
// }else {
// mBinding.rlAdditional.setVisibility(View.GONE);
// mBinding.ivEmoj.setSelected(false);
// L.e("keyboard open");
// }
// }
// });
loadData();
}
Aggregations