Author: Adam Evyčędo <git@apiote.xyz>
handle stop alerts
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt index d7b5e04ee08a2a9ad3261b7c57fbc19f1be4b1f2..38af68e15afc52a001ccc1b82da91fec2e6c0b7a 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt @@ -61,6 +61,7 @@ private val linesFilter = mutableMapOf() private val linesFilterTemporary = mutableMapOf<String, Boolean>() private var startTime: LocalTime = LocalTime.MIN private var endTime: LocalTime = LocalTime.MAX + private var alertDescriptions: String = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -80,7 +81,24 @@ linesFilterTemporary.forEach { linesFilter[it.key] = it.value } getDepartures() } + binding.moreButton.setOnClickListener { + MaterialAlertDialogBuilder(this) + .setTitle("Alerts") + .setPositiveButton(R.string.ok) { _, _ -> } + .setMessage(alertDescriptions) + } + viewModel.departures.observe(this) { stopDepartures -> + if (stopDepartures.alerts.isNotEmpty()) { + binding.alerts.visibility = View.VISIBLE + binding.alertsText.text = stopDepartures.alerts.joinToString(separator = "\n") { it.header } + alertDescriptions = stopDepartures.alerts.map { it.description }.filter { it != "" } + .joinToString(separator = "\n") + binding.moreButton.visibility = if (alertDescriptions == "") View.GONE else View.VISIBLE + + } else { + binding.alerts.visibility = View.GONE + } updateItems( stopDepartures.departures .filter { d -> diff --git a/app/src/main/res/layout/activity_departures.xml b/app/src/main/res/layout/activity_departures.xml index 810a40970deda47a8f5b21fc10695ef66a555e3f..873f304d42f6344e8c7ee0e9c769214f00d61b22 100644 --- a/app/src/main/res/layout/activity_departures.xml +++ b/app/src/main/res/layout/activity_departures.xml @@ -23,6 +23,7 @@ android:visibility="gone" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <com.google.android.material.card.MaterialCardView + android:id="@+id/alerts" android:layout_width="match_parent" android:layout_height="100dp" app:cardBackgroundColor="?attr/colorSurface" @@ -35,6 +36,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.textview.MaterialTextView + android:id="@+id/alerts_text" android:layout_width="0dp" android:layout_marginStart="8dp" android:layout_marginEnd="8dp"