package com.adealink.weparty.commonui.widget.floatview.mode.fix

import android.app.Activity
import com.adealink.frame.log.Log
import com.adealink.weparty.commonui.ext.contentView
import com.adealink.weparty.commonui.ext.safeAction
import com.adealink.weparty.commonui.widget.floatview.data.TAG_FLOAT_VIEW
import com.adealink.weparty.commonui.widget.floatview.mode.ApplicationModeWindowManager

/**
 * 问题机型: Android14 + 摩托罗拉手机
 * 问题现象: A页面跳转B页面, 跳转期间操作Window(示意流程如下),页面会卡住, A的onStop回调会延时2-4s才显示B页面
 *         A(onPause) 操作WindowManager.removeView
 *           |
 *         B(onCreate,onResume) 操作WindowManager.addView
 *           |
 *          ...(延时4s)
 *           |
 *         A(onStop) 此时B才恢复卡顿,页面展示

 * 解决办法: 待B.contentView渲染之后再执行操作WindowManager.adView
 */
class Android14ModeWindowManager : ApplicationModeWindowManager() {

    companion object {
        private const val SUB_TAG = "Application14ModeWindowManager"
    }

    override fun onResume(activity: Activity) {
        activity.contentView()?.safeAction {
            Log.d(
                TAG_FLOAT_VIEW,
                "${SUB_TAG}, onResume, addView: currentWindowManager: ${activity.windowManager}"
            )
            doOnResume(activity)
        }
    }

    override fun onPause(activity: Activity) {
        activity.contentView()?.safeAction {
            Log.d(
                TAG_FLOAT_VIEW,
                "${SUB_TAG}, onPause, removeView: currentWindowManager: ${activity.windowManager}"
            )
            doOnPause(activity)
        }
    }

}