Skip to content

Commit

Permalink
Update BottomNavigationView
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangnv65 committed May 13, 2021
1 parent 583e8e8 commit 8d859d0
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vt.extendedbeaglelib.common
package com.vt.extendedbeaglelib.common.callback

import android.net.Uri

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vt.extendedbeaglelib.common
package com.vt.extendedbeaglelib.common.callback

import android.net.Uri

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vt.extendedbeaglelib.common
package com.vt.extendedbeaglelib.common.callback

import android.net.Uri

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vt.beagle_ui.common
package com.vt.extendedbeaglelib.common.enum_class

enum class FontStyle {
SEMI_BOLD,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vt.extendedbeaglelib.common
package com.vt.extendedbeaglelib.common.enum_class

import br.com.zup.beagle.core.BeagleJson

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.vt.extendedbeaglelib.common.enum_class

import br.com.zup.beagle.core.BeagleJson

@BeagleJson
enum class TabInfoType {
BEAGLE,
NATIVE
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import br.com.zup.beagle.android.action.Action
import br.com.zup.beagle.android.utils.handleEvent
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.annotation.RegisterAction
import com.vt.extendedbeaglelib.common.CapturePhotoListener
import com.vt.extendedbeaglelib.common.callback.CapturePhotoListener
import com.vt.extendedbeaglelib.common.Constants.PERMISSION_CAMERA
import com.vt.extendedbeaglelib.ui.AppBeagleActivity
import com.vt.extendedbeaglelib.utils.bus.SingleBus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import br.com.zup.beagle.android.action.Action
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.annotation.RegisterAction
import com.vt.extendedbeaglelib.R
import com.vt.extendedbeaglelib.common.Gravity
import com.vt.extendedbeaglelib.common.enum_class.Gravity
import com.vt.extendedbeaglelib.ui.FragmentDrawer

@RegisterAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import br.com.zup.beagle.android.utils.handleEvent
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.annotation.RegisterAction
import com.vt.extendedbeaglelib.common.Constants.PERMISSION_PHOTO
import com.vt.extendedbeaglelib.common.PickLocalPhotoListener
import com.vt.extendedbeaglelib.common.callback.PickLocalPhotoListener
import com.vt.extendedbeaglelib.ui.AppBeagleActivity
import com.vt.extendedbeaglelib.utils.bus.SingleBus
import com.vt.extendedbeaglelib.utils.bus.SingleBusKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.view.View
import br.com.zup.beagle.android.action.Action
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.annotation.RegisterAction
import com.vt.beagle_ui.data.model.BadgeModel
import com.vt.extendedbeaglelib.data.model.BadgeModel
import com.vt.extendedbeaglelib.utils.bus.SingleBus
import com.vt.extendedbeaglelib.utils.bus.SingleBusKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.vt.beagle_ui.data.model.BadgeModel
import com.vt.beagle_ui.data.model.TabInfo
import com.vt.extendedbeaglelib.R
import com.vt.extendedbeaglelib.common.enum_class.TabInfoType
import com.vt.extendedbeaglelib.data.model.BadgeModel
import com.vt.extendedbeaglelib.data.model.TabInfo
import com.vt.extendedbeaglelib.ui.BaseFragment
import com.vt.extendedbeaglelib.utils.bus.SingleBus
import com.vt.extendedbeaglelib.utils.bus.SingleBusKey
Expand Down Expand Up @@ -53,10 +54,10 @@ class BottomNavigationView(context: Context) : LinearLayout(context) {
}

fun setupMenu(
tabItems: List<TabInfo>,
selectedColor: String? = "#3596EC",
unselectedColor: String? = "#788793",
activity: AppCompatActivity
tabItems: List<TabInfo>,
selectedColor: String? = "#3596EC",
unselectedColor: String? = "#788793",
activity: AppCompatActivity
) {
if (tabItems.isNotEmpty()) {
val fragmentManager: FragmentManager = activity.supportFragmentManager
Expand All @@ -78,8 +79,8 @@ class BottomNavigationView(context: Context) : LinearLayout(context) {
.load(tabItems[i].remoteIconUrl)
.into(object : SimpleTarget<Drawable?>() {
override fun onResourceReady(
resource: Drawable,
@Nullable transition: Transition<in Drawable?>?
resource: Drawable,
@Nullable transition: Transition<in Drawable?>?
) {
if (i == 0) {
menu.findItem(R.id.default_page).apply {
Expand All @@ -95,7 +96,7 @@ class BottomNavigationView(context: Context) : LinearLayout(context) {
setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
}

if (i == tabItems.size-1) {
if (i == tabItems.size - 1) {
notificationMenuItemId = menuItemId
}
}
Expand All @@ -105,34 +106,45 @@ class BottomNavigationView(context: Context) : LinearLayout(context) {
}

private fun generateFragment(
tabItems: List<TabInfo>,
fragmentManager: FragmentManager)
tabItems: List<TabInfo>,
fragmentManager: FragmentManager)
{
val fragmentTransaction = fragmentManager.beginTransaction()

for (i in tabItems.indices) {
val homeFragmentInstance = BaseFragment.newInstance(tabItems[i].api) // pass the destination

fragmentTransaction.add(
R.id.server_driven_container,
homeFragmentInstance,
tabItems[i].title
)

if (i == 0) {
fragmentTransaction.show(homeFragmentInstance)
tempFragment = homeFragmentInstance
} else {
fragmentTransaction.hide(homeFragmentInstance)
if (tabItems[i].type == TabInfoType.BEAGLE) {
tabItems[i].api?.let {
val endpoint = "/beagle$it"
val homeFragmentInstance = BaseFragment.newInstance(endpoint)

fragmentTransaction.add(
R.id.server_driven_container,
homeFragmentInstance,
tabItems[i].title
)

if (i == 0) {
fragmentTransaction.show(homeFragmentInstance)
tempFragment = homeFragmentInstance
} else {
fragmentTransaction.hide(homeFragmentInstance)
}
}
} else if (tabItems[i].type == TabInfoType.NATIVE) {
tabItems[i].className?.let {
Log.d("dLog", "Native fragment -> $it")
// val nativeFragmentClass = Class.forName(it)
// val nativeFragmentInstance = nativeFragmentClass.newInstance()
}
}
}

fragmentTransaction.commit()
}

private fun setupListener(
tabItems: List<TabInfo>,
fragmentManager: FragmentManager)
tabItems: List<TabInfo>,
fragmentManager: FragmentManager)
{
navigationBar.setOnNavigationItemSelectedListener { item ->
val fragmentTransaction = fragmentManager.beginTransaction()
Expand All @@ -156,17 +168,17 @@ class BottomNavigationView(context: Context) : LinearLayout(context) {
}

private fun setNavigationTextColor(
navigationView: BottomNavigationView,
selectedColor: String? = "#3596EC",
unselectedColor: String? = "#788793"
navigationView: BottomNavigationView,
selectedColor: String? = "#3596EC",
unselectedColor: String? = "#788793"
) {
val colors = intArrayOf(
Color.parseColor(unselectedColor),
Color.parseColor(selectedColor)
Color.parseColor(unselectedColor),
Color.parseColor(selectedColor)
)
val states = arrayOf(
intArrayOf(android.R.attr.state_enabled, -android.R.attr.state_checked),
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked)
intArrayOf(android.R.attr.state_enabled, -android.R.attr.state_checked),
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked)
)

navigationView.itemTextColor = ColorStateList(states, colors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.view.View
import android.widget.LinearLayout
import com.vt.extendedbeaglelib.R
import com.vt.extendedbeaglelib.ui.AppBeagleActivity
import com.vt.extendedbeaglelib.common.ImageSetListener
import com.vt.extendedbeaglelib.common.callback.ImageSetListener
import com.vt.extendedbeaglelib.utils.bus.SingleBus
import com.vt.extendedbeaglelib.utils.bus.SingleBusKey
import com.vt.extendedbeaglelib.utils.extensions.loadGlide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.widget.LinearLayout
import android.widget.Toast
import com.github.mikephil.charting.animation.Easing
import com.github.mikephil.charting.data.PieEntry
import com.vt.beagle_ui.data.model.PieChartSlice
import com.vt.extendedbeaglelib.data.model.PieChartSlice
import com.vt.extendedbeaglelib.R
import com.vt.extendedbeaglelib.utils.extensions.updateData
import kotlinx.android.synthetic.main.layout_pie_chart.view.*
Expand All @@ -21,16 +21,16 @@ class PieChart(context: Context) : LinearLayout(context){
}

fun setupPieChart(
dataset: List<PieChartSlice>,
valueTextColor: String,
valueTextSize: Float,
sliceSpace: Float,
isHoleNeeded: Boolean,
holeRadius: Float,
holeColor: String,
holeText: String,
holeTextColor: String,
holeTextSize: Float
dataset: List<PieChartSlice>,
valueTextColor: String,
valueTextSize: Float,
sliceSpace: Float,
isHoleNeeded: Boolean,
holeRadius: Float,
holeColor: String,
holeText: String,
holeTextColor: String,
holeTextSize: Float
) {
if (dataset.isNotEmpty()) {
val listData = mutableListOf<PieEntry>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import android.view.Gravity
import android.view.View
import android.widget.LinearLayout
import br.com.zup.beagle.widget.core.TextAlignment
import com.vt.beagle_ui.common.FontStyle
import com.vt.extendedbeaglelib.common.enum_class.FontStyle
import com.vt.extendedbeaglelib.R
import kotlinx.android.synthetic.main.layout_custom_text_view.view.*

Expand All @@ -23,15 +23,15 @@ class TextView constructor(
}

fun setText(
text: String? = "",
textColor: String = "#000000",
cornerRadius: Double? = null,
backgroundColor: String? = null,
fontSize: Double = 17.0,
fontName: String? = null,
fontStyle: FontStyle = FontStyle.NORMAL,
numberOfLines: Int = 1,
textAlignment: TextAlignment = TextAlignment.LEFT
text: String? = "",
textColor: String = "#000000",
cornerRadius: Double? = null,
backgroundColor: String? = null,
fontSize: Double = 17.0,
fontName: String? = null,
fontStyle: FontStyle = FontStyle.NORMAL,
numberOfLines: Int = 1,
textAlignment: TextAlignment = TextAlignment.LEFT
) {
if (text.equals("")) {
parentBackground.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import androidx.appcompat.app.AppCompatActivity
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.android.widget.WidgetView
import br.com.zup.beagle.annotation.RegisterWidget
import com.vt.beagle_ui.data.model.TabInfo
import com.vt.extendedbeaglelib.data.model.TabInfo
import com.vt.extendedbeaglelib.components.widget_views.BottomNavigationView

@RegisterWidget
class BottomNavigationView(
private val tabItems: List<TabInfo>,
private val selectedColor: String? = "#3596EC",
private val unselectedColor: String? = "#788793"
private val tabItems: List<TabInfo>,
private val selectedColor: String? = "#3596EC",
private val unselectedColor: String? = "#788793"
): WidgetView() {
override fun buildView(rootView: RootView): View {
return BottomNavigationView(rootView.getContext()).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import br.com.zup.beagle.android.utils.handleEvent
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.android.widget.WidgetView
import br.com.zup.beagle.annotation.RegisterWidget
import com.vt.extendedbeaglelib.common.ImageSetListener
import com.vt.extendedbeaglelib.common.callback.ImageSetListener
import com.vt.extendedbeaglelib.components.widget_views.CustomImageView
import java.io.ByteArrayOutputStream

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.android.widget.WidgetView
import br.com.zup.beagle.annotation.RegisterWidget
import br.com.zup.beagle.widget.core.TextAlignment
import com.vt.beagle_ui.common.FontStyle
import com.vt.extendedbeaglelib.common.enum_class.FontStyle
import com.vt.extendedbeaglelib.components.widget_views.TextView

@RegisterWidget
class Label(
val text: Bind<String>?,
val textColor: Bind<String>?,
val cornerRadius: Double? = null,
val backgroundColor: String? = null,
val fontSize: Double = 17.0,
val fontName: String? = null,
val fontStyle: FontStyle = FontStyle.NORMAL,
val numberOfLines: Int = 1,
val textAlignment: TextAlignment = TextAlignment.LEFT
val text: Bind<String>?,
val textColor: Bind<String>?,
val cornerRadius: Double? = null,
val backgroundColor: String? = null,
val fontSize: Double = 17.0,
val fontName: String? = null,
val fontStyle: FontStyle = FontStyle.NORMAL,
val numberOfLines: Int = 1,
val textAlignment: TextAlignment = TextAlignment.LEFT
) : WidgetView() {
override fun buildView(rootView: RootView): View {
return TextView(rootView.getContext()).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import android.view.View
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.android.widget.WidgetView
import br.com.zup.beagle.annotation.RegisterWidget
import com.vt.beagle_ui.data.model.PieChartSlice
import com.vt.extendedbeaglelib.data.model.PieChartSlice
import com.vt.extendedbeaglelib.components.widget_views.PieChart

@RegisterWidget
class PieChart(
private val dataset: List<PieChartSlice>,
private val valueTextColor: String = "#ffffff",
private val valueTextSize: Float = 12F,
private val sliceSpace: Float = 3F,
private val isHoleNeeded: Boolean = false,
private val holeRadius: Float = 0f,
private val holeColor: String = "#ffffff",
private val holeText: String = "",
private val holeTextColor: String = "#000000",
private val holeTextSize: Float = 12F,
private val width: Int = 100,
private val height: Int = 100
private val dataset: List<PieChartSlice>,
private val valueTextColor: String = "#ffffff",
private val valueTextSize: Float = 12F,
private val sliceSpace: Float = 3F,
private val isHoleNeeded: Boolean = false,
private val holeRadius: Float = 0f,
private val holeColor: String = "#ffffff",
private val holeText: String = "",
private val holeTextColor: String = "#000000",
private val holeTextSize: Float = 12F,
private val width: Int = 100,
private val height: Int = 100
): WidgetView() {
override fun buildView(rootView: RootView): View {
return PieChart(rootView.getContext()).apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vt.beagle_ui.data.model
package com.vt.extendedbeaglelib.data.model

data class BadgeModel(
val number: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vt.beagle_ui.data.model
package com.vt.extendedbeaglelib.data.model

data class PieChartSlice(
val percentage: Float,
Expand Down
Loading

0 comments on commit 8d859d0

Please sign in to comment.