Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimsn98 committed Mar 16, 2021
1 parent 51c68d8 commit 8ed0d3a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 33 deletions.
Expand Up @@ -6,9 +6,11 @@ import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
import androidx.customview.widget.ExploreByTouchHelper


class AccessibleExploreByTouchHelper(private val host : SmoothBottomBar,
private val bottomBarItems : List<BottomBarItem>,
private val onClickAction : (id : Int) -> Unit) : ExploreByTouchHelper(host) {
class AccessibleExploreByTouchHelper(
private val host : SmoothBottomBar,
private val bottomBarItems : List<BottomBarItem>,
private val onClickAction : (id : Int) -> Unit
) : ExploreByTouchHelper(host) {

override fun getVisibleVirtualViews(virtualViewIds: MutableList<Int>) {
//defining simple ids for each item of the bottombar
Expand All @@ -22,7 +24,6 @@ class AccessibleExploreByTouchHelper(private val host : SmoothBottomBar,
return (x / itemWidth).toInt()
}


@Suppress("DEPRECATION") // setBoundsInParent is required by [ExploreByTouchHelper]
override fun onPopulateNodeForVirtualView(
virtualViewId: Int,
Expand Down Expand Up @@ -54,7 +55,6 @@ class AccessibleExploreByTouchHelper(private val host : SmoothBottomBar,
return false
}


private fun updateBoundsForBottomItem(index: Int): Rect {
val itemBounds = Rect()
val itemWidth = host.width / bottomBarItems.size
Expand All @@ -65,4 +65,4 @@ class AccessibleExploreByTouchHelper(private val host : SmoothBottomBar,
itemBounds.bottom = host.height
return itemBounds
}
}
}
13 changes: 8 additions & 5 deletions lib/src/main/java/me/ibrahimsn/lib/BottomBarParser.kt
Expand Up @@ -30,6 +30,7 @@ class BottomBarParser(private val context: Context, @XmlRes res: Int) {
var itemText: String? = null
var itemDrawable: Drawable? = null
var contentDescription : String? = null

for (index in 0 until attributeCount) {
when (parser.getAttributeName(index)) {
ICON_ATTRIBUTE ->
Expand All @@ -55,20 +56,22 @@ class BottomBarParser(private val context: Context, @XmlRes res: Int) {
}
}

if (itemDrawable == null)
if (itemDrawable == null) {
throw Throwable("Item icon can not be null!")
}

return BottomBarItem(itemText ?: "",
contentDescription ?: itemText ?: "",
return BottomBarItem(
itemText.toString(),
contentDescription ?: itemText.toString(),
itemDrawable,
alpha = 0)
alpha = 0
)
}

companion object {
private const val ITEM_TAG = "item"
private const val ICON_ATTRIBUTE = "icon"
private const val TITLE_ATTRIBUTE = "title"
private const val CONTENT_DESCRIPTION_ATTRIBUTE = "contentDescription"

}
}
Expand Up @@ -12,6 +12,7 @@ import java.lang.ref.WeakReference
* Created by Mayokun Adeniyi on 24/04/2020.
*/
class NavigationComponentHelper {

companion object {

fun setupWithNavController(
Expand Down
25 changes: 3 additions & 22 deletions lib/src/main/java/me/ibrahimsn/lib/SmoothBottomBar.kt
Expand Up @@ -2,6 +2,7 @@ package me.ibrahimsn.lib

import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
Expand All @@ -24,7 +25,6 @@ import androidx.core.view.ViewCompat
import androidx.navigation.NavController
import kotlin.math.roundToInt


class SmoothBottomBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
Expand Down Expand Up @@ -239,16 +239,15 @@ class SmoothBottomBar @JvmOverloads constructor(
isFakeBoldText = true
}

private var exploreByTouchHelper : AccessibleExploreByTouchHelper

var exploreByTouchHelper : AccessibleExploreByTouchHelper
init {
obtainStyledAttributes(attrs, defStyleAttr)
exploreByTouchHelper = AccessibleExploreByTouchHelper(this, items, ::onClickAction)

ViewCompat.setAccessibilityDelegate(this, exploreByTouchHelper)
}


private fun obtainStyledAttributes(attrs: AttributeSet?, defStyleAttr: Int) {
val typedArray = context.theme.obtainStyledAttributes(
attrs,
Expand All @@ -262,77 +261,62 @@ class SmoothBottomBar @JvmOverloads constructor(
R.styleable.SmoothBottomBar_backgroundColor,
barBackgroundColor
)

barIndicatorColor = typedArray.getColor(
R.styleable.SmoothBottomBar_indicatorColor,
barIndicatorColor
)

barIndicatorRadius = typedArray.getDimension(
R.styleable.SmoothBottomBar_indicatorRadius,
barIndicatorRadius
)

barSideMargins = typedArray.getDimension(
R.styleable.SmoothBottomBar_sideMargins,
barSideMargins
)

barCornerRadius = typedArray.getDimension(
R.styleable.SmoothBottomBar_cornerRadius,
barCornerRadius
)

itemPadding = typedArray.getDimension(
R.styleable.SmoothBottomBar_itemPadding,
itemPadding
)

itemTextColor = typedArray.getColor(
R.styleable.SmoothBottomBar_textColor,
itemTextColor
)

itemTextSize = typedArray.getDimension(
R.styleable.SmoothBottomBar_textSize,
itemTextSize
)

itemIconSize = typedArray.getDimension(
R.styleable.SmoothBottomBar_iconSize,
itemIconSize
)

itemIconMargin = typedArray.getDimension(
R.styleable.SmoothBottomBar_iconMargin,
itemIconMargin
)

itemIconTint = typedArray.getColor(
R.styleable.SmoothBottomBar_iconTint,
itemIconTint
)

itemIconTintActive = typedArray.getColor(
R.styleable.SmoothBottomBar_iconTintActive,
itemIconTintActive
)

itemActiveIndex = typedArray.getInt(
R.styleable.SmoothBottomBar_activeItem,
itemActiveIndex
)

itemFontFamily = typedArray.getResourceId(
R.styleable.SmoothBottomBar_itemFontFamily,
itemFontFamily
)

itemAnimDuration = typedArray.getInt(
R.styleable.SmoothBottomBar_duration,
itemAnimDuration.toInt()
).toLong()

itemMenuRes = typedArray.getResourceId(
R.styleable.SmoothBottomBar_menu,
itemMenuRes
Expand Down Expand Up @@ -377,7 +361,6 @@ class SmoothBottomBar @JvmOverloads constructor(
applyItemActiveIndex()
}


override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)

Expand Down Expand Up @@ -466,8 +449,6 @@ class SmoothBottomBar @JvmOverloads constructor(
}
}



private fun tintAndDrawIcon(
item: BottomBarItem,
index: Int,
Expand All @@ -484,6 +465,7 @@ class SmoothBottomBar @JvmOverloads constructor(
/**
* Handle item clicks
*/
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent?): Boolean {
when(event?.action){
MotionEvent.ACTION_DOWN -> {
Expand Down Expand Up @@ -606,7 +588,6 @@ class SmoothBottomBar @JvmOverloads constructor(
}
}


companion object {
private const val INVALID_RES = -1
private const val DEFAULT_INDICATOR_COLOR = "#2DFFFFFF"
Expand Down

0 comments on commit 8ed0d3a

Please sign in to comment.