Parking Widgets APIs
In order to interact with the Parking API, we have defined the following model that can be used.
ParkingModel
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | data class ParkingModel(
@SerializedName("shopping_cart")
val parkingShoppingCartModel: ParkingShoppingCartModel? = null,
@SerializedName("start_time")
var startTime: String? = null,
@SerializedName("end_time")
var endTime: String? = null,
@SerializedName("duration")
var duration: Int? = null,
@SerializedName("input_source")
var source: String? = null,
@SerializedName("status")
val status: VoiceStatus? = null
) : Serializable
|
Using FragmentManager
| val bundle = Bundle().apply {
putSerializable("bundle_key", parkingModel)
}
fragmentManager.beginTransaction().add(
R.id.fragment_container,
ParkingFragment::class.java,
bundle,
ParkingFragment::class.java.name
).commit()
|
Using intents
| val intent = Intent(
"com.telenav.commerce.widgets.UPDATE_PARKING_RESERVATION_WIDGET",
Uri.parse("telenav://commerce.widgets")
).apply {
putExtra("context", Gson().toJson(parkingModel))
}
context.sendBroadcast(intent)
|
Using FragmentManager
| fragmentManager.popBackStack()
|
Using intents
| val hideIntent = Intent(
"com.telenav.commerce.widgets.CLOSE_PARKING_FLOW_WIDGET",
Uri.parse("telenav://commerce.widgets")
)
context.sendBroadcast(hideIntent)
|
Once the Parking fragment is inflated into the view, its contents can be changed directly from code if needed, no user interaction with the screen being required.
There are two cases for such updates:
Selecting another route
1.User selects another route to the parking spot, affecting the ETA which modifies the start time
| val intent = Intent(
"com.telenav.commerce.widgets.UPDATE_PARKING_RESERVATION_WIDGET_FOR_ROUTE_SELECTION",
Uri.parse("telenav://commerce.widgets")
).apply {
putExtra("context", Gson().toJson(updatedRouteParkingModel))
}
context.sendBroadcast(intent)
|
Modifying the current model
2.The current model is modified by some mechanism and the app needs to update the parking widget accordingly:
| val intent = Intent(
"com.telenav.commerce.widgets.UPDATE_PARKING_RESERVATION_WIDGET",
Uri.parse("telenav://commerce.widgets")
).apply {
putExtra("context", Gson().toJson(updatedParkingModel))
}
context.sendBroadcast(intent)
|