Commit 613d0d77 by 万齐军

feat: webView传入JsMethod

parent 60a45ede
......@@ -2,13 +2,17 @@ package com.ydl.component.service;
import android.app.Activity;
import android.content.Context;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.ydl.component.service.web.WebJavascriptHandler;
import com.tencent.smtt.sdk.WebView;
import com.ydl.component.service.web.WVClickAbstractListener;
import com.ydl.component.service.web.WebJavascriptHandler;
import com.ydl.webview.IJavascriptHandler;
import com.ydl.webview.IWebService;
import com.ydl.webview.TellData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created by haorui on 2019-10-10.
......@@ -24,7 +28,7 @@ public class WebServiceImpl implements IWebService {
@NotNull
@Override
public IJavascriptHandler getJavascripHandler(@NotNull Activity activity, @NotNull TellData tellData) {
return new WebJavascriptHandler(new WVClickAbstractListener(activity));
public IJavascriptHandler getJavascripHandler(@NotNull Activity activity, @Nullable WebView webView, @NotNull TellData tellData) {
return new WebJavascriptHandler(webView, new WVClickAbstractListener(activity));
}
}
......@@ -2,6 +2,9 @@ package com.ydl.component.service.web
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import com.tencent.smtt.sdk.WebView
import com.ydl.confide.home.event.ConfideDialogEvent
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
......@@ -11,7 +14,7 @@ import com.yidianling.common.tools.ToastUtil
import de.greenrobot.event.EventBus
class JsMethod {
class JsMethod(private val webView: WebView?) {
fun handle(param: String): Boolean {
......@@ -57,6 +60,14 @@ class JsMethod {
}
return true
}
"has_audio_permission" -> {
val callback = param.getAsJsonPrimitive("callback").asString
if (callback.isNullOrBlank()) return true
val topActivity = BaseActivityMgr.INST.getTopActivity()
val grantedPermission = XXPermissions.isGrantedPermission(topActivity, Permission.RECORD_AUDIO)
webView?.loadUrl("javascript:$callback(${if (grantedPermission) 1 else 0})")
return true
}
else -> {
return false
}
......
......@@ -3,6 +3,7 @@ package com.ydl.component.service.web
import android.webkit.JavascriptInterface
import androidx.fragment.app.FragmentActivity
import com.google.gson.Gson
import com.tencent.smtt.sdk.WebView
import com.ydl.confide.api.ConfideRoute
import com.ydl.confide.api.IConfideService
import com.ydl.js_module.manager.WebViewRouterManager
......@@ -21,18 +22,13 @@ import com.yidianling.user.UserHelper
* update by harvie on 2017/7/04
*/
class WebJavascriptHandler : IJavascriptHandler{
class WebJavascriptHandler(private val webView: WebView?, private val wvEnventPro: WebViewClientClickListener?) : IJavascriptHandler() {
private val js = JsMethod()
private val js = JsMethod(webView)
override fun getUriAppendSuffix(): String {
return "platform_main_theme=00C9E2&platform_main_theme_light=00D4DF&platform_main_theme_bright=EAFAFC"
}
var wvEnventPro: WebViewClientClickListener? = null
constructor(listener: WebViewClientClickListener) : super() {
this.wvEnventPro = listener
}
@JavascriptInterface
fun sendDataToOC(params: String) {
......
......@@ -416,7 +416,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() {
wv_content?.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY //滚动条风格,为0指滚动条不占用空间,直接覆盖在网页上
mJtoJHandle = WebModularServiceUtils.getWebService()
.getJavascripHandler(requireActivity(), tellData = TellData())
.getJavascripHandler(requireActivity(), wv_content, tellData = TellData())
wv_content?.addJavascriptInterface(mJtoJHandle, "javascriptHandler")
// var jumpurl = "http://192.168.210.152/jy/listenMask?listenerId=257&isFromApp=1"
......
......@@ -18,7 +18,6 @@ import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.R
import com.yidianling.uikit.custom.http.response.ServiceItemBean
import com.yidianling.uikit.custom.widget.expertConsultService.callback.ConsultServiceViewCallback
class ExpertConsultWebview : RelativeLayout {
private var doctorID: String
......@@ -53,7 +52,7 @@ class ExpertConsultWebview : RelativeLayout {
jumpUrl =
HttpConfig.MH5_URL + "wb/product/chat/template?doctorId=${doctorID}&cateId=${productBean.getcatenewId()}&productId=${productBean.productDto.id}"
val jtoJHandle = WebModularServiceUtils.getWebService()
.getJavascripHandler(mContext as Activity, tellData = TellData())
.getJavascripHandler(mContext as Activity, wv_content, tellData = TellData())
val url = WebUrlParamsUtils.getSuffix(jumpUrl, jtoJHandle.getUriAppendSuffix())
wv_content.loadUrl(url)
}
......@@ -134,7 +133,7 @@ class ExpertConsultWebview : RelativeLayout {
wv_content!!.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY //滚动条风格,为0指滚动条不占用空间,直接覆盖在网页上
val jtoJHandle = WebModularServiceUtils.getWebService()
.getJavascripHandler(mContext as Activity, tellData = TellData())
.getJavascripHandler(mContext as Activity, wv_content, tellData = TellData())
wv_content!!.addJavascriptInterface(jtoJHandle, "javascriptHandler")
val url = WebUrlParamsUtils.getSuffix(jumpUrl, jtoJHandle.getUriAppendSuffix())
......
......@@ -62,7 +62,7 @@ class ChooseMusicActivity : BaseActivity() {
super.onCreate(savedInstanceState)
getParam()
var tellData = TellData()
jtoJHandle = getWebService().getJavascripHandler(this, tellData.also { tellData = it })
jtoJHandle = getWebService().getJavascripHandler(this, null, tellData.also { tellData = it })
initView()
}
......
/*___Generated_by_IDEA___*/
package com.ydl.webview;
/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */
public final class BuildConfig {
public final static boolean DEBUG = Boolean.parseBoolean(null);
}
\ No newline at end of file
/*___Generated_by_IDEA___*/
package com.ydl.webview;
/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
public final class Manifest {
}
\ No newline at end of file
/*___Generated_by_IDEA___*/
package com.ydl.webview;
/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
public final class R {
}
\ No newline at end of file
......@@ -2,11 +2,12 @@ package com.ydl.webview
import android.app.Activity
import com.alibaba.android.arouter.facade.template.IProvider
import com.tencent.smtt.sdk.WebView
/**
* Created by haorui on 2019-10-10.
* Des:
*/
interface IWebService : IProvider {
fun getJavascripHandler(activity: Activity, tellData: TellData): IJavascriptHandler
fun getJavascripHandler(activity: Activity, webView: WebView?, tellData: TellData): IJavascriptHandler
}
......@@ -394,7 +394,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
setUrlHeightParams();
EventBus.getDefault().register(this);
jtoJHandle = WebModularServiceUtils.Companion.getWebService().getJavascripHandler(this, tellData = tellData);
jtoJHandle = WebModularServiceUtils.Companion.getWebService().getJavascripHandler(this, wv_content, tellData);
init();
if (startType == 1) {
......
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