11package company.tap.tapcheckout_android.theme
2+
23import android.content.Context
34import android.graphics.Typeface
45import android.util.AttributeSet
@@ -9,12 +10,10 @@ import androidx.annotation.DrawableRes
910import androidx.appcompat.widget.AppCompatImageView
1011import androidx.cardview.widget.CardView
1112import androidx.constraintlayout.widget.ConstraintLayout
12-
1313import company.tap.tapcheckout_android.R
1414
1515import company.tap.taplocalizationkit.LocalizationManager
1616
17-
1817class TapBrandView : LinearLayout {
1918
2019 val poweredByImage by lazy { findViewById<AppCompatImageView >(R .id.poweredByImage) }
@@ -25,71 +24,56 @@ class TapBrandView : LinearLayout {
2524 val backTitle by lazy { findViewById<TextView >(R .id.back_title) }
2625
2726 @DrawableRes
28- val logoIcon: Int =
29- if (ThemeManager .currentTheme.isNotEmpty() && ThemeManager .currentTheme. contains(" dark" )) {
27+ private val logoIcon: Int =
28+ if (ThemeManager .currentTheme.contains(" dark" )) {
3029 R .drawable.poweredbytap2
31- } else if (ThemeManager .currentTheme.isNotEmpty() && ThemeManager .currentTheme.contains(" light" )) {
32- R .drawable.poweredbytap2
33- } else R .drawable.poweredbytap2
34-
30+ } else {
31+ R .drawable.poweredbytap2
32+ }
3533
36- /* *
37- * Simple constructor to use when creating a TapHeader from code.
38- * @param con] ext The Context the view is running in, through which it can
39- * access the current theme, resources, etc.
40- **/
41- constructor (context: Context ) : super (context)
34+ constructor (context: Context ) : super (context) {
35+ initView(context)
36+ }
4237
43- /* *
44- * @param context The Context the view is running in, through which it can
45- * access the current theme, resources, etc.
46- * @param attrs The attributes of the XML Button tag being used to inflate the view.
47- *
48- */
49- constructor (context: Context , attrs: AttributeSet ? ) : super (context, attrs)
38+ constructor (context: Context , attrs: AttributeSet ? ) : super (context, attrs) {
39+ initView(context)
40+ }
5041
51- /* *
52- * @param context The Context the view is running in, through which it can
53- * access the current theme, resources, etc.
54- * @param attrs The attributes of the XML Button tag being used to inflate the view.
55- * @param defStyleAttr The resource identifier of an attribute in the current theme
56- * whose value is the the resource id of a style. The specified style’s
57- * attribute values serve as default values for the button. Set this parameter
58- * to 0 to avoid use of default values.
59- */
60- constructor (context: Context , attrs: AttributeSet ? , defStyleAttr: Int ) : super (
61- context,
62- attrs,
63- defStyleAttr
64- )
42+ constructor (context: Context , attrs: AttributeSet ? , defStyleAttr: Int ) : super (context, attrs, defStyleAttr) {
43+ initView(context)
44+ }
6545
66- init {
46+ private fun initView ( context : Context ) {
6747 inflate(context, R .layout.tap_brandview, this )
6848 poweredByImage.setImageResource(logoIcon)
6949 backTitle.text = resources.getString(R .string.back)
7050
71- // backTitle.setTextColor(loadAppThemManagerFromPath(AppColorTheme.PoweredByTapBackButtonLabelColor))
72- // imageBack.backgroundTintList =
73- // ColorStateList.valueOf(loadAppThemManagerFromPath(AppColorTheme.PoweredByTapBackButtonIconColor))
74-
75-
51+ val typeface = loadTypefaceFromLibrary(context)
7652
53+ backTitle?.typeface = typeface
7754 if (LocalizationManager .getLocale(context).language == " ar" ) {
7855 imageBack.rotation = 180f
79- backTitle?.typeface = Typeface .createFromAsset(
80- context?.assets, TapFont .tapFontType(
81- TapFont .TajawalMedium
82- )
83- )
84- }else {
85- backTitle?.typeface = Typeface .createFromAsset(
86- context?.assets, TapFont .tapFontType(
87- TapFont .RobotoRegular
88- )
89- )
9056 }
9157 }
9258
59+ private fun loadTypefaceFromLibrary (context : Context ): Typeface ? {
60+ return try {
61+ val fontPath = if (LocalizationManager .getLocale(context).language == " ar" ) {
62+ TapFont .tapFontType(TapFont .TajawalMedium )
63+ } else {
64+ TapFont .tapFontType(TapFont .RobotoRegular )
65+ }
9366
67+ // ✅ Use class loader to get library context for font access
68+ val assetManager = this .javaClass.classLoader?.let {
69+ context.createPackageContext(context.packageName, 0 ).assets
70+ } ? : context.assets
9471
95- }
72+ Typeface .createFromAsset(assetManager, fontPath)
73+
74+ } catch (e: Exception ) {
75+ e.printStackTrace()
76+ null
77+ }
78+ }
79+ }
0 commit comments