NTP-15317 | FontUtil Optimization (#13784)

This commit is contained in:
Shivam Goyal
2024-11-26 17:25:53 +05:30
committed by GitHub
parent 3d8d44fb90
commit 0eee1bc5ef
933 changed files with 4539 additions and 4528 deletions

View File

@@ -19,7 +19,7 @@ import com.navi.design.calendar.model.DateTransformData
import com.navi.design.calendar.model.WeekDayData
import com.navi.design.databinding.NaviCalendarItemViewBinding
import com.navi.design.font.FontWeightEnum
import com.navi.design.utils.getFontStyle
import com.navi.design.font.getFontStyle
import java.util.*
class NaviCalendarItemView
@@ -93,7 +93,8 @@ constructor(
private fun highlightSelection() {
binding.dateTv.apply {
setTextColor(ResourcesCompat.getColor(resources, R.color.black, null))
typeface = ResourcesCompat.getFont(context, getFontStyle(FontWeightEnum.TT_MEDIUM.name))
typeface =
ResourcesCompat.getFont(context, getFontStyle(FontWeightEnum.NAVI_HEADLINE_REGULAR))
background =
ResourcesCompat.getDrawable(resources, R.drawable.circular_light_green_16dp, null)
}
@@ -113,7 +114,10 @@ constructor(
?: kotlin.run {
setTextColor(ResourcesCompat.getColor(resources, R.color.white, null))
typeface =
ResourcesCompat.getFont(context, getFontStyle(FontWeightEnum.TT_MEDIUM))
ResourcesCompat.getFont(
context,
getFontStyle(FontWeightEnum.NAVI_HEADLINE_REGULAR)
)
background =
ResourcesCompat.getDrawable(
resources,
@@ -127,7 +131,8 @@ constructor(
private fun setUnselected() {
binding.dateTv.apply {
background = null
typeface = ResourcesCompat.getFont(context, getFontStyle(FontWeightEnum.TT_REGULAR))
typeface =
ResourcesCompat.getFont(context, getFontStyle(FontWeightEnum.NAVI_BODY_REGULAR))
setTextColor(ResourcesCompat.getColor(resources, R.color.descriptionColor9, null))
}
}
@@ -137,7 +142,8 @@ constructor(
background = null
alpha = 0.3F
setTextColor(ResourcesCompat.getColor(resources, R.color.descriptionColor9, null))
typeface = ResourcesCompat.getFont(context, getFontStyle(FontWeightEnum.TT_REGULAR))
typeface =
ResourcesCompat.getFont(context, getFontStyle(FontWeightEnum.NAVI_BODY_REGULAR))
}
}
}

View File

@@ -11,6 +11,7 @@ import android.os.Build
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.databinding.BindingAdapter
import com.navi.design.font.getFont
import com.navi.design.theme.*
import com.navi.design.utils.spToPx
@@ -89,8 +90,7 @@ fun TextView.setStyleDetails(textStyle: TextStyle) {
// Retrieve values from typography and set on text view
apply {
textSize = typography.fontSize.value
typeface =
ResourcesCompat.getFont(context, typography.fontWeight.getFont(typography.fontFamily))
typeface = ResourcesCompat.getFont(context, typography.fontWeight.getFont())
letterSpacing = context.spToPx(typography.letterSpacing.value)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

View File

@@ -18,6 +18,7 @@ import androidx.appcompat.widget.AppCompatEditText
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import com.navi.design.R
import com.navi.design.font.getFontStyle
import com.navi.design.utils.*
class NaviEditText(context: Context, attrs: AttributeSet) : AppCompatEditText(context, attrs) {

View File

@@ -0,0 +1,120 @@
/*
*
* * Copyright © 2022-2024 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/
package com.navi.design.font
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import com.navi.design.R
fun getFontStyle(fontWeight: FontWeightEnum?): Int = getFontStyle(fontWeight?.name)
fun getFontStyle(fontWeightName: String?): Int =
when (fontWeightName) {
/** Navi Headline - Regular (400) */
FontWeightEnum.NAVI_HEADLINE_REGULAR.name,
FontWeightEnum.TT_MEDIUM.name,
FontWeightEnum.ROBOTO_MEDIUM.name,
FontWeightEnum.BOLD.name,
FontWeightEnum.NAVI_BOLD.name -> R.font.navi_headline_regular
/** Navi Headline - Bold (700) */
FontWeightEnum.NAVI_HEADLINE_BOLD.name,
FontWeightEnum.TT_BOLD.name -> R.font.navi_headline_bold
/** Navi Body - Regular (400) */
FontWeightEnum.NAVI_BODY_REGULAR.name,
FontWeightEnum.TT_REGULAR.name,
FontWeightEnum.ROBOTO_REGULAR.name,
FontWeightEnum.REGULAR.name,
FontWeightEnum.SEMI_BOLD.name,
FontWeightEnum.NAVI_REGULAR.name,
FontWeightEnum.NAVI_SEMI_BOLD.name -> R.font.navi_body_regular
/** Navi Body - Demi Bold (600) */
FontWeightEnum.NAVI_BODY_DEMI_BOLD.name,
FontWeightEnum.TT_SEMI_BOLD.name,
FontWeightEnum.ROBOTO_BOLD.name,
FontWeightEnum.EXTRA_BOLD.name,
FontWeightEnum.NAVI_EXTRA_BOLD.name,
FontWeightEnum.NAVI_BLACK.name -> R.font.navi_body_demi_bold
/** Fallback */
else -> R.font.navi_body_regular
}
val naviFontFamily: FontFamily =
FontFamily(
/** Navi Headline - Regular (400) */
Font(getFontStyle(FontWeightEnum.NAVI_HEADLINE_REGULAR), FontWeight.Medium),
/** Navi Headline - Bold (700) */
Font(getFontStyle(FontWeightEnum.NAVI_HEADLINE_BOLD), FontWeight.Bold),
/** Navi Body - Regular (400) */
Font(getFontStyle(FontWeightEnum.NAVI_BODY_REGULAR), FontWeight.Normal),
/** Navi Body - Demi Bold (600) */
Font(getFontStyle(FontWeightEnum.NAVI_BODY_DEMI_BOLD), FontWeight.SemiBold),
)
fun getFontWeight(fontWeight: FontWeightEnum?): FontWeight = getFontWeight(fontWeight?.name)
fun getFontWeight(fontWeightName: String?): FontWeight =
when (fontWeightName) {
/** Navi Headline - Regular (400) */
FontWeightEnum.NAVI_HEADLINE_REGULAR.name,
FontWeightEnum.TT_MEDIUM.name,
FontWeightEnum.ROBOTO_MEDIUM.name,
FontWeightEnum.BOLD.name,
FontWeightEnum.NAVI_BOLD.name -> FontWeight.Medium
/** Navi Headline - Bold (700) */
FontWeightEnum.NAVI_HEADLINE_BOLD.name,
FontWeightEnum.TT_BOLD.name -> FontWeight.Bold
/** Navi Body - Regular (400) */
FontWeightEnum.NAVI_BODY_REGULAR.name,
FontWeightEnum.TT_REGULAR.name,
FontWeightEnum.ROBOTO_REGULAR.name,
FontWeightEnum.REGULAR.name,
FontWeightEnum.SEMI_BOLD.name,
FontWeightEnum.NAVI_REGULAR.name,
FontWeightEnum.NAVI_SEMI_BOLD.name -> FontWeight.Normal
/** Navi Body - Demi Bold (600) */
FontWeightEnum.NAVI_BODY_DEMI_BOLD.name,
FontWeightEnum.TT_SEMI_BOLD.name,
FontWeightEnum.ROBOTO_BOLD.name,
FontWeightEnum.EXTRA_BOLD.name,
FontWeightEnum.NAVI_EXTRA_BOLD.name,
FontWeightEnum.NAVI_BLACK.name -> FontWeight.SemiBold
/** Fallback */
else -> FontWeight.Normal
}
fun FontWeight?.getFont(): Int = getFontStyle(this?.toEnum())
fun FontWeight?.toEnum(): FontWeightEnum =
when (this) {
/** Navi Headline - Regular (400) */
FontWeight.Medium -> FontWeightEnum.NAVI_HEADLINE_REGULAR
/** Navi Headline - Bold (700) */
FontWeight.Bold -> FontWeightEnum.NAVI_HEADLINE_BOLD
/** Navi Body - Regular (400) */
FontWeight.Normal -> FontWeightEnum.NAVI_BODY_REGULAR
/** Navi Body - Demi Bold (600) */
FontWeight.SemiBold -> FontWeightEnum.NAVI_BODY_DEMI_BOLD
/** Fallback */
else -> FontWeightEnum.NAVI_BODY_REGULAR
}

View File

@@ -8,61 +8,120 @@
package com.navi.design.font
enum class FontWeightEnum {
/** Navi Body - Regular (400) */
TT_REGULAR,
/** Navi Headline - Regular (400) */
TT_MEDIUM,
/** Navi Body - DemiBold (600) */
TT_SEMI_BOLD,
/** Navi Headline - Bold (700) */
TT_BOLD,
/** For Navi Pay usage only * */
/** ================================================================================= */
/** -------------------------- Navi Headline - Regular (400) ------------------------ */
/** ================================================================================= */
NAVI_HEADLINE_REGULAR,
NAVI_HEADLINE_BOLD,
NAVI_BODY_REGULAR,
NAVI_BODY_DEMI_BOLD,
@Deprecated("Use 'TT_REGULAR' instead.", ReplaceWith("TT_REGULAR"), DeprecationLevel.WARNING)
ROBOTO_REGULAR,
@Deprecated("Use 'TT_MEDIUM' instead.", ReplaceWith("TT_MEDIUM"), DeprecationLevel.WARNING)
@Deprecated(
message = "Use 'NAVI_HEADLINE_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_HEADLINE_REGULAR"),
level = DeprecationLevel.WARNING,
)
TT_MEDIUM,
@Deprecated(
message = "Use 'NAVI_HEADLINE_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_HEADLINE_REGULAR"),
level = DeprecationLevel.WARNING,
)
ROBOTO_MEDIUM,
@Deprecated(
"Use 'TT_SEMI_BOLD' instead.",
ReplaceWith("TT_SEMI_BOLD"),
DeprecationLevel.WARNING
message = "Use 'NAVI_HEADLINE_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_HEADLINE_REGULAR"),
level = DeprecationLevel.WARNING,
)
ROBOTO_BOLD,
@Deprecated("Use 'TT_REGULAR' instead.", ReplaceWith("TT_REGULAR"), DeprecationLevel.WARNING)
REGULAR,
@Deprecated("Use 'TT_REGULAR' instead.", ReplaceWith("TT_REGULAR"), DeprecationLevel.WARNING)
SEMI_BOLD,
@Deprecated("Use 'TT_MEDIUM' instead.", ReplaceWith("TT_MEDIUM"), DeprecationLevel.WARNING)
BOLD,
@Deprecated(
"Use 'TT_SEMI_BOLD' instead.",
ReplaceWith("TT_SEMI_BOLD"),
DeprecationLevel.WARNING
message = "Use 'NAVI_HEADLINE_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_HEADLINE_REGULAR"),
level = DeprecationLevel.WARNING,
)
NAVI_BOLD,
/** ================================================================================= */
/** -------------------------- Navi Headline - Bold (700) --------------------------- */
/** ================================================================================= */
NAVI_HEADLINE_BOLD,
@Deprecated(
message = "Use 'NAVI_HEADLINE_BOLD' instead.",
replaceWith = ReplaceWith(expression = "NAVI_HEADLINE_BOLD"),
level = DeprecationLevel.WARNING,
)
TT_BOLD,
/** ================================================================================= */
/** -------------------------- Navi Body - Regular (400) ---------------------------- */
/** ================================================================================= */
NAVI_BODY_REGULAR,
@Deprecated(
message = "Use 'NAVI_BODY_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_REGULAR"),
level = DeprecationLevel.WARNING,
)
TT_REGULAR,
@Deprecated(
message = "Use 'NAVI_BODY_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_REGULAR"),
level = DeprecationLevel.WARNING,
)
ROBOTO_REGULAR,
@Deprecated(
message = "Use 'NAVI_BODY_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_REGULAR"),
level = DeprecationLevel.WARNING,
)
REGULAR,
@Deprecated(
message = "Use 'NAVI_BODY_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_REGULAR"),
level = DeprecationLevel.WARNING,
)
SEMI_BOLD,
@Deprecated(
message = "Use 'NAVI_BODY_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_REGULAR"),
level = DeprecationLevel.WARNING,
)
NAVI_REGULAR,
@Deprecated(
message = "Use 'NAVI_BODY_REGULAR' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_REGULAR"),
level = DeprecationLevel.WARNING,
)
NAVI_SEMI_BOLD,
/** ================================================================================= */
/** -------------------------- Navi Body - Demi Bold (600) -------------------------- */
/** ================================================================================= */
NAVI_BODY_DEMI_BOLD,
@Deprecated(
message = "Use 'NAVI_BODY_DEMI_BOLD' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_DEMI_BOLD"),
level = DeprecationLevel.WARNING,
)
TT_SEMI_BOLD,
@Deprecated(
message = "Use 'NAVI_BODY_DEMI_BOLD' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_DEMI_BOLD"),
level = DeprecationLevel.WARNING,
)
ROBOTO_BOLD,
@Deprecated(
message = "Use 'NAVI_BODY_DEMI_BOLD' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_DEMI_BOLD"),
level = DeprecationLevel.WARNING,
)
EXTRA_BOLD,
@Deprecated("Use 'TT_REGULAR' instead.", ReplaceWith("TT_REGULAR"), DeprecationLevel.WARNING)
NAVI_REGULAR,
@Deprecated("Use 'TT_REGULAR' instead.", ReplaceWith("TT_REGULAR"), DeprecationLevel.WARNING)
NAVI_SEMI_BOLD,
@Deprecated("Use 'TT_MEDIUM' instead.", ReplaceWith("TT_MEDIUM"), DeprecationLevel.WARNING)
NAVI_BOLD,
@Deprecated(
"Use 'TT_SEMI_BOLD' instead.",
ReplaceWith("TT_SEMI_BOLD"),
DeprecationLevel.WARNING
message = "Use 'NAVI_BODY_DEMI_BOLD' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_DEMI_BOLD"),
level = DeprecationLevel.WARNING,
)
NAVI_EXTRA_BOLD,
@Deprecated(
"Use 'TT_SEMI_BOLD' instead.",
ReplaceWith("TT_SEMI_BOLD"),
DeprecationLevel.WARNING
message = "Use 'NAVI_BODY_DEMI_BOLD' instead.",
replaceWith = ReplaceWith(expression = "NAVI_BODY_DEMI_BOLD"),
level = DeprecationLevel.WARNING,
)
NAVI_BLACK
NAVI_BLACK,
}

