diff --git a/app/src/main/java/com/idormy/sms/forwarder/entity/setting/DingtalkGroupRobotSetting.kt b/app/src/main/java/com/idormy/sms/forwarder/entity/setting/DingtalkGroupRobotSetting.kt index 860a6183..b006c055 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/entity/setting/DingtalkGroupRobotSetting.kt +++ b/app/src/main/java/com/idormy/sms/forwarder/entity/setting/DingtalkGroupRobotSetting.kt @@ -1,5 +1,6 @@ package com.idormy.sms.forwarder.entity.setting +import com.idormy.sms.forwarder.R import java.io.Serializable data class DingtalkGroupRobotSetting( @@ -8,4 +9,15 @@ data class DingtalkGroupRobotSetting( var atAll: Boolean? = false, var atMobiles: String? = "", var atDingtalkIds: String? = "", -) : Serializable \ No newline at end of file + var msgtype: String? = "text", + val titleTemplate: String? = "", +) : Serializable { + + fun getMsgTypeCheckId(): Int { + return if (msgtype == "markdown") { + R.id.rb_msg_type_markdown + } else { + R.id.rb_msg_type_text + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/idormy/sms/forwarder/fragment/senders/DingtalkGroupRobotFragment.kt b/app/src/main/java/com/idormy/sms/forwarder/fragment/senders/DingtalkGroupRobotFragment.kt index db0485be..fcf83d98 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/fragment/senders/DingtalkGroupRobotFragment.kt +++ b/app/src/main/java/com/idormy/sms/forwarder/fragment/senders/DingtalkGroupRobotFragment.kt @@ -7,6 +7,8 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.CompoundButton +import android.widget.EditText +import android.widget.RadioGroup import androidx.fragment.app.viewModels import com.google.gson.Gson import com.idormy.sms.forwarder.R @@ -126,16 +128,25 @@ class DingtalkGroupRobotFragment : BaseFragment + binding!!.layoutCustomTemplate.visibility = if (checkedId == R.id.rb_msg_type_markdown) View.VISIBLE else View.GONE + } LiveEventBus.get(KEY_SENDER_TEST, String::class.java).observe(this) { mCountDownHelper?.finish() } } @@ -155,7 +166,24 @@ class DingtalkGroupRobotFragment : BaseFragment { + CommonUtils.insertOrReplaceText2Cursor(etTitleTemplate, getString(R.string.tag_from)) + return + } + R.id.bt_insert_extra -> { + CommonUtils.insertOrReplaceText2Cursor(etTitleTemplate, getString(R.string.tag_card_slot)) + return + } + R.id.bt_insert_time -> { + CommonUtils.insertOrReplaceText2Cursor(etTitleTemplate, getString(R.string.tag_receive_time)) + return + } + R.id.bt_insert_device_name -> { + CommonUtils.insertOrReplaceText2Cursor(etTitleTemplate, getString(R.string.tag_device_name)) + return + } R.id.btn_test -> { mCountDownHelper?.start() Thread { @@ -227,8 +255,10 @@ class DingtalkGroupRobotFragment : BaseFragment = mutableMapOf() - msgMap["msgtype"] = "text" + msgMap["msgtype"] = setting.msgtype ?: "text" val atMap: MutableMap = mutableMapOf() msgMap["at"] = atMap @@ -86,9 +86,13 @@ class DingtalkGroupRobotUtils private constructor() { } } - val textText: MutableMap = mutableMapOf() - textText["content"] = content - msgMap["text"] = textText + if ("markdown" == msgMap["msgtype"]) { + val titleTemplate = setting.titleTemplate.toString() + val title = rule?.let { msgInfo.getTitleForSend(titleTemplate, it.regexReplace) } ?: msgInfo.getTitleForSend(titleTemplate) + msgMap["markdown"] = mutableMapOf("title" to title, "text" to content) + } else { + msgMap["text"] = mutableMapOf("content" to content) + } val requestMsg: String = Gson().toJson(msgMap) Log.i(TAG, "requestMsg:$requestMsg") diff --git a/app/src/main/res/layout/fragment_senders_dingtalk_group_robot.xml b/app/src/main/res/layout/fragment_senders_dingtalk_group_robot.xml index 404024b4..84f1800c 100644 --- a/app/src/main/res/layout/fragment_senders_dingtalk_group_robot.xml +++ b/app/src/main/res/layout/fragment_senders_dingtalk_group_robot.xml @@ -184,6 +184,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +