First, a content store item is defined, so that map styles can be requested from it.
privateval contentStore =ContentStore()
Then fetchAvailableStyles() gets the list of map styles available for download from the online content store server.
contentStore.asyncGetStoreContentList() launches the request to get the list.
The onStarted listener is called when the content store service is started, and the list of styles download started.
The onCompleted listener is defined to detect when the list of styles download is complete.
At that point, if the list is not empty, the listener selects the first style (index 0) or the style in the middle of the list (if the list has multiple elements) and starts downloading that style automatically, though in a real-world use case, the user would select which style to download.
MainActivity overrides the onCreate() function which calls the fetchAvailableStyles() function to get the list of map styles from the content store on the server.
That function then automatically downloads and then applies a style, as soon as it obtains the list of styles.