wangxiang 1 year ago
parent
commit
0f51527a92
  1. 8
      app/src/main/java/com/kanglai/push/ui/activity/InstantActivity.java
  2. 11
      app/src/main/java/com/kanglai/push/ui/adapter/SoloChatRoomAdapter.java
  3. 11
      app/src/main/java/com/kanglai/push/ui/vm/InstantViewModel.java
  4. 7
      app/src/main/res/layout/activity_instant.xml

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

@ -68,15 +68,18 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
super.mViewModel.mActivity = this; super.mViewModel.mActivity = this;
mAdapter = new SoloChatRoomAdapter(); mViewModel.localPushChatMsg = getIntent().getParcelableExtra(CommonConstant.INSTANT_LAUNCHER_RESULT_KEY);
mAdapter = new SoloChatRoomAdapter(mViewModel.localPushChatMsg);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
mRecyclerView = findViewById(R.id.instant_recycler); mRecyclerView = findViewById(R.id.instant_recycler);
mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
refreshLayout = findViewById(R.id.instant_smart_refresh); refreshLayout = findViewById(R.id.instant_smart_refresh);
refreshLayout.setEnableRefresh(false);
refreshLayout.setEnableAutoLoadMore(true);
refreshLayout.setEnableNestedScroll(false);
refreshLayout.setEnableScrollContentWhenLoaded(true); refreshLayout.setEnableScrollContentWhenLoaded(true);
refreshLayout.setOnLoadMoreListener(mViewModel::loadMore); refreshLayout.setOnLoadMoreListener(mViewModel::loadMore);
refreshLayout.setDisableContentWhenRefresh(true);
input_box = findViewById(R.id.instant_input_box); 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_line = findViewById(R.id.iv_more_line);
@ -85,7 +88,6 @@ public class InstantActivity extends BaseActivity<ActivityInstantBinding, Instan
more_fill.setOnClickListener(view -> changBottomType()); more_fill.setOnClickListener(view -> changBottomType());
bottom_grid = findViewById(R.id.instant_grid); bottom_grid = findViewById(R.id.instant_grid);
layout_footer = findViewById(R.id.layout_footer); layout_footer = findViewById(R.id.layout_footer);
mViewModel.localPushChatMsg = getIntent().getParcelableExtra(CommonConstant.INSTANT_LAUNCHER_RESULT_KEY);
mViewModel.setTitleText(mViewModel.localPushChatMsg.getUserName()); mViewModel.setTitleText(mViewModel.localPushChatMsg.getUserName());
if ("2".equals(mViewModel.localPushChatMsg.getUserType()) || "5".equals(mViewModel.localPushChatMsg.getUserType()) || "0".equals(mViewModel.localPushChatMsg.getUserType())){ if ("2".equals(mViewModel.localPushChatMsg.getUserType()) || "5".equals(mViewModel.localPushChatMsg.getUserType()) || "0".equals(mViewModel.localPushChatMsg.getUserType())){
layout_footer.setVisibility(View.INVISIBLE); layout_footer.setVisibility(View.INVISIBLE);

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

@ -10,6 +10,7 @@ import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.kanglai.push.R; import com.kanglai.push.R;
import com.kanglai.push.constant.CacheConstant; import com.kanglai.push.constant.CacheConstant;
import com.kanglai.push.entity.LocalPushChatMsg;
import com.kanglai.push.entity.PushChatMessage; import com.kanglai.push.entity.PushChatMessage;
import com.kanglai.push.entity.User; import com.kanglai.push.entity.User;
@ -25,12 +26,15 @@ public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{
public ArrayList<PushChatMessage> mItemList = new ArrayList<>(); public ArrayList<PushChatMessage> mItemList = new ArrayList<>();
public User user = 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 friendData;
public SoloChatRoomAdapter() { public SoloChatRoomAdapter(LocalPushChatMsg friendData) {
this.friendData = friendData;
} }
public SoloChatRoomAdapter(ArrayList<PushChatMessage> mItemList) { public SoloChatRoomAdapter(ArrayList<PushChatMessage> mItemList, LocalPushChatMsg friendData) {
this.mItemList = mItemList; this.mItemList = mItemList;
this.friendData = friendData;
} }
@Override @Override
@ -75,8 +79,7 @@ public class SoloChatRoomAdapter extends ChatRoomListRecyclerAdapter{
private void onItemBindingOther(ViewHolder holder, PushChatMessage item) { private void onItemBindingOther(ViewHolder holder, PushChatMessage item) {
holder.right_layout.setVisibility(View.GONE); holder.right_layout.setVisibility(View.GONE);
holder.left_layout.setVisibility(View.VISIBLE); holder.left_layout.setVisibility(View.VISIBLE);
//后端需要设置头像值 loadAvatar(holder.left_avatar, friendData.getAvatar());
//loadAvatar(holder.right_avatar, user.getAvatar());
holder.chatting_left_img.setVisibility(View.VISIBLE); holder.chatting_left_img.setVisibility(View.VISIBLE);
holder.left_text.setText(item.getText()); holder.left_text.setText(item.getText());
} }

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

@ -168,15 +168,12 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{
if (!CollectionUtils.isEmpty(data)) { if (!CollectionUtils.isEmpty(data)) {
Collections.reverse(data); Collections.reverse(data);
mActivity.mAdapter.refresh(data); mActivity.mAdapter.refresh(data);
mActivity.mRecyclerView.scrollToPosition(mActivity.mAdapter.getItemCount() - 1);
} }
} else { } else ToastUtil.showBottomWarn(R.getMsg());
refresh.finishRefresh(false);
ToastUtil.showBottomWarn(R.getMsg());
}
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
refresh.finishRefresh(false);
ExceptionHandle.baseExceptionMsg(e); ExceptionHandle.baseExceptionMsg(e);
} }
@Override @Override
@ -209,9 +206,7 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{
} }
Collections.reverse(pushChatMessages); Collections.reverse(pushChatMessages);
mActivity.mAdapter.loadMore(msgVo.getData()); mActivity.mAdapter.loadMore(msgVo.getData());
if (mActivity.mAdapter.getItemCount() < R.getTotal()) { layout.finishLoadMore();
layout.finishLoadMore();
} else layout.finishLoadMoreWithNoMoreData();
} else ToastUtil.show(R.getMsg()); } else ToastUtil.show(R.getMsg());
} }

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

@ -21,10 +21,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
android:scaleY="-1" android:scaleY="-1">
app:srlEnableRefresh="false"
app:srlEnableAutoLoadMore="false"
app:srlEnableNestedScrolling="false">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/instant_recycler" android:id="@+id/instant_recycler"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -37,7 +34,7 @@
tools:itemCount="1" tools:itemCount="1"
android:scaleY="-1" android:scaleY="-1"
tools:listitem="@layout/item_chat_room"/> tools:listitem="@layout/item_chat_room"/>
<com.scwang.smart.refresh.header.ClassicsHeader <com.scwang.smart.refresh.footer.ClassicsFooter
android:id="@+id/instant_smart_header" android:id="@+id/instant_smart_header"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

Loading…
Cancel
Save