Bookmark Android
Setup
Add the following dependencies in the build.gradle
file of your application:
The activity launching Bookmark must handle the following configuration changes: orientation|screenSize
declared into your AndroidManifest.xml
:
Implementation
Warning
Make sure to read the modules configuration section before proceeding
This module is set up by calling BookmarkUI.getInstance()
. The singleton behaves like a builder in which each method allows you to configure the module. Then, you need to call the init()
method at the end. You should call this method in an Application
subclass.
This method takes the following parameters:
Name | Required | Description | Type | Default |
---|---|---|---|---|
context |
Context in which the module is launched | Context |
||
token |
Get your token | String |
||
configuration |
Module configuration object | AroundMeConfiguration |
null |
|
configurationJsonFile |
Module configuration JSON file name | String |
null |
Example
Navigation listener
Since the module launches its own fragments, you may want your application to be aware of navigation events.
For that, you have to set a navigation listener by calling this method before init()
.
bookmarkNavigationListenerImpl
should be the class instance implementingBookmarkNavigationListener
interface.
This interface gives you the method onBack()
for any back event between two fragments and the method onNavigate
for the reverse.
Each method has a BookmarkNavigationListener.Event
parameter you can rely on.
// Navigation events
ADD_ADDRESS_BACK_TO_FAVORITES
EXTERNAL_TO_ADD_ADDRESSES
EXTERNAL_TO_FAVORITES
FAVORITES_BACK_TO_EXTERNAL
FAVORITES_TO_JOURNEY
FAVORITES_TO_ADD_ADDRESS
FAVORITES_TO_ROADMAP
Events tracking
In order to receive the list of generated events within Bookmark module, you have to attach the tracker to the module instance.
You can call this method before or after init()
.
bookmarkTrackerImpl
should be the class instance implementingBookmarkTracker
interface.
Launching
Bookmark has a single entry point FavoriteFragment
.
Assuming you have an Activity
with a fragment container, refer to the following example to launch the entry screen fragment:
supportFragmentManager.beginTransaction().run {
replace(R.id.container_id, FavoriteFragment.newInstance(), "TAG")
addToBackStack("TAG")
commit()
}
Manipulating data
The module provides the ability to directly manipulate data for use in custom screens.
Methods
The various CRUD methods are accessed through BookmarkUI.getInstance().data
.
Create
Create a new favorite address
Param | Type | Description |
---|---|---|
address |
SharedData.AddressBookmark |
Favorite address to create |
Create a new favorite journey
Param | Type | Description |
---|---|---|
journey |
SharedData.JourneyBookmark |
Favorite journey to create |
Create a new favorite POI
Param | Type | Description |
---|---|---|
poi |
SharedData.PoiBookmark |
Favorite POI to create |
Create a new favorite station
Param | Type | Description |
---|---|---|
station |
SharedData.StationBookmark |
Favorite station to create |
Read
Fetch a favorite address data. Returns SharedData.AddressBookmark
or null
if not found.
Param | Type | Description |
---|---|---|
id |
String |
Id of the favorite address to fetch |
Fetch all favorite addresses. Returns a list of SharedData.AddressBookmark
or an empty list if there is no data.
Fetch a favorite journey data. Returns SharedData.JourneyBookmark
or null
if not found.
Param | Type | Description |
---|---|---|
travelId |
String |
Travel id of the favorite journey to fetch |
Fetch all favorite journeys. Returns a list of SharedData.JourneyBookmark
or an empty list if there is no data.
Fetch a favorite POI data. Returns SharedData.PoiBookmark
or null
if not found.
Param | Type | Description |
---|---|---|
id |
String |
Id of the favorite POI to fetch |
Fetch all favorite POIs. Returns a list of SharedData.PoiBookmark
or an empty list if there is no data.
Fetch a favorite station data. Returns SharedData.StationBookmark
or null
if not found.
Param | Type | Description |
---|---|---|
stopAreaId |
String |
Navitia stop area id of the favorite station to fetch |
lineId |
String |
Navitia line id of the favorite station to fetch |
Fetch all favorite stations. Returns a list of SharedData.StationBookmark
or an empty list if there is no data.
Update
Update an existing favorite address
Param | Type | Description |
---|---|---|
address |
SharedData.AddressBookmark |
Favorite address to update |
Update an existing favorite journey
Param | Type | Description |
---|---|---|
journey |
SharedData.JourneyBookmark |
Favorite journey to update |
Update an existing favorite POI
Param | Type | Description |
---|---|---|
poi |
SharedData.PoiBookmark |
Favorite poi to update |
Update an existing favorite station
Param | Type | Description |
---|---|---|
station |
SharedData.StationBookmark |
Favorite station to update |
Delete
Delete an existing favorite address
Param | Type | Description |
---|---|---|
id |
String |
Id of the favorite address to delete |
Delete an existing favorite journey
Param | Type | Description |
---|---|---|
travelId |
String |
Travel id of the favorite journey to delete |
Delete an existing favorite POI
Param | Type | Description |
---|---|---|
id |
String |
Id of the favorite POI to delete |
Delete an existing favorite station
Param | Type | Description |
---|---|---|
stopAreaId |
String |
Navitia stop area id of the favorite station to delete |
lineId |
String |
Navitia line id of the favorite station to delete |
Data
AddressBookmark
Name | Required | Description | Type |
---|---|---|---|
databaseId |
Unique database id | Long? |
|
id |
Unique address id | String |
|
name |
Address name | String |
|
houseNumber |
House number | Int |
|
roadName |
Address label | String |
|
postalCode |
Address postal code | String |
|
city |
Address city | String |
|
type |
Address type home , work or custom |
String |
|
additionalInformation |
Free field to save extra data | String |
JourneyBookmark
Name | Required | Description | Type |
---|---|---|---|
databaseId |
Unique database id | Long? |
|
travelId |
Unique journey id | String |
|
from |
Departure name | String |
|
fromId |
Departure Navitia id | String |
|
to |
Arrival name | String |
|
toId |
Arrival Navitia id | String |
|
sections |
Array of included journey sections | List<SharedData.SectionBookmark> |
|
isBikeSpecific |
Array of connection modes. For example: ["bike", "walking"] |
Boolean |
|
additionalInformation |
Free field to save extra data | String |
LineBookmark
Name | Required | Description | Type |
---|---|---|---|
id |
Navitia line id | String |
|
code |
Navitia line code | String |
|
textColor |
Navitia line text color in hex format | String |
|
color |
Navitia line color in hex format | String |
|
commercialModeId |
Navitia public transport commercial mode. Example: commercial_mode:Bus |
String |
|
commercialModeName |
Navitia public transport commercial name. Example: Bus |
String |
|
physicalMode |
Navitia public transport physical mode id. Example: physical_mode:Bus |
String |
|
networkId |
Navitia public transport network id. Example: network:xxx:Operator_21 |
String |
|
networkName |
Navitia public transport network name. Example: Operator 21 |
String |
SectionBookmark
Name | Required | Description | Type |
---|---|---|---|
type |
Section type. Example: public_transport |
String |
|
mode |
Section mode. Example: walking |
String |
|
lineId |
Navitia line id | String |
|
lineCode |
Navitia line code | String |
|
lineTextColor |
Navitia line text color in HEX format | String |
|
lineColor |
Navitia line color in HEX format | String |
|
commercialMode |
Navitia public transport commercial mode. Example: commercial_mode:Bus |
String |
|
physicalMode |
Navitia public transport physical mode. Example: physical_mode:Bus |
String |
|
duration |
Section duration in seconds | Int |
PoiBookmark
Name | Required | Description | Type |
---|---|---|---|
databaseId |
Unique database id | Long? |
|
id |
Unique POI id | String |
|
coords |
POI coordinates | LatLng |
|
name |
POI name | String |
|
address |
POI address | AddressBookmark |
|
type |
POI type | String |
|
typeId |
Navitia POI type id. Example: poi_type:amenity:hospital |
String |
|
providerId |
Navitia POI provider id | String |
|
additionalInformation |
Free field to save extra data | String |
StationBookmark
Name | Required | Description | Type |
---|---|---|---|
databaseId |
Unique database id | Long? |
|
stopAreaId |
Navitia stop area id | String |
|
coords |
Station coordinates | LatLng |
|
name |
Station name | String |
|
lines |
Station lines | List<SharedData.LineBookmark> |
|
additionalInformation |
Free field to save extra data | String |
Communicating with other modules or the app
Bookmark module can exchange data with or navigate to either other modules or the host application.
To do this, the host application must initialize Router
. This singleton will ensure communication between the different modules or the app. Communication will not occur unless those are registered beforehand:
Application
Some route or callbacks are delegated to the application.
If you have to receive some module data, the Router
module must register a receiver with the right parameter:
appRouterDataImpl
should be the class instance implementingAppRouter.Data
interface. We recommend using anApplication
subclass.
If you have to handle navigation between modules, the Router
module must also register a receiver:
appRouterUiImpl
should be the class instance implementingAppRouter.UI
interface. We recommend using aApplication
subclass.
Data interface methods
Param | Type | Description |
---|---|---|
id |
String |
Updated favorite station id |
Modules
Journey
Enabling
This module communicates with Journey module in order to get directions for a chosen itinerary. You should enable the go_from_go_to
parameter in the features configuration.
Method
The following method from the AppRouter.UI
interface should be implemented by the host application to enable navigation to the Journey module or any other custom screens. Note that the parameters of these methods can be ignored as needed.
override fun openJourneysViaHost(
origin: SharedData.JourneyPoint?,
destination: SharedData.JourneyPoint?,
showDirectlyAutoCompletion: Boolean,
showDirectlyJourneysSearch: Boolean
) {
// launch the journey module screen or your custom screen
}
Param | Type | Description |
---|---|---|
origin |
SharedData.JourneyPoint? |
Desired starting point of the journey. Optional |
destination |
SharedData.JourneyPoint? |
Desired endpoint of the journey. Optional |
showDirectlyAutoCompletion |
Boolean |
Directly displays the search for the starting point and/or endpoint. If true, showDirectlyJourneysSearch can only be false |
showDirectlyJourneysSearch |
Boolean |
Directly displays the journey search. If true, showDirectlyAutoCompletion can only be false |
Theming
The module uses graphical components from Material Design 3. To ensure these components function correctly and get displayed properly on the screen, it is crucial to apply the appropriate parent theme:
- Replace by the specific theme. For example:
Theme.Material3.Light.NoActionBar