This is an Android application developed in Kotlin for the "Mobile Computing - Winter 2024" course, Assignment 2. The app tracks flight journeys and provides average flight time recommendations, including delays, as per the assignment requirements. This README documents the current implementation status and how I have addressed the assignment questions.
- Link: https://github.com/sameer-singh-godara/Flight-Tracker
- The repository is private; please ensure access is granted to the instructor via GitHub for evaluation.
- Utilizing the API and Downloading Data (5 marks):
- Implemented
AviationStackApi.ktto interface with the AviationStack API, fetching flight data using multiple API keys for redundancy. ThegetFlightDatafunction supports queries by flight number, status, and airport codes. The user inputs the flight number, and the app fetches the corresponding data from the API.
- Implemented
- Creation of the UI (5 marks):
- Designed
activity_main.xmlwith aConstraintLayoutandLinearLayoutcontaining an input field for flight numbers, buttons for tracking, stats, and history, a progress bar, error text, and a scrollable details section withflightNumberText,mainContentText, andlastUpdatedText.
- Designed
- Parsing of JSON Files (5 marks):
- Defined
FlightResponse.ktand nested data classes (FlightData,Departure,Arrival, etc.) to parse JSON responses from the API into structured Kotlin objects using GsonConverterFactory.
- Defined
- Proper Output and Running Code (10 marks):
- In
MainActivity.kt, theupdateUIfunction displays flight details (e.g., airline, departure/arrival times, live tracking) inmainContentText. The app runs with minute-by-minute refresh using aHandler, and the code handles API responses successfully.
- In
- Validation of User Input, Proper Error Messages, and Running App (5 marks):
- Added input validation in
trackFlightto check for empty flight numbers, displaying errors viashowError. Multiple API key attempts ensure robustness, with error messages like "All API keys exhausted" shown if all fail.
- Added input validation in
- Creation of Database and Schema (10 marks):
- Created
FlightStatsDatabase.ktusing Room to manage aflight_statstable, withFlightStatsEntity.ktdefining columns forid,route,durationMinutes,delayMinutes, andtimestamp. A migration from version 1 to 2 adds thedelayMinutescolumn.
- Created
- Insertion of Data into the Database and Sending Queries (10 marks):
- Implemented
saveFlightStatsinMainActivity.ktto insert flight data into the database.FlightStatsDao.ktincludesinsertandgetRouteHistoryqueries to store and retrieve data.
- Implemented
- Identification of Cases Where Calculation is Necessary, and Computing It (10 marks):
- Added
calculateFlightDurationandcalculateRouteStatsinMainActivity.ktto compute flight durations and average delays based on scheduled times and delays fromFlightData. The average duration is calculated by first taking the input flight number from the user, then the API fetches its route, and another call is made to find other flights running on that route.updateStatsUIdisplays these averages.
- Added
- Creation of Background Jobs (10 marks):
- Implemented
RouteStatsWorker.ktusing WorkManager to run a periodic job (daily) that fetches three flights per day for a route and saves them to the database.scheduleRouteStatsJobinMainActivity.ktsets up the job with constraints.
- Implemented
- Correct Output (10 marks):
- The
showHistoryfunction retrieves and displays route history with average durations, whileupdateStatsUIshows average time and delay of flights running for the particular route. The output is formatted inmainContentTextand updates correctly.
- The
- Kotlin:
MainActivity.kt: Handles UI updates, API calls, database operations, and background job scheduling.AviationStackApi.kt: Defines the API interface with Retrofit.FlightData.kt: Data classes for JSON parsing.FlightTrackerApp.kt: Initializes the Room database.FlightStatsDao.kt: DAO for database queries.FlightStatsDatabase.kt: Room database definition.FlightStatsEntity.kt: Entity for theflight_statstable.RouteStatsWorker.kt: Background worker for route stats collection.
- XML:
activity_main.xml(UI layout).
- Enhance API error handling and optimize refresh intervals.
- Add unit tests for calculations and database operations.
- Improve UI responsiveness and add more detailed stats visualization.
- Files Uploaded: Kotlin sources, XML layouts, and this README are committed to the GitHub repository.
- Submission Method: Uploaded to both Google Classroom and the private GitHub repository https://github.com/sameer-singh-godara/Flight-Tracker.