package com.quyunshuo.androidbaseframemvvm.common.util

import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import com.quyunshuo.androidbaseframemvvm.base.BaseApplication

object UiUtil {
    fun getStringRes(id: Int): String {
        return BaseApplication.context.getResources().getString(id)
    }

    fun getColorRes(id: Int): Int {
        return ContextCompat.getColor(BaseApplication.context, id)
    }

    fun getStringArrayRes(id: Int): Array<String> {
        return BaseApplication.context.getResources().getStringArray(id)
    }

    fun getDrawableRes(id: Int): Drawable {
        return BaseApplication.context.getResources().getDrawable(id)
    }

    fun getDimensionRes(id: Int): Float {
        return BaseApplication.context.getResources().getDimension(id)
    }

    fun getDimensionPixelRes(id: Int): Int {
        return BaseApplication.context.getResources().getDimensionPixelOffset(id)
    }


    fun getResId(variableName: String?, c: Class<*>): Int {
        try {
            val idField = c.getDeclaredField(variableName)
            return idField.getInt(idField)
        } catch (e: Exception) {
            e.printStackTrace()
            return -1
        }
    }
}