Skip to content

Commit

Permalink
fix colour resources crash on android 11
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Jul 24, 2022
1 parent 154f9f6 commit b8fef3f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ abstract class PortfolioVH(itemView: View) : RecyclerView.ViewHolder(itemView),
protected val positiveColor: Int = ContextCompat.getColor(itemView.context, R.color.positive_green)
protected val negativeColor: Int = ContextCompat.getColor(itemView.context, R.color.negative_red)
protected val neutralColor: Int by lazy {
val typedValue = TypedValue()
val theme: Theme = itemView.context.theme
theme.resolveAttribute(com.google.android.material.R.attr.colorOnSurfaceVariant, typedValue, true)
ContextCompat.getColor(itemView.context, typedValue.data)
try {
val typedValue = TypedValue()
val theme: Theme = itemView.context.theme
theme.resolveAttribute(
com.google.android.material.R.attr.colorOnSurfaceVariant,
typedValue,
true
)
ContextCompat.getColor(itemView.context, typedValue.data)
} catch (e: Exception) {
ContextCompat.getColor(itemView.context, R.color.text_2)
}
}

@Throws(Exception::class) protected abstract fun updateView(quote: Quote, color: Int)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-night/color_palette.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<color name="negative_red">#ff6666</color>
<color name="positive_green">#ccff66</color>
<color name="positive_green_dark">#009900</color>
<color name="text_2">#fff3f3f3</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/color_palette.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
<color name="negative_red">#e55b5b</color>
<color name="positive_green">#009900</color>
<color name="positive_green_dark">#006b00</color>
<color name="text_2">#6e6e6e</color>

</resources>

0 comments on commit b8fef3f

Please sign in to comment.