Skip to content

Commit 8125a4c

Browse files
committed
fix bug
1 parent 9dfc530 commit 8125a4c

5 files changed

Lines changed: 45 additions & 34 deletions

File tree

app/src/main/java/com/cxz/wanandroid/ext/Ext.kt

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package com.cxz.wanandroid.ext
22

33
import android.app.Activity
44
import android.content.Context
5-
import com.google.android.material.snackbar.Snackbar
6-
import androidx.fragment.app.Fragment
7-
import androidx.core.content.ContextCompat
85
import android.util.Log
96
import android.view.View
107
import android.view.ViewGroup
@@ -13,9 +10,13 @@ import android.webkit.WebView
1310
import android.webkit.WebViewClient
1411
import android.widget.Checkable
1512
import android.widget.TextView
13+
import androidx.core.content.ContextCompat
14+
import androidx.fragment.app.Fragment
15+
import com.cxz.wanandroid.BuildConfig
1616
import com.cxz.wanandroid.R
1717
import com.cxz.wanandroid.app.App
1818
import com.cxz.wanandroid.widget.CustomToast
19+
import com.google.android.material.snackbar.Snackbar
1920
import com.just.agentweb.AgentWeb
2021
import com.just.agentweb.DefaultWebClient
2122
import java.text.SimpleDateFormat
@@ -32,11 +33,17 @@ fun Any.loge(content: String?) {
3233
}
3334

3435
fun 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

3845
fun Fragment.showToast(content: String) {
39-
CustomToast(this?.activity?.applicationContext, content).show()
46+
CustomToast(this.requireContext(), content).show()
4047
}
4148

4249
fun 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
*/
8289
fun 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
* 格式化当前日期

app/src/main/java/com/cxz/wanandroid/ui/activity/ContentActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ContentActivity : BaseMvpSwipeBackActivity<ContentContract.View, ContentCo
9393

9494
val webView = NestedScrollAgentWebView(this)
9595

96-
val layoutParams = androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams(-1, -1)
96+
val layoutParams = CoordinatorLayout.LayoutParams(-1, -1)
9797
layoutParams.behavior = AppBarLayout.ScrollingViewBehavior()
9898

9999
mAgentWeb = shareUrl.getAgentWeb(

app/src/main/java/com/cxz/wanandroid/webclient/BaseWebClient.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ open class BaseWebClient : WebViewClient() {
6060
}
6161

6262
override fun shouldInterceptRequest(view: WebView?, url: String?): WebResourceResponse? {
63-
loge(TAG, "------------>>$url")
63+
loge(TAG, "shouldInterceptRequest: $url")
6464
if (shouldInterceptRequest(Uri.parse(url))) {
6565
return WebResourceResponse(null, null, null)
6666
}
@@ -78,12 +78,12 @@ open class BaseWebClient : WebViewClient() {
7878

7979
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
8080
super.onPageStarted(view, url, favicon)
81-
loge(TAG, "onPageStarted---->>$url")
81+
loge(TAG, "onPageStarted: $url")
8282
}
8383

8484
override fun onPageFinished(view: WebView?, url: String?) {
8585
super.onPageFinished(view, url)
86-
loge(TAG, "onPageFinished---->>$url")
86+
loge(TAG, "onPageFinished: $url")
8787
}
8888

8989
override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler?, error: SslError?) {

app/src/main/java/com/cxz/wanandroid/widget/WebContainer.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import com.cxz.wanandroid.utils.SettingUtil
1515
* @date 2019/11/24
1616
* @desc WebContainer
1717
*/
18-
class WebContainer constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
19-
CoordinatorLayout(context, attrs, defStyleAttr) {
18+
class WebContainer : CoordinatorLayout {
2019

2120
private var mDarkTheme: Boolean = false
2221

@@ -29,6 +28,12 @@ class WebContainer constructor(context: Context, attrs: AttributeSet? = null, de
2928
}
3029
}
3130

31+
constructor(context: Context) : super(context)
32+
33+
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
34+
35+
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
36+
3237
override fun dispatchDraw(canvas: Canvas) {
3338
super.dispatchDraw(canvas)
3439
if (mDarkTheme) {

app/src/main/res/layout/activity_content.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
android:id="@+id/cl_main"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6-
android:background="@color/viewBackground"
7-
android:orientation="vertical">
6+
android:background="@color/viewBackground">
87

98
<include layout="@layout/toolbar" />
109

0 commit comments

Comments
 (0)