wangxiang 1 year ago
parent
commit
b844c688fd
  1. 58
      app/src/main/java/com/kanglai/push/ui/activity/InstantActivity.java
  2. 19
      app/src/main/java/com/kanglai/push/ui/adapter/ChatRoomListRecyclerAdapter.java
  3. 123
      app/src/main/java/com/kanglai/push/ui/adapter/SoloChatRoomAdapter.java
  4. 86
      app/src/main/java/com/kanglai/push/ui/vm/InstantViewModel.java
  5. BIN
      app/src/main/res/drawable-xxhdpi/skin_messages_right_bubble_highlighted.9.png
  6. 0
      app/src/main/res/drawable-xxhdpi/skin_messages_right_bubble_wechat.9.png
  7. 6
      app/src/main/res/drawable/skin_messages_right_bubble.xml
  8. 69
      app/src/main/res/layout/activity_instant.xml
  9. 165
      app/src/main/res/layout/item_chat_room.xml

58
app/src/main/java/com/kanglai/push/ui/activity/InstantActivity.java

@ -66,30 +66,33 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan @@ -66,30 +66,33 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan
return BR.viewModel;
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.mViewModel.mActivity = this;
// 其他基础控件
mAdapter = new SoloChatRoomAdapter();
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
mRecyclerView = findViewById(R.id.instant_recycler);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
refreshLayout = findViewById(R.id.instant_smart_refresh);
refreshLayout.setEnableScrollContentWhenLoaded(true);
refreshLayout.setOnLoadMoreListener(mViewModel::loadMore);
refreshLayout.setDisableContentWhenRefresh(true);
input_box = findViewById(R.id.instant_input_box);
input_box.setFilters(new InputFilter[]{ViewFilterUtil.getNoSpecialCharactersFilter()}); // 去空格、换行符等特殊符号
input_box.setFilters(new InputFilter[]{ViewFilterUtil.getNoSpecialCharactersFilter()});
more_line = findViewById(R.id.iv_more_line);
more_fill = findViewById(R.id.iv_more_fill);
more_line.setOnClickListener(view -> changBottomType());
more_fill.setOnClickListener(view -> changBottomType());
bottom_grid = findViewById(R.id.instant_grid);
layout_footer = findViewById(R.id.layout_footer);
localPushChatMsg = getIntent().getParcelableExtra(CommonConstant.INSTANT_LAUNCHER_RESULT_KEY);
if (localPushChatMsg != null) {
mViewModel.adverseData = localPushChatMsg;
mViewModel.init();
judgeViewType(localPushChatMsg);
mViewModel.adverseData = getIntent().getParcelableExtra(CommonConstant.INSTANT_LAUNCHER_RESULT_KEY);
mViewModel.setTitleText(localPushChatMsg.getUserName());
if ("2".equals(localPushChatMsg.getUserType()) || "5".equals(localPushChatMsg.getUserType()) || "0".equals(localPushChatMsg.getUserType())){
layout_footer.setVisibility(View.INVISIBLE);
}
mViewModel.initData(refreshLayout);
mSubscription = RxBus.getInstance().toObservable(com.dolphin.umeng.entity.PushChatMessage.class)
.compose(RxUtil.schedulersTransformer())
.compose(RxUtil.exceptionTransformer())
@ -110,25 +113,6 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan @@ -110,25 +113,6 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan
}
public void adapterInit(ArrayList<PushChatMessage> requestList) {
final SoloChatRoomAdapter soloChatRoomAdapter = new SoloChatRoomAdapter(requestList, localPushChatMsg);
mAdapter = soloChatRoomAdapter;
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this); // 初始化垂直适配器
mRecyclerView = findViewById(R.id.instant_recycler);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
refreshLayout = findViewById(R.id.instant_smart_refresh);
refreshLayout.setEnableRefresh(true);
refreshLayout.setEnableLoadMore(false);
refreshLayout.setEnableAutoLoadMore(true);
refreshLayout.setEnableScrollContentWhenLoaded(true);
refreshLayout.setOnRefreshListener(v -> mViewModel.loadMore());
refreshLayout.setDisableContentWhenRefresh(true);
mRecyclerView.scrollToPosition(mAdapter.getItemCount() - 1);
}
public void setActivitieResult() {
if (!mAdapter.mItemList.isEmpty()) {
setResult(RESULT_OK, new Intent().putExtra(CommonConstant.INSTANT_LAUNCHER_RESULT_KEY, new LocalPushChatMsg()
@ -142,17 +126,6 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan @@ -142,17 +126,6 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan
}
}
/**
* 加载不同用户类型时的界面
* app端不能给 系统/企业用户/企业内部/系统 用户发消息
*/
private void judgeViewType(LocalPushChatMsg data) {
mViewModel.setTitleText(data.getUserName()); // 标题
if ("2".equals(data.getUserType()) || "5".equals(data.getUserType()) || "0".equals(data.getUserType())){
layout_footer.setVisibility(View.INVISIBLE);
}
}
/** 底部功能模块显示开关 */
private void changBottomType(){
isShowBottom = !isShowBottom;
@ -180,6 +153,5 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan @@ -180,6 +153,5 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan
protected void onDestroy() {
super.onDestroy();
RxSubscriptions.remove(mSubscription);
if (mAdapter != null) mAdapter.clear();
}
}

19
app/src/main/java/com/kanglai/push/ui/adapter/ChatRoomListRecyclerAdapter.java

@ -4,13 +4,12 @@ import android.view.LayoutInflater; @@ -4,13 +4,12 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.blankj.utilcode.util.LogUtils;
import com.kanglai.push.R;
/**
@ -58,11 +57,16 @@ public class ChatRoomListRecyclerAdapter extends RecyclerView.Adapter<ChatRoomLi @@ -58,11 +57,16 @@ public class ChatRoomListRecyclerAdapter extends RecyclerView.Adapter<ChatRoomLi
protected static class ViewHolder extends RecyclerView.ViewHolder{
// 每个item包含的控件
public LinearLayout left_layout; // 左侧消息盒子(对方)
public RelativeLayout left_layout; // 左侧消息盒子(对方)
public ImageView left_avatar; // 左头像
public TextView left_text; // 左文字
public LinearLayout right_layout; // 右侧~(我方)
public RelativeLayout right_layout; // 右侧~(我方)
public ImageView right_avatar;
public ImageView chatting_left_img;
public ImageView chatting_right_img;
public TextView right_text;
public TextView send_time; // 发送时间
public TextView system_msg; // 系统消息
@ -74,9 +78,12 @@ public class ChatRoomListRecyclerAdapter extends RecyclerView.Adapter<ChatRoomLi @@ -74,9 +78,12 @@ public class ChatRoomListRecyclerAdapter extends RecyclerView.Adapter<ChatRoomLi
left_text = v.findViewById(R.id.chatting_left_text);
right_layout = v.findViewById(R.id.layout_chatting_right);
right_avatar = v.findViewById(R.id.iv_avatar_right);
right_text = v.findViewById(R.id.chatting_rigth_text);
right_text = v.findViewById(R.id.chatting_right_text);
send_time = v.findViewById(R.id.tv_send_time);
system_msg = v.findViewById(R.id.tv_system_msg);
chatting_left_img = v.findViewById(R.id.chatting_left_img);
chatting_right_img = v.findViewById(R.id.chatting_right_img);
}
}

123
app/src/main/java/com/kanglai/push/ui/adapter/SoloChatRoomAdapter.java

@ -1,53 +1,36 @@ @@ -1,53 +1,36 @@
package com.kanglai.push.ui.adapter;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import com.blankj.utilcode.util.CacheDiskUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.kanglai.push.R;
import com.kanglai.push.constant.CacheConstant;
import com.kanglai.push.entity.LocalPushChatMsg;
import com.kanglai.push.entity.PushChatMessage;
import com.kanglai.push.entity.User;
import com.kanglai.push.util.CustomDeserializer;
import com.kanglai.push.util.TimeFormatUtil;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
/**
* 单人聊天室适配器
* @Author: liusixiang007
* @since: 2023/6/9
*/
public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{
public ArrayList<PushChatMessage> mItemList;
public ArrayList<PushChatMessage> mItemList = new ArrayList<>();
public User userData = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, com.kanglai.push.entity.User.CREATOR, new User()); // 当前登录用户的数据
public User user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, com.kanglai.push.entity.User.CREATOR, new User()); // 当前登录用户的数据
public LocalPushChatMsg adverseData; // 聊天方数据
public String alias; // 对方id
public String userId; // 我方id
// private EventListener mEventListener; 单列点击事件
public SoloChatRoomAdapter() {
}
public SoloChatRoomAdapter(ArrayList<PushChatMessage> mItemList, LocalPushChatMsg adverseData) {
public SoloChatRoomAdapter(ArrayList<PushChatMessage> mItemList) {
this.mItemList = mItemList;
this.adverseData = adverseData;
this.alias = adverseData.getId();
this.userId = userData.getId();
}
@Override
@ -57,38 +40,55 @@ public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{ @@ -57,38 +40,55 @@ public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
final PushChatMessage item = mItemList.get(position);
if (TextUtils.isEmpty(item.getUserId())) return; // 接收id为空时 再不展示数据
if (alias.equals(item.getUserId())){
onItemBindingTime(holder, item, position);
if (StringUtils.equals(user.getId(), item.getUserId())) {
onItemBindingMine(holder, item);
} else {
onItemBindingOther(holder, item);
return;
}
if (userId.equals(item.getUserId())){
onItemBindingMine(holder, item);
return;
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
private void onItemBindingTime(ViewHolder holder, PushChatMessage model, int index) {
PushChatMessage prev;
Date lastTime = null;
Date currentTime = null;
if (index > 0) {
prev = mItemList.get(index - 1);
if (prev.getCreateTime() != null) {
try {
lastTime = dateFormat.parse(prev.getCreateTime());
currentTime = dateFormat.parse(model.getCreateTime());
} catch (ParseException ignored) {}
}
}
if ((lastTime != null && currentTime!=null) && (currentTime.getTime() - lastTime.getTime() < 5 * 60 * 1000)) {
holder.send_time.setVisibility(View.GONE);
} else {
holder.send_time.setVisibility(View.VISIBLE);
holder.send_time.setText(model.getCreateTime());
}
}
/*展示其他人的消息*/
private void onItemBindingOther(ViewHolder holder, PushChatMessage item) {
holder.system_msg.setVisibility(View.GONE);
holder.send_time.setText(TimeFormatUtil.formatTimeUI(item.getCreateTime()));
holder.right_layout.setVisibility(View.GONE);
holder.left_layout.setVisibility(View.VISIBLE);
//后端需要设置头像值
//loadAvatar(holder.right_avatar, user.getAvatar());
holder.chatting_left_img.setVisibility(View.VISIBLE);
holder.left_text.setText(item.getText());
loadAvatar(holder.left_avatar, adverseData.getAvatar());
}
/*展示自己的消息*/
private void onItemBindingMine(ViewHolder holder, PushChatMessage item) {
holder.system_msg.setVisibility(View.GONE);
holder.send_time.setText(TimeFormatUtil.formatTimeUI(item.getCreateTime()));
holder.left_layout.setVisibility(View.GONE);
holder.right_layout.setVisibility(View.VISIBLE);
loadAvatar(holder.right_avatar, user.getAvatar());
holder.chatting_right_img.setVisibility(View.VISIBLE);
holder.right_text.setText(item.getText());
loadAvatar(holder.right_avatar, userData.getAvatar());
}
/*加载头像*/
private void loadAvatar(ImageView avatar, String url) {
Glide.with(avatar.getContext())
.load(url)
@ -100,12 +100,8 @@ public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{ @@ -100,12 +100,8 @@ public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{
.into(avatar);
}
/**
* 刷新数据
* @param collection
* @return
*/
public SoloChatRoomAdapter refresh(Collection<PushChatMessage> collection){
public SoloChatRoomAdapter refresh(Collection<PushChatMessage> collection) {
mItemList.clear();
mItemList.addAll(collection);
notifyDataSetChanged();
@ -113,35 +109,18 @@ public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{ @@ -113,35 +109,18 @@ public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{
return this;
}
/**
* 加载历史记录
* @param collection
* @return
*/
public SoloChatRoomAdapter loadHistory(Collection<PushChatMessage> collection){
// mItemList.addAll(0, collection);
notifyItemRangeInserted(0, collection.size());
return this;
}
/**
* 加载是数组最后的一条数据
* @param
* @return
*/
public SoloChatRoomAdapter refreshLastDate(){
notifyItemRangeInserted(mItemList.size() - 1, 1);
public SoloChatRoomAdapter loadMore(Collection<PushChatMessage> collection) {
mItemList.addAll(collection);
notifyDataSetChanged();
return this;
}
/** 销毁数据 */
public SoloChatRoomAdapter clear(){
mItemList.clear();
notifyDataSetChanged();
public SoloChatRoomAdapter insert(Collection<PushChatMessage> collection) {
mItemList.addAll(0, collection);
notifyItemRangeInserted(0, collection.size());
return this;
}
public SoloChatRoomAdapter append(PushChatMessage pushChatMessage){
mItemList.add(pushChatMessage);
notifyItemRangeInserted(mItemList.size() - 1, 1);

86
app/src/main/java/com/kanglai/push/ui/vm/InstantViewModel.java

@ -1,12 +1,8 @@ @@ -1,12 +1,8 @@
package com.kanglai.push.ui.vm;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.icu.text.SimpleDateFormat;
import android.icu.util.Calendar;
import android.os.Handler;
import android.os.Looper;
import android.util.Pair;
import android.view.View;
@ -26,7 +22,6 @@ import com.dolphin.core.util.RxUtil; @@ -26,7 +22,6 @@ import com.dolphin.core.util.RxUtil;
import com.dolphin.core.util.ToastUtil;
import com.kanglai.push.app.AppApplication;
import com.kanglai.push.constant.CacheConstant;
import com.kanglai.push.constant.CommonConstant;
import com.kanglai.push.di.component.DaggerServiceComponent;
import com.kanglai.push.entity.LocalPushChatMsg;
import com.kanglai.push.entity.MsgVo;
@ -35,7 +30,7 @@ import com.kanglai.push.entity.User; @@ -35,7 +30,7 @@ import com.kanglai.push.entity.User;
import com.kanglai.push.service.PushService;
import com.kanglai.push.ui.activity.InstantActivity;
import com.kanglai.push.util.LocalPushChatMsgUtil;
import com.luck.picture.lib.config.PictureConfig;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import java.util.ArrayList;
import java.util.Collections;
@ -59,17 +54,10 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{ @@ -59,17 +54,10 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{
public User user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, User.CREATOR, new User());
public LocalPushChatMsg adverseData; // 对方用户基础信息
public int size = 10;
public int current = 1;
public String cursor = "";
public ArrayList<LocalPushChatMsg> localPushChatMsgs; // 本地缓存的列表数据
/** 所有的记录数据 */
private ArrayList<PushChatMessage> requestList = new ArrayList<>();
public InstantViewModel(@NonNull Application application) {
super(application);
DaggerServiceComponent
@ -159,11 +147,10 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{ @@ -159,11 +147,10 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{
});
});
public void init() {
public void initData(RefreshLayout refresh) {
pushService.listFriendHistoryMessage(
MapUtils.newHashMap(
Pair.create("size", size),
Pair.create("current", current),
Pair.create("size", pageSize),
Pair.create("alias", adverseData.getId()),
Pair.create("userId", user.getId())
))
@ -173,40 +160,34 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{ @@ -173,40 +160,34 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{
.subscribe(new DisposableObserver<ResultResponse<Map<String, Object>>>() {
@Override
public void onNext(ResultResponse<Map<String, Object>> R) {
if (R.getCode() == R.SUCCESS ) {
if (R.getCode() == R.SUCCESS) {
MsgVo msgVo = (MsgVo) R.getData();
cursor = msgVo.getCursor();
List<PushChatMessage> data = msgVo.getData();
if (CollectionUtils.isEmpty(data)) { // 暂无
return;
if (!CollectionUtils.isEmpty(data)) {
Collections.reverse(data);
mActivity.mAdapter.refresh(data);
}
} else {
refresh.finishRefresh(false);
ToastUtil.showBottomWarn(R.getMsg());
}
Collections.reverse(data); // 把顺序颠倒下方便排列
requestList.addAll(data);
}else ToastUtil.showBottomWarn(R.getMsg());
}
@Override
public void onError(Throwable e) {
refresh.finishRefresh(false);
ExceptionHandle.baseExceptionMsg(e);
}
@Override
public void onComplete() {
if (requestList.size() > 0) mActivity.adapterInit(requestList); // 有新数据才做界面刷新
}
public void onComplete() {}
});
}
public void loadMore() { // 加载更多数据
if (CollectionUtils.isEmpty(requestList)) { // 如果此时的列表为空 则重新初始化
init();
return;
}
public void loadMore(RefreshLayout layout) {
pushService.listFriendHistoryMessage(
MapUtils.newHashMap(
Pair.create("size", size),
Pair.create("current", current + 1),
Pair.create("size", pageSize),
Pair.create("current", pageCurrent += 1),
Pair.create("alias", adverseData.getId()),
Pair.create("userId", user.getId())
))
@ -219,41 +200,28 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{ @@ -219,41 +200,28 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{
if (R.getCode() == R.SUCCESS) {
MsgVo msgVo = (MsgVo) R.getData();
cursor = msgVo.getCursor();
List<PushChatMessage> data = msgVo.getData();
if (CollectionUtils.isEmpty(data)) {
ToastUtil.showBottomSuccess("已加载全部数据");
mActivity.refreshLayout.setEnableRefresh(false);
return;
}
Collections.reverse(data);
if (data.get(0).getId().equals(requestList.get(0).getId())){
ToastUtil.showBottomSuccess("暂无更多");
List<PushChatMessage> pushChatMessages = msgVo.getData();
if (CollectionUtils.isEmpty(pushChatMessages)) {
ToastUtil.showBottomSuccess("数据加载完毕");
mActivity.refreshLayout.setEnableRefresh(false);
return;
}
requestList.addAll(0, data);
mActivity.mAdapter.loadHistory(data);
current = current + 1;
if (data.size() < size){
ToastUtil.showBottomSuccess("已加载全部聊天数据");
mActivity.refreshLayout.setEnableRefresh(false);
}
}else ToastUtil.showBottomWarn(R.getMsg());
Collections.reverse(pushChatMessages);
mActivity.mAdapter.loadMore(msgVo.getData());
if (mActivity.mAdapter.getItemCount() < R.getTotal()) {
layout.finishLoadMore();
} else layout.finishLoadMoreWithNoMoreData();
} else ToastUtil.show(R.getMsg());
}
@Override
public void onError(Throwable e) {
mActivity.refreshLayout.finishRefresh(false);
layout.finishLoadMore(false);
ExceptionHandle.baseExceptionMsg(e);
}
@Override
public void onComplete() {
/** 完成刷新 */
mActivity.refreshLayout.finishRefresh();
}
public void onComplete() {}
});
}
}

BIN
app/src/main/res/drawable-xxhdpi/skin_messages_right_bubble_highlighted.9.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

0
app/src/main/res/drawable-xxhdpi/skin_messages_right_bubble.9.png → app/src/main/res/drawable-xxhdpi/skin_messages_right_bubble_wechat.9.png

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

6
app/src/main/res/drawable/skin_messages_right_bubble.xml

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/skin_messages_right_bubble_highlighted" />
<item android:drawable="@drawable/skin_messages_right_bubble_wechat" />
</selector>

69
app/src/main/res/layout/activity_instant.xml

@ -7,51 +7,53 @@ @@ -7,51 +7,53 @@
<data>
<variable name="viewModel" type="com.kanglai.push.ui.vm.InstantViewModel" />
</data>
<RelativeLayout
<LinearLayout
android:background="#F3F4F6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- 顶部任务栏 -->
<include
android:id="@+id/layout_toolbar"
layout="@layout/layout_toolbar"
binding:toolbarViewModel="@{viewModel.toolbarViewModel}" />
<!-- 消息刷新布局 -->
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/instant_smart_refresh"
tools:ignore="MissingClass"
android:layout_below="@+id/layout_toolbar"
android:layout_above="@+id/layout_footer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleY="-1"
app:srlEnableRefresh="false"
app:srlEnableAutoLoadMore="false"
app:srlEnableNestedScrolling="false">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/instant_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="match_parent">
android:overScrollMode="never"
android:scrollbars="none"
android:fadeScrollbars="false"
android:dividerHeight="0dp"
android:divider="@android:color/transparent"
tools:itemCount="1"
android:scaleY="-1"
tools:listitem="@layout/item_chat_room"/>
<com.scwang.smart.refresh.header.ClassicsHeader
android:id="@+id/instant_smart_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlTextPulling="@string/instant_header_pulling"
app:srlTextLoading="@string/instant_header_load"
app:srlTextRelease="@string/instant_header_release"
app:srlTextFinish="@string/instant_header_finish"
app:srlTextFailed="@string/instant_header_fail"
app:srlPrimaryColor="@color/common_app_them"
app:srlAccentColor="@android:color/white"/>
<androidx.recyclerview.widget.RecyclerView
android:overScrollMode="never"
android:id="@+id/instant_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:scaleY="-1"
app:srlTextPulling="下拉加载更多"/>
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
<LinearLayout
android:id="@+id/layout_footer"
android:background="@color/white"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="5dip"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 输入框 -->
android:layout_height="wrap_content"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -60,8 +62,8 @@ @@ -60,8 +62,8 @@
android:gravity="center_vertical">
<ImageView
android:id="@+id/iv_more_line"
android:layout_marginLeft="@dimen/dp_2"
android:layout_marginRight="@dimen/dp_7"
android:layout_marginStart="@dimen/dp_2"
android:layout_marginEnd="@dimen/dp_7"
android:src="@drawable/icon_btn_add_line"
android:background="?attr/selectableItemBackgroundBorderless"
android:layout_width="@dimen/dp_32"
@ -69,8 +71,8 @@ @@ -69,8 +71,8 @@
<ImageView
android:visibility="gone"
android:id="@+id/iv_more_fill"
android:layout_marginLeft="@dimen/dp_2"
android:layout_marginRight="@dimen/dp_7"
android:layout_marginStart="@dimen/dp_2"
android:layout_marginEnd="@dimen/dp_7"
android:src="@drawable/icon_btn_add_fill"
android:background="?attr/selectableItemBackgroundBorderless"
android:layout_width="@dimen/dp_32"
@ -87,7 +89,9 @@ @@ -87,7 +89,9 @@
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/instant_message_input_box"/>
android:background="@drawable/instant_message_input_box"
android:autofillHints="msg"
tools:ignore="LabelFor" />
<TextView
android:id="@+id/instant_send_btn"
android:text="发 送"
@ -95,11 +99,12 @@ @@ -95,11 +99,12 @@
android:textColor="@color/white"
android:gravity="center"
android:background="@drawable/icon_btn_primary_radius_bg"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_2"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_2"
android:layout_width="@dimen/dp_50"
android:layout_height="@dimen/dp_34"
binding:onClickCommand="@{viewModel.sendMsgClickCommand}"/>
binding:onClickCommand="@{viewModel.sendMsgClickCommand}"
tools:ignore="SpUsage" />
</LinearLayout>
<!-- 其他操作 -->
<GridLayout
@ -142,5 +147,5 @@ @@ -142,5 +147,5 @@
</GridLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</layout>

165
app/src/main/res/layout/item_chat_room.xml

@ -2,125 +2,126 @@ @@ -2,125 +2,126 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 发送时间 -->
android:padding="@dimen/dp_10">
<TextView
android:id="@+id/tv_send_time"
android:text="08:00"
android:textColor="@color/black50"
android:textSize="@dimen/sp_12"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!-- 左边消息 -->
<LinearLayout
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:text="@string/app_name"
android:textSize="@dimen/sp_8"
android:paddingLeft="3dip"
android:paddingRight="3dip"
android:textColor="#aaaaaa"/>
<RelativeLayout
android:id="@+id/layout_chatting_left"
android:layout_marginTop="@dimen/dp_5"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 左侧头像 -->
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<ImageView
android:id="@+id/iv_avatar_left"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_40"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginLeft="@dimen/dp_10"
android:src="@drawable/icon_links_avatar"/>
<!-- 左侧聊天框 -->
android:layout_width="@dimen/dp_38"
android:layout_height="@dimen/dp_38"
android:layout_alignParentTop="true"
android:src="@drawable/icon_links_avatar"
android:focusable="false"/>
<LinearLayout
android:id="@+id/chatting_frame_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:gravity="left"
android:minWidth="@dimen/dp_60"
android:layout_marginStart="10dp"
android:layout_marginEnd="55dp"
android:layout_toEndOf="@+id/iv_avatar_left"
android:gravity="center"
android:minWidth="60dp"
android:background="@drawable/skin_messages_left_bubble"
android:orientation="vertical">
<FrameLayout
android:layout_margin="@dimen/dp_2"
android:layout_margin="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="match_parent"
tools:ignore="UselessParent">
<ImageView
android:id="@+id/chatting_left_img"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
tools:src="@mipmap/ico_dialogx_error"/>
<TextView
android:id="@+id/chatting_left_text"
android:layout_margin="5dp"
android:textSize="@dimen/sp_13"
android:textStyle="bold"
android:singleLine="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dp_5"
android:gravity="left"
android:layout_gravity="center"
android:maxWidth="@dimen/dp_230"
android:layout_alignParentEnd="true"
android:text="都可以使用RippleDrawable来达到水波纹特效,而且必须处于可点击状态,"
android:textSize="@dimen/sp_14"/>
android:gravity="start"
android:textColor="#444444"
android:text="@string/app_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</FrameLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<!-- 右边消息 -->
<LinearLayout
<RelativeLayout
android:id="@+id/layout_chatting_right"
android:layout_marginTop="@dimen/dp_5"
android:gravity="end"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 右侧聊天框 -->
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<ImageView
android:id="@+id/iv_avatar_right"
android:layout_width="@dimen/dp_38"
android:layout_height="@dimen/dp_38"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:src="@drawable/icon_links_avatar"
android:focusable="false"/>
<LinearLayout
android:id="@+id/chatting_frame_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:gravity="center"
android:maxWidth="@dimen/dp_60"
android:layout_marginStart="55dp"
android:layout_marginEnd="10dp"
android:layout_toStartOf="@+id/iv_avatar_right"
android:background="@drawable/skin_messages_right_bubble"
android:gravity="center"
android:minWidth="60dp"
android:orientation="vertical">
<FrameLayout
android:layout_margin="@dimen/dp_2"
android:layout_margin="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
tools:ignore="UselessParent">
<ImageView
android:visibility="visible"
android:id="@+id/chatting_right_img"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
tools:src="@mipmap/ico_dialogx_error"/>
<TextView
android:id="@+id/chatting_rigth_text"
android:id="@+id/chatting_right_text"
android:layout_margin="5dp"
android:textSize="@dimen/sp_13"
android:textStyle="bold"
android:singleLine="false"
android:maxWidth="@dimen/dp_230"
android:gravity="right"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:gravity="right"
android:textColor="#444444"
android:text="@string/app_name"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dp_5"
android:text="测试内容,任何view处于可点击状态,都可以使用RippleDrawable来达到水波纹特效,而且必须处于可点击状态,才会出现波纹动画效果"
android:textSize="@dimen/sp_14"/>
android:layout_width="wrap_content"
tools:ignore="RtlHardcoded" />
</FrameLayout>
</LinearLayout>
<!-- 右侧头像 -->
<ImageView
android:id="@+id/iv_avatar_right"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_40"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_5"
android:src="@drawable/icon_links_avatar"/>
</LinearLayout>
</RelativeLayout>
<!-- 系统消息内容 默认隐藏 -->
<TextView
android:visibility="gone"
android:id="@+id/tv_system_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="@dimen/dp_10"
android:textColor="#eeeeee"
android:textSize="@dimen/sp_12"
android:text="系统消息"
android:background="@drawable/icon_btn_swipeable_bg1"
android:paddingTop="@dimen/dp_2"
android:paddingBottom="@dimen/dp_2"
android:paddingLeft="@dimen/dp_5"
android:paddingRight="@dimen/dp_5"/>
</LinearLayout>
Loading…
Cancel
Save