Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed setting background color used in pills #5927

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import androidx.annotation.AttrRes

object ContextUtils {

/**
* Be careful when using this method to retrieve colors, especially for those defined
* using selectors as it might not work well.
* In such cases consider using [com.google.android.material.color.MaterialColors.getColor] instead.
*/
@JvmStatic
fun getThemeAttributeValue(context: Context, @AttrRes resId: Int): Int {
val outValue = TypedValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.google.android.material.color.MaterialColors
import org.odk.collect.android.R
import org.odk.collect.android.utilities.FormsRepositoryProvider
import org.odk.collect.androidshared.system.ContextUtils.getThemeAttributeValue
Expand Down Expand Up @@ -35,15 +36,15 @@ object InstanceListItemView {
pill.visibility = View.VISIBLE
pill.setIcon(org.odk.collect.icons.R.drawable.ic_baseline_rule_24)
pill.setText(string.draft_errors)
pill.setPillBackgroundColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorErrorContainer))
pill.setPillBackgroundColor(MaterialColors.getColor(pill, 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, com.google.android.material.R.attr.colorSurfaceContainerHighest))
pill.setPillBackgroundColor(MaterialColors.getColor(pill, com.google.android.material.R.attr.colorSurfaceContainerHighest))
pill.setTextColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnSurface))
pill.setIconTint(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnSurface))
}
Expand Down