Skip to content

Design and Architecture

Jonathan Chen edited this page Mar 20, 2024 · 3 revisions

Data Source

The NetworkApi interface provides the structure for backend API calls (i.e. GET vs. POST and request bodies). The actual OkHttp/Retrofit client is provided by Dagger code generation, which is specified in NetworkModule.

The RouteRepository singleton is the origin of all network calls to the backend. To accomplish this, RouteRepository interfaces with NetworkApi. Once RouteRepository retrieves data, it is emitted through Flows corresponding to the data retrieved. These Flows are accessible from the ViewModels which have a reference to the RouteRepository singleton.

The UserPreferencesRepository singleton is the origin of all requests for locally stored data. This is to store favorites and preferences. UserPreferencesRepository uses DataStores to set and retrieve values from local storage.

ViewModels

HomeViewModel

The HomeViewModel exposes stopFlow, the list of all stops, to its Views. The list of all stops is used primarily for searching. Searching uses a StateFlow searchQuery of the current query in the search bar and combines it with stopFlow to create a new Flow with a list of search-filtered stops. This new queryFlow is exposed to its Views.

HomeViewModel also exposes lastRouteFlow, which holds the data from the last request to backend for possible routes.

RouteViewModel

TODO

FavoritesViewModel

TODO

Views

HomeScreen updates its UI through the Flows exposed from HomeViewModel.

RouteScreen updates its UI using lastRouteFlow and calls the ViewModel function getRoute to get new updated data from lastRouteFlow.

Clone this wiki locally