-
Notifications
You must be signed in to change notification settings - Fork 0
Android article for Additional Details #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matiasholst
wants to merge
6
commits into
main
Choose a base branch
from
android/additional-details
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5f58046
Added article for additional details
matiasholst 64a4319
Update sdks-and-frameworks/android/additional-location-details.md
matiasholst c8bbcde
moved link below search in summary
matiasholst e7d5ed3
added additional details docs for ios
a39a543
Apply suggestions from code review
5b2dc2a
Merge pull request #178 from MapsPeople/ios/additional-details
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
sdks-and-frameworks/android/additional-location-details.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
|
|
||
| # Additional Location Details | ||
|
|
||
| MapsIndoors locations can have a variety of additional details, such as phone numbers, websites, emails, and opening hours. These details can be managed in the CMS, read [this article](products/cms/additional-location-details.md) for how to set them up or edit them. | ||
|
|
||
| This guide shows how to access and display these details in your Android app, both in code and in a Jetpack Compose UI. | ||
|
|
||
| --- | ||
|
|
||
| ## Accessing Additional Details in Code | ||
|
|
||
| Each `MPLocation` object contains an `additionalDetails` property, which is a list of detail objects. Each detail has a type, value, key, and other fields. You can iterate through these details and handle them according to their type. | ||
|
|
||
| {% code title="Print all details example" overflow="wrap" lineNumbers="true" %} | ||
| ```kotlin | ||
| fun printDetails(location: MPLocation) { | ||
| // Get the list of additional details from the location | ||
| val details = location.additionalDetails | ||
| if (details.isNullOrEmpty()) return // No details to print | ||
|
|
||
| for (detail in details) { | ||
| // Only print active details | ||
| if (detail.active != true) continue | ||
|
|
||
| // Print a message depending on the detail type | ||
| print( | ||
| when (detail.detailType) { | ||
| MPDetailType.Text -> | ||
| // Text details (e.g. description) | ||
| "${location.name} additional information: ${detail.value}" | ||
| MPDetailType.Phone -> | ||
| // Phone details (all details have a key for identification) | ||
| "${location.name}'s phone number (${detail.key}): ${detail.value}" | ||
| MPDetailType.URL -> | ||
| // URL details (details can have user friendly display text) | ||
| "${location.name}'s website: ${detail.value} (label: ${detail.displayText})" | ||
| MPDetailType.Email -> | ||
| // Email details (details can be supplied with an icon URL) | ||
| "${location.name}'s email: ${detail.value} (icon: ${detail.icon})" | ||
| MPDetailType.OpeningHours -> | ||
| // Opening hours (has a special field 'openingHours' that is only used for this) | ||
| "${location.name} opening hours: ${detail.openingHours?.toString()}" | ||
| null -> | ||
| // Unknown detail type | ||
| "Unknown detail type for ${location.name}" | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| ``` | ||
| {% endcode %} | ||
|
|
||
| > **Note:** A single location can have multiple details of the same type. Use unique keys to distinguish them. | ||
|
|
||
| ### Filtering and Printing Specific Details | ||
|
|
||
| Your locations can have multiple details, in this case the location has mutile phone numbers: customer service and sales with the respective keys `customerService` and `sales`, you can filter and print them by key: | ||
|
|
||
| {% code title="Print specific phone numbers example" overflow="wrap" lineNumbers="true" %} | ||
| ```kotlin | ||
| fun printPhoneNumbers(location: MPLocation) { | ||
| // Get the list of additional details | ||
| val details = location.additionalDetails | ||
| if (details.isNullOrEmpty()) return | ||
|
|
||
| // Filter for phone number details | ||
| details.filter { it.detailType == MPDetailType.Phone }.forEach { phoneDetail -> | ||
| // Print a message based on the key | ||
| when (phoneDetail.key) { | ||
| "customerService" -> print("Reach Customer Service: ${phoneDetail.value}") | ||
| "sales" -> print("Reach Sales: ${phoneDetail.value}") | ||
| else -> print("Reach ${phoneDetail.displayText} number: ${phoneDetail.value}") | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| {% endcode %} | ||
|
|
||
| --- | ||
|
|
||
| ## Displaying Additional Details in Jetpack Compose UI | ||
|
|
||
| You can present additional details in your app's UI using Jetpack Compose. Below are two examples: one for showing all phone numbers, and one for showing all details in a single list. | ||
|
|
||
| ### Example: Show All Phone Numbers | ||
|
|
||
| {% code title="PhoneNumbersList composable" overflow="wrap" lineNumbers="true" %} | ||
| ```kotlin | ||
| @Composable | ||
| fun PhoneNumbersList(location: MPLocation) { | ||
| // Filter for phone number details | ||
| val phoneDetails = location.additionalDetails | ||
| ?.filter { it.detailType == MPDetailType.Phone } | ||
| .orEmpty() | ||
|
|
||
| if (phoneDetails.isEmpty()) { | ||
| // Show a message if there are no phone numbers | ||
| Text("No phone numbers available") | ||
| return | ||
| } | ||
|
|
||
| // Display each phone number in a column | ||
| Column { | ||
| phoneDetails.forEach { detail -> | ||
| // Choose a label based on the key | ||
| val label = when (detail.key) { | ||
| "customerService" -> "Customer Service" | ||
| "sales" -> "Sales" | ||
| else -> detail.displayText ?: "Other" | ||
| } | ||
| // Show the label and value | ||
| Text("$label: ${detail.value}") | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| {% endcode %} | ||
|
|
||
| --- | ||
|
|
||
| ### Example: Show All Details in a Single UI | ||
|
|
||
| You can display all available details for a location in a single composable. This example shows phone numbers, emails, URLs, text, and opening hours in a unified list, with comments explaining each step: | ||
|
|
||
| {% code title="LocationDetailsList composable" overflow="wrap" lineNumbers="true" %} | ||
| ```kotlin | ||
| @Composable | ||
| fun LocationDetailsList(location: MPLocation) { | ||
| // Get all active details for the location | ||
| val details = location.additionalDetails.orEmpty().filter { it.active == true } | ||
|
|
||
| if (details.isEmpty()) { | ||
| // Show a message if there are no details | ||
| Text("No details available") | ||
| return | ||
| } | ||
|
|
||
| // Display all details in a column, sorted by type for grouping | ||
| Column { | ||
| details.sortedBy { it.detailType?.ordinal ?: 0 }.forEach { detail -> | ||
| when (detail.detailType) { | ||
| MPDetailType.Phone -> { | ||
| // Show phone numbers with a label based on the key | ||
| val label = when (detail.key) { | ||
| "customerService" -> "Customer Service" | ||
| "sales" -> "Sales" | ||
| else -> detail.displayText ?: "Other Phone" | ||
| } | ||
| Text("$label: ${detail.value}") | ||
| } | ||
| MPDetailType.Email -> { | ||
| // Show email address | ||
| Text("Email: ${detail.value}") | ||
| } | ||
| MPDetailType.URL -> { | ||
| // Show website with display text if available | ||
| val label = detail.displayText ?: "Website" | ||
| Text("$label: ${detail.value}") | ||
| } | ||
| MPDetailType.Text -> { | ||
| // Show generic text info | ||
| Text("Info: ${detail.value}") | ||
| } | ||
| MPDetailType.OpeningHours -> { | ||
| // Show opening hours, or N/A if missing | ||
| Text("Opening hours: ${detail.openingHours?.toString() ?: "N/A"}") | ||
| } | ||
| else -> { | ||
| // Fallback for unknown types | ||
| Text("Other: ${detail.value}") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| {% endcode %} | ||
|
|
||
| This composable will show all the different types of additional details for a location in a single list, making it easy to present all relevant information to the user. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.