VehicleManager
This module gets vehicle profiles from BeNomad servers (BeMap credentials required) and uses a Room Database for handling data persistence. It also provides model classes required for both Planner and Navigation modules.
Module VehicleManager
Dependencies
This module depends on other BeNomad's modules :
Core
Settings
Error Manager
Note : in order to use this module, you have to initialize the Core module with a valid purchase UUID. See the documentation of the Core module for more details.*
Other module's dependencies :
kapt "androidx.room:room-compiler:2.3.0"
implementation "com.google.code.gson:gson:2.8.7"
implementation "androidx.room:room-runtime:2.3.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.10"
implementation "androidx.core:core-ktx:1.9.0"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation "com.google.android.material:material:1.8.0"Implementation
In order to interact with the module first you need to initialize a 'VehicleRepository' instance:
private val vehicleRepository: VehicleRepository by lazy {
BeMapVehicleRepository(appContext, "your_login", "your_password", "api_url")
}
}Get manufacturers list
Here is how to fetch and get all vehicles manufacturers :
CoroutineScope(Dispatchers.IO).launch {
val error = vehicleRepository.fetchManufacturers() //saved in local database
if (error != null) {
//an error occurred
return@launch
}
val availableBrands = vehicleRepository.getAllManufacturers()
}Each time manufacturers are fetched, local database is updated.
Get vehicle models of a manufacturer
Here is how to fetch and get vehicles models of a given manufacturer :
CoroutineScope(Dispatchers.IO).launch {
val error = vehicleRepository.fetchVehicleModels(manufacturer) //saved in local database
if (error != null) {
//an error occurred
return@launch
}
val vehicleModels = vehicleRepository.getVehicleModels(manufacturer)
}This allows you to show all available models of a manufacturers. In order to reduce data consumption, this method does not download the full vehicle profile of each model. To use a vehicle for routing and navigation, you must get its full profile using its ID.
Get the full vehicle profile
Here is how to fetch and get a vehicle model with its full profile in order to use it in route computations and navigation :
CoroutineScope(Dispatchers.IO).launch {
val error = vehicleRepository.fetchFullVehicleModel(vehicleModel.id)
if (error != null) {
//an error occurred
return@launch
}
val fullVehicleModel = vehicleRepository.getVehicleModelWithId(modelId)
//You can now construct a Vehicle object with this model and use it in your route plan. Check Planner modules for more details.
}