Skip to content

Commit

Permalink
remove item badges, refactor code, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimsn98 committed Apr 10, 2020
1 parent d7f09cd commit 3f920bd
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 486 deletions.
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,6 @@ bottomBar.setOnItemReselectedListener(object: OnItemReselectedListener {
})
```

- Add badge to a specific item
```kotlin
bottomBar.setBadge(1, Badge(
badgeSize = 20F,
badgeBoxCornerRadius = 8F,
badgeColor = ContextCompat.getColor(this , R.color.colorBadge),
badgeText = "99+",
badgeTextColor = Color.BLACK,
badgeType = BadgeType.BOX // or BadgeType.CIRCLE
))

bottomBar.removeBadge(1)
```

## Customization

```xml
Expand Down Expand Up @@ -133,6 +119,37 @@ dependencies {
}
```

## Contributors ✨
<table>
<tr>
<td align="center">
<a href="https://github.com/brookmg">
<img src="https://avatars3.githubusercontent.com/u/7487888?s=460&u=7ba52b250536b301987aaa350f605bbaf3ffa8ed&v=4" width="100px;" alt=""/><br />
<sub><b>brookmg</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/rezaepsilon0">
<img src="https://avatars0.githubusercontent.com/u/18679475?s=460&u=a5e771cc32bff987aceccafa55edab06a8aa804f&v=4" width="100px;" alt=""/><br />
<sub><b>rezaepsilon0</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/amitdash291">
<img src="https://avatars2.githubusercontent.com/u/18529185?s=460&v=4" width="100px;" alt=""/><br />
<sub><b>amitdash291</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/tobiasschuerg">
<img src="https://avatars2.githubusercontent.com/u/1324555?s=460&v=4" width="100px;" alt=""/><br />
<sub><b>tobiasschuerg</b></sub>
</a>
</td>
</tr>
</table>


## License

```
Expand Down
26 changes: 0 additions & 26 deletions app/src/main/java/me/ibrahimsn/smoothbottombar/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package me.ibrahimsn.smoothbottombar

import android.graphics.Color
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import kotlinx.android.synthetic.main.activity_main.*
import me.ibrahimsn.lib.Badge
import me.ibrahimsn.lib.BadgeType

class MainActivity : AppCompatActivity(R.layout.activity_main) {

Expand All @@ -20,27 +16,5 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
bottomBar.onItemReselected = {
status.text = "Item $it re-selected"
}

// Delay 1 second before drawing the badges ( just to notice the animation )
bottomBar.postDelayed({
bottomBar.setBadge(0, Badge(
badgeSize = 12F,
badgeColor = ContextCompat.getColor(this , R.color.colorBadge)
))

bottomBar.setBadge(1, Badge(
badgeSize = 20F,
badgeBoxCornerRadius = 8F,
badgeColor = ContextCompat.getColor(this , R.color.colorBadge),
badgeText = "99+",
badgeTextColor = Color.BLACK,
badgeType = BadgeType.BOX
))
} , 1000);

// Remove the badge from item at index 0 after 4 seconds
bottomBar.postDelayed({
bottomBar.removeBadge(0)
} , 4000);
}
}
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
app:backgroundColor="@color/colorPrimary"
app:textColor="@color/colorTextPrimary"
app:textSize="14sp"
app:cornerRadius="10dp"
app:iconSize="24dp"
app:indicatorColor="#2DFFFFFF"
app:indicatorRadius="10dp"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.6.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
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Oct 25 12:42:27 EET 2019
#Fri Apr 10 16:03:05 EET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
16 changes: 0 additions & 16 deletions lib/src/main/java/me/ibrahimsn/lib/Badge.kt

This file was deleted.

9 changes: 0 additions & 9 deletions lib/src/main/java/me/ibrahimsn/lib/BadgeType.kt

This file was deleted.

7 changes: 3 additions & 4 deletions lib/src/main/java/me/ibrahimsn/lib/BottomBarItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package me.ibrahimsn.lib
import android.graphics.RectF
import android.graphics.drawable.Drawable

data class BottomBarItem(
data class BottomBarItem (
var title: String,
val icon: Drawable,
var rect: RectF = RectF(),
var alpha: Int,
var badge: Badge?
)
var alpha: Int
)
10 changes: 7 additions & 3 deletions lib/src/main/java/me/ibrahimsn/lib/BottomBarParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class BottomBarParser(private val context: Context, @XmlRes res: Int) {
for (index in 0 until attributeCount) {
when (parser.getAttributeName(index)) {
ICON_ATTRIBUTE ->
itemDrawable = ContextCompat.getDrawable(context, parser.getAttributeResourceValue(index, 0))
itemDrawable = ContextCompat.getDrawable(
context,
parser.getAttributeResourceValue(index, 0)
)

TITLE_ATTRIBUTE -> {
itemText = try {
context.getString(parser.getAttributeResourceValue(index, 0))
Expand All @@ -50,6 +54,6 @@ class BottomBarParser(private val context: Context, @XmlRes res: Int) {
if (itemDrawable == null)
throw Throwable("Item icon can not be null!")

return BottomBarItem(itemText ?: "", itemDrawable, alpha = 0, badge = null)
return BottomBarItem(itemText ?: "", itemDrawable, alpha = 0)
}
}
}
3 changes: 0 additions & 3 deletions lib/src/main/java/me/ibrahimsn/lib/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ object Constants {

const val OPAQUE = 255
const val TRANSPARENT = 0

const val COS_45 = 0.525321988
const val SHADOW_MULTIPLIER = 1.5f
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package me.ibrahimsn.lib

interface OnItemReselectedListener {
fun onItemReselect(pos: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package me.ibrahimsn.lib

interface OnItemSelectedListener {
fun onItemSelect(pos: Int)
}
}
Loading

0 comments on commit 3f920bd

Please sign in to comment.