Skip to content

Commit

Permalink
支持自定义不显示title bar
Browse files Browse the repository at this point in the history
  • Loading branch information
sovegetables committed Jan 13, 2021
1 parent 17e08f5 commit 321d2f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
39 changes: 22 additions & 17 deletions agronweb/src/main/java/cn/sovegetables/web/CommonWebActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ open class CommonWebActivity : BaseActivity() {
webConfig = getWebConfig(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_common_web)

val updater : TopBarItemUpdater = topBarAction.leftItemUpdater()
if(webConfig.withCloseIconAndClosePage){
updater.iconRes(R.drawable.ic_agron_web_close_black)
}else{
updater.iconRes(R.drawable.ic_delegate_arrow_back)
}
if(!webConfig.enableAutoTitle && !TextUtils.isEmpty(webConfig.title)){
if(webConfig.isCenterTitle){
topBarAction.topBarUpdater.title(webConfig.title)
.update()
if(webConfig.enable){
val updater : TopBarItemUpdater = topBarAction.leftItemUpdater()
if(webConfig.withCloseIconAndClosePage){
updater.iconRes(R.drawable.ic_agron_web_close_black)
}else{
updater.text(webConfig.title)
updater.iconRes(R.drawable.ic_delegate_arrow_back)
}
if(!webConfig.enableAutoTitle && !TextUtils.isEmpty(webConfig.title)){
if(webConfig.isCenterTitle){
topBarAction.topBarUpdater.title(webConfig.title)
.update()
}else{
updater.text(webConfig.title)
}
}
updater.update()
}
updater.update()

val url = webConfig.url
val downloadListener = sModule.downloadListenerModule()
downloadListener?.attachWeb(web, this)
Expand All @@ -111,6 +111,9 @@ open class CommonWebActivity : BaseActivity() {
web.addWebChromeClient(videoFullScreenHandler)
web.addWebChromeClient(object : WebChromeClientAdapter(){
override fun onReceivedTitle(view: WebView?, title: String?) {
if(!webConfig.enable){
return
}
if(webConfig.enableAutoTitle){
if(webConfig.isCenterTitle){
topBarAction.topBarUpdater.title(title)
Expand All @@ -130,9 +133,11 @@ open class CommonWebActivity : BaseActivity() {

val pageListener = object : IWebModule.WebProgressViewModuleAdapter(){
override fun onPageFinished(view: WebView?, url: String?) {
topBarAction.findRightItemUpdaterById(SHARE_TOP_ITEM_ID)
.visibility(View.VISIBLE)
.update()
if(webConfig.enable){
topBarAction.findRightItemUpdaterById(SHARE_TOP_ITEM_ID)
.visibility(View.VISIBLE)
.update()
}
}
}
web.addWebChromeClient(WebChromeClientCompat(pageListener))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/cn/sovegetables/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MainActivity : AppCompatActivity() {

et_input.setText("http://134.175.132.191:18085")
btn_go.setOnClickListener {
CommonWebActivity.start(this, WebConfig(url = et_input.text.toString(), statusColorInt = Color.BLUE,
CommonWebActivity.start(this, WebConfig(url = et_input.text.toString(), statusColorInt = Color.BLUE, enable = false,
shareType = WebConfig.TYPE_SHARE_DEFAULT,
enableAutoTitle = true,
withCloseIconAndClosePage = false) )
Expand Down

0 comments on commit 321d2f1

Please sign in to comment.