Kaynağa Gözat

fix: chat text

tongmengxiao 6 ay önce
ebeveyn
işleme
fcf09737c7

+ 24 - 0
baseswago/src/main/java/com/swago/baseswago/util/StringUtils.kt

@@ -0,0 +1,24 @@
+package com.swago.baseswago.util
+
+import org.json.JSONObject
+import java.util.regex.Pattern
+
+object StringUtils {
+    fun extractJsonObjects(text: String): List<JSONObject> {
+        val jsonObjects = mutableListOf<JSONObject>()
+        val pattern = Pattern.compile("\\{.*?\\}")
+        val matcher = pattern.matcher(text)
+
+        while (matcher.find()) {
+            val jsonString = matcher.group()
+            try {
+                val jsonObject = JSONObject(jsonString)
+                jsonObjects.add(jsonObject)
+            } catch (e: Exception) {
+                e.printStackTrace()
+            }
+        }
+
+        return jsonObjects
+    }
+}

+ 18 - 2
tuikit/src/main/java/com/tencent/qcloud/tim/uikit/modules/chat/base/ChatManagerKit.java

@@ -6,6 +6,8 @@ import android.os.Message;
 import android.text.TextUtils;
 
 import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.swago.baseswago.util.UserInfo;
 import com.tencent.imsdk.BaseConstants;
 import com.tencent.imsdk.v2.V2TIMAdvancedMsgListener;
 import com.tencent.imsdk.v2.V2TIMCallback;
