Skip to content

Commit

Permalink
Use when instead of if
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Oct 28, 2023
1 parent 9c7c39d commit e8f947f
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ object InstanceListItemView {

val pill = view.findViewById<MaterialPill>(R.id.chip)
if (pill != null) {
if (instance.status == Instance.STATUS_INVALID || instance.status == Instance.STATUS_INCOMPLETE) {
pill.visibility = View.VISIBLE
pill.setIcon(R.drawable.baseline_rule_24)
pill.setText(string.draft_errors)
pill.setPillBackgroundColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorErrorContainer))
pill.setTextColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnErrorContainer))
pill.setIconTint(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnErrorContainer))
} else if (instance.status == Instance.STATUS_VALID) {
pill.visibility = View.VISIBLE
pill.setIcon(R.drawable.baseline_check_24)
pill.setText(string.draft_no_errors)
pill.setPillBackgroundColor(getThemeAttributeValue(context, R.attr.colorSurfaceContainerHighest))
pill.setTextColor(getThemeAttributeValue(context, R.attr.colorOnSurfaceContainerHighest))
pill.setIconTint(getThemeAttributeValue(context, R.attr.colorOnSurfaceContainerHighest))
} else {
pill.visibility = View.GONE
when (instance.status) {
Instance.STATUS_INVALID, Instance.STATUS_INCOMPLETE -> {
pill.visibility = View.VISIBLE
pill.setIcon(R.drawable.baseline_rule_24)
pill.setText(string.draft_errors)
pill.setPillBackgroundColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorErrorContainer))
pill.setTextColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnErrorContainer))
pill.setIconTint(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnErrorContainer))
}
Instance.STATUS_VALID -> {
pill.visibility = View.VISIBLE
pill.setIcon(R.drawable.baseline_check_24)
pill.setText(string.draft_no_errors)
pill.setPillBackgroundColor(getThemeAttributeValue(context, R.attr.colorSurfaceContainerHighest))
pill.setTextColor(getThemeAttributeValue(context, R.attr.colorOnSurfaceContainerHighest))
pill.setIconTint(getThemeAttributeValue(context, R.attr.colorOnSurfaceContainerHighest))
}
else -> {
pill.visibility = View.GONE
}
}
}

Expand Down

0 comments on commit e8f947f

Please sign in to comment.