Commit 52c2fe29 by 王宇航

1.6.4

用泛型會解析失敗,轉用String
parent 32862f7d
...@@ -2,18 +2,14 @@ package com.example.demo ...@@ -2,18 +2,14 @@ package com.example.demo
import android.app.Activity import android.app.Activity
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.widget.TextView import android.widget.TextView
import com.example.gingersoft_connect.R import com.example.gingersoft_connect.R
import com.gingersoft.connect.SendCallback import com.gingersoft.connect.SendCallback
import com.gingersoft.connect.bean.Action import com.gingersoft.connect.bean.Action
import com.gingersoft.connect.bean.FoodInfoBean import com.gingersoft.connect.bean.FoodInfoBean
import com.gingersoft.connect.bean.MessageBuilder import com.gingersoft.connect.bean.MessageBuilder
import com.gingersoft.connect.bean.MessageSender
import com.gingersoft.connect.bean.OrderInfoBean import com.gingersoft.connect.bean.OrderInfoBean
import com.gingersoft.connect.utils.GingerSoftConnect import com.gingersoft.connect.utils.GingerSoftConnect
import java.text.SimpleDateFormat
import java.util.Date
class MainActivity : Activity() { class MainActivity : Activity() {
......
package com.gingersoft.connect.bean package com.gingersoft.connect.bean
class MessageBean<T>( class MessageBean(
/** /**
* 消息唯一ID,發送消息過去,服務端收到後會發送一條成功接收消息,通過這個code來區分是哪條消息 * 消息唯一ID,發送消息過去,服務端收到後會發送一條成功接收消息,通過這個code來區分是哪條消息
*/ */
var code: Int = 0, var code: Int = 0,
var action: String? = null, var action: String? = null,
var data: T? = null var data: String? = null
) )
\ No newline at end of file
...@@ -12,7 +12,7 @@ import kotlinx.coroutines.runBlocking ...@@ -12,7 +12,7 @@ import kotlinx.coroutines.runBlocking
class MessageSender( class MessageSender(
private val connect: GingerSoftConnect, private val connect: GingerSoftConnect,
private val webSocketClient: MyWebSocketClient, private val webSocketClient: MyWebSocketClient,
private val msg: MessageBean<*> private val msg: MessageBean
) { ) {
fun send(): GingerSoftConnect { fun send(): GingerSoftConnect {
......
...@@ -10,7 +10,7 @@ object MsgParser { ...@@ -10,7 +10,7 @@ object MsgParser {
val parserMap by lazy { mutableMapOf<String, MsgProcess>() } val parserMap by lazy { mutableMapOf<String, MsgProcess>() }
fun process(msgBean: MessageBean<*>?): SocketCallbackBean? { fun process(msgBean: MessageBean?): SocketCallbackBean? {
return if (msgBean != null) { return if (msgBean != null) {
val result = parserMap[msgBean.action.toString()]?.processMsg(msgBean.data) val result = parserMap[msgBean.action.toString()]?.processMsg(msgBean.data)
if (result != null) { if (result != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment