/**
 * Kotlin扩展属性和扩展函数
 */
package com.common.commonlib.utils

import android.app.Activity
import android.content.res.Resources
import android.util.TypedValue
import android.view.View

/**
 * Kt扩展属性，判断Activity是否存活
 */
val Activity?.isAlive: Boolean
    get() = !(this?.isDestroyed ?: true || this?.isFinishing ?: true)

/**
 * Boolean转Visibility
 */
fun Boolean.toVisibility() = if (this) View.VISIBLE else View.GONE

/**
 * Float dp2px
 */
val Float.dp: Float
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP,
        this,
        Resources.getSystem().displayMetrics
    )

/**
 * Int dp2px
 */
val Int.dp: Float
    get() = this.toFloat().dp

