Skip to content

Commit

Permalink
add callbacks for Java, update Kotlin version
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimsn98 committed Nov 21, 2019
1 parent 8a3232a commit 1d90df9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.3.60'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package me.ibrahimsn.lib

interface OnItemReselectedListener {
fun onItemReselect(pos: Int)
}
5 changes: 5 additions & 0 deletions lib/src/main/java/me/ibrahimsn/lib/OnItemSelectedListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package me.ibrahimsn.lib

interface OnItemSelectedListener {
fun onItemSelect(pos: Int)
}
13 changes: 13 additions & 0 deletions lib/src/main/java/me/ibrahimsn/lib/SmoothBottomBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class SmoothBottomBar : View {

private var items = listOf<BottomBarItem>()

private var onItemSelectedListener: OnItemSelectedListener? = null
private var onItemReselectedListener: OnItemReselectedListener? = null

var onItemSelected: (Int) -> Unit = {}
var onItemReselected: (Int) -> Unit = {}

Expand Down Expand Up @@ -188,8 +191,10 @@ class SmoothBottomBar : View {
if (itemId != this.activeItemIndex) {
setActiveItem(itemId)
onItemSelected(itemId)
onItemSelectedListener?.onItemSelect(itemId)
} else {
onItemReselected(itemId)
onItemReselectedListener?.onItemReselect(itemId)
}
}
}
Expand Down Expand Up @@ -249,4 +254,12 @@ class SmoothBottomBar : View {
private fun d2p(dp: Float): Float {
return resources.displayMetrics.densityDpi.toFloat() / 160.toFloat() * dp
}

fun setOnItemSelectedListener(listener: OnItemSelectedListener) {
this.onItemSelectedListener = listener
}

fun setOnItemReselectedListener(listener: OnItemReselectedListener) {
this.onItemReselectedListener = listener
}
}

0 comments on commit 1d90df9

Please sign in to comment.