package com.adealink.weparty.commonui.widget.util

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Build
import android.view.View
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes

fun Context.getColorX(@ColorRes id: Int): Int {
    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        getColor(id)
    } else {
        resources.getColor(id)
    }
}

fun View.getColorX(@ColorRes id: Int): Int {
    return context.getColorX(id)
}

@SuppressLint("UseCompatLoadingForDrawables")
fun Context.getDrawableX(@DrawableRes id: Int): Drawable? {
    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        getDrawable(id)
    } else {
        resources.getDrawable(id)
    }
}

fun View.getDrawableX(@DrawableRes id: Int): Drawable? {
    return context.getDrawableX(id)
}