From b13185d71dc03566db15e5bef0bbc23df3cd9456 Mon Sep 17 00:00:00 2001 From: "belfu.ogretir" Date: Fri, 11 Oct 2024 08:41:37 +0300 Subject: [PATCH] fix QuantityPickerView invalid font resource issue --- .../uicomponents/quantitypickerview/BindingAdapters.kt | 2 +- .../quantitypickerview/QuantityPickerTextAppearance.kt | 2 +- .../uicomponents/quantitypickerview/QuantityPickerView.kt | 4 +++- .../quantitypickerview/QuantityPickerViewState.kt | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/BindingAdapters.kt b/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/BindingAdapters.kt index 6a86eca..abc55d4 100644 --- a/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/BindingAdapters.kt +++ b/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/BindingAdapters.kt @@ -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) } diff --git a/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerTextAppearance.kt b/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerTextAppearance.kt index 3dd0777..c1de5d7 100644 --- a/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerTextAppearance.kt +++ b/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerTextAppearance.kt @@ -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? ) diff --git a/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerView.kt b/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerView.kt index 49ec98b..3c9cfd0 100644 --- a/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerView.kt +++ b/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerView.kt @@ -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 @@ -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, diff --git a/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerViewState.kt b/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerViewState.kt index f6f25ea..1ba3d29 100644 --- a/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerViewState.kt +++ b/libraries/quantity-picker-view/src/main/java/com/trendyol/uicomponents/quantitypickerview/QuantityPickerViewState.kt @@ -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