Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RouteCell refactor to display multiple combinations of directions #48

Merged
merged 8 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 22 additions & 65 deletions app/src/main/java/com/cornellappdev/transit/models/RouteModels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.ui.graphics.Color
import com.cornellappdev.transit.ui.theme.LateRed
import com.cornellappdev.transit.ui.theme.LiveGreen
import com.cornellappdev.transit.util.TimeUtils
import java.util.Locale

/**
* Enum representing whether a bus is late
Expand All @@ -31,79 +32,35 @@ enum class BusLateness {
/**
* Class representing a total path for a route
*/
sealed class Transport {
abstract val startTime: String
abstract val arriveTime: String
abstract val lateness: BusLateness

class WalkOnly(
override val startTime: String,
override val arriveTime: String,
override val lateness: BusLateness = BusLateness.NONE,
val distance: String,
val dest: String
) : Transport()

class WalkAndBus(
override val startTime: String,
override val arriveTime: String,
val distance: String,
val start: String,
val dest: String,
val timeToBoard: Int,
val endStop: String,
val bus: Int,
override val lateness: BusLateness
) : Transport()

class BusOnly(
override val startTime: String,
override val arriveTime: String,
val distance: String,
val start: String,
val dest: String,
val transferStop: String,
val timeToBoard: Int,
val firstBus: Int,
val secondBus: Int,
override val lateness: BusLateness
) : Transport()
}
data class Transport(
val startTime: String,
val arriveTime: String,
val lateness: BusLateness,
val distance: String,
val start: String,
val walkOnly: Boolean,
val timeToBoard: Int,
val directionList: List<Direction>
)

/**
* Create a Transport object from Route
*/
@RequiresApi(Build.VERSION_CODES.O)
fun Route.toTransport(): Transport {
// TODO: We need to change the Transport class to accurately reflect all possible route configs
val allBus = this.directions.all { dir ->
dir.type == DirectionType.DEPART
}

val containsBus = this.directions.any { dir ->
dir.type == DirectionType.DEPART
}

if (allBus || containsBus) {
return Transport.BusOnly(
startTime = TimeUtils.getHHMM(this.departureTime),
arriveTime = TimeUtils.getHHMM(this.arrivalTime),
distance = String.format("%.1f", this.travelDistance),
start = this.startName,
dest = this.endName,
firstBus = this.directions[0].routeId?.toInt() ?: 0,
lateness = BusLateness.LATE,
secondBus = this.directions[1].routeId?.toInt() ?: 0,
timeToBoard = 0,
transferStop = ""

)
} else {
return Transport.WalkOnly(
startTime = TimeUtils.getHHMM(this.departureTime),
arriveTime = TimeUtils.getHHMM(this.arrivalTime),
dest = this.endName,
distance = String.format("%.1f", this.travelDistance)
)
}

return Transport(
startTime = TimeUtils.getHHMM(this.departureTime),
arriveTime = TimeUtils.getHHMM(this.arrivalTime),
distance = String.format(Locale.US, "%.1f", this.travelDistance),
start = this.startName,
walkOnly = !containsBus,
lateness = if (containsBus) BusLateness.LATE else BusLateness.NONE,
timeToBoard = 0,
directionList = this.directions
)
}
Loading