Commit 9072aa05 by huangzhicong

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

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