build.gradle
api "org.jetbrains.kotlin:kotlin-reflect:1.6.10"
//https://github.com/stfalcon-studio/ChatKit
//image-picker:https://github.com/zhihu/Matisse
//api 'pub.devrel:easypermissions:3.0.0'
public class Colors {
public String primary = "";
public String warning = "";
public String error = "";
public String grey = "";
public String white = "";
public String black = "";
}
class KotlinReflection {
companion object {
private var mKotlinReflection: KotlinReflection? = null
fun getInstance(): KotlinReflection {
if (mKotlinReflection == null) {
synchronized(KotlinReflection::class.java) {
if (mKotlinReflection == null) {
mKotlinReflection = KotlinReflection()
}
}
}
return mKotlinReflection!!
}
}
/**
* Find color name of given style.
*
* linkText -> tertiary
*/
fun findColorName(style: String, colors: Colors?): Any? {
colors?.let { _colors ->
val gColors = gColorSet(colors)
val colorField = gColors[style]
colorField?.let {
val field = it as? KProperty1<Any, *>
return field?.get(_colors)
}
}
return null
}
/**
* Store the theme's global Colors in a HashMap for quick lookups
*/
private val gColorSet = HashMap<String, KProperty1<out Colors, *>>()
private fun gColorSet(colors: ChatColors?): HashMap<String, KProperty1<out Colors, *>> {
if (gColorSet.isEmpty()) {
colors?.let {
val colorFields = it::class.memberProperties
colorFields.forEach {
gColorSet.set(it.name, it)
}
}
}
return gColorSet
}
}