Skip to content

Commit

Permalink
hotfix/get-font-bug
Browse files Browse the repository at this point in the history
hotfix:: getFont() bug
  • Loading branch information
qamarelsafadi authored Apr 10, 2022
2 parents 57c9554 + 52dc416 commit 5c9596b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
app:cbn_selected_icon_size="48dp"
app:cbn_selectedIconColor="@color/white"
app:cbn_titleColor="@color/white"
app:cbn_titleFont="@font/book"
app:cbn_titleFont="@font/bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ class BottomNavigationItem @JvmOverloads constructor(
set(value) {
field = value
if (allowDraw && field != null)
binding.badgeTxt.typeface = field
binding.badgeTxt.typeface = value
}

private var titleFont: Typeface? = null
var titleFont: Typeface? = null
set(value) {
field = value
if (allowDraw && field != null)
binding.titleTxt.typeface = field
binding.titleTxt.typeface = value
}

var rippleColor = 0
Expand Down Expand Up @@ -223,17 +223,14 @@ class BottomNavigationItem @JvmOverloads constructor(
var isItemSelected = false
set(value) {
field = value
val d = GradientDrawable()
if (isTextVisible == 1) binding.titleTxt.gone()
val d = GradientDrawable()
d.setColor(circleColor)
d.shape = GradientDrawable.OVAL
if (!isItemSelected) {
binding.fl.background = RippleDrawable(ColorStateList.valueOf(rippleColor), null, d)
} else {
if (isItemSelected) {
{
binding.fl.setBackgroundColor(Color.TRANSPARENT)
}.withDelay(200)

}
}

Expand Down Expand Up @@ -283,12 +280,13 @@ class BottomNavigationItem @JvmOverloads constructor(
animateProgress(false, isAnimate)
isItemSelected = false
binding.titleTxt.visible()
binding.iconIv.setMargins(0,2,0,0)
binding.iconIv.setMargins(0, 2, 0, 0)
}

fun selectedItem(isAnimate: Boolean = true) {
if (!isItemSelected)
if (!isItemSelected){
animateProgress(true, isAnimate)
}
isItemSelected = true
binding.titleTxt.gone()
val layoutParams = binding.fabView.layoutParams as FrameLayout.LayoutParams
Expand All @@ -298,7 +296,7 @@ class BottomNavigationItem @JvmOverloads constructor(
val iconTvParams = binding.iconIv.layoutParams as LinearLayout.LayoutParams
iconTvParams.gravity = Gravity.CENTER
binding.iconIv.layoutParams = iconTvParams
binding.iconIv.setMargins(0,12,0,0)
binding.iconIv.setMargins(0, 12, 0, 0)
}

private fun animateProgress(enableCell: Boolean, isAnimate: Boolean = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.Gravity
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.annotation.RequiresApi
import androidx.core.content.res.ResourcesCompat
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.navigation.NavController
import com.qamar.curvedbottomnaviagtion.enum.NavigationType
Expand Down Expand Up @@ -208,13 +209,18 @@ class CurvedBottomNavigation : FrameLayout {
getColor(R.styleable.CurvedBottomNavigationView_cbn_rippleColor, rippleColor)
shadowColor =
getColor(R.styleable.CurvedBottomNavigationView_cbn_shadowColor, shadowColor)
val typeface = getFont(R.styleable.CurvedBottomNavigationView_cbn_badgeFont)
if (typeface != null)
badgeFontType = typeface
val typefaceTitle = getFont(R.styleable.CurvedBottomNavigationView_cbn_badgeFont)
if (typefaceTitle != null)
titleFontType = typefaceTitle

if (hasValue(R.styleable.CurvedBottomNavigationView_cbn_badgeFont)) {
val fontId = getResourceId(R.styleable.CurvedBottomNavigationView_cbn_badgeFont, -1)
val typeface = ResourcesCompat.getFont(context, fontId)
badgeFontType = typeface
}
if (hasValue(R.styleable.CurvedBottomNavigationView_cbn_titleFont)) {
val fontId = getResourceId(R.styleable.CurvedBottomNavigationView_cbn_titleFont, -1)
val typeface = ResourcesCompat.getFont(context, fontId)
if (typeface != null)
titleFontType = typeface
}
hasAnimation =
getBoolean(
R.styleable.CurvedBottomNavigationView_cbn_hasAnimation,
Expand Down Expand Up @@ -323,6 +329,7 @@ class CurvedBottomNavigation : FrameLayout {
it.badgeTextColor = badgeTextColor
it.badgeBackgroundColor = badgeBackgroundColor
it.badgeFont = badgeFontType
it.titleFont = titleFontType
it.iconSize = iconSize
it.selectedIconSize = selectedIconSize
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -86,3 +87,11 @@ fun View.setMargins(
requestLayout()
}
}
fun Any.log(tag: String = "") {
if (tag.equals("")) {
Log.d("TAG_QMR", this.toString())
} else {
Log.d("TAG_QMR $tag", this.toString())

}
}

0 comments on commit 5c9596b

Please sign in to comment.