完成弹窗互斥

This commit is contained in:
董宏宇
2021-08-20 17:07:14 +08:00
parent 0dabf6b433
commit 2e1d8122cb
2 changed files with 20 additions and 11 deletions

View File

@@ -38,7 +38,7 @@ class WarningFloat {
*/
class Builder(private val activity: Context) {
// 创建浮窗数据类,方便管理配置
private val config = WarningNotificationConfig()
val config = WarningNotificationConfig()
/**
* 设置浮窗的吸附模式
@@ -138,12 +138,14 @@ class WarningFloat {
/**
* 创建浮窗包括Activity浮窗和系统浮窗如若系统浮窗无权限先进行权限申请
*/
fun show() = when {
// 未设置浮窗布局文件/布局视图,不予创建
config.layoutId == null && config.layoutView == null ->
Logger.e(TAG, "需要传入 layoutId 或 layoutView ")
// 申请浮窗权限
else -> WarningFloatWindowManager.create(activity, config)
fun show() = apply {
when {
// 未设置浮窗布局文件/布局视图,不予创建
config.layoutId == null && config.layoutView == null ->
Logger.e(TAG, "需要传入 layoutId 或 layoutView ")
// 申请浮窗权限
else -> WarningFloatWindowManager.create(activity, config)
}
}
}

View File

@@ -24,6 +24,8 @@ import kotlinx.android.synthetic.main.fragment_warning.*
class MoGoWarningFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>(),
MoGoWarningContract.View {
var mWarningFloat: WarningFloat.Builder? = null
override fun initViews() {}
override fun getLayoutId(): Int {
@@ -60,12 +62,11 @@ class MoGoWarningFragment : MvpFragment<MoGoWarningContract.View?, WaringPresent
)
)
if (!TextUtils.isEmpty(ttsContent)) {
AIAssist.getInstance(activity)
.speakTTSVoice(ttsContent)
if (mWarningFloat != null) {
WarningFloat.dismiss(mWarningFloat!!.config.floatTag, true)
}
WarningFloat.with(it)
mWarningFloat = WarningFloat.with(it)
.setTag(tag)
.setLayout(notificationView)
.setSidePattern(SidePattern.TOP)
@@ -92,6 +93,12 @@ class MoGoWarningFragment : MvpFragment<MoGoWarningContract.View?, WaringPresent
})
.show()
// 创建弹窗成功才进行TTS播报
if (mWarningFloat != null && !TextUtils.isEmpty(ttsContent)) {
AIAssist.getInstance(activity)
.speakTTSVoice(ttsContent)
}
}
}