LineSuggestion.kt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package ml.adamsprogs.bimba.models.suggestions
  2. import android.content.Context
  3. import ml.adamsprogs.bimba.R
  4. import ml.adamsprogs.bimba.models.gtfs.Route
  5. class LineSuggestion(name: String, private val route: Route) : GtfsSuggestion(name) {
  6. override fun getIcon(): Int {
  7. return when (route.type) {
  8. Route.TYPE_BUS -> R.drawable.ic_bus
  9. Route.TYPE_TRAM -> R.drawable.ic_tram
  10. else -> R.drawable.ic_vehicle
  11. }
  12. }
  13. override fun getBody(context: Context): String {
  14. return name
  15. }
  16. override fun getColour(): Int {
  17. return route.colour
  18. }
  19. override fun getBgColour(): Int {
  20. return route.textColour
  21. }
  22. override fun compareTo(other: GtfsSuggestion): Int {
  23. return if (other is LineSuggestion)
  24. name.padStart(3, '0').compareTo(other.name.padStart(3, '0'))
  25. else
  26. name.compareTo(other.name)
  27. }
  28. override fun equals(other: Any?): Boolean {
  29. if (other == null || other !is GtfsSuggestion)
  30. return false
  31. return if (other is LineSuggestion)
  32. name.padStart(3, '0') == other.name.padStart(3, '0')
  33. else
  34. name == other.name
  35. }
  36. override fun hashCode(): Int {
  37. var result = route.hashCode()
  38. result = 31 * result + name.hashCode()
  39. return result
  40. }
  41. }