@@ -42,6 +44,9 @@ import java.util.List;
 
 import static com.tencent.imsdk.v2.V2TIMMessage.V2TIM_MSG_STATUS_SEND_FAIL;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 public abstract class ChatManagerKit extends V2TIMAdvancedMsgListener implements MessageRevokedManager.MessageRevokeHandler, IBaseMessageSender {
     private static final String TAG = ChatManagerKit.class.getSimpleName();
 
@@ -461,8 +466,7 @@ public abstract class ChatManagerKit extends V2TIMAdvancedMsgListener implements
         v2TIMOfflinePushInfo.setExt(new Gson().toJson(containerBean).getBytes());
         // OPPO必须设置ChannelID才可以收到推送消息,这个channelID需要和控制台一致
         v2TIMOfflinePushInfo.setAndroidOPPOChannelID("tuikit");
-
-        final V2TIMMessage v2TIMMessage = message.getTimMessage();
+        V2TIMMessage v2TIMMessage = message.getTimMessage();
         if (!isGroup) {
             v2TIMMessage.setExcludedFromUnreadCount(TUIKitConfigs.getConfigs().getGeneralConfig().isExcludedFromUnreadCount());
         } else if (!TextUtils.isEmpty(groupType) &&
@@ -472,6 +476,18 @@ public abstract class ChatManagerKit extends V2TIMAdvancedMsgListener implements
         }
 
         v2TIMMessage.setExcludedFromLastMessage(TUIKitConfigs.getConfigs().getGeneralConfig().isExcludedFromLastMessage());
+        if (!TextUtils.isEmpty(UserInfo.INSTANCE.getUserInfo().getAndroid_chat_special())){
+            V2TIMCustomElem elem = new V2TIMCustomElem();
+            JSONObject jsonObject = new JSONObject();
+            try {
+                jsonObject.put("android_chat_special", UserInfo.INSTANCE.getUserInfo().getAndroid_chat_special());
+                jsonObject.put("ios_chat_special", UserInfo.INSTANCE.getUserInfo().getIos_chat_special());
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+            elem.setData(jsonObject.toString().getBytes());
+            v2TIMMessage.getTextElem().appendElem(elem);
+        }
 
         String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,
                 V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {

+ 4 - 4
tuikit/src/main/java/com/tencent/qcloud/tim/uikit/modules/chat/layout/input/InputLayout.java

@@ -546,7 +546,7 @@ public class InputLayout extends InputLayoutUI implements View.OnClickListener,
                     if (UserInfo.INSTANCE.getUserInfo().getPrivate_msg_status()==1){
                         Toast.makeText(AppContext.getContext(), AppContext.getContext().getResources().getString(R.string.you_are_been_forbid), Toast.LENGTH_SHORT).show();
                     }else {
-                        if (Integer.parseInt(UserInfo.INSTANCE.getUserInfo().getUser_level()) >=5 || Integer.parseInt(UserInfo.INSTANCE.getUserInfo().getUser_wealth_level()) >=5 || UserInfo.INSTANCE.getUserInfo().getIs_recharge() ==1){
+//                        if (Integer.parseInt(UserInfo.INSTANCE.getUserInfo().getUser_level()) >=5 || Integer.parseInt(UserInfo.INSTANCE.getUserInfo().getUser_wealth_level()) >=5 || UserInfo.INSTANCE.getUserInfo().getIs_recharge() ==1){
                             if (mMessageHandler != null) {
                                 if(mChatLayout.getChatInfo().getType() == V2TIMConversation.V2TIM_GROUP && !atUserInfoMap.isEmpty()) {
                                     //发送时通过获取输入框匹配上@的昵称list,去从map中获取ID list。
@@ -560,9 +560,9 @@ public class InputLayout extends InputLayoutUI implements View.OnClickListener,
                                     mMessageHandler.sendMessage(MessageInfoUtil.buildTextMessage(mTextInput.getText().toString().trim()));
                                 }
                             }
-                        } else {
-                            showLevelDialog();
-                        }
+//                        } else {
+//                            showLevelDialog();
+//                        }
 
                     }
                 }else {

+ 36 - 11
tuikit/src/main/java/com/tencent/qcloud/tim/uikit/modules/chat/layout/message/holder/MessageContentHolder.java

@@ -1,5 +1,6 @@
 package com.tencent.qcloud.tim.uikit.modules.chat.layout.message.holder;
 
+import android.graphics.drawable.NinePatchDrawable;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Gravity;
@@ -13,14 +14,24 @@ import com.bumptech.glide.Glide;
 import com.opensource.svgaplayer.SVGADrawable;
 import com.opensource.svgaplayer.SVGAImageView;
 import com.swago.baseswago.util.AppContext;
+import com.swago.baseswago.util.DianJiuUtil;
+import com.swago.baseswago.util.StringUtils;
 import com.swago.baseswago.util.UserInfo;
+import com.tencent.imsdk.message.CustomElement;
+import com.tencent.imsdk.v2.V2TIMCustomElem;
 import com.tencent.imsdk.v2.V2TIMMessage;
 import com.tencent.qcloud.tim.uikit.R;
 import com.tencent.qcloud.tim.uikit.config.TUIKitConfigs;
 import com.tencent.qcloud.tim.uikit.modules.message.MessageInfo;
 import com.tencent.qcloud.tim.uikit.utils.ToastUtil;
 
+import org.json.JSONObject;
+
+import java.util.List;
+
 import de.hdodenhof.circleimageview.CircleImageView;
+import kotlin.Unit;
+import kotlin.jvm.functions.Function1;
 
 public abstract class MessageContentHolder extends MessageEmptyHolder {
 
@@ -59,9 +70,13 @@ public abstract class MessageContentHolder extends MessageEmptyHolder {
         if (msg.isSelf()) {
             leftUserIcon.setVisibility(View.GONE);
             rightUserIcon.setVisibility(View.VISIBLE);
+            leftSvgaImage.setVisibility(View.INVISIBLE);
+            rightSvgaImage.setVisibility(View.VISIBLE);
         } else {
             leftUserIcon.setVisibility(View.VISIBLE);
             rightUserIcon.setVisibility(View.GONE);
+            leftSvgaImage.setVisibility(View.VISIBLE);
+            rightSvgaImage.setVisibility(View.INVISIBLE);
         }
 
         //// 用户昵称设置
@@ -121,13 +136,29 @@ public abstract class MessageContentHolder extends MessageEmptyHolder {
             sendingProgress.setVisibility(View.GONE);
         }
 
-        //// 聊天气泡设置
-        if (msg.isSelf()) {
-            if (properties.getRightBubble() != null && properties.getRightBubble().getConstantState() != null) {
-                msgContentFrame.setBackground(properties.getRightBubble().getConstantState().newDrawable());
+        String customElem = msg.getTimMessage().toString();
+        List<JSONObject> customEle = StringUtils.INSTANCE.extractJsonObjects(customElem);
+        if (!customEle.isEmpty()){
+            String android_chat_special = customEle.get(0).optString("android_chat_special");
+            DianJiuUtil.INSTANCE.loadDian9Tu(AppContext.getContext(), android_chat_special, new Function1<NinePatchDrawable, Unit>() {
+                @Override
+                public Unit invoke(NinePatchDrawable ninePatchDrawable) {
+                    if (ninePatchDrawable != null){
+                        msgContentLinear.setBackground(ninePatchDrawable);
+                    }
+                    return null;
+                }
+            });
+        } else {
+            if (msg.isSelf()){
+                msgContentLinear.setBackgroundResource(R.drawable.bg_chat_purple);
             } else {
-                msgContentFrame.setBackgroundResource(R.drawable.bg_chat_purple);
+                msgContentLinear.setBackgroundResource(R.drawable.bg_chat_white);
             }
+        }
+
+        //// 聊天气泡设置
+        if (msg.isSelf()) {
             if (properties.getRightSvgaAvatar() != null){
                 SVGADrawable drawable = new SVGADrawable(properties.getRightSvgaAvatar());
                 rightSvgaImage.setVisibility(View.VISIBLE);
@@ -137,12 +168,6 @@ public abstract class MessageContentHolder extends MessageEmptyHolder {
                 rightSvgaImage.setVisibility(View.INVISIBLE);
             }
         } else {
-            if (properties.getLeftBubble() != null && properties.getLeftBubble().getConstantState() != null) {
-                msgContentFrame.setBackground(properties.getLeftBubble().getConstantState().newDrawable());
-                msgContentFrame.setLayoutParams(msgContentFrame.getLayoutParams());
-            } else {
-                msgContentFrame.setBackgroundResource(R.drawable.bg_chat_white);
-            }
             if (properties.getLeftSvgaAvatar() != null){
                 SVGADrawable drawable = new SVGADrawable(properties.getLeftSvgaAvatar());
                 leftSvgaImage.setVisibility(View.VISIBLE);

+ 18 - 0
tuikit/src/main/java/com/tencent/qcloud/tim/uikit/modules/message/MessageInfo.java

@@ -148,6 +148,8 @@ public class MessageInfo implements IBaseInfo, Serializable {
     private boolean peerRead;
     private boolean isIgnoreShow = false;
     private V2TIMMessage timMessage;
+    private String android_chat_special;
+    private String ios_chat_special;
 
     /**
      * 获取消息唯一标识
@@ -480,4 +482,20 @@ public class MessageInfo implements IBaseInfo, Serializable {
     public boolean getIsIgnoreShow() {
         return isIgnoreShow;
     }
+
+    public String getAndroid_chat_special() {
+        return android_chat_special;
+    }
+
+    public void setAndroid_chat_special(String android_chat_special) {
+        this.android_chat_special = android_chat_special;
+    }
+
+    public String getIos_chat_special() {
+        return ios_chat_special;
+    }
+
+    public void setIos_chat_special(String ios_chat_special) {
+        this.ios_chat_special = ios_chat_special;
+    }
 }

+ 2 - 2
tuikit/src/main/res/layout/message_adapter_item_content.xml

@@ -53,7 +53,7 @@
             android:id="@+id/svgAvatar_left"
             android:layout_width="41dp"
             android:layout_height="41dp"
-            android:visibility="visible"
+            android:visibility="invisible"
             app:autoPlay="true"
             app:loopCount="0"
             android:layout_alignParentLeft="true"
@@ -73,7 +73,7 @@
             android:id="@+id/svgAvatar_right"
             android:layout_width="41dp"
             android:layout_height="41dp"
-            android:visibility="visible"
+            android:visibility="invisible"
             app:autoPlay="true"
             app:loopCount="0"
             android:layout_alignParentRight="true"