@@ -2,9 +2,6 @@ package com.cxz.wanandroid.ext
22
33import android.app.Activity
44import android.content.Context
5- import com.google.android.material.snackbar.Snackbar
6- import androidx.fragment.app.Fragment
7- import androidx.core.content.ContextCompat
85import android.util.Log
96import android.view.View
107import android.view.ViewGroup
@@ -13,9 +10,13 @@ import android.webkit.WebView
1310import android.webkit.WebViewClient
1411import android.widget.Checkable
1512import android.widget.TextView
13+ import androidx.core.content.ContextCompat
14+ import androidx.fragment.app.Fragment
15+ import com.cxz.wanandroid.BuildConfig
1616import com.cxz.wanandroid.R
1717import com.cxz.wanandroid.app.App
1818import com.cxz.wanandroid.widget.CustomToast
19+ import com.google.android.material.snackbar.Snackbar
1920import com.just.agentweb.AgentWeb
2021import com.just.agentweb.DefaultWebClient
2122import java.text.SimpleDateFormat
@@ -32,11 +33,17 @@ fun Any.loge(content: String?) {
3233}
3334
3435fun loge (tag : String , content : String? ) {
35- Log .e(tag, content ? : " " )
36+ if (BuildConfig .DEBUG ) {
37+ Log .e(tag, content ? : " " )
38+ }
39+ }
40+
41+ fun showToast (content : String ) {
42+ CustomToast (App .context, content).show()
3643}
3744
3845fun Fragment.showToast (content : String ) {
39- CustomToast (this ?.activity?.applicationContext , content).show()
46+ CustomToast (this .requireContext() , content).show()
4047}
4148
4249fun Context.showToast (content : String ) {
@@ -47,7 +54,7 @@ fun Activity.showSnackMsg(msg: String) {
4754 val snackbar = Snackbar .make(this .window.decorView, msg, Snackbar .LENGTH_SHORT )
4855 val view = snackbar.view
4956 view.findViewById<TextView >(R .id.snackbar_text)
50- .setTextColor(ContextCompat .getColor(this , R .color.white))
57+ .setTextColor(ContextCompat .getColor(this , R .color.white))
5158 snackbar.show()
5259}
5360
@@ -56,7 +63,7 @@ fun Fragment.showSnackMsg(msg: String) {
5663 val snackbar = Snackbar .make(this .activity!! .window.decorView, msg, Snackbar .LENGTH_SHORT )
5764 val view = snackbar.view
5865 view.findViewById<TextView >(R .id.snackbar_text)
59- .setTextColor(ContextCompat .getColor(this .activity!! , R .color.white))
66+ .setTextColor(ContextCompat .getColor(this .activity!! , R .color.white))
6067 snackbar.show()
6168}
6269
@@ -80,26 +87,26 @@ inline fun <T : View> T.setSingleClickListener(time: Long = 1000, crossinline bl
8087 * getAgentWeb
8188 */
8289fun String.getAgentWeb (
83- activity : Activity ,
84- webContent : ViewGroup ,
85- layoutParams : ViewGroup .LayoutParams ,
86- webView : WebView ,
87- webViewClient : WebViewClient ? ,
88- webChromeClient : WebChromeClient ? ,
89- indicatorColor : Int
90+ activity : Activity ,
91+ webContent : ViewGroup ,
92+ layoutParams : ViewGroup .LayoutParams ,
93+ webView : WebView ,
94+ webViewClient : WebViewClient ? ,
95+ webChromeClient : WebChromeClient ? ,
96+ indicatorColor : Int
9097): AgentWeb = AgentWeb .with (activity)// 传入Activity or Fragment
91- .setAgentWebParent(webContent, 1 , layoutParams)// 传入AgentWeb 的父控件
92- .useDefaultIndicator(indicatorColor, 2 )// 使用默认进度条
93- .setWebView(webView)
94- .setWebViewClient(webViewClient)
95- .setWebChromeClient(webChromeClient)
96- .setMainFrameErrorView(R .layout.agentweb_error_page, - 1 )
97- .setSecurityType(AgentWeb .SecurityType .STRICT_CHECK )
98- .setOpenOtherPageWays(DefaultWebClient .OpenOtherPageWays .ASK )// 打开其他应用时,弹窗咨询用户是否前往其他应用
99- .interceptUnkownUrl()
100- .createAgentWeb()//
101- .ready()
102- .go(this )
98+ .setAgentWebParent(webContent, 1 , layoutParams)// 传入AgentWeb 的父控件
99+ .useDefaultIndicator(indicatorColor, 2 )// 使用默认进度条
100+ .setWebView(webView)
101+ .setWebViewClient(webViewClient)
102+ .setWebChromeClient(webChromeClient)
103+ .setMainFrameErrorView(R .layout.agentweb_error_page, - 1 )
104+ .setSecurityType(AgentWeb .SecurityType .STRICT_CHECK )
105+ .setOpenOtherPageWays(DefaultWebClient .OpenOtherPageWays .ASK )// 打开其他应用时,弹窗咨询用户是否前往其他应用
106+ .interceptUnkownUrl()
107+ .createAgentWeb()//
108+ .ready()
109+ .go(this )
103110
104111/* *
105112 * 格式化当前日期
0 commit comments