Commit 9072aa05 by huangzhicong

去掉singleOptions,jssdk定义只有一个参数时args即为参数

parent 6d73cc3c
......@@ -18,7 +18,6 @@ import com.maxrocky.nativeview.R
import com.maxrocky.nativeview.WebViewProxy
import com.maxrocky.nativeview.contract.*
import com.maxrocky.nativeview.model.StorageOptions
import com.maxrocky.nativeview.model.SingleOptions
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
......@@ -152,28 +151,20 @@ class MainFragment : Fragment() {
@JavascriptInterface
fun execute(sessionId: Int, method: String, args: String) {
when (method) {
"selectFile" -> {
val options = gson.fromJson<SingleOptions<String>>(args, SingleOptions::class.java)
selectFileContract.selectFile(sessionId, options.data1)
}
"selectFile" -> selectFileContract.selectFile(sessionId, args)
"selectPhoto" -> selectPhotoContract.selectPhoto(sessionId)
"openCamera" -> cameraContract.openCamera(sessionId)
"recordAudio" -> {
if (args.isNotEmpty()) {
val options = gson.fromJson<SingleOptions<Int>>(args, SingleOptions::class.java)
recordAudioContract.recordAudio(sessionId, options.data1)
} else {
recordAudioContract.recordAudio(sessionId)
}
}
"cropPhoto" -> {
val options = gson.fromJson<SingleOptions<String>>(args, SingleOptions::class.java)
cropContract.cropPhoto(sessionId, Uri.parse(options.data1))
}
"recordAudio" ->
recordAudioContract.recordAudio(sessionId, args.toIntOrNull())
"cropPhoto" ->
cropContract.cropPhoto(sessionId, Uri.parse(args))
"captureVideo" -> videoContract.captureVideo(sessionId)
"qrcode" -> qrCodeContract.qrcode(sessionId)
"storageValue" -> {
val options = gson.fromJson<StorageOptions<String, String>>(args, StorageOptions::class.java)
val options = gson.fromJson<StorageOptions<String, String>>(
args,
StorageOptions::class.java
)
storageContract.storageValue(sessionId, options.key, options.value)
}
"acquireValue" -> storageContract.acquireValue(sessionId, args)
......
package com.maxrocky.nativeview.model
data class SingleOptions<T>(val data1: T)
data class StorageOptions<T, U>(val key: T, val value: U)
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 sign in to comment