布局
这个提交包含在:
父节点
acd57b3724
当前提交
3497b02341
@ -338,7 +338,7 @@ public class ImManager implements IMInterface {
|
||||
}
|
||||
String msg = GsonImplHelp.get().toJson(message);
|
||||
try {
|
||||
mqttClient.publish("server1" + packetType, msg.getBytes(Charsets.UTF_8), 2, false);
|
||||
mqttClient.publish("server" + packetType, msg.getBytes(Charsets.UTF_8), 2, false);
|
||||
// 如果是发送的消息,需要应答
|
||||
if (PacketType.SEND == packetType) {
|
||||
if (null != callback)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.org.bjca.trust.android.lib.im.im.msg;
|
||||
|
||||
|
||||
import cn.org.bjca.trust.android.lib.im.bean.UserInfo;
|
||||
import cn.org.bjca.trust.android.lib.im.enums.PacketType;
|
||||
import cn.org.bjca.trust.android.lib.im.im.bean.PacketMessage;
|
||||
|
||||
@ -11,6 +12,15 @@ public class ConnectedMessage extends PacketMessage {
|
||||
|
||||
private int status;
|
||||
private String msg;
|
||||
private UserInfo userInfo;
|
||||
|
||||
public UserInfo getUserInfo() {
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
public void setUserInfo(UserInfo userInfo) {
|
||||
this.userInfo = userInfo;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
|
||||
@ -2,6 +2,8 @@ package cn.org.bjca.trust.android.lib.im.kit;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import cn.org.bjca.trust.android.lib.im.bean.UserInfo;
|
||||
|
||||
public interface SdkInterface {
|
||||
|
||||
void setIMSDKListener(IMSDKListener listener);
|
||||
@ -14,6 +16,9 @@ public interface SdkInterface {
|
||||
|
||||
void logout(IMSDKCallback callback);
|
||||
|
||||
UserInfo getUser();
|
||||
UserInfo getUser(String userId);
|
||||
|
||||
|
||||
String getVersion();
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
|
||||
import cn.org.bjca.trust.android.lib.im.BuildConfig;
|
||||
import cn.org.bjca.trust.android.lib.im.SZYXDbHelper;
|
||||
import cn.org.bjca.trust.android.lib.im.bean.UserInfo;
|
||||
import cn.org.bjca.trust.android.lib.im.cfg.Constant;
|
||||
import cn.org.bjca.trust.android.lib.im.common.DeviceHelper;
|
||||
import cn.org.bjca.trust.android.lib.im.http.HttpManage;
|
||||
@ -76,6 +77,15 @@ public class SZYXImManager implements SdkInterface {
|
||||
IMHelper.getInstance().logout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserInfo getUser() {
|
||||
return UserManager.getInstance().getUserInfoForMsg();
|
||||
}
|
||||
@Override
|
||||
public UserInfo getUser(String userId) {
|
||||
return UserManager.getInstance().getUserInfoForMsg();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
|
||||
@ -20,7 +20,7 @@ import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
||||
public class ChatActivity extends BaseActivity<ActivityChatBinding> {
|
||||
|
||||
private ChatVM vm;
|
||||
private final ChatAdapter adapter = new ChatAdapter();
|
||||
private ChatAdapter adapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@ -30,6 +30,7 @@ public class ChatActivity extends BaseActivity<ActivityChatBinding> {
|
||||
@Override
|
||||
public void initView(Bundle savedInstanceState) {
|
||||
super.initView(savedInstanceState);
|
||||
this.adapter = new ChatAdapter(mContext);
|
||||
vm = new ViewModelProvider(this).get(ChatVM.class);
|
||||
String userId = getIntent().getStringExtra("userId");
|
||||
String userName = getIntent().getStringExtra("userName");
|
||||
|
||||
@ -1,39 +1,76 @@
|
||||
package cn.org.bjca.trust.android.imdemo.ui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.xuqm.base.adapter.BaseNormalAdapter;
|
||||
import com.xuqm.base.adapter.ItemViewDelegate;
|
||||
import com.xuqm.base.adapter.ViewHolder;
|
||||
import com.xuqm.base.common.LogHelper;
|
||||
import com.xuqm.base.common.TimeHelper;
|
||||
|
||||
import cn.org.bjca.trust.android.imdemo.R;
|
||||
import cn.org.bjca.trust.android.lib.im.enums.MsgType;
|
||||
import cn.org.bjca.trust.android.imdemo.databinding.ChatViewTextBinding;
|
||||
import cn.org.bjca.trust.android.lib.im.SZYXImSdk;
|
||||
import cn.org.bjca.trust.android.lib.im.im.msg.message.SZYXMessage;
|
||||
|
||||
public class ChatAdapter extends BaseNormalAdapter<SZYXMessage> {
|
||||
public ChatAdapter() {
|
||||
private Context mContext;
|
||||
|
||||
public ChatAdapter(Context context) {
|
||||
this.mContext = context;
|
||||
addItemViewDelegate(new ItemViewDelegate<SZYXMessage>() {
|
||||
@Override
|
||||
public int getItemViewLayoutId() {
|
||||
return R.layout.chat_view_text;
|
||||
return R.layout.chat_view_root_l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForViewType(SZYXMessage item, int position) {
|
||||
return item.getMsgType().equals(MsgType.Text);
|
||||
return item.isArrive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert(ViewHolder holder, SZYXMessage item, int position) {
|
||||
if (item.isArrive()) {
|
||||
holder.setText(R.id.left, item.getTextMessage().getText());
|
||||
holder.setVisibility(R.id.left, true);
|
||||
holder.setVisibility(R.id.right, false);
|
||||
} else {
|
||||
holder.setText(R.id.right, item.getTextMessage().getText());
|
||||
holder.setVisibility(R.id.left, false);
|
||||
holder.setVisibility(R.id.right, true);
|
||||
}
|
||||
holder.setImage(R.id.avatar, item.getFromClient().getFaceUrl());
|
||||
holder.setText(R.id.name, item.getFromClient().getNickName());
|
||||
ChatAdapter.this.convert(holder, item, position);
|
||||
}
|
||||
});
|
||||
addItemViewDelegate(new ItemViewDelegate<SZYXMessage>() {
|
||||
@Override
|
||||
public int getItemViewLayoutId() {
|
||||
return R.layout.chat_view_root_r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForViewType(SZYXMessage item, int position) {
|
||||
return !item.isArrive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert(ViewHolder holder, SZYXMessage item, int position) {
|
||||
holder.setImage(R.id.avatar, SZYXImSdk.getInstance().getUser().getFaceUrl());
|
||||
ChatAdapter.this.convert(holder, item, position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void convert(ViewHolder holder, SZYXMessage item, int position) {
|
||||
holder.setText(R.id.time, TimeHelper.getStringFormMillis(item.getTimestamp(), "yyyy-MM-dd HH:mm"));
|
||||
LinearLayout root = holder.getView(R.id.content);
|
||||
switch (item.getMsgType()) {
|
||||
case Text:
|
||||
ChatViewTextBinding text = DataBindingUtil.inflate(LayoutInflater.from(this.mContext), R.layout.chat_view_text, root, true);
|
||||
text.text.setText(item.getTextMessage().getText());
|
||||
break;
|
||||
case Image:
|
||||
break;
|
||||
default:
|
||||
DataBindingUtil.inflate(LayoutInflater.from(this.mContext), R.layout.chat_view_unknown, root, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:background="#F6F6F6"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.ChatActivity">
|
||||
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:paddingHorizontal="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="2023-06-16 14:44"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:src="@drawable/picture_btn_music_shape"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/time" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:textColor="#767581"
|
||||
android:textSize="11sp"
|
||||
app:layout_constraintStart_toEndOf="@+id/avatar"
|
||||
app:layout_constraintTop_toTopOf="@+id/avatar" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:background="#8CCEED"
|
||||
android:gravity="left"
|
||||
android:minWidth="70dp"
|
||||
android:minHeight="40dp"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp"
|
||||
app:layout_constraintStart_toEndOf="@+id/avatar"
|
||||
app:layout_constraintTop_toBottomOf="@+id/name"
|
||||
app:layout_constraintWidth_max="240dp">
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/status"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:src="@drawable/ic_loading"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/content"
|
||||
app:layout_constraintStart_toEndOf="@+id/content"
|
||||
app:layout_constraintTop_toTopOf="@+id/content" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:paddingHorizontal="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="2023-06-16 14:44"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:src="@drawable/picture_btn_music_shape"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/time" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:text="小明"
|
||||
android:textColor="#767581"
|
||||
android:textSize="10sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toStartOf="@+id/avatar"
|
||||
app:layout_constraintTop_toTopOf="@+id/avatar" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:background="#FFFFFF"
|
||||
android:gravity="right"
|
||||
android:minWidth="70dp"
|
||||
android:minHeight="40dp"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/avatar"
|
||||
app:layout_constraintTop_toBottomOf="@+id/name"
|
||||
app:layout_constraintWidth_max="240dp">
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/status"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:src="@drawable/ic_loading"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/content"
|
||||
app:layout_constraintEnd_toStartOf="@+id/content"
|
||||
app:layout_constraintTop_toTopOf="@+id/content" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -1,23 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="45dp"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<TextView
|
||||
android:id="@+id/left"
|
||||
<layout>
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:text="hhdhsao"/>
|
||||
<TextView
|
||||
android:id="@+id/right"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:text="sda"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
android:textColor="#12111E"
|
||||
android:textSize="14sp" />
|
||||
</layout>
|
||||
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="未知消息"
|
||||
android:textColor="#12111E"
|
||||
android:textSize="14sp" />
|
||||
</layout>
|
||||
@ -12,16 +12,16 @@ public class SZYXPushManager implements PushInterface {
|
||||
@Override
|
||||
public void init(Context mContext) {
|
||||
//初始化push
|
||||
try {
|
||||
PushClient.getInstance(mContext).initialize();
|
||||
} catch (VivoPushException e) {
|
||||
Log.e("=====>0", e.getMessage());
|
||||
}
|
||||
|
||||
// 打开push开关, 关闭为turnOffPush,详见api接入文档
|
||||
PushClient.getInstance(mContext).turnOnPush(state -> {
|
||||
Log.e("=====>1", state + "");
|
||||
Log.e("=====>2", PushClient.getInstance(mContext).getRegId());
|
||||
});
|
||||
// try {
|
||||
// PushClient.getInstance(mContext).initialize();
|
||||
// } catch (VivoPushException e) {
|
||||
// Log.e("=====>0", e.getMessage());
|
||||
// }
|
||||
//
|
||||
// // 打开push开关, 关闭为turnOffPush,详见api接入文档
|
||||
// PushClient.getInstance(mContext).turnOnPush(state -> {
|
||||
// Log.e("=====>1", state + "");
|
||||
// Log.e("=====>2", PushClient.getInstance(mContext).getRegId());
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户