Author: Adam Evyčędo <git@apiote.xyz>
separate arrivals and departures in favourites
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/Favourites.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/Favourites.kt index bc7ebbe9a139b516dc13113707601dffa5f0826b..11c0a85d49513a4f0720a5ca7a1854bc429b73c9 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/Favourites.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/Favourites.kt @@ -57,9 +57,9 @@ return false } val favouritesSame = oldFav.feedName == newFav.feedName && - oldFav.stopName == newFav.stopName && - oldFav.sequence == newFav.sequence && - oldFav.lines == newFav.lines + oldFav.stopName == newFav.stopName && + oldFav.sequence == newFav.sequence && + oldFav.lines == newFav.lines if (!favouritesSame) { return false @@ -74,13 +74,13 @@ return false } return oldDeparture!!.get().id == newDeparture!!.get().id && - oldDeparture!!.get().vehicle.Line == newDeparture!!.get().vehicle.Line && - oldDeparture!!.get().vehicle.Headsign == newDeparture!!.get().vehicle.Headsign && - oldDeparture!!.get().statusText( - context, - false, - lastUpdate - ) == newDeparture!!.get().statusText(context, false) + oldDeparture!!.get().vehicle.Line == newDeparture!!.get().vehicle.Line && + oldDeparture!!.get().vehicle.Headsign == newDeparture!!.get().vehicle.Headsign && + oldDeparture!!.get().statusText( + context, + false, + lastUpdate + ) == newDeparture!!.get().statusText(context, false) } } @@ -151,8 +151,12 @@ class FavouriteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val root: View = itemView.findViewById(R.id.favourite) val feedName: TextView = itemView.findViewById(R.id.feed_name) val lineIcon: ImageView = itemView.findViewById(R.id.line_icon) + val arrivalStatus: TextView = itemView.findViewById(R.id.arrival_status) val arrivalTime: TextView = itemView.findViewById(R.id.arrival_time) - val arrivalTimeFull: TextView = itemView.findViewById(R.id.departure_full_time) + val arrivalTimeFull: TextView = itemView.findViewById(R.id.arrival_full_time) + val departureStatus: TextView = itemView.findViewById(R.id.departure_status) + val departureTime: TextView = itemView.findViewById(R.id.departure_time) + val departureTimeFull: TextView = itemView.findViewById(R.id.departure_full_time) val lineName: TextView = itemView.findViewById(R.id.departure_line) val headsign: TextView = itemView.findViewById(R.id.departure_headsign) val stopHeadline: TextView = itemView.findViewById(R.id.stop_name) @@ -181,15 +185,13 @@ holder.arrivalTime.text = "" holder.arrivalTimeFull.text = "" holder.headsign.text = "" } else { - val statusTexts =event.get().statusText(context, false) + val statusTexts = event.get().statusText(context, false) val vehicle = event.get().vehicle holder.feedName.text = favourite.feedName holder.stopHeadline.text = favourite.stopName holder.lineIcon.setImageDrawable(vehicle.Line.icon(context)) holder.lineIcon.contentDescription = vehicle.Line.kind.name holder.lineName.text = vehicle.Line.name - holder.arrivalTime.text = statusTexts.first - holder.arrivalTimeFull.text = event.get().arrivalTimeString(context) holder.headsign.text = context.getString(R.string.departure_headsign, vehicle.Headsign) holder.headsign.contentDescription = @@ -197,10 +199,87 @@ context.getString( R.string.departure_headsign_content_description, vehicle.Headsign ) + + with(event.get()) { + if (arrivalTime == departureTime) { + holder.arrivalStatus.visibility = View.GONE + holder.arrivalTime.visibility = View.GONE + holder.arrivalTimeFull.visibility = View.GONE + holder.departureTime.apply { + text = statusTexts.second + visibility = View.VISIBLE + } + holder.departureTimeFull.apply { + text = departureTimeString(context) + visibility = View.VISIBLE + } + if (!exact) { + holder.departureStatus.apply { + text = context.getString(R.string.approximately) + visibility = View.VISIBLE + } + } else { + holder.departureStatus.visibility = View.GONE + } + } else { + if (arrivalTime != null) { + holder.arrivalTimeFull.apply { + visibility = View.VISIBLE + text = arrivalTimeString(context) + } + holder.arrivalTime.apply { + visibility = View.VISIBLE + text = statusTexts.first + } + holder.arrivalStatus.apply { + visibility = View.VISIBLE + text = if (!exact) { + context.getString(R.string.arrival_approximate) + } else { + context.getString(R.string.arrival) + } + } + } else { + holder.arrivalStatus.visibility = View.GONE + holder.arrivalTime.visibility = View.GONE + holder.arrivalTimeFull.visibility = View.GONE + } + if (departureTime != null) { + holder.departureTimeFull.apply { + visibility = View.VISIBLE + text = departureTimeString(context) + } + holder.departureTime.apply { + visibility = View.VISIBLE + text = statusTexts.second + } + holder.departureStatus.apply { + visibility = View.VISIBLE + text = if (!exact) { + context.getString(R.string.departure_approximate) + } else { + context.getString(R.string.departure) + } + } + } else { + holder.departureStatus.visibility = View.GONE + holder.departureTime.visibility = View.GONE + holder.departureTimeFull.visibility = View.GONE + } + } + } } holder.root.setOnClickListener { - context.startActivity(DeparturesActivity.getIntent(context, favourite.stopCode, favourite.stopName, favourite.feedID, favourite.lines.toTypedArray())) + context.startActivity( + DeparturesActivity.getIntent( + context, + favourite.stopCode, + favourite.stopName, + favourite.feedID, + favourite.lines.toTypedArray() + ) + ) } } } 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 6e375b9056ef7f69e650ef9f137ce9debc822557..4940f08af9d4ad035a6363e1565b3c5d890fdafc 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 @@ -123,10 +123,12 @@ visibility = View.VISIBLE text = context?.getString(R.string.approximately) } } else { - holder?.arrivalStatus?.visibility = View.GONE + holder?.arrivalStatus?.visibility = View.INVISIBLE } - holder?.arrivalStatus?.visibility = View.GONE - holder?.arrivalTime?.text = statusTexts.first + holder?.arrivalTime?.apply{ + text = statusTexts.first + visibility = View.VISIBLE + } holder?.departureStatus?.visibility = View.GONE holder?.departureTime?.visibility = View.GONE } else { @@ -388,7 +390,10 @@ } } else { findViewById<TextView>(R.id.arrival_status).visibility = View.GONE } - findViewById<TextView>(R.id.arrival_time).text = event.arrivalTimeString(ctx) + findViewById<TextView>(R.id.arrival_time).apply { + text = event.arrivalTimeString(ctx) + visibility = View.VISIBLE + } findViewById<TextView>(R.id.departure_status).visibility = View.GONE findViewById<TextView>(R.id.departure_time).visibility = View.GONE } else { diff --git a/app/src/main/res/layout/departure.xml b/app/src/main/res/layout/departure.xml index c1310c161e81ddac5ab13247ebbc4d3a6a354c08..c3d8f14918808281ed2d6ce28a9ac3855f866213 100644 --- a/app/src/main/res/layout/departure.xml +++ b/app/src/main/res/layout/departure.xml @@ -18,9 +18,9 @@ android:id="@+id/line_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_marginStart="8dp" - app:layout_constraintBottom_toTopOf="@+id/departure_headsign" + app:layout_constraintBottom_toBottomOf="@+id/departure_line" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="@+id/arrival_time" + app:layout_constraintTop_toTopOf="@+id/departure_line" tool:ignore="ContentDescription" tool:srcCompat="@drawable/bus_black" /> @@ -77,6 +77,7 @@ android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall" app:layout_constraintEnd_toStartOf="@id/arrival_time" + app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toEndOf="@+id/line_icon" app:layout_constraintTop_toTopOf="parent" tool:text="Circle" /> diff --git a/app/src/main/res/layout/favourite.xml b/app/src/main/res/layout/favourite.xml index e6d8ea9e5c3dbbd3ba471413765bea8240f1cf2e..95a9c6df8a26ff0f088dff74b94e33c311ccc7e5 100644 --- a/app/src/main/res/layout/favourite.xml +++ b/app/src/main/res/layout/favourite.xml @@ -45,10 +45,20 @@ android:layout_height="24dp" android:layout_marginStart="8dp" app:layout_constraintBottom_toTopOf="@+id/departure_headsign" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="@+id/arrival_time" + app:layout_constraintTop_toTopOf="@+id/departure_line" tool:ignore="ContentDescription" tool:srcCompat="@drawable/bus_black" /> + <com.google.android.material.textview.MaterialTextView + android:id="@+id/arrival_status" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginTop="8dp" + android:textAppearance="@style/TextAppearance.Material3.LabelSmall" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + tool:text="approx. arr." /> <com.google.android.material.textview.MaterialTextView android:id="@+id/arrival_time" android:layout_width="wrap_content" @@ -56,17 +66,47 @@ android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="@+id/departure_line" + app:layout_constraintTop_toBottomOf="@+id/arrival_status" tool:text="1hr" /> <com.google.android.material.textview.MaterialTextView - android:id="@+id/departure_full_time" + android:id="@+id/arrival_full_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/TextAppearance.Material3.LabelSmall" app:layout_constraintEnd_toEndOf="@+id/arrival_time" app:layout_constraintTop_toBottomOf="@+id/arrival_time" + tool:text="18:55" /> + + <com.google.android.material.textview.MaterialTextView + android:id="@+id/departure_status" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginTop="8dp" + android:textAppearance="@style/TextAppearance.Material3.LabelSmall" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="@+id/departure_line" + tool:text="approx. dep." /> + <com.google.android.material.textview.MaterialTextView + android:id="@+id/departure_time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@+id/departure_status" + tool:text="1hr" /> + + <com.google.android.material.textview.MaterialTextView + android:id="@+id/departure_full_time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="4dp" + android:textAppearance="@style/TextAppearance.Material3.LabelSmall" + app:layout_constraintEnd_toEndOf="@+id/departure_time" + app:layout_constraintTop_toBottomOf="@+id/departure_time" tool:text="18:55" /> <com.google.android.material.textview.MaterialTextView