Improve grades dialog layout (#631)

This commit is contained in:
Dominik Korsa
2020-01-20 21:29:06 +01:00
committed by Rafał Borcz
parent 77e7e4e6e9
commit c5cadbd004
6 changed files with 84 additions and 79 deletions

View File

@ -10,6 +10,7 @@ import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Grade
import io.github.wulkanowy.utils.colorStringId
import io.github.wulkanowy.utils.getBackgroundColor
import io.github.wulkanowy.utils.getGradeColor
import io.github.wulkanowy.utils.toFormattedString
import kotlinx.android.synthetic.main.dialog_grade.*
@ -50,7 +51,12 @@ class GradeDetailsDialog : DialogFragment() {
super.onActivityCreated(savedInstanceState)
gradeDialogSubject.text = grade.subject
gradeDialogWeightValue.text = grade.weight
gradeDialogColorAndWeightValue.run {
text = context.getString(R.string.grade_weight_value, grade.weight)
setBackgroundResource(grade.getGradeColor())
}
gradeDialogDateValue.text = grade.date.toFormattedString()
gradeDialogColorValue.text = getString(grade.colorStringId)

View File

@ -24,14 +24,7 @@ fun List<GradeSummary>.calcAverage(): Double {
fun Grade.getBackgroundColor(theme: String): Int {
return when (theme) {
"grade_color" -> when (color) {
"000000" -> R.color.grade_black
"F04C4C" -> R.color.grade_red
"20A4F7" -> R.color.grade_blue
"6ECD07" -> R.color.grade_green
"B16CF1" -> R.color.grade_purple
else -> R.color.grade_material_default
}
"grade_color" -> getGradeColor()
"material" -> when (value.toInt()) {
6 -> R.color.grade_material_six
5 -> R.color.grade_material_five
@ -53,6 +46,17 @@ fun Grade.getBackgroundColor(theme: String): Int {
}
}
fun Grade.getGradeColor(): Int {
return when (color) {
"000000" -> R.color.grade_black
"F04C4C" -> R.color.grade_red
"20A4F7" -> R.color.grade_blue
"6ECD07" -> R.color.grade_green
"B16CF1" -> R.color.grade_purple
else -> R.color.grade_material_default
}
}
inline val Grade.colorStringId: Int
get() {
return when (color) {