From 4f609aa2d36025c65420e7aaf1fabd1cabc3269d Mon Sep 17 00:00:00 2001 From: "belfu.ogretir" Date: Mon, 30 Sep 2024 16:24:25 +0300 Subject: [PATCH 1/3] add Font Support for QuantityPickerView --- libraries/quantity-picker-view/README.md | 26 +++++++++---------- .../quantitypickerview/BindingAdapters.kt | 8 ++++++ .../QuantityPickerTextAppearance.kt | 4 ++- .../quantitypickerview/QuantityPickerView.kt | 14 +++++++--- .../QuantityPickerViewState.kt | 13 +++++++--- .../main/res/layout/view_quantity_picker.xml | 2 -- .../src/main/res/values/attrs.xml | 1 + .../QuantityPickerViewActivity.kt | 9 ++++--- 8 files changed, 51 insertions(+), 26 deletions(-) diff --git a/libraries/quantity-picker-view/README.md b/libraries/quantity-picker-view/README.md index 3b01a4df..48245ea8 100644 --- a/libraries/quantity-picker-view/README.md +++ b/libraries/quantity-picker-view/README.md @@ -54,6 +54,7 @@ To set programmatically, you can call `QuantityPickerView.setQuantityPickerViewS | qpv_quantityBackgroundVerticalPadding | quantityBackgroundVerticalPadding | padding for quantity background vertically if `orientation` is `horizontal`, else horizontal padding. | `2dp` | | qpv_add_contentDescription | text | Text for Add Image of Talkback | "" | | qpv_remove_contentDescription | text | Text for Remove Image of Talkback | "" | +| qpv_fontFamily | fontFamily | Font family for texts. | | # Public methods @@ -63,12 +64,13 @@ To set programmatically, you can call `QuantityPickerView.setQuantityPickerViewS | setQuantity | quantity: Int | To set quantity immediately. | | setMaxQuantity | maxQuantity: Int | To set maxQuantity immediately. | | setMinQuantity | minQuantity: Int | To set minQuantity immediately. | -| setBackgroundImageDrawable | background: Drawable | To set backgroundImageDrawable immediately. | +| setBackgroundImageDrawable | background: Drawable | To set backgroundImageDrawable immediately. | | stopLoading | | To stop current loading. | | reset | | To stop loading and set currentQuantity to 0. | | incrementQuantityBy | quantity | increments current total quantity by quantity parameter | ## Listeners + To get updates on **QuantityPickerView** you need to set this listeners: | Listener | Data | Return | Information | @@ -83,17 +85,12 @@ To get updates on **QuantityPickerView** you need to set this listeners: From XML, you can use attributes like below: ```xml + + android:id="@+id/quantity_picker_view" android:layout_width="match_parent" + android:layout_height="36dp" app:qpv_currentQuantity="1" app:qpv_maxQuantity="10" + app:qpv_minQuantity="1" app:qpv_quantityBackground="@drawable/qpv_shape_default_background" + app:qpv_quantityTextSize="14sp" app:qpv_text="Add to Cart" app:qpv_textSize="12sp" /> ``` To set *QuantityPickerViewState* programmatically: @@ -112,16 +109,19 @@ val viewState = QuantityPickerViewState( progressTintColor = themeColor(R.attr.colorAccent), quantityTextColor = themeColor(R.attr.colorPrimary) ) - + findViewById(R.id.quantity_picker_view).setQuantityPickerViewState(viewState) ``` ## Contributors -This library is maintained mainly by Trendyol Android Team members but also other Android lovers contributes. + +This library is maintained mainly by Trendyol Android Team members but also other Android lovers +contributes. We developed this component for our needs, there is lots of improvements need to be implemented. # License + Copyright 2022 Trendyol.com Licensed under the Apache License, Version 2.0 (the "License"); 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 5f4f57f1..6a86eca4 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 @@ -3,6 +3,8 @@ package com.trendyol.uicomponents.quantitypickerview import android.graphics.Typeface import android.util.TypedValue import androidx.appcompat.widget.AppCompatTextView +import androidx.core.content.res.ResourcesCompat + internal fun AppCompatTextView.setTextAppearance( quantityPickerTextAppearance: QuantityPickerTextAppearance @@ -16,4 +18,10 @@ internal fun AppCompatTextView.setTextAppearance( setTypeface(typeface, style) setTextSize(TypedValue.COMPLEX_UNIT_PX, quantityPickerTextAppearance.textSize.toFloat()) setTextColor(quantityPickerTextAppearance.textColor) + + //or to support all versions use + if (quantityPickerTextAppearance.textFontFamily != -1) { + 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 aef61794..3dd0777f 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 @@ -1,9 +1,11 @@ package com.trendyol.uicomponents.quantitypickerview import androidx.annotation.ColorInt +import androidx.annotation.FontRes data class QuantityPickerTextAppearance( @ColorInt val textColor: Int, val textSize: Int, - val textStyle: Int + val textStyle: 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 06e684cf..49ec98ba 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 @@ -153,7 +153,7 @@ class QuantityPickerView : ConstraintLayout { fun setMinQuantity(minQuantity: Int) = setQuantityPickerViewState(viewState.getWithMinQuantity(minQuantity)) - fun setBackgroundImageDrawable(background: Drawable){ + fun setBackgroundImageDrawable(background: Drawable) { setQuantityPickerViewState(viewState.getWithBackgroundDrawable(background)) } @@ -286,6 +286,8 @@ class QuantityPickerView : ConstraintLayout { val removeContentDescription = it.getString( R.styleable.QuantityPickerView_qpv_remove_contentDescription ) ?: "" + val textFontFamily = + it.getResourceId(R.styleable.QuantityPickerView_qpv_fontFamily, -1) return QuantityPickerViewState( text = text, @@ -314,7 +316,8 @@ class QuantityPickerView : ConstraintLayout { maxQuantity = maxQuantity, minQuantity = minQuantity, addContentDescription = addContentDescription, - removeContentDescription = removeContentDescription + removeContentDescription = removeContentDescription, + textFontFamily = textFontFamily ) } } @@ -360,7 +363,12 @@ class QuantityPickerView : ConstraintLayout { visibility = viewState.getProgressBarVisibility() indeterminateTintList = ColorStateList.valueOf(viewState.progressTintColor) val progressVerticalPadding = viewState.progressVerticalPadding - setPadding(paddingLeft, progressVerticalPadding, paddingRight, progressVerticalPadding) + setPadding( + paddingLeft, + progressVerticalPadding, + paddingRight, + progressVerticalPadding + ) } with(imageAdd) { contentDescription = viewState.addContentDescription 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 da494178..4b34839d 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 @@ -2,8 +2,11 @@ package com.trendyol.uicomponents.quantitypickerview import android.content.Context import android.graphics.drawable.Drawable +import android.graphics.fonts.FontFamily import android.view.View import androidx.annotation.ColorInt +import androidx.annotation.FontRes +import org.intellij.lang.annotations.JdkConstants.FontStyle data class QuantityPickerViewState( private val text: String, @@ -32,7 +35,8 @@ data class QuantityPickerViewState( val disabledAddIconDrawable: Drawable? = addIconDrawable, val disabledSubtractIconDrawable: Drawable? = subtractIconDrawable, val addContentDescription: String, - val removeContentDescription: String + val removeContentDescription: String, + @FontRes val textFontFamily: Int ) { internal fun isInQuantityMode(): Boolean = currentQuantity > 0 @@ -58,10 +62,10 @@ data class QuantityPickerViewState( } fun getQuantityPickerTextAppearance(): QuantityPickerTextAppearance = - QuantityPickerTextAppearance(textColor, textSize, textStyle) + QuantityPickerTextAppearance(textColor, textSize, textStyle, textFontFamily) fun getQuantityTextAppearance() = - QuantityPickerTextAppearance(quantityTextColor, quantityTextSize, quantityTextStyle) + QuantityPickerTextAppearance(quantityTextColor, quantityTextSize, quantityTextStyle, textFontFamily) fun getQuantity() = currentQuantity.takeIf { it != 0 }?.toString() @@ -208,7 +212,8 @@ data class QuantityPickerViewState( maxQuantity = 0, minQuantity = 0, addContentDescription = "", - removeContentDescription = "" + removeContentDescription = "", + textFontFamily = -1 ) } } diff --git a/libraries/quantity-picker-view/src/main/res/layout/view_quantity_picker.xml b/libraries/quantity-picker-view/src/main/res/layout/view_quantity_picker.xml index 22bf904f..79772038 100644 --- a/libraries/quantity-picker-view/src/main/res/layout/view_quantity_picker.xml +++ b/libraries/quantity-picker-view/src/main/res/layout/view_quantity_picker.xml @@ -39,7 +39,6 @@ android:id="@+id/text" android:layout_width="0dp" android:layout_height="0dp" - android:fontFamily="sans-serif-medium" android:gravity="center" android:includeFontPadding="false" android:maxLines="1" @@ -56,7 +55,6 @@ android:id="@+id/quantityText" android:layout_width="0dp" android:layout_height="0dp" - android:fontFamily="sans-serif-medium" android:gravity="center" android:includeFontPadding="false" android:minEms="3" diff --git a/libraries/quantity-picker-view/src/main/res/values/attrs.xml b/libraries/quantity-picker-view/src/main/res/values/attrs.xml index 95b21b1b..6d0d625c 100644 --- a/libraries/quantity-picker-view/src/main/res/values/attrs.xml +++ b/libraries/quantity-picker-view/src/main/res/values/attrs.xml @@ -10,6 +10,7 @@ + diff --git a/sample/src/main/java/com/trendyol/uicomponents/QuantityPickerViewActivity.kt b/sample/src/main/java/com/trendyol/uicomponents/QuantityPickerViewActivity.kt index 3570fe5b..4ab85717 100644 --- a/sample/src/main/java/com/trendyol/uicomponents/QuantityPickerViewActivity.kt +++ b/sample/src/main/java/com/trendyol/uicomponents/QuantityPickerViewActivity.kt @@ -15,10 +15,12 @@ class QuantityPickerViewActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(ActivityQuantityPickerViewBinding.inflate(layoutInflater).also { binding = it }.root) + setContentView( + ActivityQuantityPickerViewBinding.inflate(layoutInflater).also { binding = it }.root + ) val viewState = QuantityPickerViewState( - text = "Fresh Money", + text = "غداً", textSize = asSP(12), quantityTextSize = asSP(14), backgroundDrawable = drawable(QuantityPickerViewR.drawable.qpv_shape_default_background), @@ -34,7 +36,8 @@ class QuantityPickerViewActivity : AppCompatActivity() { progressVerticalPadding = asDP(6), quantityBackgroundVerticalPadding = asDP(6), addContentDescription = "Add", - removeContentDescription = "Remove" + removeContentDescription = "Remove", + textFontFamily = -1 ) binding.quantityPickerView2.setQuantityPickerViewState(viewState) From 8017e7ae8f7824b09ba85ede06fbf6e3658de1df Mon Sep 17 00:00:00 2001 From: "belfu.ogretir" Date: Mon, 30 Sep 2024 16:25:29 +0300 Subject: [PATCH 2/3] add Font Support for QuantityPickerView --- .../uicomponents/quantitypickerview/QuantityPickerViewState.kt | 2 -- 1 file changed, 2 deletions(-) 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 4b34839d..f6f25ea7 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 @@ -2,11 +2,9 @@ package com.trendyol.uicomponents.quantitypickerview import android.content.Context import android.graphics.drawable.Drawable -import android.graphics.fonts.FontFamily import android.view.View import androidx.annotation.ColorInt import androidx.annotation.FontRes -import org.intellij.lang.annotations.JdkConstants.FontStyle data class QuantityPickerViewState( private val text: String, From 27f8329fd0a3050e8c413068953ec3a62d69866a Mon Sep 17 00:00:00 2001 From: "belfu.ogretir" Date: Tue, 1 Oct 2024 15:50:15 +0300 Subject: [PATCH 3/3] add Font Support for Dialogs --- .../trendyol/uicomponents/dialogs/Builder.kt | 33 +++++++++---- .../uicomponents/dialogs/DialogFragment.kt | 48 ++++++++++++++----- .../dialogs/DialogFragmentArguments.kt | 6 ++- .../uicomponents/dialogs/DialogViewState.kt | 19 ++++++-- .../dialogs/list/DialogListAdapter.kt | 16 +++++-- .../dialogs/list/DialogListItemViewState.kt | 7 ++- .../list/info/DialogInfoListAdapter.kt | 10 +++- .../list/info/DialogInfoListItemViewState.kt | 8 +++- .../main/res/layout/view_quantity_picker.xml | 1 + .../src/main/res/values/attrs.xml | 2 +- .../com/trendyol/uicomponents/Extensions.kt | 11 +++++ .../QuantityPickerViewActivity.kt | 2 +- 12 files changed, 129 insertions(+), 34 deletions(-) diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.kt index 3793d816..65ea0c7b 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.kt @@ -1,10 +1,9 @@ package com.trendyol.uicomponents.dialogs import android.text.SpannableString -import android.webkit.DownloadListener -import android.webkit.WebView import androidx.annotation.ColorInt import androidx.annotation.DrawableRes +import androidx.annotation.FontRes open class Builder internal constructor() { @@ -13,13 +12,23 @@ open class Builder internal constructor() { var titleTextColor: Int? = null var titleTextPosition: TextPosition? = null var showCloseButton: Boolean = false - @ColorInt var closeButtonColor: Int? = null - @DrawableRes var closeButtonDrawable: Int? = null + + @ColorInt + var closeButtonColor: Int? = null + + @DrawableRes + var closeButtonDrawable: Int? = null var closeButtonListener: ((DialogFragment) -> Unit)? = null var animateCornerRadiusWhenExpand: Boolean = false var onDialogDismissListener: ((DialogFragment) -> Unit)? = null var cornerRadius: Float? = null var isFullHeightWebView: Boolean = false + + @FontRes + var titleFontFamily: Int? = null + + @FontRes + var contentFontFamily: Int? = null } open class InfoDialogBuilder internal constructor() : Builder() { @@ -54,7 +63,9 @@ open class InfoDialogBuilder internal constructor() : Builder() { titleTextPosition = it.titleTextPosition, contentTextPosition = it.contentTextPosition, webViewContent = it.webViewContent, - isFullHeightWebView = it.isFullHeightWebView + isFullHeightWebView = it.isFullHeightWebView, + titleFontFamily = it.titleFontFamily, + contentFontFamily = it.contentFontFamily ).toBundle() this.closeButtonListener = it.closeButtonListener ?: { } this.onDismissListener = it.onDialogDismissListener ?: {} @@ -86,7 +97,9 @@ open class AgreementDialogBuilder internal constructor() : InfoDialogBuilder() { contentImage = it.contentImage, rightButtonText = it.rightButtonText, leftButtonText = it.leftButtonText, - webViewContent = it.webViewContent + webViewContent = it.webViewContent, + titleFontFamily = it.titleFontFamily, + contentFontFamily = it.contentFontFamily ).toBundle() closeButtonListener = it.closeButtonListener rightButtonClickListener = it.rightButtonClickListener @@ -133,7 +146,9 @@ class SelectionDialogBuilder internal constructor() : InfoDialogBuilder() { selectedItemDrawable = it.selectedItemDrawable, selectedTextColor = it.selectedTextColor, showRadioButton = it.showRadioButton, - webViewContent = it.webViewContent + webViewContent = it.webViewContent, + titleFontFamily = it.titleFontFamily, + contentFontFamily = it.contentFontFamily ).toBundle() closeButtonListener = it.closeButtonListener onItemSelectedListener = it.onItemSelectedListener @@ -166,7 +181,9 @@ class InfoListDialogBuilder internal constructor() : InfoDialogBuilder() { contentImage = it.contentImage, webViewContent = it.webViewContent, infoListItems = it.infoListItems, - itemDividers = it.itemDividers + itemDividers = it.itemDividers, + titleFontFamily = it.titleFontFamily, + contentFontFamily = it.contentFontFamily ).toBundle() closeButtonListener = it.closeButtonListener this.onDismissListener = it.onDialogDismissListener ?: {} diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt index b4ea02af..5c42b2ee 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt @@ -8,7 +8,6 @@ import android.text.method.LinkMovementMethod import android.text.util.Linkify import android.view.LayoutInflater import android.view.View -import android.view.ViewConfiguration import android.view.ViewGroup import android.view.ViewOutlineProvider import android.webkit.DownloadListener @@ -47,7 +46,8 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { dialogArguments.showItemsAsHtml, dialogArguments.selectedItemDrawable, dialogArguments.selectedTextColor, - dialogArguments.showRadioButton + dialogArguments.showRadioButton, + dialogArguments.contentFontFamily ) } @@ -57,7 +57,11 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { ViewModelProviders.of(this)[DialogListViewModel::class.java] } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { binding = FragmentDialogBinding.inflate(inflater, container, false) return binding.root } @@ -66,7 +70,8 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { if (dialogArguments.animateCornerRadiusWhenExpand) { animateCornerRadiusWithStateChanged() } else { - val cornerRadius = dialogArguments.cornerRadius ?: requireContext().pixel(R.dimen.ui_components_dialogs_corner_radius) + val cornerRadius = dialogArguments.cornerRadius + ?: requireContext().pixel(R.dimen.ui_components_dialogs_corner_radius) binding.cardView.outlineProvider = BottomSheetOutlineProvider(radius = cornerRadius) } @@ -90,13 +95,21 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { initializeSelectionDialog(items) } dialogArguments.infoListItems?.let { items -> - initializeInfoListDialog(items, dialogArguments.itemDividers) + initializeInfoListDialog( + items, + dialogArguments.itemDividers, + dialogArguments.contentFontFamily + ) } if (dialogArguments.horizontalPadding != null || dialogArguments.verticalPadding != null) { - val topPadding = dialogArguments.verticalPadding?.toInt() ?: nestedScrollView.paddingTop - val bottomPadding = dialogArguments.verticalPadding?.toInt() ?: nestedScrollView.paddingBottom - val startPadding = dialogArguments.horizontalPadding?.toInt() ?: nestedScrollView.paddingStart - val endPadding = dialogArguments.horizontalPadding?.toInt() ?: nestedScrollView.paddingEnd + val topPadding = + dialogArguments.verticalPadding?.toInt() ?: nestedScrollView.paddingTop + val bottomPadding = + dialogArguments.verticalPadding?.toInt() ?: nestedScrollView.paddingBottom + val startPadding = + dialogArguments.horizontalPadding?.toInt() ?: nestedScrollView.paddingStart + val endPadding = + dialogArguments.horizontalPadding?.toInt() ?: nestedScrollView.paddingEnd nestedScrollView.setPadding(startPadding, topPadding, endPadding, bottomPadding) } } @@ -135,10 +148,12 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { private fun initializeInfoListDialog( items: List>, - itemDividers: List + itemDividers: List, + fontFamily: Int? ) { with(binding.recyclerViewItems) { infoListAdapter.setItems(items) + infoListAdapter.contentFontFamily = fontFamily itemDividers.forEach { addItemDecoration(ItemDecorator(it)) } @@ -162,11 +177,15 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { isSearchEnabled = dialogArguments.enableSearch, isClearSearchButtonVisible = dialogArguments.showClearSearchButton, searchHint = dialogArguments.searchHint, - titleBackgroundColor = dialogArguments.titleBackgroundColor ?: R.color.ui_components_dialogs_gray, - titleTextColor = dialogArguments.titleTextColor ?: R.color.ui_components_dialogs_primary_text_color, + titleBackgroundColor = dialogArguments.titleBackgroundColor + ?: R.color.ui_components_dialogs_gray, + titleTextColor = dialogArguments.titleTextColor + ?: R.color.ui_components_dialogs_primary_text_color, titleTextPosition = dialogArguments.titleTextPosition ?: TextPosition.START, contentTextPosition = dialogArguments.contentTextPosition ?: TextPosition.START, webViewContent = dialogArguments.webViewContent, + titleFontFamily = dialogArguments.titleFontFamily, + contentFontFamily = dialogArguments.contentFontFamily ) with(binding) { @@ -178,6 +197,7 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { text = viewState.title textAlignment = viewState.getTitleTextPosition() setTextColor(viewState.getTitleTextColor(context)) + typeface = viewState.getTitleFontFamily(context) } with(viewDialogHeader.imageClose) { visibility = viewState.getCloseButtonVisibility() @@ -191,6 +211,7 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { text = viewState.getContent() textAlignment = viewState.getContentTextPosition() visibility = viewState.getContentTextVisibility() + typeface = viewState.getContentFontFamily(context) } with(webViewContent) { visibility = viewState.getWebViewContentVisibility() @@ -209,6 +230,7 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { with(editTextSearch) { hint = viewState.searchHint visibility = viewState.isSearchVisible() + typeface = viewState.getContentFontFamily(context) } imageClearSearchQuery.visibility = viewState.getClearButtonVisibility() recyclerViewItems.visibility = viewState.getListVisibility() @@ -310,4 +332,4 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { return fragmentManager.findFragmentByTag(TAG) as? DialogFragment } } -} +} \ No newline at end of file diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragmentArguments.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragmentArguments.kt index a611832c..4764bce3 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragmentArguments.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragmentArguments.kt @@ -2,10 +2,10 @@ package com.trendyol.uicomponents.dialogs import android.os.Bundle import android.os.Parcelable -import android.webkit.WebView import androidx.annotation.ColorInt import androidx.annotation.ColorRes import androidx.annotation.DrawableRes +import androidx.annotation.FontRes import androidx.core.os.bundleOf import kotlinx.parcelize.Parcelize @@ -39,7 +39,9 @@ class DialogFragmentArguments( val webViewContent: WebViewContent? = null, val infoListItems: List>? = null, val itemDividers: List = emptyList(), - val isFullHeightWebView : Boolean = false + val isFullHeightWebView: Boolean = false, + @FontRes val titleFontFamily: Int? = null, + @FontRes val contentFontFamily: Int? = null ) : Parcelable { fun toBundle() = bundleOf("ARGUMENTS" to this) diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt index 66383c2d..ee3e75f5 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt @@ -6,7 +6,9 @@ import android.view.View import androidx.annotation.ColorInt import androidx.annotation.ColorRes import androidx.annotation.DrawableRes +import androidx.annotation.FontRes import androidx.core.content.ContextCompat +import androidx.core.content.res.ResourcesCompat import androidx.core.text.HtmlCompat import com.trendyol.dialog.R @@ -29,6 +31,8 @@ data class DialogViewState( val titleTextPosition: TextPosition, val contentTextPosition: TextPosition, val webViewContent: WebViewContent?, + @FontRes val titleFontFamily: Int?, + @FontRes val contentFontFamily: Int?, ) { fun getTitleVisibility(): Int = if (title.isNullOrEmpty().not()) View.VISIBLE else View.GONE @@ -40,10 +44,17 @@ data class DialogViewState( } @ColorInt - fun getTitleBackgroundColor(context: Context): Int = ContextCompat.getColor(context, titleBackgroundColor) + fun getTitleBackgroundColor(context: Context): Int = + ContextCompat.getColor(context, titleBackgroundColor) fun getTitleTextColor(context: Context) = ContextCompat.getColor(context, titleTextColor) + fun getTitleFontFamily(context: Context) = + titleFontFamily?.let { ResourcesCompat.getFont(context, it) } + + fun getContentFontFamily(context: Context) = + contentFontFamily?.let { ResourcesCompat.getFont(context, it) } + fun getTitleTextPosition(): Int { return when (titleTextPosition) { TextPosition.CENTER -> 4 @@ -71,7 +82,8 @@ data class DialogViewState( } } - fun getContentImageVisibility(): Int = if (contentImage?.takeIf { it != 0 } != null) View.VISIBLE else View.GONE + fun getContentImageVisibility(): Int = + if (contentImage?.takeIf { it != 0 } != null) View.VISIBLE else View.GONE fun getContentTextVisibility(): Int = if (content.isNotEmpty()) View.VISIBLE else View.GONE @@ -86,7 +98,8 @@ data class DialogViewState( fun isSearchVisible(): Int = if (isSearchEnabled) View.VISIBLE else View.GONE - fun getClearButtonVisibility(): Int = if (isClearSearchButtonVisible) View.VISIBLE else View.GONE + fun getClearButtonVisibility(): Int = + if (isClearSearchButtonVisible) View.VISIBLE else View.GONE fun getListVisibility(): Int = if (isListVisible) View.VISIBLE else View.GONE diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt index 08f0318e..1dbfb969 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt @@ -2,6 +2,7 @@ package com.trendyol.uicomponents.dialogs.list import android.view.LayoutInflater import android.view.ViewGroup +import androidx.annotation.FontRes import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.trendyol.dialog.databinding.ItemUiComponentsSelectionDialogBinding @@ -10,7 +11,8 @@ internal class DialogListAdapter( private val showItemsAsHtml: Boolean, private val selectedItemDrawable: Int?, private val selectedTextColor: Int?, - private val showRadioButton: Boolean + private val showRadioButton: Boolean, + @FontRes private val contentFontFamily: Int? ) : ListAdapter, DialogListAdapter.ItemViewHolder>(ListItemDiffCallback()) { var onItemSelectedListener: ((Int) -> Unit)? = null @@ -25,7 +27,13 @@ internal class DialogListAdapter( } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder = - ItemViewHolder(ItemUiComponentsSelectionDialogBinding.inflate(LayoutInflater.from(parent.context), parent, false)) + ItemViewHolder( + ItemUiComponentsSelectionDialogBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + ) inner class ItemViewHolder( private val binding: ItemUiComponentsSelectionDialogBinding @@ -48,7 +56,8 @@ internal class DialogListAdapter( selectedItemDrawable = selectedItemDrawable, selectedTextColor = selectedTextColor, isChecked = item.first, - showRadioButton = showRadioButton + showRadioButton = showRadioButton, + contentFontFamily = contentFontFamily ) with(binding) { @@ -59,6 +68,7 @@ internal class DialogListAdapter( with(radioButtonItem) { text = viewState.getText() setTextColor(viewState.getSelectedTextColor(context)) + typeface = viewState.getFontFamily(context) } with(imageViewCheckedDrawable) { setImageDrawable(viewState.getSelectedItemDrawable(context)) diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListItemViewState.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListItemViewState.kt index 115b6603..3226704d 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListItemViewState.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListItemViewState.kt @@ -3,7 +3,9 @@ package com.trendyol.uicomponents.dialogs.list import android.content.Context import android.graphics.drawable.Drawable import android.view.View +import androidx.annotation.FontRes import androidx.core.content.ContextCompat +import androidx.core.content.res.ResourcesCompat import androidx.core.text.HtmlCompat import com.trendyol.dialog.R @@ -13,7 +15,8 @@ data class DialogListItemViewState( val selectedItemDrawable: Int?, val selectedTextColor: Int?, val isChecked: Boolean, - val showRadioButton: Boolean + val showRadioButton: Boolean, + @FontRes val contentFontFamily: Int?, ) { fun getText(): CharSequence = @@ -39,5 +42,7 @@ data class DialogListItemViewState( fun getRadioButtonVisibility(): Int = if (showRadioButton) View.VISIBLE else View.GONE fun getRadioButtonChecked(): Boolean = isChecked + + fun getFontFamily(context: Context) = contentFontFamily?.let { ResourcesCompat.getFont(context, it) } } diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/info/DialogInfoListAdapter.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/info/DialogInfoListAdapter.kt index 360e455d..52fed1f9 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/info/DialogInfoListAdapter.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/info/DialogInfoListAdapter.kt @@ -2,12 +2,18 @@ package com.trendyol.uicomponents.dialogs.list.info import android.view.LayoutInflater import android.view.ViewGroup +import androidx.annotation.FontRes import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.trendyol.dialog.databinding.ItemUiComponentsInfoListDialogBinding internal class DialogInfoListAdapter( -) : ListAdapter, DialogInfoListAdapter.ItemViewHolder>(InfoListItemDiffCallback()) { +) : ListAdapter, DialogInfoListAdapter.ItemViewHolder>( + InfoListItemDiffCallback() +) { + + @FontRes + var contentFontFamily: Int? = null fun setItems(list: List>) { submitList(list.toMutableList()) @@ -34,6 +40,8 @@ internal class DialogInfoListAdapter( with(binding) { textKey.text = viewState.key textValue.text = viewState.value + textKey.typeface = viewState.getFontFamily(textKey.context, contentFontFamily) + textValue.typeface = viewState.getFontFamily(textValue.context, contentFontFamily) } } } diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/info/DialogInfoListItemViewState.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/info/DialogInfoListItemViewState.kt index 46cd857f..fe59c167 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/info/DialogInfoListItemViewState.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/info/DialogInfoListItemViewState.kt @@ -1,7 +1,13 @@ package com.trendyol.uicomponents.dialogs.list.info +import android.content.Context +import androidx.core.content.res.ResourcesCompat + data class DialogInfoListItemViewState( val key: CharSequence, val value: CharSequence, -) +){ + + fun getFontFamily(context: Context, fontFamily:Int?) = fontFamily?.let { ResourcesCompat.getFont(context, it) } +} diff --git a/libraries/quantity-picker-view/src/main/res/layout/view_quantity_picker.xml b/libraries/quantity-picker-view/src/main/res/layout/view_quantity_picker.xml index 79772038..525fa2f8 100644 --- a/libraries/quantity-picker-view/src/main/res/layout/view_quantity_picker.xml +++ b/libraries/quantity-picker-view/src/main/res/layout/view_quantity_picker.xml @@ -39,6 +39,7 @@ android:id="@+id/text" android:layout_width="0dp" android:layout_height="0dp" + android:fontFamily="sans-serif-medium" android:gravity="center" android:includeFontPadding="false" android:maxLines="1" diff --git a/libraries/quantity-picker-view/src/main/res/values/attrs.xml b/libraries/quantity-picker-view/src/main/res/values/attrs.xml index 6d0d625c..c910b536 100644 --- a/libraries/quantity-picker-view/src/main/res/values/attrs.xml +++ b/libraries/quantity-picker-view/src/main/res/values/attrs.xml @@ -10,7 +10,7 @@ - + diff --git a/sample/src/main/java/com/trendyol/uicomponents/Extensions.kt b/sample/src/main/java/com/trendyol/uicomponents/Extensions.kt index 713c9c3f..d56b0a6e 100644 --- a/sample/src/main/java/com/trendyol/uicomponents/Extensions.kt +++ b/sample/src/main/java/com/trendyol/uicomponents/Extensions.kt @@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable import android.util.TypedValue import androidx.annotation.AttrRes import androidx.annotation.DrawableRes +import androidx.annotation.FontRes import androidx.appcompat.content.res.AppCompatResources // from https://stackoverflow.com/a/55573791 @@ -22,3 +23,13 @@ fun Context.asSP(value: Int): Int = fun Context.asDP(value: Int): Int = (value * resources.displayMetrics.density).toInt() + +@FontRes +fun Context.themeFont(@AttrRes attribute: Int): Int { + val typedValue = TypedValue() + if (theme.resolveAttribute(attribute, typedValue, true)) { + return typedValue.resourceId + } else { + throw IllegalArgumentException("[android.util.TypedValue] has returned 0 for given resId=$attribute") + } +} diff --git a/sample/src/main/java/com/trendyol/uicomponents/QuantityPickerViewActivity.kt b/sample/src/main/java/com/trendyol/uicomponents/QuantityPickerViewActivity.kt index 4ab85717..e72e45a7 100644 --- a/sample/src/main/java/com/trendyol/uicomponents/QuantityPickerViewActivity.kt +++ b/sample/src/main/java/com/trendyol/uicomponents/QuantityPickerViewActivity.kt @@ -20,7 +20,7 @@ class QuantityPickerViewActivity : AppCompatActivity() { ) val viewState = QuantityPickerViewState( - text = "غداً", + text = "Fresh Money", textSize = asSP(12), quantityTextSize = asSP(14), backgroundDrawable = drawable(QuantityPickerViewR.drawable.qpv_shape_default_background),