Skip to content
Victory Square Partners

Insight

Continuing the Compose Multiplatform Journey: Weather and AI at Your Fingertips

7AM In The Morning You hit snooze too many times. Rain's hammering down like the sky's personally offended by your morning. Your smartwatch pings: "Grab the boots. Ditch the white shirt.”A buzz from your pocket: “Pack…

Insight· Cata Vanciu

7AM In The Morning

You hit snooze too many times.

Rain’s hammering down like the sky’s personally offended by your morning. Your smartwatch pings: “Grab the boots. Ditch the white shirt.”A buzz from your pocket: “Pack an umbrella - storms clearing by lunch.”

Magic? Nah, just what happens when your AI assistant actually pays attention to the world outside.

Introduction: Where We Left Off and Where We’re Heading Now

Last time, we talked big: the exciting vision of building a smart AI assistant using Compose Multiplatform (CMP). We explored CMP’s power to create stunning UIs across Android, iOS, desktop, web, and even wearables, all from a single Kotlin codebase. The objective was clear: an intelligent companion, unified across devices, designed to simplify daily life.

Now comes the next step: making our assistant truly intelligent by connecting it to the real world. This is the first chapter in our “Foundation” series - where we’ll systematically build the core capabilities that transform a simple app into an intelligent companion.

Environmental Awareness: The Big Picture

A smart assistant should understand its environment - weather conditions, location context, calendar events, and personal preferences. This comprehensive awareness is what transforms a simple app into an intelligent companion.

Our Starting Point: Weather-Based Clothing Advice

For this implementation, we’re focusing on one specific but practical capability: intelligent clothing recommendations based on real-time weather data.

We’ll integrate weather APIs with Gemini AI to create an assistant that understands current conditions and suggests what to wear accordingly. It’s a focused approach that delivers immediate value while establishing the foundation for more sophisticated features.

Ready to make your assistant weather-smart? Let’s dive into the technical details.

Extended AI Assistant Architecture: Connecting to the Real World

Our initial AI assistant concept aimed for a robust core, focusing on future conversational abilities and consistent UI over all platforms. To fulfill its promise as an intelligent, anticipatory companion, it first needs to perceive and react to its environment. This is where we start building its “awareness.”

The goal for this stage of our assistant is practical yet powerful: imagine our future AI not just answering questions, but proactively telling you, based on the real weather outside, what outfit might be best for your day. This capability transforms a concept into a truly insightful and useful application.

To begin building this awareness, we’re focusing on two core architectural additions to our Compose Multiplatform project:

  • The Weather API Network Module: This module will be our app’s “eyes” on the outside world. It’s designed to fetch up-to-the-minute weather conditions, like temperature, precipitation, and wind, from a chosen external weather service.

  • The Gemini AI Integration Module: This is where the initial spark of our assistant’s “intelligence” will reside. We’ll feed the raw weather data into the Gemini AI model. Gemini will then process this information, combined with carefully crafted prompts, to generate natural language suggestions for appropriate attire.

The planned data flow for this new functionality is straightforward: our assistant first gets the user’s location (currently just a hardcoded value). This location then goes to the Weather API to retrieve current weather data. That weather data, along with specific instructions, is then sent to the Gemini AI. Gemini processes this input and returns smart clothing recommendations. Finally, these AI-generated suggestions are seamlessly displayed within our Compose Multiplatform UI. This structured approach is how we’re starting to build our intelligent assistant, one smart feature at a time.

Technical Deep Dive: Integrating the Weather API

To imbue our assistant with real-world awareness, our first step was to integrate a reliable weather data source. For this, we chose OpenWeatherMap due to its widespread adoption and straightforward API. Our objective was simple: fetch current weather conditions for a specified city.

To handle our network requests, we leveraged Ktor Client, a powerful and flexible HTTP client specifically designed for Kotlin Multiplatform. For deserializing the JSON responses into usable Kotlin objects, we opted for kotlinx.serialization, which integrates seamlessly with Ktor.

Our approach to fetching data involved a direct API call to OpenWeatherMap’s current weather endpoint. Here’s a simplified look at the request:

As you can see, we pass the city name (using the q parameter) and our weatherApiKey as essential parameters. The q parameter is a common convention in API design, serving as a shorthand for “query.” In this case, it tells the OpenWeatherMap API to search for weather data based on the city name we provide.

Upon receiving a successful response, OpenWeatherMap provides a JSON payload containing various weather details. To make this data easily accessible and type-safe in our Kotlin code, we defined several data classes using kotlinx.serialization annotations:

This clear data modeling allows us to easily extract essential information like temperature (temp), humidity (humidity), and the weather’s main condition (main) and description.