Commit b72f91de by 万齐军

feat: 添加js方法

parent 2d9f6402
package com.ydl.component.service.web
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.ydl.confide.home.event.ConfideDialogEvent
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.ydl.ydlcommon.base.BaseActivityMgr
import com.ydl.ydlcommon.ui.Loading
import com.yidianling.common.tools.ToastUtil
import de.greenrobot.event.EventBus
class JsMethod {
fun handle(param: String): Boolean {
try {
val obj = JsonParser().parse(param).asJsonObject
val cmd = obj.getAsJsonObject("cmd")
val actionName = cmd?.getAsJsonPrimitive("action_name")?.asString
if (actionName.isNullOrBlank()) return false
return innerHandle(actionName, cmd)
} catch (throwable: Throwable) {
throwable.printStackTrace()
return false
}
}
private fun innerHandle(actionName: String, obj: JsonObject): Boolean {
val param = obj.getAsJsonObject("params")
when (actionName) {
"handle_confide_btn" -> {
val show = param.getAsJsonPrimitive("show").asInt
EventBus.getDefault().post(ConfideDialogEvent(show))
return true
}
"show_loading" -> {
val topActivity = BaseActivityMgr.INST.getTopActivity()
Loading.show(topActivity)
return true
}
"close_loading" -> {
Loading.close()
return true
}
"open_app_eval_list"->{
val url = param.getAsJsonPrimitive("url").asString
val topActivity = BaseActivityMgr.INST.getTopActivity()
NewH5Activity.start(topActivity, H5Params(url, ""))
return true
}
"toast" -> {
val msg = param.getAsJsonPrimitive("msg").asString
if (!msg.isNullOrBlank()) {
ToastUtil.toastShort(msg)
}
return true
}
else -> {
return false
}
}
}
}
\ No newline at end of file
...@@ -22,6 +22,9 @@ import com.yidianling.user.UserHelper ...@@ -22,6 +22,9 @@ import com.yidianling.user.UserHelper
*/ */
class WebJavascriptHandler : IJavascriptHandler{ class WebJavascriptHandler : IJavascriptHandler{
private val js = JsMethod()
override fun getUriAppendSuffix(): String { override fun getUriAppendSuffix(): String {
return "platform_main_theme=00C9E2&platform_main_theme_light=00D4DF&platform_main_theme_bright=EAFAFC" return "platform_main_theme=00C9E2&platform_main_theme_light=00D4DF&platform_main_theme_bright=EAFAFC"
} }
...@@ -47,6 +50,7 @@ class WebJavascriptHandler : IJavascriptHandler{ ...@@ -47,6 +50,7 @@ class WebJavascriptHandler : IJavascriptHandler{
if (YDLRouterManager.router(params)) { if (YDLRouterManager.router(params)) {
return return
} }
if (js.handle(params)) return
val jsData = Gson().fromJson(params, H5JsBean::class.java) val jsData = Gson().fromJson(params, H5JsBean::class.java)
//是否登录 //是否登录
if (jsData.cmd?.action_name != null && jsData.cmd!!.action_name.equals("login")) { if (jsData.cmd?.action_name != null && jsData.cmd!!.action_name.equals("login")) {
......
...@@ -20,6 +20,8 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment ...@@ -20,6 +20,8 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.tencent.smtt.export.external.interfaces.JsResult import com.tencent.smtt.export.external.interfaces.JsResult
import com.tencent.smtt.sdk.* import com.tencent.smtt.sdk.*
import com.ydl.confide.R import com.ydl.confide.R
import com.ydl.confide.home.event.ChangeAnotherExpertEvent
import com.ydl.confide.home.event.ConfideDialogEvent
import com.ydl.confide.home.http.ConfideHomeApi import com.ydl.confide.home.http.ConfideHomeApi
import com.ydl.confide.router.PhoneCallIn import com.ydl.confide.router.PhoneCallIn
import com.ydl.utils.WebUrlParamsUtils import com.ydl.utils.WebUrlParamsUtils
...@@ -34,6 +36,7 @@ import com.ydl.ydlnet.YDLHttpUtils ...@@ -34,6 +36,7 @@ import com.ydl.ydlnet.YDLHttpUtils
import com.yidianling.common.tools.ToastUtil import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.api.service.IImService import com.yidianling.im.api.service.IImService
import com.yidianling.user.api.service.IUserService import com.yidianling.user.api.service.IUserService
import de.greenrobot.event.EventBus
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import java.util.* import java.util.*
...@@ -60,6 +63,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() { ...@@ -60,6 +63,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() {
lateinit var first_order: View lateinit var first_order: View
lateinit var confideProgress: View lateinit var confideProgress: View
lateinit var layout_change_text: View lateinit var layout_change_text: View
lateinit var layoutBottom: View
lateinit var itemView: View lateinit var itemView: View
...@@ -85,6 +89,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() { ...@@ -85,6 +89,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.AppBottomSheet) setStyle(STYLE_NORMAL, R.style.AppBottomSheet)
EventBus.getDefault().register(this)
} }
override fun onCreateView( override fun onCreateView(
...@@ -104,6 +109,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() { ...@@ -104,6 +109,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() {
onLoadDialStatus(doctorId) onLoadDialStatus(doctorId)
// + // +
wv_content = view.findViewById<ProgressWebView>(com.ydl.webview.R.id.wv_content) wv_content = view.findViewById<ProgressWebView>(com.ydl.webview.R.id.wv_content)
wv_content.progressbar.visibility = View.GONE
close_webview_Icon = view.findViewById<View>(R.id.close_webview_Icon) close_webview_Icon = view.findViewById<View>(R.id.close_webview_Icon)
text_title = view.findViewById<TextView>(R.id.text_title) text_title = view.findViewById<TextView>(R.id.text_title)
line = view.findViewById<View>(R.id.line) line = view.findViewById<View>(R.id.line)
...@@ -145,6 +151,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() { ...@@ -145,6 +151,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() {
layoutChange = itemView.findViewById<View>(R.id.layoutChange) layoutChange = itemView.findViewById<View>(R.id.layoutChange)
confideProgress = itemView.findViewById<View>(R.id.confide_progress) confideProgress = itemView.findViewById<View>(R.id.confide_progress)
layout_change_text = itemView.findViewById<View>(R.id.layout_change_text) layout_change_text = itemView.findViewById<View>(R.id.layout_change_text)
layoutBottom = itemView.findViewById<View>(R.id.layoutBottom)
tvCall = itemView.findViewById<TextView>(R.id.tvCall) tvCall = itemView.findViewById<TextView>(R.id.tvCall)
tvTime = itemView.findViewById<TextView>(R.id.tvTime) tvTime = itemView.findViewById<TextView>(R.id.tvTime)
first_order = itemView.findViewById<TextView>(R.id.first_order) first_order = itemView.findViewById<TextView>(R.id.first_order)
...@@ -239,7 +246,19 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() { ...@@ -239,7 +246,19 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() {
} }
} }
} }
fun updateChange(doctorId: String,title:String, uid: String) {
fun onEventMainThread(event: ConfideDialogEvent) {
// 第一位表示拨打按钮,第二位代表再换一位按钮
val show = event.show
layoutCall.visibility = if (show and 0x01 == 0x01) View.VISIBLE else View.GONE
layoutChange.visibility = if (show and 0x02 == 0x01) View.VISIBLE else View.GONE
}
fun onEventMainThread(event: ChangeAnotherExpertEvent) {
updateChange(event.doctorID, event.title, event.uid)
}
private fun updateChange(doctorId: String,title:String, uid: String) {
if (doctorId == "0") {//没有下一位了 if (doctorId == "0") {//没有下一位了
layoutChange.visibility = View.GONE layoutChange.visibility = View.GONE
return return
...@@ -304,13 +323,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() { ...@@ -304,13 +323,7 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() {
override fun onProgressChanged(view: WebView, newProgress: Int) { override fun onProgressChanged(view: WebView, newProgress: Int) {
if (newProgress == 100) { if (newProgress == 100) {
wv_content.progressbar.visibility = View.GONE
callJsFun(wv_content,"setUnRead(${uid?.let { getUnReadByUid(uid = it) }})") callJsFun(wv_content,"setUnRead(${uid?.let { getUnReadByUid(uid = it) }})")
} else {
if (wv_content.progressbar.visibility == View.GONE) {
wv_content.progressbar.visibility = View.VISIBLE
}
wv_content.progressbar.progress = newProgress
} }
super.onProgressChanged(view, newProgress) super.onProgressChanged(view, newProgress)
} }
...@@ -474,4 +487,10 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() { ...@@ -474,4 +487,10 @@ class ConfideBottomSheetDialogFragment : BottomSheetDialogFragment() {
} }
}, { throwable -> throwable.printStackTrace() }) }, { throwable -> throwable.printStackTrace() })
} }
override fun onDestroy() {
super.onDestroy()
wv_content.destroy()
EventBus.getDefault().unregister(this)
}
} }
\ No newline at end of file
...@@ -4,7 +4,6 @@ import android.annotation.SuppressLint ...@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.Bundle
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
...@@ -22,7 +21,6 @@ import com.ydl.confide.home.bean.ConfideHomeDataBean ...@@ -22,7 +21,6 @@ import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.bean.ConfideHomeFiterItemBean import com.ydl.confide.home.bean.ConfideHomeFiterItemBean
import com.ydl.confide.home.config.IConfideHomeConfig import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.contract.IConfideHomeContract import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.ChangeAnotherExpertEvent
import com.ydl.confide.home.event.ConfideHomeEventImpl import com.ydl.confide.home.event.ConfideHomeEventImpl
import com.ydl.confide.home.event.IConfideHomeEvent import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.listener.ConfideHomeRecycleViewListener import com.ydl.confide.home.listener.ConfideHomeRecycleViewListener
...@@ -47,7 +45,6 @@ import com.yidianling.common.tools.RxImageTool ...@@ -47,7 +45,6 @@ import com.yidianling.common.tools.RxImageTool
import com.yidianling.common.tools.ToastUtil import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.api.service.IImService import com.yidianling.im.api.service.IImService
import com.yidianling.user.api.service.IUserService import com.yidianling.user.api.service.IUserService
import de.greenrobot.event.EventBus
import kotlinx.android.synthetic.main.confide_home_activity.* import kotlinx.android.synthetic.main.confide_home_activity.*
import kotlinx.android.synthetic.main.confide_title_bar.* import kotlinx.android.synthetic.main.confide_title_bar.*
...@@ -106,7 +103,7 @@ class ConfideHomeActivity : BaseLceActivity<IConfideHomeContract.View,IConfideHo ...@@ -106,7 +103,7 @@ class ConfideHomeActivity : BaseLceActivity<IConfideHomeContract.View,IConfideHo
//是否有下一页(用于判断为你推荐条数,如果首页返回少于10条 那么就可以认为没有下一页了) 默认有下一页 //是否有下一页(用于判断为你推荐条数,如果首页返回少于10条 那么就可以认为没有下一页了) 默认有下一页
private var hasMore = true private var hasMore = true
private var dp48 = 0 private var dp48 = 0
private lateinit var bottomSheetDialogFragment:ConfideBottomSheetDialogFragment private var bottomSheetDialogFragment: ConfideBottomSheetDialogFragment? = null
init { init {
//初始化参数 //初始化参数
initParam() initParam()
...@@ -153,12 +150,6 @@ class ConfideHomeActivity : BaseLceActivity<IConfideHomeContract.View,IConfideHo ...@@ -153,12 +150,6 @@ class ConfideHomeActivity : BaseLceActivity<IConfideHomeContract.View,IConfideHo
recommendList(page + 1) recommendList(page + 1)
} }
@SuppressLint("MissingSuperCall")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
EventBus.getDefault().register(this)
}
override fun recommendList(page: Int) { override fun recommendList(page: Int) {
//需要将当前列表已存在的老师uid数组发送到后端去重,因为排序实时变化 //需要将当前列表已存在的老师uid数组发送到后端去重,因为排序实时变化
this.page = page this.page = page
...@@ -280,14 +271,12 @@ class ConfideHomeActivity : BaseLceActivity<IConfideHomeContract.View,IConfideHo ...@@ -280,14 +271,12 @@ class ConfideHomeActivity : BaseLceActivity<IConfideHomeContract.View,IConfideHo
return@setOnClickListener return@setOnClickListener
} }
bottomSheetDialogFragment=ConfideBottomSheetDialogFragment() bottomSheetDialogFragment=ConfideBottomSheetDialogFragment()
bottomSheetDialogFragment.showBottomSheetDialog(this as FragmentActivity, HttpConfig.MH5_URL + ConfideRoute.h5ConfideIntro("0"),"0",true) bottomSheetDialogFragment?.showBottomSheetDialog(this as FragmentActivity, HttpConfig.MH5_URL + ConfideRoute.h5ConfideIntro("0"),"0",true)
} }
} }
fun onEventMainThread(event: ChangeAnotherExpertEvent) {
bottomSheetDialogFragment.updateChange(event.doctorID,event.title,event.uid)
}
private fun initView() { private fun initView() {
img_back.setOnClickListener { img_back.setOnClickListener {
finish() finish()
...@@ -557,7 +546,6 @@ class ConfideHomeActivity : BaseLceActivity<IConfideHomeContract.View,IConfideHo ...@@ -557,7 +546,6 @@ class ConfideHomeActivity : BaseLceActivity<IConfideHomeContract.View,IConfideHo
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
mConfideEvent!!.destoryPlayer() mConfideEvent!!.destoryPlayer()
EventBus.getDefault().unregister(this)
} }
override fun onBackPressed() { override fun onBackPressed() {
......
package com.ydl.confide.home.event package com.ydl.confide.home.event
data class ChangeAnotherExpertEvent( data class ChangeAnotherExpertEvent(
var doctorID:String, var doctorID: String,
var title:String, var title: String,
var uid:String var uid: String
) )
\ No newline at end of file
class ConfideDialogEvent(val show: Int)
\ No newline at end of file
...@@ -31,7 +31,6 @@ import com.ydl.media.view.PlayerFloatView ...@@ -31,7 +31,6 @@ import com.ydl.media.view.PlayerFloatView
import com.ydl.ydl_router.manager.YDLRouterManager import com.ydl.ydl_router.manager.YDLRouterManager
import com.ydl.ydl_router.manager.YDLRouterParams import com.ydl.ydl_router.manager.YDLRouterParams
import com.ydl.ydlcommon.base.BaseActivity import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.modular.route import com.ydl.ydlcommon.modular.route
import com.ydl.ydlcommon.router.IYDLRouterConstant import com.ydl.ydlcommon.router.IYDLRouterConstant
import com.ydl.ydlcommon.utils.remind.ToastHelper import com.ydl.ydlcommon.utils.remind.ToastHelper
...@@ -137,7 +136,7 @@ class ConfideHomeEventImpl(context: Context, var confideHomeView: IConfideHomeCo ...@@ -137,7 +136,7 @@ class ConfideHomeEventImpl(context: Context, var confideHomeView: IConfideHomeCo
ConfideBottomSheetDialogFragment() ConfideBottomSheetDialogFragment()
.showBottomSheetDialog( .showBottomSheetDialog(
mContext as FragmentActivity, mContext as FragmentActivity,
HttpConfig.MH5_URL + ConfideRoute.h5ConfideIntro(it), /*HttpConfig.MH5_URL*/"http://192.168.210.152/" + ConfideRoute.h5ConfideIntro(it),
doctorId!! doctorId!!
) )
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layoutBottom"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/platform_dp_15" android:layout_marginStart="@dimen/platform_dp_15"
......
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