Explorar el Código

Merge branch 'feature/android_im_open_instantMsg' into 'develop'

android 普通消息可打开对应的应用

See merge request o2oa/o2oa!1026
楼国栋 hace 5 años
padre
commit
952a09ab82

+ 95 - 2
o2android/app/src/main/java/net/zoneland/x/bpm/mobile/v1/zoneXBPM/app/im/O2InstantMessageActivity.kt

@@ -2,18 +2,35 @@ package net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.im
 
 import android.app.Activity
 import android.os.Bundle
+import android.support.v4.content.ContextCompat
 import android.support.v7.widget.LinearLayoutManager
+import android.text.SpannableString
+import android.text.Spanned
+import android.text.TextUtils
+import android.text.style.ForegroundColorSpan
+import android.text.style.UnderlineSpan
 import android.widget.TextView
 import kotlinx.android.synthetic.main.activity_o2_instant_message.*
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.R
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.base.BaseMVPActivity
+import net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.bbs.main.BBSMainActivity
+import net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.calendar.CalendarMainActivity
+import net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.clouddrive.CloudDriveActivity
+import net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.cms.index.CMSIndexActivity
+import net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.meeting.main.MeetingMainActivity
+import net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.o2.webview.TaskWebViewActivity
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.core.component.adapter.CommonRecycleViewAdapter
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.core.component.adapter.CommonRecyclerViewHolder
+import net.zoneland.x.bpm.mobile.v1.zoneXBPM.core.component.enums.ApplicationEnum
+import net.zoneland.x.bpm.mobile.v1.zoneXBPM.flutter.FlutterConnectActivity
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.model.bo.api.InstantMessage
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.utils.DateHelper
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.utils.extension.go
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.utils.extension.visible
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.widgets.CircleImageView
+import org.json.JSONObject
+import org.json.JSONTokener
+import java.lang.Exception
 
 class O2InstantMessageActivity : BaseMVPActivity<O2InstantMessageContract.View, O2InstantMessageContract.Presenter>(), O2InstantMessageContract.View {
     override var mPresenter: O2InstantMessageContract.Presenter = O2InstantMessagePresenter()
@@ -41,6 +58,7 @@ class O2InstantMessageActivity : BaseMVPActivity<O2InstantMessageContract.View,
                     val titleText = holder.getView<TextView>(R.id.tv_o2_chat_message_body)
                     titleText.text = t.title
                     titleText.visible()
+                    messageTypeEvent(titleText, t)
                     val time = DateHelper.imChatMessageTime(t.createTime)
                     holder.setText(R.id.tv_o2_chat_message_time, time)
                 }
@@ -66,6 +84,83 @@ class O2InstantMessageActivity : BaseMVPActivity<O2InstantMessageContract.View,
         }
     }
 
