UPDATE聊天页面改版UI
This commit is contained in:
@@ -106,7 +106,7 @@
|
||||
android:required="false" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.PDLiveConversationActivity"
|
||||
android:name="com.yunbao.main.activity.PDLiveConversationActivity"
|
||||
android:hardwareAccelerated="true"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
|
||||
|
||||
@@ -1,264 +0,0 @@
|
||||
package com.yunbao.live.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.blankj.utilcode.util.GsonUtils;
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
import com.yunbao.common.activity.SelectImageActivity;
|
||||
import com.yunbao.common.bean.IMLoginModel;
|
||||
import com.yunbao.common.bean.ImageEntity;
|
||||
import com.yunbao.common.bean.NoviceInstructorModel;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.manager.NoviceInstructorManager;
|
||||
import com.yunbao.common.manager.imrongcloud.MessageIMManager;
|
||||
import com.yunbao.live.R;
|
||||
import com.yunbao.live.bean.SearchUserBean;
|
||||
import com.yunbao.live.dialog.MenuPopuwWindow;
|
||||
import com.yunbao.live.event.InputPanelViewHolderEvent;
|
||||
import com.yunbao.live.utils.WindowSoftModeAdjustResizeExecutor;
|
||||
import com.yunbao.live.views.InputPanelViewHolder;
|
||||
import com.yunbao.live.views.PDLiveConversationFragment;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.rong.imkit.IMCenter;
|
||||
import io.rong.imkit.userinfo.RongUserInfoManager;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.UserInfo;
|
||||
|
||||
/**
|
||||
* 聊天会话界面
|
||||
*/
|
||||
public class PDLiveConversationActivity extends AbsActivity implements View.OnClickListener {
|
||||
private PDLiveConversationFragment conversationFragment;
|
||||
private PDLiveConversationActivity mContext;
|
||||
private InputPanelViewHolder inputPanel;
|
||||
private TextView titleView;
|
||||
private ImageView imgMore, imBack;
|
||||
private boolean isAdmin = false;
|
||||
private final int PERMISSION_REQUEST_CODE = 0;
|
||||
private final int SELECT_VIDEO_REQUEST = 0x0002;
|
||||
private final int SELECT_IMAGE_REQUEST = 0x0001;
|
||||
private ArrayList<ImageEntity> mSelectImages = new ArrayList<>();
|
||||
private String targetId = "";
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_conversation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void main() {
|
||||
super.main();
|
||||
EventBus.getDefault().register(this);
|
||||
mContext = this;
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
||||
initView();
|
||||
initData();
|
||||
WindowSoftModeAdjustResizeExecutor.assistActivity(this);
|
||||
//设置会话界面操作监听器
|
||||
MessageIMManager.get(this).addConversationClickListener();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据的设置
|
||||
*/
|
||||
private void initData() {
|
||||
targetId = getIntent().getStringExtra("targetId");
|
||||
NoviceInstructorModel model = NoviceInstructorManager.get(this).getNoviceInstructor();
|
||||
|
||||
//绑定聊天用户id
|
||||
inputPanel.setTargetId(targetId);
|
||||
//获取用户信息
|
||||
UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(targetId);
|
||||
if (null != userInfo) {
|
||||
titleView.setText(userInfo.getName());
|
||||
if (!TextUtils.isEmpty(userInfo.getExtra())) {
|
||||
SearchUserBean userBean = GsonUtils.fromJson(userInfo.getExtra(), SearchUserBean.class);
|
||||
//新手指导员
|
||||
if (!TextUtils.isEmpty(userBean.getIs_admin()) && TextUtils.equals(userBean.getIs_admin(), "1")) {
|
||||
if (model != null && !TextUtils.isEmpty(model.getMsgZdySendText())) {
|
||||
inputPanel.setPresetInformation(model.getMsgZdySendText());
|
||||
}
|
||||
isAdmin = true;
|
||||
imgMore.setVisibility(View.GONE);
|
||||
} else {//非指导员
|
||||
isAdmin = false;
|
||||
imgMore.setVisibility(View.VISIBLE);
|
||||
}
|
||||
inputPanel.setAdmin(isAdmin);
|
||||
Log.e("PDLiveConversation", userInfo.getExtra());
|
||||
}
|
||||
} else {
|
||||
titleView.setText("系統消息");
|
||||
inputPanel.setVisibility(View.GONE);
|
||||
}
|
||||
getDraft();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化布局
|
||||
*/
|
||||
private void initView() {
|
||||
try {
|
||||
// 添加会话界面
|
||||
conversationFragment = new PDLiveConversationFragment();
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
transaction.replace(R.id.container, conversationFragment);
|
||||
transaction.commit();
|
||||
inputPanel = findViewById(R.id.input_panel);
|
||||
titleView = findViewById(R.id.titleView);
|
||||
imgMore = findViewById(R.id.img_more);
|
||||
imBack = findViewById(R.id.btn_back);
|
||||
imgMore.setOnClickListener(this);
|
||||
imBack.setOnClickListener(this);
|
||||
|
||||
inputPanel.addMediaMessageCallback(new InputPanelViewHolder.MediaMessageCallback() {
|
||||
@Override
|
||||
public void choosePic(int intoIndex) {
|
||||
jumpPic(intoIndex);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
//菜单
|
||||
if (id == R.id.img_more) {
|
||||
IMLoginModel model = IMLoginManager.get(mContext).getUserInfo();
|
||||
new MenuPopuwWindow(mContext).setIsAdmin(model.getIsAdmin(), targetId).show(imgMore);
|
||||
} else if (id == R.id.btn_back) {//返回
|
||||
onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
//intoIndex 1=调用相机,2=照片选取,3=视频选取
|
||||
public void jumpPic(int intoIndex) {
|
||||
String permission1=Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||
String permission2= Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
permission1=Manifest.permission.READ_MEDIA_IMAGES;
|
||||
permission2=Manifest.permission.READ_MEDIA_VIDEO;
|
||||
}
|
||||
|
||||
//选择图片
|
||||
int isPermission1 = ContextCompat.checkSelfPermission(mContext, permission1);
|
||||
int isPermission2 = ContextCompat.checkSelfPermission(mContext, permission2);
|
||||
if (isPermission1 == PackageManager.PERMISSION_GRANTED && isPermission2 == PackageManager.PERMISSION_GRANTED) {
|
||||
startActivity(intoIndex);
|
||||
} else {
|
||||
//申请权限
|
||||
ActivityCompat.requestPermissions(mContext, new String[]{permission1,
|
||||
permission2}, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
private void startActivity(int intoIndex) {
|
||||
mSelectImages.clear();
|
||||
Intent intent = new Intent(mContext, SelectImageActivity.class);
|
||||
intent.putParcelableArrayListExtra("selected_images", mSelectImages);
|
||||
intent.putExtra("intoIndex", intoIndex);
|
||||
if (intoIndex == 3) {
|
||||
startActivityForResult(intent, SELECT_VIDEO_REQUEST);
|
||||
} else {
|
||||
startActivityForResult(intent, SELECT_IMAGE_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取草稿箱信息系
|
||||
*/
|
||||
private void getDraft() {
|
||||
RongIMClient.getInstance().getTextMessageDraft(Conversation.ConversationType.PRIVATE, targetId, new RongIMClient.ResultCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String s) {
|
||||
if (!TextUtils.isEmpty(s))
|
||||
inputPanel.setPresetInformation(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(RongIMClient.ErrorCode errorCode) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == SELECT_IMAGE_REQUEST && data != null) {
|
||||
ArrayList<ImageEntity> selectImages = data.getParcelableArrayListExtra(SelectImageActivity.EXTRA_RESULT);
|
||||
for (ImageEntity entity : selectImages) {
|
||||
inputPanel.sendImageFile(entity.getPath());
|
||||
}
|
||||
|
||||
} else if (requestCode == SELECT_VIDEO_REQUEST && data != null) {
|
||||
ArrayList<ImageEntity> selectImages = data.getParcelableArrayListExtra(SelectImageActivity.EXTRA_RESULT);
|
||||
for (ImageEntity entity : selectImages) {
|
||||
inputPanel.sendVideoFile(entity.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//获取输入框信息存进输入框
|
||||
String content = inputPanel.getPresetInformation();
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
IMCenter.getInstance().saveTextMessageDraft(Conversation.ConversationType.PRIVATE, targetId, content, null);
|
||||
}
|
||||
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
//消息中心
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageIMEvent(String event) {
|
||||
if (!TextUtils.isEmpty(event)) {
|
||||
titleView.setText(event);
|
||||
}
|
||||
}
|
||||
|
||||
//消息中心
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onInputPanelViewHolderEvent(InputPanelViewHolderEvent event) {
|
||||
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
inputPanel.hidePluginList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yunbao.live.dialog;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -7,6 +8,8 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.yunbao.common.message.content.MessageChatTipsContent;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.live.R;
|
||||
import com.yunbao.live.event.InputPanelViewHolderEvent;
|
||||
|
||||
@@ -17,6 +20,7 @@ import io.rong.imkit.model.UiMessage;
|
||||
import io.rong.imkit.widget.adapter.IViewProviderListener;
|
||||
import io.rong.imkit.widget.adapter.ViewHolder;
|
||||
import io.rong.imlib.model.Message;
|
||||
import io.rong.imlib.model.MessageContent;
|
||||
|
||||
/**
|
||||
* 会话页面更改已读未读
|
||||
@@ -30,12 +34,16 @@ public class PDLiveMessageListAdapter extends MessageListAdapter {
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
super.onBindViewHolder(holder, position);
|
||||
Message.MessageDirection messageDirection = mDataList.get(position).getMessage().getMessageDirection();
|
||||
MessageContent content = mDataList.get(position).getMessage().getContent();
|
||||
ImageView readReceipt = holder.getConvertView().findViewById(R.id.rc_read_receipt);
|
||||
TextView rcEdit = holder.getConvertView().findViewById(R.id.rc_edit);
|
||||
if (rcEdit!=null){
|
||||
rcEdit.setVisibility(View.GONE);
|
||||
}
|
||||
holder.getConvertView().setBackgroundColor(Color.parseColor("#00000000"));
|
||||
holder.itemView.setBackgroundColor(Color.parseColor("#00000000"));
|
||||
ImageView readReceiptNew = holder.getConvertView().findViewById(R.id.rc_read_receipt_new);
|
||||
|
||||
if (readReceiptNew!=null){
|
||||
if (messageDirection==Message.MessageDirection.SEND){
|
||||
readReceiptNew.setVisibility(View.VISIBLE);
|
||||
@@ -50,6 +58,9 @@ public class PDLiveMessageListAdapter extends MessageListAdapter {
|
||||
if (readReceipt!=null){
|
||||
readReceipt.setVisibility(View.GONE);
|
||||
}
|
||||
if(content instanceof MessageChatTipsContent){
|
||||
readReceiptNew.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
holder.getConvertView().setOnTouchListener(new View.OnTouchListener() {
|
||||
|
||||
@@ -1,18 +1,59 @@
|
||||
package com.yunbao.live.views;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import com.yunbao.common.event.PDChatInputModeEvent;
|
||||
import com.yunbao.live.dialog.PDLiveMessageListAdapter;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import io.rong.imkit.conversation.ConversationFragment;
|
||||
import io.rong.imkit.conversation.MessageListAdapter;
|
||||
import io.rong.imkit.conversation.extension.InputMode;
|
||||
import io.rong.imkit.conversation.extension.RongExtensionViewModel;
|
||||
|
||||
/**
|
||||
* 聊天详情页面
|
||||
*/
|
||||
public class PDLiveConversationFragment extends ConversationFragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
view.setBackgroundColor(Color.parseColor("#00000000"));
|
||||
|
||||
mRongExtensionViewModel.getInputModeLiveData().observe(getViewLifecycleOwner(), new Observer<InputMode>() {
|
||||
@Override
|
||||
public void onChanged(InputMode inputMode) {
|
||||
}
|
||||
});
|
||||
mRongExtension.getInputPanel().getEditText().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
EventBus.getDefault().post(new PDChatInputModeEvent(InputMode.TextInput));
|
||||
}
|
||||
});
|
||||
mRongExtension.getInputPanel().getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean b) {
|
||||
EventBus.getDefault().post(new PDChatInputModeEvent(InputMode.TextInput));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessageListAdapter onResolveAdapter() {
|
||||
return new PDLiveMessageListAdapter(this);
|
||||
}
|
||||
|
||||
|
||||
public RongExtensionViewModel getRongExtensionViewModel() {
|
||||
return mRongExtensionViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/root_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/view_title" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:background="@color/gray3" />
|
||||
|
||||
<!--套一层Layout,不然控件就透明了-->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:background="@color/white"
|
||||
android:layout_height="wrap_content">
|
||||
<com.yunbao.live.views.InputPanelViewHolder
|
||||
android:id="@+id/input_panel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -3,8 +3,8 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:visibility="gone"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/input_panel_voice_toggle"
|
||||
@@ -20,7 +20,10 @@
|
||||
<EditText
|
||||
android:id="@+id/edit_btn"
|
||||
style="@style/EditTextStyle.Alignment"
|
||||
android:hint="@string/activity_msg_chat_input_hint"
|
||||
android:layout_width="0dp"
|
||||
android:drawableStart="@mipmap/ic_message_chat_input"
|
||||
android:drawablePadding="5dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="6.5dp"
|
||||
@@ -40,8 +43,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/rc_ext_input_panel_editbox_height"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginTop="6.5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginBottom="6.5dp"
|
||||
android:background="@drawable/rc_ext_voice_idle_button"
|
||||
android:gravity="center"
|
||||
@@ -59,12 +62,12 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6.5dp"
|
||||
android:layout_marginBottom="6.5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginBottom="6.5dp"
|
||||
android:src="@drawable/rc_ext_input_panel_emoji"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/input_panel_add_or_send" />
|
||||
app:layout_constraintEnd_toStartOf="@+id/input_panel_add_or_send"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/input_panel_add_or_send"
|
||||
|
||||
Reference in New Issue
Block a user