Skip to content
Snippets Groups Projects
Commit cb56e38d authored by Dani Mahardhika's avatar Dani Mahardhika
Browse files

Automatically set issue label title color based on background color

parent 58ee51ad
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,6 +3,7 @@ package com.commit451.gitlab.extension
import android.graphics.Color
import android.support.annotation.ColorInt
import com.commit451.gitlab.model.api.Label
import com.commit451.gitlab.util.ColorUtil
 
@ColorInt
fun Label.getColor(): Int {
Loading
Loading
@@ -11,5 +12,9 @@ fun Label.getColor(): Int {
} catch (e: Exception) {
return Color.TRANSPARENT
}
}
 
@ColorInt
fun Label.getTitleColor(): Int {
return ColorUtil.getTitleColor(getColor())
}
\ No newline at end of file
package com.commit451.gitlab.util
 
import android.graphics.Color
import android.support.annotation.ColorInt
 
/**
Loading
Loading
@@ -10,4 +11,18 @@ object ColorUtil {
fun convertColorIntToString(@ColorInt color: Int): String {
return String.format("#%06X", 0xFFFFFF and color)
}
fun getTitleColor(@ColorInt color: Int): Int {
val darkness = 1.0 - (0.299 * Color.red(color).toDouble() +
0.587 * Color.green(color).toDouble() +
0.114 * Color.blue(color).toDouble()) / 255.0
if (darkness < 0.35) {
val hsv = FloatArray(3)
Color.colorToHSV(color, hsv)
hsv[2] *= 0.25f
return Color.HSVToColor(hsv)
}
return Color.WHITE;
}
}
package com.commit451.gitlab.viewHolder
 
import android.graphics.Color
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
Loading
Loading
@@ -9,6 +10,7 @@ import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.R
import com.commit451.gitlab.extension.getColor
import com.commit451.gitlab.extension.getTitleColor
import com.commit451.gitlab.model.api.Label
 
/**
Loading
Loading
@@ -33,6 +35,7 @@ class AddLabelViewHolder(view: View) : RecyclerView.ViewHolder(view) {
 
fun bind(label: Label) {
textTitle.text = label.name
textTitle.setTextColor(label.getTitleColor())
textTitle.setBackgroundColor(label.getColor())
}
}
\ No newline at end of file
Loading
Loading
@@ -9,6 +9,7 @@ import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.R
import com.commit451.gitlab.extension.getColor
import com.commit451.gitlab.extension.getTitleColor
import com.commit451.gitlab.model.api.Label
 
/**
Loading
Loading
@@ -34,6 +35,7 @@ class LabelViewHolder(view: View) : RecyclerView.ViewHolder(view) {
 
fun bind(label: Label) {
textTitle.text = label.name
textTitle.setTextColor(label.getTitleColor())
viewColor.setBackgroundColor(label.getColor())
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment