Bimba.git

commit cc78cefdeb6242cafbc75ea04fbec14506cf72c6

Author: Adam Evyčędo <git@apiote.xyz>

fix icons visibility in map bottom sheet

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
index 3b5808e28369577c337af7ef16bfc6ec5886d820..3db828fe006fd51ea405a73c18f9814fa71cb704 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
@@ -17,15 +17,20 @@ import android.widget.Button
 import android.widget.ImageView
 import android.widget.TextView
 import android.widget.Toast
-import androidx.constraintlayout.widget.Group
+import androidx.appcompat.widget.TooltipCompat
 import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
+import com.google.android.material.bottomsheet.BottomSheetDialog
 import com.google.android.material.bottomsheet.BottomSheetDialogFragment
 import kotlinx.coroutines.launch
+import org.osmdroid.views.MapView
 import xyz.apiote.bimba.czwek.R
 import xyz.apiote.bimba.czwek.departures.DeparturesActivity
+import xyz.apiote.bimba.czwek.dpToPixelI
+import xyz.apiote.bimba.czwek.repo.CongestionLevel
 import xyz.apiote.bimba.czwek.repo.Locatable
+import xyz.apiote.bimba.czwek.repo.OccupancyStatus
 import xyz.apiote.bimba.czwek.repo.OnlineRepository
 import xyz.apiote.bimba.czwek.repo.Position
 import xyz.apiote.bimba.czwek.repo.Stop
@@ -57,11 +62,8 @@ 		const val TAG = "MapBottomSheet"
 	}
 
 	private fun showVehicle(content: View, vehicle: Vehicle) {
-		content.findViewById<Group>(R.id.stop_group).visibility = View.GONE
-		content.findViewById<Group>(R.id.vehicle_group).visibility = View.VISIBLE
-
 		context?.let { ctx ->
-			content.findViewById<TextView>(R.id.title).apply {
+			content.findViewById<TextView>(R.id.time).apply {
 				text = ctx.getString(R.string.vehicle_headsign, vehicle.Line.name, vehicle.Headsign)
 				contentDescription = ctx.getString(
 					R.string.vehicle_headsign_content_description,
@@ -69,50 +71,103 @@ 					vehicle.Line.name,
 					vehicle.Headsign
 				)
 			}
+
+			content.findViewById<TextView>(R.id.line).visibility = View.GONE
+
+			content.findViewById<MapView>(R.id.map).visibility = View.GONE
+			content.findViewById<ImageView>(R.id.boarding_icon).visibility = View.GONE
+			content.findViewById<ImageView>(R.id.rt_icon).visibility = View.GONE
+			// TODO vehicle accessible
+			content.findViewById<ImageView>(R.id.wheelchair_icon).visibility = View.GONE
+
 			// todo units -- [3.2] settings or system-based
 			content.findViewById<TextView>(R.id.speed_text).text =
 				ctx.getString(R.string.speed_in_km_per_h, vehicle.Speed * 3.6)
-			content.findViewById<TextView>(R.id.congestion_text).text = vehicle.congestion(ctx)
-			content.findViewById<TextView>(R.id.occupancy_text).text = vehicle.occupancy(ctx)
-			content.findViewById<ImageView>(R.id.ac).visibility =
-				if (vehicle.getCapability(Vehicle.Capability.AC)) {
-					View.VISIBLE
-				} else {
-					View.GONE
-				}
-			content.findViewById<ImageView>(R.id.bike).visibility =
-				if (vehicle.getCapability(Vehicle.Capability.BIKE)) {
-					View.VISIBLE
-				} else {
-					View.GONE
-				}
-			content.findViewById<ImageView>(R.id.voice).visibility =
-				if (vehicle.getCapability(Vehicle.Capability.VOICE)) {
-					View.VISIBLE
-				} else {
-					View.GONE
-				}
-			content.findViewById<ImageView>(R.id.ticket).visibility =
-				if (vehicle.let {
-						it.getCapability(Vehicle.Capability.TICKET_DRIVER) || it.getCapability(Vehicle.Capability.TICKET_MACHINE)
-					}) {
-					View.VISIBLE
-				} else {
-					View.GONE
-				}
-			content.findViewById<ImageView>(R.id.usb).visibility =
-				if (vehicle.getCapability(Vehicle.Capability.USB_CHARGING)) {
-					View.VISIBLE
-				} else {
-					View.GONE
-				}
+
+			// XXX visibility is somehow ignored
+			content.findViewById<TextView>(R.id.congestion_text).let {
+				it.alpha =
+					if (vehicle.congestionLevel == CongestionLevel.UNKNOWN) 0f else 1f
+				it.text = vehicle.congestion(ctx)
+			}
+			content.findViewById<ImageView>(R.id.congestion_icon).alpha =
+				if (vehicle.congestionLevel == CongestionLevel.UNKNOWN) 0f else 1f
+
+			content.findViewById<TextView>(R.id.occupancy_text).let {
+				it.alpha =
+					if (vehicle.occupancyStatus == OccupancyStatus.UNKNOWN) 0f else 1f
+				it.text = vehicle.occupancy(ctx)
+			}
+			content.findViewById<ImageView>(R.id.occupancy_icon).alpha =
+				if (vehicle.occupancyStatus == OccupancyStatus.UNKNOWN) 0f else 1f
+
+			content.findViewById<ImageView>(R.id.ac).let {
+				TooltipCompat.setTooltipText(
+					it,
+					getString(R.string.air_condition_content_description)
+				)
+				it.visibility =
+					if (vehicle.getCapability(Vehicle.Capability.AC)) {
+						View.VISIBLE
+					} else {
+						View.GONE
+					}
+			}
+			content.findViewById<ImageView>(R.id.bike).let {
+				TooltipCompat.setTooltipText(
+					it,
+					getString(R.string.bicycles_allowed_content_description)
+				)
+				it.visibility =
+					if (vehicle.getCapability(Vehicle.Capability.BIKE)) {
+						View.VISIBLE
+					} else {
+						View.GONE
+					}
+			}
+			content.findViewById<ImageView>(R.id.voice).let {
+				TooltipCompat.setTooltipText(
+					it,
+					getString(R.string.voice_announcements_content_description)
+				)
+				it.visibility =
+					if (vehicle.getCapability(Vehicle.Capability.VOICE)) {
+						View.VISIBLE
+					} else {
+						View.GONE
+					}
+			}
+			content.findViewById<ImageView>(R.id.ticket).let { ticketImage ->
+				TooltipCompat.setTooltipText(
+					ticketImage,
+					getString(R.string.tickets_sold_content_description)
+				)
+				ticketImage.visibility =
+					if (vehicle.let {
+							it.getCapability(Vehicle.Capability.TICKET_DRIVER) || it.getCapability(Vehicle.Capability.TICKET_MACHINE)
+						}) {
+						View.VISIBLE
+					} else {
+						View.GONE
+					}
+			}
+			content.findViewById<ImageView>(R.id.usb).let {
+				TooltipCompat.setTooltipText(
+					it,
+					getString(R.string.usb_charging_content_description)
+				)
+				it.visibility =
+					if (vehicle.getCapability(Vehicle.Capability.USB_CHARGING)) {
+						View.VISIBLE
+					} else {
+						View.GONE
+					}
+			}
 		}
 	}
 
 	private fun showStop(content: View, stop: Stop) {
 		context?.let { ctx ->
-			content.findViewById<Group>(R.id.stop_group).visibility = View.VISIBLE
-			content.findViewById<Group>(R.id.vehicle_group).visibility = View.GONE
 			content.findViewById<TextView>(R.id.title).text = stop.name
 			content.findViewById<Button>(R.id.departures_button).setOnClickListener {
 				val intent = Intent(ctx, DeparturesActivity::class.java).apply {
@@ -150,20 +205,23 @@ 		inflater: LayoutInflater,
 		container: ViewGroup?,
 		savedInstanceState: Bundle?
 	): View {
-		val content = inflater.inflate(R.layout.map_bottom_sheet, container, false)
-		content.apply {
-			when (locatable) {
-				is Vehicle -> {
+		(dialog as BottomSheetDialog).behavior.peekHeight = dpToPixelI(110f)
+		return when (locatable) {
+			is Vehicle -> {
+				inflater.inflate(R.layout.departure_bottom_sheet, container, false).apply {
 					showVehicle(this, locatable)
 				}
+			}
 
-				is Stop -> {
+			is Stop -> {
+				inflater.inflate(R.layout.map_bottom_sheet, container, false).apply {
 					showStop(this, locatable)
 				}
 			}
+
+			else -> {
+				return inflater.inflate(R.layout.map_bottom_sheet, container, false)
+			}
 		}
-		//(dialog as BottomSheetDialog).behavior.peekHeight = dpToPixelI(90f)
-
-		return content
 	}
 }
\ No newline at end of file




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/departures/Departures.kt b/app/src/main/java/xyz/apiote/bimba/czwek/departures/Departures.kt
index 2869aa89f82c9be9f49bd2def90c97062754b177..f32543b27998684e574ff93a3c320fdda4e097aa 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/departures/Departures.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/departures/Departures.kt
@@ -11,7 +11,6 @@ import android.content.res.Configuration.UI_MODE_NIGHT_MASK
 import android.content.res.Configuration.UI_MODE_NIGHT_UNDEFINED
 import android.content.res.Configuration.UI_MODE_NIGHT_YES
 import android.os.Bundle
-import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
@@ -101,7 +100,10 @@ 		override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
 			val oldDeparture = oldDepartures[oldItemPosition]
 			val newDeparture = newDepartures[newItemPosition]
 			return oldDeparture.vehicle.Line == newDeparture.vehicle.Line && oldDeparture.vehicle.Headsign == newDeparture.vehicle.Headsign &&
-				oldDeparture.statusText(context, false, lastUpdate) == newDeparture.statusText(context, false)
+				oldDeparture.statusText(context, false, lastUpdate) == newDeparture.statusText(
+				context,
+				false
+			)
 		}
 	}
 
@@ -119,7 +121,13 @@ 		return BimbaDepartureViewHolder(rowView)
 	}
 
 	override fun onBindViewHolder(holder: BimbaDepartureViewHolder, position: Int) {
-		BimbaDepartureViewHolder.bind(departures[position], holder, context, showAsTime, onClickListener)
+		BimbaDepartureViewHolder.bind(
+			departures[position],
+			holder,
+			context,
+			showAsTime,
+			onClickListener
+		)
 	}
 
 	override fun getItemCount(): Int = departures.size
@@ -225,7 +233,7 @@ 				it.visibility =
 					if (departure.vehicle.congestionLevel == CongestionLevel.UNKNOWN) View.INVISIBLE else View.VISIBLE
 				it.text = departure.vehicle.congestion(ctx)
 			}
-			findViewById<TextView>(R.id.congestion_icon).visibility =
+			findViewById<ImageView>(R.id.congestion_icon).visibility =
 				if (departure.vehicle.congestionLevel == CongestionLevel.UNKNOWN) View.INVISIBLE else View.VISIBLE
 
 			findViewById<TextView>(R.id.occupancy_text).let {
@@ -233,7 +241,7 @@ 				it.visibility =
 					if (departure.vehicle.occupancyStatus == OccupancyStatus.UNKNOWN) View.INVISIBLE else View.VISIBLE
 				it.text = departure.vehicle.occupancy(ctx)
 			}
-			findViewById<TextView>(R.id.occupancy_icon).visibility =
+			findViewById<ImageView>(R.id.occupancy_icon).visibility =
 				if (departure.vehicle.occupancyStatus == OccupancyStatus.UNKNOWN) View.INVISIBLE else View.VISIBLE
 
 			findViewById<ImageView>(R.id.ac).let {




diff --git a/app/src/main/res/layout/map_bottom_sheet.xml b/app/src/main/res/layout/map_bottom_sheet.xml
index 24a9d0f75191b3c2fb2a4dec332d713083618041..506faff1102fcb87a8e740af19e810c5852770cb 100644
--- a/app/src/main/res/layout/map_bottom_sheet.xml
+++ b/app/src/main/res/layout/map_bottom_sheet.xml
@@ -8,7 +8,6 @@ -->
 
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 	xmlns:app="http://schemas.android.com/apk/res-auto"
-	xmlns:tool="http://schemas.android.com/tools"
 	android:layout_width="match_parent"
 	android:layout_height="wrap_content"
 	android:paddingBottom="16dp">
@@ -32,12 +31,6 @@ 		android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall"
 		app:layout_constraintEnd_toEndOf="parent"
 		app:layout_constraintStart_toStartOf="parent"
 		app:layout_constraintTop_toTopOf="parent" />
-
-	<androidx.constraintlayout.widget.Group
-		android:id="@+id/stop_group"
-		android:layout_width="wrap_content"
-		android:layout_height="wrap_content"
-		app:constraint_referenced_ids="change_options,departures_button,navigation_button" />
 
 	<com.google.android.material.textview.MaterialTextView
 		android:id="@+id/change_options"
@@ -72,144 +65,5 @@ 		app:icon="@drawable/open_outside"
 		app:layout_constraintEnd_toEndOf="parent"
 		app:layout_constraintStart_toStartOf="parent"
 		app:layout_constraintTop_toBottomOf="@+id/departures_button" />
-
-	<androidx.constraintlayout.widget.Group
-		android:id="@+id/vehicle_group"
-		android:layout_width="wrap_content"
-		android:layout_height="wrap_content"
-		app:constraint_referenced_ids="speed_icon,speed_text,congestion_icon,congestion_text,occupancy_icon,occupancy_text,ac,bike,voice,ticket,usb" />
-
-	<ImageView
-		android:id="@+id/speed_icon"
-		android:layout_width="16dp"
-		android:layout_height="16dp"
-		android:layout_marginEnd="8dp"
-		android:importantForAccessibility="no"
-		app:layout_constraintBottom_toBottomOf="@+id/speed_text"
-		app:layout_constraintEnd_toStartOf="@+id/speed_text"
-		app:layout_constraintTop_toTopOf="@+id/speed_text"
-		app:srcCompat="@drawable/speed" />
-
-	<com.google.android.material.textview.MaterialTextView
-		android:id="@+id/speed_text"
-		android:layout_width="wrap_content"
-		android:layout_height="wrap_content"
-		android:layout_marginTop="8dp"
-		android:layout_marginEnd="8dp"
-		android:textAppearance="@style/TextAppearance.Material3.BodyLarge"
-		app:layout_constraintEnd_toStartOf="@+id/middle"
-		app:layout_constraintTop_toBottomOf="@id/title"
-		tool:text="10 Vl" />
-
-	<ImageView
-		android:id="@+id/congestion_icon"
-		android:layout_width="16dp"
-		android:layout_height="16dp"
-		android:layout_marginStart="8dp"
-		android:layout_marginEnd="8dp"
-		android:importantForAccessibility="no"
-		app:layout_constraintBottom_toBottomOf="@+id/congestion_text"
-		app:layout_constraintStart_toStartOf="@+id/middle"
-		app:layout_constraintTop_toTopOf="@+id/congestion_text"
-		app:srcCompat="@drawable/traffic" />
-
-	<com.google.android.material.textview.MaterialTextView
-		android:id="@+id/congestion_text"
-		android:layout_width="wrap_content"
-		android:layout_height="wrap_content"
-		android:layout_marginStart="8dp"
-		android:layout_marginTop="8dp"
-		android:layout_marginEnd="8dp"
-		android:textAppearance="@style/TextAppearance.Material3.BodyLarge"
-		app:layout_constraintStart_toEndOf="@id/congestion_icon"
-		app:layout_constraintTop_toBottomOf="@id/title"
-		tool:text="smooth traffic" />
-
-	<ImageView
-		android:id="@+id/occupancy_icon"
-		android:layout_width="16dp"
-		android:layout_height="16dp"
-		android:layout_marginStart="8dp"
-		android:layout_marginEnd="8dp"
-		android:importantForAccessibility="no"
-		app:layout_constraintBottom_toBottomOf="@+id/occupancy_text"
-		app:layout_constraintStart_toStartOf="@+id/middle"
-		app:layout_constraintTop_toTopOf="@+id/occupancy_text"
-		app:srcCompat="@drawable/crowd" />
-
-	<com.google.android.material.textview.MaterialTextView
-		android:id="@+id/occupancy_text"
-		android:layout_width="wrap_content"
-		android:layout_height="wrap_content"
-		android:layout_marginStart="8dp"
-		android:layout_marginTop="8dp"
-		android:layout_marginEnd="8dp"
-		android:textAppearance="@style/TextAppearance.Material3.BodyLarge"
-		app:layout_constraintStart_toEndOf="@id/occupancy_icon"
-		app:layout_constraintTop_toBottomOf="@id/congestion_text"
-		tool:text="empty vehicle" />
-
-	<androidx.constraintlayout.widget.Guideline
-		android:id="@+id/middle"
-		android:layout_width="wrap_content"
-		android:layout_height="wrap_content"
-		android:orientation="vertical"
-		app:layout_constraintGuide_percent=".5" />
-
-	<androidx.constraintlayout.helper.widget.Flow
-		android:layout_width="0dp"
-		android:layout_height="wrap_content"
-		android:layout_marginStart="8dp"
-		android:layout_marginTop="16dp"
-		android:layout_marginEnd="8dp"
-		app:constraint_referenced_ids="ac,bike,voice,ticket,usb"
-		app:flow_horizontalGap="4dp"
-		app:flow_horizontalStyle="packed"
-		app:flow_verticalGap="4dp"
-		app:flow_wrapMode="chain"
-		app:layout_constraintEnd_toEndOf="parent"
-		app:layout_constraintStart_toStartOf="parent"
-		app:layout_constraintTop_toBottomOf="@+id/occupancy_text" />
-
-	<ImageView
-		android:id="@+id/ac"
-		android:layout_width="24dp"
-		android:layout_height="24dp"
-		android:contentDescription="@string/air_condition_content_description"
-		app:srcCompat="@drawable/ac"
-		tool:ignore="MissingConstraints" />
-
-	<ImageView
-		android:id="@+id/bike"
-		android:layout_width="24dp"
-		android:layout_height="24dp"
-		android:contentDescription="@string/bicycles_allowed_content_description"
-		app:srcCompat="@drawable/bike"
-		tool:ignore="MissingConstraints" />
-
-	<ImageView
-		android:id="@+id/voice"
-		android:layout_width="24dp"
-		android:layout_height="24dp"
-		android:contentDescription="@string/voice_announcements_content_description"
-		app:srcCompat="@drawable/voice"
-		tool:ignore="MissingConstraints" />
-
-	<ImageView
-		android:id="@+id/ticket"
-		android:layout_width="24dp"
-		android:layout_height="24dp"
-		android:contentDescription="@string/tickets_sold_content_description"
-		app:srcCompat="@drawable/ticket"
-		tool:ignore="MissingConstraints" />
-
-	<ImageView
-		android:id="@+id/usb"
-		android:layout_width="24dp"
-		android:layout_height="24dp"
-		android:contentDescription="@string/usb_charging_content_description"
-		app:srcCompat="@drawable/usb"
-		tool:ignore="MissingConstraints" />
-
 
 </androidx.constraintlayout.widget.ConstraintLayout>