xuqm 1 년 전
부모
커밋
3497b02341

+ 1 - 1
SzyxImSdk/src/main/java/cn/org/bjca/trust/android/lib/im/im/manager/ImManager.java

@@ -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)

+ 10 - 0
SzyxImSdk/src/main/java/cn/org/bjca/trust/android/lib/im/im/msg/ConnectedMessage.java

@@ -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;

+ 5 - 0
SzyxImSdk/src/main/java/cn/org/bjca/trust/android/lib/im/kit/SdkInterface.java

@@ -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();
 }

+ 10 - 0
SzyxImSdk/src/main/java/cn/org/bjca/trust/android/lib/im/manager/SZYXImManager.java

@@ -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() {

+ 2 - 1
app/src/main/java/cn/org/bjca/trust/android/imdemo/ui/ChatActivity.java

@@ -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");

+ 51 - 14
app/src/main/java/cn/org/bjca/trust/android/imdemo/ui/adapter/ChatAdapter.java

@@ -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_root_l;
+            }
+
+            @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, 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_text;
+                return R.layout.chat_view_root_r;
             }
 
             @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, 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;
+        }
+    }
 }

+ 1 - 0
app/src/main/res/layout/activity_chat.xml

@@ -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">
 

+ 69 - 0
app/src/main/res/layout/chat_view_root_l.xml

@@ -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>

+ 71 - 0
app/src/main/res/layout/chat_view_root_r.xml

@@ -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>

+ 7 - 20
app/src/main/res/layout/chat_view_text.xml

@@ -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>

+ 11 - 0
app/src/main/res/layout/chat_view_unknown.xml

@@ -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>

+ 11 - 11
szyxpushsdk/src/main/java/cn/org/bjca/trust/android/lib/push/push/SZYXPushManager.java

@@ -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());
+//        });
     }
 }