package cn.flightfeather.thirdappmodule.module.base
|
|
import android.graphics.drawable.Drawable
|
import android.support.v7.widget.Toolbar
|
import android.view.View
|
import android.widget.ImageView
|
import android.widget.TextView
|
|
/**
|
* @author riku
|
* Date: 2019/5/8
|
* toolbar设置接口
|
*/
|
interface ToolbarSetInterface {
|
fun initToolbar() {
|
if (toolbarEnabled()) {
|
//设置用户头像点击事件
|
getHeadIcon().setOnClickListener {
|
onHeadIconClick()
|
}
|
//左侧按钮
|
getHeadIconRes()?.let {
|
val icon = getHeadIcon()
|
if (icon is ImageView) {
|
icon.setImageDrawable(it)
|
}
|
}
|
//toolbar标题文字
|
getMyTitleTextView()?.apply {
|
getTitleText()?.let {
|
text = it
|
visibility = if (getTitleEnabled()) View.VISIBLE else View.INVISIBLE
|
}
|
}
|
//右侧菜单按钮
|
val menuList = getMenus() ?: emptyList()
|
val visibilities = getMenuVisibility()
|
val resources = getMenuRes()
|
val listeners = getMenuClickListener()
|
for (index in menuList.indices) {
|
menuList[index].apply {
|
visibility = if (index < visibilities.size) visibilities[index]
|
?: View.GONE else View.GONE
|
if (this is ImageView) {
|
setImageDrawable(if (index < resources.size) resources[index] else null)
|
}
|
setOnClickListener(if (index < listeners.size) listeners[index] else null)
|
}
|
}
|
}
|
}
|
fun getToolBar(): Toolbar
|
|
fun toolbarEnabled(): Boolean
|
|
//toolbar左侧图标
|
fun getHeadIcon(): View
|
//toolbar左侧图标点击事件
|
fun onHeadIconClick()
|
//左侧按钮的图片资源
|
fun getHeadIconRes(): Drawable? = null
|
|
//toolbar居中标题
|
fun getMyTitleTextView(): TextView?
|
//是否展示标题栏中间标题
|
fun getTitleEnabled(): Boolean
|
//标题内容
|
fun getTitleText(): String?
|
|
|
//toolbar 右侧菜单
|
fun getMenus():List<View>?
|
//三个菜单按钮的可见性
|
fun getMenuVisibility(): List<Int?>
|
//三个菜单按钮的图片资源
|
fun getMenuRes(): List<Drawable?>
|
//三个菜单按钮的文本
|
fun getMenuText(): List<String?> = emptyList()
|
//三个菜单按钮的点击事件
|
fun getMenuClickListener(): List<View.OnClickListener?>
|
}
|