Skip to content

Commit

Permalink
Merge pull request #68 from st235/feature/implemented_menu_class
Browse files Browse the repository at this point in the history
Feature/implemented menu class
  • Loading branch information
st235 authored Apr 3, 2021
2 parents 2964311 + 565233a commit 1ae726b
Show file tree
Hide file tree
Showing 19 changed files with 589 additions and 461 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,22 @@ Firstly, you should declare your view in xml file
app:layout_constraintStart_toStartOf="parent" />
```

Then you should add menu items to your navigation component
Then you should add menu items to your navigation menu
To access menu call `bottomBar.menu` on your navigation view

```kotlin
val bottomBar: ExpandableBottomBar = findViewById(R.id.expandable_bottom_bar)

bottomBar.addItems(
MenuItemDescriptor.Builder(context = this)
.addItem(R.id.icon_home, R.drawable.ic_bug, R.string.text, Color.GRAY)
.addItem(R.id.icon_go, R.drawable.ic_gift, R.string.text2, 0xFFFF77A9)
.addItem(R.id.icon_left, R.drawable.ic_one, R.string.text3, 0xFF58A5F0)
.addItem(R.id.icon_right, R.drawable.ic_two, R.string.text4, 0xFFBE9C91)
.build()
val menu = bottomBar.menu

menu.add(
MenuItemDescriptor.Builder(
this,
R.id.icon_home,
R.drawable.ic_home,
R.string.text,
Color.GRAY
)
.build()
)

bottomBar.onItemSelectedListener = { view, menuItem ->
Expand Down Expand Up @@ -185,7 +189,8 @@ Then you should reference this xml file at the view attributes
/**
* Returns notification object
*/
val notification = bottomBar.getMenuItemFor(i.itemId).notification() // itemId is R.id.action_id
val menu = bottomBar.menu
val notification = menu.findItemById(i.itemId).notification() // itemId is R.id.action_id

notification.show() // shows simple dot-notification
notification.show("string literal") // shows notification with counter. Counter could not exceed the 4 symbols length
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ dependencies {
implementation project(':lib-expandablebottombar')

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.4'
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import github.com.st235.expandablebottombar.R;
import github.com.st235.lib_expandablebottombar.ExpandableBottomBar;
import github.com.st235.lib_expandablebottombar.Menu;
import github.com.st235.lib_expandablebottombar.MenuItem;
import github.com.st235.lib_expandablebottombar.MenuItemDescriptor;

public class JavaActivity extends AppCompatActivity {
Expand All @@ -20,22 +22,30 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_java);

ExpandableBottomBar bottomBar = findViewById(R.id.expandable_bottom_bar);
Menu menu = bottomBar.getMenu();

bottomBar.addItems(
new MenuItemDescriptor.Builder(this)
.addItem(R.id.icon_home, R.drawable.ic_home, R.string.text, Color.GRAY)
.addItem(R.id.icon_likes, R.drawable.ic_likes, R.string.text2, 0xffff77a9)
.addItem(R.id.icon_bookmarks, R.drawable.ic_bookmarks, R.string.text3, 0xff58a5f0)
.addItem(R.id.icon_settings, R.drawable.ic_settings, R.string.text4, 0xffbe9c91)
.build()
menu.add(
new MenuItemDescriptor.Builder(this, R.id.icon_home, R.drawable.ic_home, R.string.text, Color.GRAY).build()
);

bottomBar.setOnItemSelectedListener((view, item) -> {
menu.add(
new MenuItemDescriptor.Builder(this, R.id.icon_likes, R.drawable.ic_likes, R.string.text2, 0xffff77a9).build()
);

menu.add(
new MenuItemDescriptor.Builder(this, R.id.icon_bookmarks, R.drawable.ic_bookmarks, R.string.text3, 0xff58a5f0).build()
);

menu.add(
new MenuItemDescriptor.Builder(this, R.id.icon_settings, R.drawable.ic_settings, R.string.text4, 0xffbe9c91).build()
);

bottomBar.setOnItemSelectedListener((view, item, byUser) -> {
Log.d(TAG, "selected: " + item.toString());
return null;
});

bottomBar.setOnItemReselectedListener((view, item) -> {
bottomBar.setOnItemReselectedListener((view, item, byUser) -> {
Log.d(TAG, "reselected: " + item.toString());
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.graphics.ColorUtils
import github.com.st235.expandablebottombar.R
import github.com.st235.lib_expandablebottombar.ExpandableBottomBar
import github.com.st235.lib_expandablebottombar.Notification
import kotlinx.android.synthetic.main.activity_xml_declared.*

class NotificationBadgeActivity : AppCompatActivity() {
Expand All @@ -27,7 +26,7 @@ class NotificationBadgeActivity : AppCompatActivity() {

color.setBackgroundColor(ColorUtils.setAlphaComponent(Color.GRAY, 60))

bottomBar.onItemSelectedListener = { v, i ->
bottomBar.onItemSelectedListener = { v, i, _ ->
val anim = ViewAnimationUtils.createCircularReveal(color,
bottomBar.x.toInt() + v.x.toInt() + v.width / 2,
bottomBar.y.toInt() + v.y.toInt() + v.height / 2, 0F,
Expand All @@ -37,7 +36,7 @@ class NotificationBadgeActivity : AppCompatActivity() {
anim.start()
}

bottomBar.onItemReselectedListener = { v, i ->
bottomBar.onItemReselectedListener = { v, i, _ ->
val notification = i.notification()

if (v.tag == null) {
Expand All @@ -59,7 +58,7 @@ class NotificationBadgeActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.clear -> {
for (menuItem in bottomBar.getMenuItems()) {
for (menuItem in bottomBar.menu) {
menuItem.notification().clear()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,69 @@ class ProgrammaticallyCreatedDemoActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_programmatically_declared)

val color: View = findViewById(R.id.color)
val colorView: View = findViewById(R.id.color)
val bottomBar: ExpandableBottomBar = findViewById(R.id.expandable_bottom_bar)

color.setBackgroundColor(ColorUtils.setAlphaComponent(Color.GRAY, 60))

bottomBar.addItems(
MenuItemDescriptor.Builder(this)
.addItem(
R.id.icon_home,
R.drawable.ic_home,
R.string.text, Color.GRAY)
.addItem(
R.id.icon_likes,
R.drawable.ic_likes
).textRes(R.string.text2).colorRes(
R.color.colorLike
).create()
.addItem(
R.id.icon_bookmarks,
R.drawable.ic_bookmarks,
R.string.text3, Color.parseColor("#58a5f0"))
.addItem(
R.id.icon_settings,
R.drawable.ic_settings,
R.string.text4, Color.parseColor("#be9c91"))
.build()
colorView.setBackgroundColor(ColorUtils.setAlphaComponent(Color.GRAY, 60))

val menu = bottomBar.menu

menu.add(
MenuItemDescriptor.Builder(
this,
R.id.icon_home,
R.drawable.ic_home,
R.string.text, Color.GRAY
)
.build()
)

menu.add(
MenuItemDescriptor.Builder(
this,
R.id.icon_likes,
R.drawable.ic_likes
)
.textRes(R.string.text2)
.colorRes(R.color.colorLike)
.build()
)

menu.add(
MenuItemDescriptor.Builder(
this,
R.id.icon_bookmarks,
R.drawable.ic_bookmarks,
R.string.text3,
Color.parseColor("#58a5f0")
)
.build()
)

menu.add(
MenuItemDescriptor.Builder(
this,
R.id.icon_settings,
R.drawable.ic_settings,
R.string.text4,
Color.parseColor("#be9c91")
)
.build()
)

bottomBar.onItemSelectedListener = { v, i ->
val anim = ViewAnimationUtils.createCircularReveal(color,
bottomBar.onItemSelectedListener = { v, i, _ ->
val anim = ViewAnimationUtils.createCircularReveal(
colorView,
bottomBar.x.toInt() + v.x.toInt() + v.width / 2,
bottomBar.y.toInt() + v.y.toInt() + v.height / 2, 0F,
findViewById<View>(android.R.id.content).height.toFloat())
color.setBackgroundColor(ColorUtils.setAlphaComponent(i.activeColor, 60))
findViewById<View>(android.R.id.content).height.toFloat()
)
colorView.setBackgroundColor(ColorUtils.setAlphaComponent(i.activeColor, 60))
anim.duration = 420
anim.start()
}

bottomBar.onItemReselectedListener = { _, i ->
bottomBar.onItemReselectedListener = { _, i, _ ->
Log.d("ExpandableBottomBar", "OnReselected: ${i.id}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class XmlDeclaredActivity : AppCompatActivity() {

color.setBackgroundColor(ColorUtils.setAlphaComponent(Color.GRAY, 60))

bottomBar.onItemSelectedListener = { v, i ->
bottomBar.onItemSelectedListener = { v, i, _ ->
val anim = ViewAnimationUtils.createCircularReveal(color,
bottomBar.x.toInt() + v.x.toInt() + v.width / 2,
bottomBar.y.toInt() + v.y.toInt() + v.height / 2, 0F,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package github.com.st235.expandablebottombar.screens.navigation
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI
import github.com.st235.expandablebottombar.R
import github.com.st235.lib_expandablebottombar.navigation.ExpandableBottomBarNavigationUI
import kotlinx.android.synthetic.main.activiy_navigation.*
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ android.useAndroidX=true

GROUP=com.github.st235

VERSION_CODE=42
VERSION_NAME=1.3.2
VERSION_CODE=45
VERSION_NAME=1.4.0

POM_DESCRIPTION=A new way to improve navigation in your app.
POM_URL=https://github.com/st235/ExpandableBottomBar
Expand Down
6 changes: 3 additions & 3 deletions lib-expandablebottombar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4'

testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
Loading

0 comments on commit 1ae726b

Please sign in to comment.