Skip to content

Commit

Permalink
Merge pull request #131 from Trendyol/bugfix/addValidFontControlForQu…
Browse files Browse the repository at this point in the history
…antityPicker

fix QuantityPickerView invalid font resource issue
  • Loading branch information
belfuogretir authored Oct 11, 2024
2 parents 3c486f2 + b13185d commit e8123b7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal fun AppCompatTextView.setTextAppearance(
setTextColor(quantityPickerTextAppearance.textColor)

//or to support all versions use
if (quantityPickerTextAppearance.textFontFamily != -1) {
if (quantityPickerTextAppearance.textFontFamily != -1 && quantityPickerTextAppearance.textFontFamily != null) {
val typeface = ResourcesCompat.getFont(context, quantityPickerTextAppearance.textFontFamily)
setTypeface(typeface)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ data class QuantityPickerTextAppearance(
@ColorInt val textColor: Int,
val textSize: Int,
val textStyle: Int,
@FontRes val textFontFamily: Int
@FontRes val textFontFamily: Int?
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.trendyol.uicomponents.quantitypickerview
import android.content.Context
import android.graphics.drawable.Drawable
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -286,8 +287,9 @@ class QuantityPickerView : ConstraintLayout {
val removeContentDescription = it.getString(
R.styleable.QuantityPickerView_qpv_remove_contentDescription
) ?: ""
val textFontFamily =
val textFontFamily: Int? = runCatching {
it.getResourceId(R.styleable.QuantityPickerView_qpv_fontFamily, -1)
}.getOrNull()

return QuantityPickerViewState(
text = text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class QuantityPickerViewState(
val disabledSubtractIconDrawable: Drawable? = subtractIconDrawable,
val addContentDescription: String,
val removeContentDescription: String,
@FontRes val textFontFamily: Int
@FontRes val textFontFamily: Int?
) {

internal fun isInQuantityMode(): Boolean = currentQuantity > 0
Expand Down

0 comments on commit e8123b7

Please sign in to comment.