+    private fun messageTypeEvent(textView: TextView, msg: InstantMessage) {
+        val type = msg.type
+        if (type.startsWith("task_")) {
+            if (!type.contains("_delete")) {
+                openWork(msg, textView)
+            }
+        }else if (type.startsWith("taskCompleted_")) {
+            if (!type.contains("_delete")) {
+                setLinkStyle(textView) {
+
+                }
+            }
+        }else if (type.startsWith("read_")) {
+            if (!type.contains("_delete")) {
+                openWork(msg, textView)
+            }
+        }else if (type.startsWith("readCompleted_")) {
+            if (!type.contains("_delete")) {
+                openWork(msg, textView)
+            }
+        }else if (type.startsWith("review_")||type.startsWith("work_")||type.startsWith("process_")) {
+            if (!type.contains("_delete")) {
+                openWork(msg, textView)
+            }
+        }else if (type.startsWith("meeting_")) {
+            setLinkStyle(textView) {
+                go<MeetingMainActivity>()
+            }
+        }else if (type.startsWith("attachment_")) {
+            setLinkStyle(textView) {
+                go<CloudDriveActivity>()
+            }
+        }else if (type.startsWith("calendar_")) {
+            setLinkStyle(textView) {
+                go<CalendarMainActivity>()
+            }
+        }else if (type.startsWith("cms_")) {
+            setLinkStyle(textView) {
+                go<CMSIndexActivity>()
+            }
+        }else if (type.startsWith("bbs_")) {
+            setLinkStyle(textView) {
+                go<BBSMainActivity>()
+            }
+        }else if (type.startsWith("mind_")) {
+            setLinkStyle(textView) {
+                go<FlutterConnectActivity>(FlutterConnectActivity.startFlutterAppWithRoute(ApplicationEnum.MindMap.key))
+            }
+        }else {
+        }
+    }
+
+    private fun openWork(msg: InstantMessage, textView: TextView) {
+        val json = JSONTokener(msg.body).nextValue()
+        if (json is JSONObject) {
+            val work = try {json.getString("work")}catch (e: Exception){null}
+            val workCompleted = try {json.getString("workCompleted")}catch (e: Exception){null}
+            if (!TextUtils.isEmpty(work) || !TextUtils.isEmpty(workCompleted)) {
+                setLinkStyle(textView) {
+                    go<TaskWebViewActivity>(TaskWebViewActivity.start(work, workCompleted, ""))
+                }
+            }
+        }
+    }
+
+    private fun setLinkStyle(textView: TextView, openClick:(() -> Unit)) {
+        val text = textView.text
+        if (!TextUtils.isEmpty(text)) {
+            val len = text.length
+            val span  = SpannableString(text)
+            span.setSpan(ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary_blue)), 0, len,  Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
+            span.setSpan(UnderlineSpan(), 0, len , Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
+            textView.text = span
+            textView.setOnClickListener { openClick() }
+        }
+    }
+
 
     private fun messageTypeAvatar(type: String) : Int {
         if (type.startsWith("task_")) {
@@ -90,8 +185,6 @@ class O2InstantMessageActivity : BaseMVPActivity<O2InstantMessageContract.View,
             return R.mipmap.app_bbs
         }else if (type.startsWith("mind_")) {
             return R.mipmap.app_mind_map
-        }else if (type.startsWith("attachment_")) {
-            return R.mipmap.app_attendance
         }else {
             return R.mipmap.app_o2_ai
         }

+ 14 - 10
o2android/app/src/main/java/net/zoneland/x/bpm/mobile/v1/zoneXBPM/app/o2/webview/JSInterfaceO2mBiz.kt

@@ -38,17 +38,21 @@ class JSInterfaceO2mBiz  private constructor(val activity: FragmentActivity?) {
     fun postMessage(message: String?) {
         if (!TextUtils.isEmpty(message)) {
             XLog.debug(message)
-            val json = JSONTokener(message).nextValue()
-            if (json is JSONObject) {
-                when (json.getString("type")) {
-                    "contact.departmentPicker" -> departmentsPicker(message!!)
-                    "contact.identityPicker" -> identityPicker(message!!)
-                    "contact.groupPicker" -> groupPicker(message!!)
-                    "contact.personPicker" -> personPicker(message!!)
-                    "contact.complexPicker" -> complexPicker(message!!)
+            try {
+                val json = JSONTokener(message).nextValue()
+                if (json is JSONObject) {
+                    when (json.getString("type")) {
+                        "contact.departmentPicker" -> departmentsPicker(message!!)
+                        "contact.identityPicker" -> identityPicker(message!!)
+                        "contact.groupPicker" -> groupPicker(message!!)
+                        "contact.personPicker" -> personPicker(message!!)
+                        "contact.complexPicker" -> complexPicker(message!!)
+                    }
+                } else {
+                    XLog.error("message 格式错误!!!")
                 }
-            } else {
-                XLog.error("message 格式错误!!!")
+            } catch (e: Exception) {
+                XLog.error("", e)
             }
         } else {
             XLog.error("o2mBiz.postMessage error, 没有传入message内容!")

+ 18 - 14
o2android/app/src/main/java/net/zoneland/x/bpm/mobile/v1/zoneXBPM/app/o2/webview/JSInterfaceO2mNotification.kt

@@ -47,21 +47,25 @@ class JSInterfaceO2mNotification  private constructor (val activity: Activity?)
     fun postMessage(message: String?) {
         if (!TextUtils.isEmpty(message)) {
             XLog.debug(message)
-            val json = JSONTokener(message).nextValue()
-            if (json is JSONObject) {
-                val type = json.getString("type")
-                when(type) {
-                    "alert" -> alert(message!!)
-                    "confirm" -> confirm(message!!)
-                    "prompt" -> prompt(message!!)
-                    "vibrate" -> vibrate(message!!)
-                    "toast" -> toast(message!!)
-                    "actionSheet" -> actionSheet(message!!)
-                    "showLoading" -> showLoading(message!!)
-                    "hideLoading" -> hideLoading(message!!)
+            try {
+                val json = JSONTokener(message).nextValue()
+                if (json is JSONObject) {
+                    val type = json.getString("type")
+                    when(type) {
+                        "alert" -> alert(message!!)
+                        "confirm" -> confirm(message!!)
+                        "prompt" -> prompt(message!!)
+                        "vibrate" -> vibrate(message!!)
+                        "toast" -> toast(message!!)
+                        "actionSheet" -> actionSheet(message!!)
+                        "showLoading" -> showLoading(message!!)
+                        "hideLoading" -> hideLoading(message!!)
+                    }
+                }else {
+                    XLog.error("message 格式错误!!!")
                 }
-            }else {
-                XLog.error("message 格式错误!!!")
+            } catch (e: Exception) {
+                XLog.error("", e)
             }
         }else {
             XLog.error("o2mNotification.postMessage error, 没有传入message内容!")

+ 21 - 17
o2android/app/src/main/java/net/zoneland/x/bpm/mobile/v1/zoneXBPM/app/o2/webview/JSInterfaceO2mUtil.kt

@@ -55,24 +55,28 @@ class JSInterfaceO2mUtil private constructor(val activity: FragmentActivity?) {
     fun postMessage(message: String?) {
         if (!TextUtils.isEmpty(message)) {
             XLog.debug(message)
-            val json = JSONTokener(message).nextValue()
-            if (json is JSONObject) {
-                val type = json.getString("type")
-                when (type) {
-                    "date.datePicker" -> datePicker(message!!)
-                    "date.timePicker" -> timePicker(message!!)
-                    "date.dateTimePicker" -> dateTimePicker(message!!)
-                    "calendar.chooseOneDay" -> calendarDatePicker(message!!)
-                    "calendar.chooseDateTime" -> calendarDateTimePicker(message!!)
-                    "calendar.chooseInterval" -> calendarDateIntervalPicker(message!!)
-                    "device.getPhoneInfo" -> deviceGetPhoneInfo(message!!)
-                    "device.scan" -> deviceScan(message!!)
-                    "navigation.setTitle" -> navigationSetTitle(message!!)
-                    "navigation.close" -> navigationClose(message!!)
-                    "navigation.goBack" -> navigationGoBack(message!!)
+            try {
+                val json = JSONTokener(message).nextValue()
+                if (json is JSONObject) {
+                    val type = json.getString("type")
+                    when (type) {
+                        "date.datePicker" -> datePicker(message!!)
+                        "date.timePicker" -> timePicker(message!!)
+                        "date.dateTimePicker" -> dateTimePicker(message!!)
+                        "calendar.chooseOneDay" -> calendarDatePicker(message!!)
+                        "calendar.chooseDateTime" -> calendarDateTimePicker(message!!)
+                        "calendar.chooseInterval" -> calendarDateIntervalPicker(message!!)
+                        "device.getPhoneInfo" -> deviceGetPhoneInfo(message!!)
+                        "device.scan" -> deviceScan(message!!)
+                        "navigation.setTitle" -> navigationSetTitle(message!!)
+                        "navigation.close" -> navigationClose(message!!)
+                        "navigation.goBack" -> navigationGoBack(message!!)
+                    }
+                } else {
+                    XLog.error("message 格式错误!!!")
                 }
-            } else {
-                XLog.error("message 格式错误!!!")
+            } catch (e: Exception) {
+                XLog.error("", e)
             }
         } else {
             XLog.error("o2mUtil.postMessage error, 没有传入message内容!")

+ 10 - 5
o2android/app/src/main/java/net/zoneland/x/bpm/mobile/v1/zoneXBPM/core/service/WebSocketService.kt

@@ -16,6 +16,7 @@ import android.os.HandlerThread
 import net.zoneland.x.bpm.mobile.v1.zoneXBPM.app.im.O2IM
 import org.json.JSONTokener
 import org.json.JSONObject
+import java.lang.Exception
 
 
 class WebSocketService : Service() {
@@ -150,11 +151,15 @@ class WebSocketService : Service() {
                 XLog.info("webSocket 收到消息, message:$text")
                 val json = JSONTokener(text).nextValue()
                 if (json is JSONObject) {
-                    val type = json.getString("type")
-                    //发送im消息
-                    if (type == "im_create") {
-                        val body = json.getJSONObject("body")
-                        sendIMMessageBroadcast(body.toString())
+                    try {
+                        val type = json.getString("type")
+                        //发送im消息
+                        if (type == "im_create") {
+                            val body = json.getJSONObject("body")
+                            sendIMMessageBroadcast(body.toString())
+                        }
+                    } catch (e: Exception) {
+                        XLog.error("", e)
                     }
                 }
             }