@@ -56,9 +56,11 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
5656
5757 private val topArrow: ImageView
5858 private val bottomArrow: ImageView
59+ private val buildingButton: ImageView
5960
6061 private var indoorFloors: List <IndoorFloor > = emptyList()
6162 private var selectedFloorId: String? = null
63+ private var isBuildingSelected = false
6264 private lateinit var presenter: IndoorSelectorPluginImpl
6365
6466 init {
@@ -75,11 +77,20 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
7577 cornerRadius = cornerRadiusPx
7678 }
7779
78- addView(scrollView, LayoutParams (itemHeightPx, LayoutParams .WRAP_CONTENT ))
80+ buildingButton = createBuildingButton()
81+ addView(buildingButton)
82+
83+ val scrollParams = LayoutParams (itemHeightPx, LayoutParams .WRAP_CONTENT ).apply {
84+ topMargin = itemHeightPx
85+ }
86+ addView(scrollView, scrollParams)
7987
8088 topArrow = createArrowButton(isUp = true )
8189 bottomArrow = createArrowButton(isUp = false )
8290
91+ (topArrow.layoutParams as LayoutParams ).topMargin = itemHeightPx
92+ (bottomArrow.layoutParams as LayoutParams ).topMargin = itemHeightPx
93+
8394 addView(topArrow)
8495 addView(bottomArrow)
8596
@@ -141,6 +152,10 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
141152 setTextSize(TypedValue .COMPLEX_UNIT_SP , FLOOR_LABEL_TEXT_SIZE_SP )
142153
143154 setOnClickListener {
155+ if (isBuildingSelected) {
156+ isBuildingSelected = false
157+ updateBuildingButtonStyle()
158+ }
144159 if (::presenter.isInitialized) {
145160 presenter.onFloorSelected(level.id)
146161 }
@@ -165,7 +180,8 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
165180 for (i in 0 until containerLayout.childCount) {
166181 val view = containerLayout.getChildAt(i) as TextView
167182 val level = indoorFloors.getOrNull(i) ? : continue
168- val isActive = level.id == activeId
183+ // When building button is active, no floor appears highlighted
184+ val isActive = ! isBuildingSelected && level.id == activeId
169185
170186 view.setBackgroundColor(if (isActive) selectedBg else Color .TRANSPARENT )
171187 view.setTextColor(if (isActive) selectedTxt else normalTxt)
@@ -174,7 +190,8 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
174190
175191 private fun updateContainerHeight () {
176192 val visibleCount = indoorFloors.size.coerceAtMost(MAX_VISIBLE_ITEMS )
177- val targetHeight = visibleCount * itemHeightPx
193+ // Add 1 for the building button
194+ val targetHeight = (visibleCount + 1 ) * itemHeightPx
178195
179196 updateLayoutParams {
180197 it.height = targetHeight
@@ -217,6 +234,45 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
217234 }
218235 }
219236
237+ private fun createBuildingButton () = ImageView (context).apply {
238+ scaleType = ImageView .ScaleType .CENTER_INSIDE
239+ setBackgroundColor(ContextCompat .getColor(context, R .color.mapbox_indoor_bg))
240+ setImageResource(R .drawable.mapbox_indoor_selector_building)
241+ contentDescription = context.getString(R .string.mapbox_indoorselector_building)
242+ setColorFilter(ContextCompat .getColor(context, R .color.mapbox_indoor_text), PorterDuff .Mode .SRC_IN )
243+
244+ layoutParams = LayoutParams (itemHeightPx, itemHeightPx).apply {
245+ gravity = Gravity .TOP
246+ }
247+
248+ setOnClickListener { onBuildingButtonTapped() }
249+ }
250+
251+ private fun onBuildingButtonTapped () {
252+ if (isBuildingSelected) return
253+ isBuildingSelected = true
254+ updateBuildingButtonStyle()
255+ if (::presenter.isInitialized) {
256+ presenter.onBuildingSelected()
257+ }
258+ }
259+
260+ private fun updateBuildingButtonStyle () {
261+ val bgColor = if (isBuildingSelected) {
262+ ContextCompat .getColor(context, R .color.mapbox_indoor_selected_bg)
263+ } else {
264+ ContextCompat .getColor(context, R .color.mapbox_indoor_bg)
265+ }
266+ val iconColor = if (isBuildingSelected) {
267+ ContextCompat .getColor(context, R .color.mapbox_indoor_selected_text)
268+ } else {
269+ ContextCompat .getColor(context, R .color.mapbox_indoor_text)
270+ }
271+ buildingButton.setBackgroundColor(bgColor)
272+ buildingButton.setColorFilter(iconColor, PorterDuff .Mode .SRC_IN )
273+ updateSelectionHighlight(selectedFloorId)
274+ }
275+
220276 private inline fun updateLayoutParams (block : (LayoutParams ) -> Unit ) {
221277 (layoutParams as ? LayoutParams )?.let {
222278 block(it)
0 commit comments