修复聊天室消息大于99消息会混乱的问题
This commit is contained in:
parent
1bde99f6c9
commit
99938f6ed6
@ -47,6 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/10/10.
|
||||
@ -127,7 +128,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
if (isSlideToBottom(recyclerView)) return;
|
||||
if (isSlideToBottom(recyclerView) || dy == 0) return;
|
||||
mRecyclerViewScrolledDy = dy;
|
||||
}
|
||||
});
|
||||
@ -379,16 +380,22 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
public void insertItem(LiveChatBean bean) {
|
||||
|
||||
if (bean == null) {
|
||||
return;
|
||||
}
|
||||
int size = mList.size();
|
||||
//设置最大展示99条消息
|
||||
if (size == 100) {
|
||||
mList.remove(0);
|
||||
mList.subList(0, 50).clear();
|
||||
notifyItemRangeRemoved(0, 50);
|
||||
}
|
||||
mList.add(bean);
|
||||
if (getItemCount() == 1 ) {
|
||||
notifyDataSetChanged();
|
||||
} else {
|
||||
notifyItemInserted(getItemCount());
|
||||
}
|
||||
size = mList.size();
|
||||
if (isSlideToBottom(mRecyclerView) || mRecyclerViewScrolledDy == 0) {
|
||||
scrollToBottom();
|
||||
} else {
|
||||
@ -401,11 +408,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
||||
mPosition = size;
|
||||
}
|
||||
}
|
||||
if (getItemCount() == 1) {
|
||||
notifyDataSetChanged();
|
||||
} else {
|
||||
notifyItemInserted(getItemCount());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -447,6 +450,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
public void scrollToBottom() {
|
||||
mRecyclerViewScrolledDy = 0;
|
||||
if (mList.size() > 0) {
|
||||
mRecyclerView.smoothScrollToPosition(getItemCount() - 1);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewOutlineProvider;
|
||||
@ -157,6 +158,8 @@ import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
@ -743,7 +746,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
msgNumber = (TextView) findViewById(R.id.room_msg_num);
|
||||
msgUserIcon = (RoundedImageView) findViewById(R.id.room_msg_user_icon);
|
||||
msgLayout = (ConstraintLayout) findViewById(R.id.room_msg_layout);
|
||||
ViewClicksAntiShake.clicksAntiShake(msg, this::openChatWindow);
|
||||
// ViewClicksAntiShake.clicksAntiShake(msg, this::openChatWindow);
|
||||
ViewClicksAntiShake.clicksAntiShake(msg2, this::openChatWindow);
|
||||
|
||||
lt_trickery = (LinearLayout) findViewById(R.id.lt_trickery);
|
||||
@ -925,6 +928,35 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
mViewMedal.setOnClickListener(this);
|
||||
findViewById(R.id.btn_close).setOnClickListener(this);
|
||||
mAvatar.setOnClickListener(this);
|
||||
//点击侧边消息按钮,自动发消息,测试用的
|
||||
/*msg.setOnClickListener(new View.OnClickListener() {
|
||||
long index=0;
|
||||
public TimerTask createTask() {
|
||||
return new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
LiveChatBean bean = new LiveChatBean();
|
||||
bean.setContent("test msg = "+index++);
|
||||
bean.setUserNiceName("auto");
|
||||
handler.post(()->mLiveChatAdapter.insertItem(bean));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
private TimerTask task;
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(task==null){
|
||||
task=createTask();
|
||||
new Timer().schedule(task, 0, 300);
|
||||
}else{
|
||||
task.cancel();
|
||||
task=null;
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
findViewById(R.id.btn_votes).setOnClickListener(this);
|
||||
findViewById(R.id.btn_medal_rank).setOnClickListener(this);
|
||||
findViewById(R.id.btn_noble).setOnClickListener(this);
|
||||
@ -3718,6 +3750,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
||||
* 展示新消息提示
|
||||
*/
|
||||
public void showNewMessage() {
|
||||
if (newMessage.getVisibility() == View.VISIBLE) return;
|
||||
Locale locale = mContext.getResources().getConfiguration().locale;
|
||||
String language = locale.getLanguage();
|
||||
ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.new_message_cn : R.mipmap.new_message_en, newMessage);
|
||||
|
Loading…
Reference in New Issue
Block a user