This project is a native Android (Kotlin) simulation of Moto's real-time bidding and negotiation platform. It demonstrates proficiency in concurrency, WebSocket handling, clean architecture, and lifecycle management.
The app adheres to Clean Architecture principles, utilising MVVM (Model-View-ViewModel) design pattern.
- Presentation Layer: Jetpack Compose (UI) + ViewModel (State Management).
- Domain Layer: Pure Kotlin models and Repository interfaces. Contains business logic isolated from the Android framework.
- Data Layer: Ktor Client for WebSockets, DTOs, and Repository implementation.
To ensure the timer remains accurate even when the app is backgrounded, or the process is paused by the OS (Doze mode), the timer does not count ticks.
Instead, it calculates the targetTime (startTime + duration) and derives the UI progress using System.currentTimeMillis().
- Advantage: If the app is backgrounded for 5 seconds, upon resuming, the timer immediately reflects the correct remaining time without "freezing" or drifting.
- Library: Ktor Client with OkHttp Engine.
- Resilience: The connection logic is wrapped in a
while(isActive)coroutine loop. - Reconnection: If the connection drops or the server is unreachable, the app catches the exception, delays for 3 seconds, and automatically attempts to reconnect.
- Server: Emits JSON events (
NEGOTIATIONorBID). - Repository: Maps DTOs to Domain Sealed Classes.
- ViewModel:
- Filters duplicate bids to prevent UI key crashes.
- Sorts bids by amount (Ascending).
- Updates the
MutableStateFlow<AuctionState>.
- UI: Consumes state via
collectAsStateWithLifecycleto ensure UI updates stop when the Activity is stopped.
- Backend: This app requires a local WebSocket server to function.
- Server Script: A Node.js mock server script (
server.js) is included in the MockServer directory. - Running:
- Ensure your phone/emulator and computer are on the same Wi-Fi.
- Update the IP address in
KtorRealTimeService.ktto your local machine's IP. - Run
node server.jsbefore launching the app.