Commit eb8a5a47 by 霍志良

Merge branch 'feat/zl/confide2' into 'd/v_confide_2.0'

bottomsheet修改为bottomSheetFragment

See merge request app_android_lib/YDL-Component!15
parents 0a18c2f5 6e6fe841
package com.ydl.confide.home
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.os.Bundle
import android.view.*
import android.widget.FrameLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.tencent.smtt.sdk.WebSettings
import com.ydl.confide.R
import com.ydl.webview.ProgressWebView
import com.ydl.webview.TellData
import com.ydl.webview.WebModularServiceUtils
import com.ydl.ydlcommon.base.BaseActivity
import com.yidianling.common.tools.RxImageTool
class ConfideBottomSheetDialogFragment:BottomSheetDialogFragment() {
lateinit var activity:BaseActivity;
lateinit var wv_content:ProgressWebView;
lateinit var text_title:View;
lateinit var line:View;
lateinit var rl_title:View;
lateinit var close_webview_Icon:View
lateinit var jumpUrl:String
fun showBottomSheetDialog(activity: BaseActivity,jumpUrl:String) {
this.activity=activity
this.jumpUrl=jumpUrl
show(activity.supportFragmentManager, "confide_bottom_showdialog")
}
@SuppressLint("WrongConstant")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL,R.style.AppBottomSheet)
}
override fun onStart() {
super.onStart()
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.confide_webview, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
wv_content = view.findViewById<ProgressWebView>(com.ydl.webview.R.id.wv_content)
close_webview_Icon = view.findViewById<View>(R.id.close_webview_Icon)
text_title = view.findViewById<View>(R.id.text_title)
line = view.findViewById<View>(R.id.line)
rl_title = view.findViewById<View>(R.id.rl_title)
close_webview_Icon?.setOnClickListener {
this.dismiss()
}
webViewInit(wv_content)
}
override fun setCancelable(cancelable: Boolean) {
val dialog = dialog
val touchOutsideView =
dialog?.window?.decorView?.findViewById<View>(com.google.android.material.R.id.touch_outside)
val bottomSheetView =
dialog?.window?.decorView?.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
if (cancelable) {
touchOutsideView?.setOnClickListener(View.OnClickListener {
if (dialog.isShowing) {
dialog.cancel()
}
})
BottomSheetBehavior.from<View>(bottomSheetView!!).setHideable(true)
} else {
touchOutsideView?.setOnClickListener(null)
// if false 按返回键也无法取消
// dialog.setCancelable(false)
BottomSheetBehavior.from<View>(bottomSheetView!!).setHideable(false)
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
dialog.setOnShowListener {
val itemView = LayoutInflater.from(activity).inflate(R.layout.confide_bottom_two,null,false)
val layoutCall=itemView.findViewById<View>(R.id.layoutCall)
val layoutChange=itemView.findViewById<View>(R.id.layoutChange)
val layout_change_text=itemView.findViewById<View>(R.id.layout_change_text)
val confide_progress=itemView.findViewById<View>(R.id.confide_progress)
layoutCall.setOnClickListener {
callJsFun(wv_content,"layoutCall()")
}
layoutChange.setOnClickListener {
layout_change_text.visibility=View.GONE
confide_progress.visibility=View.VISIBLE
callJsFun(wv_content,"layoutCall()")
}
val layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT
).apply { gravity= Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL }
dialog?.window?.addContentView(itemView,layoutParams)
val bottomSheet = (it as BottomSheetDialog).findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout?
val behavior = BottomSheetBehavior.from(bottomSheet!!)
behavior.peekHeight=RxImageTool.dp2px(600f)
//true是跳过peekHeight,直接滑下去,false是可以滑动到顶部还可以保持peekHeight在滑下去
// behavior?.skipCollapsed=true
behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
when (newState) {
3 -> {
rl_title.visibility=View.VISIBLE
close_webview_Icon.visibility=View.VISIBLE
text_title.visibility=View.VISIBLE
line.visibility=View.GONE
}
1 -> {
rl_title.visibility=View.VISIBLE
close_webview_Icon.visibility=View.GONE
text_title.visibility=View.GONE
line.visibility=View.VISIBLE
}
4 -> {
rl_title.visibility=View.VISIBLE
line.visibility=View.VISIBLE
}
}
}
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
})
}
return dialog
}
private fun callJsFun(wv_content: ProgressWebView,funcName:String) {
val sb = StringBuffer("javascript:")
sb.append(funcName)
wv_content.post {
try {
wv_content.loadUrl(sb.toString())
} catch (e: Exception) {
e.printStackTrace()
}
}
}
@SuppressLint("ClickableViewAccessibility")
private fun webViewInit(wv_content: ProgressWebView) {
val setting: WebSettings = wv_content?.settings!!
//支持js
//支持js
setting.setJavaScriptEnabled(true)
//设置字符编码
//设置字符编码
setting.setDefaultTextEncodingName("GBK")
setting.setDomStorageEnabled(true)
val appCachePath: String = activity?.getCacheDir()?.getAbsolutePath().toString()
setting.setAppCachePath(appCachePath)
setting.setAllowFileAccessFromFileURLs(true)
setting.setAppCacheEnabled(true)
setting.setAllowFileAccess(true)
// 解决图片不显示
// 解决图片不显示
setting.setBlockNetworkImage(false)
wv_content!!.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY //滚动条风格,为0指滚动条不占用空间,直接覆盖在网页上
var jtoJHandle = WebModularServiceUtils.getWebService()
.getJavascripHandler(activity as Activity, tellData = TellData())
wv_content!!.addJavascriptInterface(jtoJHandle, "javascriptHandler")
wv_content.loadUrl("https://m.ydl.com/jy/experts/23035?v=4.0.99&uid=9404770&ts=1652787528&toConfide=1&" +
"platform_main_theme_light=00D4DF&platform_main_theme_bright=EAFAFC&platform_main_theme=00C9E2&isFromApp=1&" +
"id=1927&ffrom=android_zhuzhan&barHeight=81&accessToken=87cba5b57f9bb196856ade3522805c11MjIwMw&sign=" +
"6ce496690d7d5a184935f986c3631cc2")
// wv_content.loadUrl(jumpUrl)
wv_content.setOnTouchListener { p0, p1 -> //canScrollVertically(-1)的值表示是否能向下滚动,false表示已经滚动到顶部
if (!wv_content.canScrollVertically(-1)) {
wv_content.requestDisallowInterceptTouchEvent(false);
} else {
wv_content.requestDisallowInterceptTouchEvent(true);
}
false;
}
}
}
\ No newline at end of file
...@@ -19,6 +19,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog ...@@ -19,6 +19,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tencent.smtt.sdk.WebSettings import com.tencent.smtt.sdk.WebSettings
import com.ydl.confide.R import com.ydl.confide.R
import com.ydl.confide.api.ConfideRoute import com.ydl.confide.api.ConfideRoute
import com.ydl.confide.home.ConfideBottomSheetDialogFragment
import com.ydl.confide.home.ConfideHomeActivity import com.ydl.confide.home.ConfideHomeActivity
import com.ydl.confide.home.adapter.ConfideHomeAdapter import com.ydl.confide.home.adapter.ConfideHomeAdapter
import com.ydl.confide.home.bean.ConfideHomeAllFiltersBean import com.ydl.confide.home.bean.ConfideHomeAllFiltersBean
...@@ -144,112 +145,12 @@ class ConfideHomeEventImpl(context: Context, var confideHomeView: IConfideHomeCo ...@@ -144,112 +145,12 @@ class ConfideHomeEventImpl(context: Context, var confideHomeView: IConfideHomeCo
*/ */
@SuppressLint("JavascriptInterface", "ClickableViewAccessibility") @SuppressLint("JavascriptInterface", "ClickableViewAccessibility")
override fun consultantClick(linkUrl: String?) { override fun consultantClick(linkUrl: String?) {
val bottomSheetDialog= mContext?.let { BottomSheetDialog(it,R.style.CustomShapeAppearanceBottomSheetDialog) } ConfideBottomSheetDialogFragment()
val bottomView = LayoutInflater.from(mContext).inflate(R.layout.confide_webview,FrameLayout(mContext),false) .showBottomSheetDialog(mContext as BaseActivity,linkUrl!!)
bottomSheetDialog?.setContentView(bottomView)
bottomSheetDialog?.show()
var wv_content = bottomSheetDialog?.findViewById<ProgressWebView>(com.ydl.webview.R.id.wv_content)
var close_webview_Icon = bottomSheetDialog?.findViewById<View>(R.id.close_webview_Icon)
var text_title = bottomSheetDialog?.findViewById<View>(R.id.text_title)
var line = bottomSheetDialog?.findViewById<View>(R.id.line)
var rl_title = bottomSheetDialog?.findViewById<View>(R.id.rl_title)
close_webview_Icon?.setOnClickListener {
bottomSheetDialog?.hide()
}
val setting: WebSettings = wv_content?.settings!!
//支持js
//支持js
setting.setJavaScriptEnabled(true)
//设置字符编码
//设置字符编码
setting.setDefaultTextEncodingName("GBK")
setting.setDomStorageEnabled(true)
val appCachePath: String = mContext?.getCacheDir()?.getAbsolutePath().toString()
setting.setAppCachePath(appCachePath)
setting.setAllowFileAccessFromFileURLs(true)
setting.setAppCacheEnabled(true)
setting.setAllowFileAccess(true)
// 解决图片不显示
// 解决图片不显示
setting.setBlockNetworkImage(false)
wv_content!!.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY //滚动条风格,为0指滚动条不占用空间,直接覆盖在网页上
var jtoJHandle = getWebService().getJavascripHandler(mContext as Activity,tellData = TellData())
wv_content!!.addJavascriptInterface(jtoJHandle, "javascriptHandler")
bottomSheetDialog?.behavior?.peekHeight=1500
bottomSheetDialog?.behavior?.addBottomSheetCallback(object :BottomSheetBehavior.BottomSheetCallback(){
override fun onStateChanged(p0: View, p1: Int) {
LogUtil.e("aaaa"+p1)
if (p1==3){
rl_title?.visibility=View.VISIBLE
close_webview_Icon?.visibility=View.VISIBLE
text_title?.visibility=View.VISIBLE
line?.visibility=View.GONE
}else if (p1==1){
rl_title?.visibility=View.VISIBLE
close_webview_Icon?.visibility=View.GONE
text_title?.visibility=View.GONE
line?.visibility=View.VISIBLE
}else if (p1==4){
rl_title?.visibility=View.VISIBLE
line?.visibility=View.VISIBLE
}
}
override fun onSlide(p0: View, p1: Float) {
}
})
val itemView = LayoutInflater.from(mContext).inflate(R.layout.confide_bottom_two,null,false)
val layoutCall=itemView.findViewById<View>(R.id.layoutCall)
val layoutChange=itemView.findViewById<View>(R.id.layoutChange)
val layout_change_text=itemView.findViewById<View>(R.id.layout_change_text)
val confide_progress=itemView.findViewById<View>(R.id.confide_progress)
layoutCall.setOnClickListener {
callJsFun(wv_content,"layoutCall()")
}
layoutChange.setOnClickListener {
layout_change_text.visibility=View.GONE
confide_progress.visibility=View.VISIBLE
callJsFun(wv_content,"layoutCall()")
}
val layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT
).apply { gravity=Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL }
bottomSheetDialog?.window?.addContentView(itemView,layoutParams)
//true是跳过peekHeight,直接滑下去,false是可以滑动到顶部还可以保持peekHeight在滑下去
// bottomSheetDialog?.behavior?.skipCollapsed=true
wv_content.loadUrl("https://m.ydl.com/jy/experts/23035?v=4.0.99&uid=9404770&ts=1652787528&toConfide=1&" +
"platform_main_theme_light=00D4DF&platform_main_theme_bright=EAFAFC&platform_main_theme=00C9E2&isFromApp=1&" +
"id=1927&ffrom=android_zhuzhan&barHeight=81&accessToken=87cba5b57f9bb196856ade3522805c11MjIwMw&sign=" +
"6ce496690d7d5a184935f986c3631cc2")
wv_content.setOnTouchListener(object :View.OnTouchListener{
override fun onTouch(p0: View?, p1: MotionEvent?): Boolean {
//canScrollVertically(-1)的值表示是否能向下滚动,false表示已经滚动到顶部
if (!wv_content.canScrollVertically(-1)) {
wv_content.requestDisallowInterceptTouchEvent(false);
}else{
wv_content.requestDisallowInterceptTouchEvent(true);
}
return false;
}
})
// link(linkUrl) // link(linkUrl)
} }
private fun callJsFun(wv_content: ProgressWebView,funcName:String) {
val sb = StringBuffer("javascript:")
sb.append(funcName)
wv_content.post {
try {
wv_content.loadUrl(sb.toString())
} catch (e: Exception) {
e.printStackTrace()
}
}
}
override fun videoShowClick(index: Int, data: List<ConfideHomeBodyBean>?) { override fun videoShowClick(index: Int, data: List<ConfideHomeBodyBean>?) {
val dataJson = if (data != null) JSON.toJSONString(data) else null val dataJson = if (data != null) JSON.toJSONString(data) else null
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
<corners android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
</selector>
\ No newline at end of file
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
<item name="colorPrimaryDark">@color/platform_main_theme</item> <item name="colorPrimaryDark">@color/platform_main_theme</item>
<item name="colorAccent">@color/platform_main_theme</item> <item name="colorAccent">@color/platform_main_theme</item>
</style> </style>
<style name="confide_dialog" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<!-- Customize your theme here. -->
</style>
<style name="CustomShapeAppearanceBottomSheetDialog" parent="Theme.MaterialComponents.Light.BottomSheetDialog"> <style name="CustomShapeAppearanceBottomSheetDialog" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="cornerFamily">rounded</item> <item name="cornerFamily">rounded</item>
<item name="cornerSizeTopRight">16dp</item> <item name="cornerSizeTopRight">16dp</item>
...@@ -18,6 +20,11 @@ ...@@ -18,6 +20,11 @@
<item name="cornerSizeBottomRight">0dp</item> <item name="cornerSizeBottomRight">0dp</item>
<item name="cornerSizeBottomLeft">0dp</item> <item name="cornerSizeBottomLeft">0dp</item>
<item name="background">@color/transparent</item> <item name="background">@color/transparent</item>
</style>
<style name="AppBottomSheet" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/AppBottomSheetStyle</item>
</style>
<style name="AppBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/confide_bottom_webview</item>
</style> </style>
</resources> </resources>
\ No newline at end of file
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