package core.util

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.text.Html
import android.text.Spanned

fun String.fromHtml(): Spanned {
    return if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
        Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY)
    } else {
        Html.fromHtml(this)
    }
}

fun CharSequence?.ifNullOrEmpty(defaultValue: CharSequence = ""): CharSequence {
    return if (isNullOrEmpty()) defaultValue else this
}

fun Context.isPkgInstalled(packageName: String?): Boolean {
    if (packageName.isNullOrEmpty()) return false

    return try {
        null != packageManager.getPackageInfo(packageName, 0)
    } catch (e: PackageManager.NameNotFoundException) {
        false
    }
}