View File

@@ -35,13 +35,13 @@ import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.navi.design.font.FontWeightEnum
import com.navi.design.font.getFontWeight
import com.navi.design.font.naviFontFamily
import com.navi.design.theme.EF0000
import com.navi.design.theme.FF4D4D4D
import com.navi.design.theme.FFEAEA
import com.navi.design.theme.FFFFFF
import com.navi.design.theme.Grey4d4d4d
import com.navi.design.theme.getFontWeight
import com.navi.design.theme.ttComposeFontFamily
data class SnackBarConfig(
@DrawableRes val leadingIconResId: Int? = null,
@@ -92,7 +92,7 @@ fun NaviSnackBar(
Text(
color = titleColor,
text = snackBarConfig.title,
fontFamily = ttComposeFontFamily,
fontFamily = naviFontFamily,
fontWeight = getFontWeight(FontWeightEnum.NAVI_HEADLINE_REGULAR),
fontSize = titleSize,
textAlign = TextAlign.Center
@@ -101,7 +101,7 @@ fun NaviSnackBar(
Text(
color = descriptionColor,
text = snackBarConfig.description,
fontFamily = ttComposeFontFamily,
fontFamily = naviFontFamily,
fontWeight = getFontWeight(FontWeightEnum.NAVI_BODY_REGULAR),
fontSize = 12.sp
)

View File

@@ -18,8 +18,8 @@ import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import com.navi.design.R
import com.navi.design.font.getFontStyle
import com.navi.design.utils.dpToPxInInt
import com.navi.design.utils.getFontStyle
import com.navi.design.utils.getStyle
import com.navi.design.utils.setViewBackground

View File

@@ -40,7 +40,7 @@ data class NaviSpan(
override fun spanBgColor(): String? = spanBgColor
override fun fontName(): String = fontName ?: FontWeightEnum.TT_REGULAR.name
override fun fontName(): String = fontName ?: FontWeightEnum.NAVI_BODY_REGULAR.name
override fun fontSize(): Double? = fontSize

View File

@@ -1,100 +0,0 @@
/*
*
* * Copyright © 2022-2024 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/
package com.navi.design.theme
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import com.navi.design.font.FontWeightEnum
import com.navi.design.utils.Constants.TT_FONT_FAMILY
import com.navi.design.utils.getFontStyle
val composeFontFamily =
FontFamily(
Font(getFontStyle(FontWeightEnum.REGULAR), FontWeight.Normal),
Font(getFontStyle(FontWeightEnum.SEMI_BOLD), FontWeight.SemiBold),
Font(getFontStyle(FontWeightEnum.BOLD), FontWeight.Bold),
Font(getFontStyle(FontWeightEnum.EXTRA_BOLD), FontWeight.ExtraBold),
Font(getFontStyle(FontWeightEnum.ROBOTO_REGULAR), FontWeight.Normal),
Font(getFontStyle(FontWeightEnum.ROBOTO_MEDIUM), FontWeight.Medium),
Font(getFontStyle(FontWeightEnum.ROBOTO_BOLD), FontWeight.Bold),
)
val ttComposeFontFamily =
FontFamily(
Font(getFontStyle(FontWeightEnum.TT_MEDIUM), FontWeight.Medium),
Font(getFontStyle(FontWeightEnum.TT_BOLD), FontWeight.Bold),
Font(getFontStyle(FontWeightEnum.TT_SEMI_BOLD), FontWeight.SemiBold),
Font(getFontStyle(FontWeightEnum.TT_REGULAR), FontWeight.Normal)
)
fun getFontWeight(fontWeight: FontWeightEnum): FontWeight {
return when (fontWeight) {
FontWeightEnum.ROBOTO_REGULAR,
FontWeightEnum.REGULAR,
FontWeightEnum.TT_REGULAR,
FontWeightEnum.NAVI_BODY_REGULAR -> FontWeight.Normal
FontWeightEnum.SEMI_BOLD,
FontWeightEnum.TT_SEMI_BOLD,
FontWeightEnum.NAVI_BODY_DEMI_BOLD -> FontWeight.SemiBold
FontWeightEnum.ROBOTO_MEDIUM,
FontWeightEnum.TT_MEDIUM,
FontWeightEnum.NAVI_HEADLINE_REGULAR -> FontWeight.Medium
FontWeightEnum.ROBOTO_BOLD,
FontWeightEnum.TT_BOLD,
FontWeightEnum.BOLD,
FontWeightEnum.NAVI_HEADLINE_BOLD -> FontWeight.Bold
FontWeightEnum.EXTRA_BOLD -> FontWeight.ExtraBold
else -> FontWeight.Normal
}
}
fun getFontFamily(fontFamily: String?): FontFamily {
return when (fontFamily) {
TT_FONT_FAMILY -> ttComposeFontFamily
else -> composeFontFamily
}
}
fun getFontWeight(fontWeight: String?): FontWeight {
return when (fontWeight) {
FontWeightEnum.TT_REGULAR.name,
FontWeightEnum.ROBOTO_REGULAR.name,
FontWeightEnum.REGULAR.name,
FontWeightEnum.NAVI_REGULAR.name -> FontWeight.Normal
FontWeightEnum.TT_SEMI_BOLD.name,
FontWeightEnum.SEMI_BOLD.name,
FontWeightEnum.NAVI_EXTRA_BOLD.name -> FontWeight.SemiBold
FontWeightEnum.ROBOTO_MEDIUM.name,
FontWeightEnum.TT_MEDIUM.name,
FontWeightEnum.NAVI_BOLD.name -> FontWeight.Medium
FontWeightEnum.ROBOTO_BOLD.name,
FontWeightEnum.TT_BOLD.name,
FontWeightEnum.BOLD.name -> FontWeight.Bold
FontWeightEnum.EXTRA_BOLD.name -> FontWeight.ExtraBold
else -> FontWeight.Normal
}
}
fun FontWeight?.toEnum(fontFamily: FontFamily?) =
if (fontFamily == ttComposeFontFamily) {
when (this) {
FontWeight.Medium -> FontWeightEnum.TT_MEDIUM
FontWeight.Bold -> FontWeightEnum.TT_BOLD
else -> FontWeightEnum.TT_MEDIUM
}
} else {
when (this) {
FontWeight.Normal -> FontWeightEnum.ROBOTO_REGULAR
FontWeight.Medium -> FontWeightEnum.ROBOTO_MEDIUM
FontWeight.Bold -> FontWeightEnum.ROBOTO_BOLD
else -> FontWeightEnum.ROBOTO_REGULAR
}
}
fun FontWeight?.getFont(fontFamily: FontFamily?) = getFontStyle(this.toEnum(fontFamily))

View File

@@ -11,61 +11,62 @@ import androidx.compose.material.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.navi.design.font.naviFontFamily
val typography =
Typography(
h1 =
TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Bold,
fontSize = 32.sp,
letterSpacing = 0.6.sp,
),
h2 =
TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Bold,
fontSize = 28.sp,
letterSpacing = 0.3.sp
),
h3 =
TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.SemiBold,
fontSize = 24.sp,
letterSpacing = 0.2.sp
),
h4 =
TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 20.sp,
letterSpacing = 0.2.sp
),
subtitle1 =
TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 16.sp,
letterSpacing = 0.3.sp
),
subtitle2 =
TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
letterSpacing = 0.3.sp
),
body1 =
TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
letterSpacing = 0.2.sp
),
body2 =
TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
letterSpacing = 0.3.sp
@@ -75,7 +76,7 @@ val typography =
val Typography.title1: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 18.sp,
letterSpacing = 0.2.sp
@@ -85,7 +86,7 @@ val Typography.title1: TextStyle
val Typography.title2: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 16.sp,
letterSpacing = 0.2.sp
@@ -95,7 +96,7 @@ val Typography.title2: TextStyle
val Typography.body3: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 12.sp,
letterSpacing = 0.sp
@@ -105,7 +106,7 @@ val Typography.body3: TextStyle
val Typography.caption1: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.SemiBold,
fontSize = 12.sp,
letterSpacing = 0.3.sp
@@ -115,7 +116,7 @@ val Typography.caption1: TextStyle
val Typography.caption2: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 10.sp,
letterSpacing = 0.2.sp
@@ -125,7 +126,7 @@ val Typography.caption2: TextStyle
val Typography.caption3: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 10.sp,
letterSpacing = 0.2.sp
@@ -135,7 +136,7 @@ val Typography.caption3: TextStyle
val Typography.overline1: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 12.sp,
letterSpacing = 0.2.sp
@@ -145,7 +146,7 @@ val Typography.overline1: TextStyle
val Typography.overline2: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 8.sp,
letterSpacing = 0.2.sp
@@ -155,7 +156,7 @@ val Typography.overline2: TextStyle
val Typography.button1: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 16.sp,
letterSpacing = 0.2.sp
@@ -165,7 +166,7 @@ val Typography.button1: TextStyle
val Typography.button2: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 14.sp,
letterSpacing = 0.2.sp
@@ -175,7 +176,7 @@ val Typography.button2: TextStyle
val Typography.button3: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 12.sp,
letterSpacing = 0.2.sp
@@ -185,7 +186,7 @@ val Typography.button3: TextStyle
val Typography.link: TextStyle
get() {
return TextStyle(
fontFamily = composeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Medium,
fontSize = 14.sp,
letterSpacing = 0.2.sp
@@ -194,7 +195,7 @@ val Typography.link: TextStyle
val Typography.tt_h1: TextStyle
get() {
return TextStyle(
fontFamily = ttComposeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 32.sp,
letterSpacing = 0.sp
@@ -203,7 +204,7 @@ val Typography.tt_h1: TextStyle
val Typography.tt_h2: TextStyle
get() {
return TextStyle(
fontFamily = ttComposeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 28.sp,
letterSpacing = 0.sp
@@ -212,7 +213,7 @@ val Typography.tt_h2: TextStyle
val Typography.tt_h3: TextStyle
get() {
return TextStyle(
fontFamily = ttComposeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 24.sp,
letterSpacing = 0.sp
@@ -221,7 +222,7 @@ val Typography.tt_h3: TextStyle
val Typography.tt_h4: TextStyle
get() {
return TextStyle(
fontFamily = ttComposeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 20.sp,
letterSpacing = 0.sp
@@ -230,7 +231,7 @@ val Typography.tt_h4: TextStyle
val Typography.tt_h6: TextStyle
get() {
return TextStyle(
fontFamily = ttComposeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 18.sp,
letterSpacing = 0.sp
@@ -240,7 +241,7 @@ val Typography.tt_h6: TextStyle
val Typography.tt_title1: TextStyle
get() {
return TextStyle(
fontFamily = ttComposeFontFamily,
fontFamily = naviFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 18.sp,
letterSpacing = 0.sp

View File

@@ -1,6 +1,6 @@
/*
*
* * Copyright © 2022 by Navi Technologies Limited
* * Copyright © 2022-2024 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/

View File

@@ -52,6 +52,7 @@ import com.navi.base.utils.orFalse
import com.navi.design.R
import com.navi.design.common.CommonViewData
import com.navi.design.font.FontWeightEnum
import com.navi.design.font.getFontStyle
import com.navi.design.textview.model.NaviSpan
import com.navi.design.textview.model.SpanInterface
import com.navi.design.textview.model.TextWithStyle
@@ -343,6 +344,39 @@ fun TextView.setSpannableString(
clickCta?.let { clickListener?.invoke(it) }
}
fun TextView.changeFontStyle(fontWeight: FontWeightEnum?) {
val spannableString = SpannableStringBuilder(text)
val size = text.toString().length
spannableString.setSpan(
ResourcesCompat.getFont(context, getFontStyle(fontWeight))?.let { typeface ->
CustomTypefaceSpan(typeface)
},
0,
size,
SpannableString.SPAN_INCLUSIVE_INCLUSIVE
)
text = spannableString
}
fun TextView.changeFontColor(color: String?) {
color?.let {
val spannableString = SpannableStringBuilder(text)
val size = text.toString().length
spannableString.setSpan(
ForegroundColorSpan(it.parseColorSafe()),
0,
size,
SpannableString.SPAN_INCLUSIVE_INCLUSIVE
)
text = spannableString
}
}
fun TextView.setFontStyle(fontWeight: FontWeightEnum) {
typeface = ResourcesCompat.getFont(context, getFontStyle(fontWeight))
}
private fun getSpanGravity(gravity: String): Layout.Alignment {
return when (gravity) {
Layout.Alignment.ALIGN_OPPOSITE.name -> Layout.Alignment.ALIGN_OPPOSITE
@@ -491,10 +525,6 @@ fun ViewGroup.replaceLayout(layoutId: Int): ViewDataBinding? {
return binding
}
fun updateFontToTTMedium(style: List<NaviSpan>?) {
style?.forEach { it.fontName = FontWeightEnum.TT_MEDIUM.name }
}
fun hexColorCodePrefix(opacity: Float): String {
if (opacity <= 0) return "00"
else if (opacity <= 1) return "03"

View File

@@ -1,77 +0,0 @@
/*
*
* * Copyright © 2022-2024 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/
package com.navi.design.utils
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import com.navi.design.R
import com.navi.design.font.FontWeightEnum
fun getFontStyle(fontWeightName: String?) =
when (fontWeightName) {
FontWeightEnum.TT_REGULAR.name,
FontWeightEnum.ROBOTO_REGULAR.name,
FontWeightEnum.SEMI_BOLD.name,
FontWeightEnum.NAVI_SEMI_BOLD.name,
FontWeightEnum.REGULAR.name,
FontWeightEnum.NAVI_REGULAR.name,
FontWeightEnum.NAVI_BODY_REGULAR.name -> R.font.tt_regular
FontWeightEnum.TT_MEDIUM.name,
FontWeightEnum.ROBOTO_MEDIUM.name,
FontWeightEnum.BOLD.name,
FontWeightEnum.NAVI_BOLD.name,
FontWeightEnum.TT_MEDIUM.name,
FontWeightEnum.NAVI_HEADLINE_REGULAR.name -> R.font.tt_medium
FontWeightEnum.TT_SEMI_BOLD.name,
FontWeightEnum.ROBOTO_BOLD.name,
FontWeightEnum.EXTRA_BOLD.name,
FontWeightEnum.NAVI_EXTRA_BOLD.name,
FontWeightEnum.NAVI_BLACK.name,
FontWeightEnum.NAVI_BODY_DEMI_BOLD.name -> R.font.tt_semi_bold
FontWeightEnum.TT_BOLD.name,
FontWeightEnum.NAVI_HEADLINE_BOLD.name -> R.font.tt_bold
else -> R.font.tt_regular
}
fun getFontStyle(fontWeight: FontWeightEnum?): Int = getFontStyle(fontWeight?.name)
fun TextView.setFontStyle(fontWeight: FontWeightEnum) {
typeface = ResourcesCompat.getFont(context, getFontStyle(fontWeight))
}
fun TextView.changeFontStyle(fontWeight: FontWeightEnum?) {
val spannableString = SpannableStringBuilder(text)
val size = text.toString().length
spannableString.setSpan(
ResourcesCompat.getFont(context, getFontStyle(fontWeight))?.let { typeface ->
CustomTypefaceSpan(typeface)
},
0,
size,
SpannableString.SPAN_INCLUSIVE_INCLUSIVE
)
text = spannableString
}
fun TextView.changeFontColor(color: String?) {
color?.let {
val spannableString = SpannableStringBuilder(text)
val size = text.toString().length
spannableString.setSpan(
ForegroundColorSpan(it.parseColorSafe()),
0,
size,
SpannableString.SPAN_INCLUSIVE_INCLUSIVE
)
text = spannableString
}
}

View File

@@ -23,7 +23,7 @@
android:textColor="@color/white"
tools:text="Move the slider"
android:textSize="@dimen/sp_10"
android:fontFamily="@font/tt_regular"
android:fontFamily="@font/navi_body_regular"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +0,0 @@
/*
*
* * Copyright © 2021-2022 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/
package com.navi.design
import org.junit.Assert.*
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View File

@@ -1,70 +0,0 @@
/*
*
* * Copyright © 2023-2024 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/
package com.navi.design.utils
import DesignR.font.tt_bold
import DesignR.font.tt_medium
import DesignR.font.tt_regular
import DesignR.font.tt_semi_bold
import com.navi.base.utils.EMPTY
import com.navi.design.font.FontWeightEnum
import org.junit.Assert.assertEquals
import org.junit.Test
class FontUtilsKtTest {
@Test
fun testGetFontStyle() {
assertEquals(tt_regular, getFontStyle(fontWeightName = "TT_REGULAR"))
assertEquals(tt_regular, getFontStyle(fontWeightName = "ROBOTO_REGULAR"))
assertEquals(tt_regular, getFontStyle(fontWeightName = "SEMI_BOLD"))
assertEquals(tt_regular, getFontStyle(fontWeightName = "NAVI_SEMI_BOLD"))
assertEquals(tt_regular, getFontStyle(fontWeightName = "REGULAR"))
assertEquals(tt_regular, getFontStyle(fontWeightName = "NAVI_REGULAR"))
assertEquals(tt_medium, getFontStyle(fontWeightName = "TT_MEDIUM"))
assertEquals(tt_medium, getFontStyle(fontWeightName = "ROBOTO_MEDIUM"))
assertEquals(tt_medium, getFontStyle(fontWeightName = "BOLD"))
assertEquals(tt_medium, getFontStyle(fontWeightName = "NAVI_BOLD"))
assertEquals(tt_semi_bold, getFontStyle(fontWeightName = "TT_SEMI_BOLD"))
assertEquals(tt_semi_bold, getFontStyle(fontWeightName = "ROBOTO_BOLD"))
assertEquals(tt_semi_bold, getFontStyle(fontWeightName = "EXTRA_BOLD"))
assertEquals(tt_semi_bold, getFontStyle(fontWeightName = "NAVI_EXTRA_BOLD"))
assertEquals(tt_semi_bold, getFontStyle(fontWeightName = "NAVI_BLACK"))
assertEquals(tt_bold, getFontStyle(fontWeightName = "TT_BOLD"))
assertEquals(tt_regular, getFontStyle(fontWeightName = EMPTY))
}
@Test
fun testGetFontStyleUsingFontWeightEnum() {
assertEquals(tt_regular, getFontStyle(fontWeight = FontWeightEnum.TT_REGULAR))
assertEquals(tt_regular, getFontStyle(fontWeight = FontWeightEnum.ROBOTO_REGULAR))
assertEquals(tt_regular, getFontStyle(fontWeight = FontWeightEnum.SEMI_BOLD))
assertEquals(tt_regular, getFontStyle(fontWeight = FontWeightEnum.NAVI_SEMI_BOLD))
assertEquals(tt_regular, getFontStyle(fontWeight = FontWeightEnum.REGULAR))
assertEquals(tt_regular, getFontStyle(fontWeight = FontWeightEnum.NAVI_REGULAR))
assertEquals(tt_medium, getFontStyle(fontWeight = FontWeightEnum.TT_MEDIUM))
assertEquals(tt_medium, getFontStyle(fontWeight = FontWeightEnum.ROBOTO_MEDIUM))
assertEquals(tt_medium, getFontStyle(fontWeight = FontWeightEnum.BOLD))
assertEquals(tt_medium, getFontStyle(fontWeight = FontWeightEnum.NAVI_BOLD))
assertEquals(tt_semi_bold, getFontStyle(fontWeight = FontWeightEnum.TT_SEMI_BOLD))
assertEquals(tt_semi_bold, getFontStyle(fontWeight = FontWeightEnum.ROBOTO_BOLD))
assertEquals(tt_semi_bold, getFontStyle(fontWeight = FontWeightEnum.EXTRA_BOLD))
assertEquals(tt_semi_bold, getFontStyle(fontWeight = FontWeightEnum.NAVI_EXTRA_BOLD))
assertEquals(tt_semi_bold, getFontStyle(fontWeight = FontWeightEnum.NAVI_BLACK))
assertEquals(tt_bold, getFontStyle(fontWeight = FontWeightEnum.TT_BOLD))
assertEquals(tt_regular, getFontStyle(fontWeight = null))
}
}