A clean, modern, and production-ready Android application that displays real-time weather information and a 7-day forecast using the OpenWeatherMap API. Built with Kotlin and following modern Android development practices, this project showcases a robust implementation of the MVVM (Model-View-ViewModel) architectural pattern.
- Real-time Weather Data: Fetches live temperature, humidity, wind speed, and weather descriptions.
- Dynamic Themes: Automatically switches the app UI background and weather icons (e.g., Sunny/Cloudy/Rainy) based on current weather conditions.
- 7-Day Forecast: Displays a clean forecast list using a dynamic
RecyclerView. - Robust Error Handling: Professional status code handling (401, 404, etc.) and explicit network connectivity checks via a generic sealed class state management system.
This project leverages the official Android Jetpack libraries and modern networking tools:
- Language: Kotlin
- Architecture: MVVM (Model-View-ViewModel)
- Networking: Retrofit2 & Gson Converter (Type-safe HTTP client & JSON parser)
- HTTP Logging: OkHttp Logging Interceptor (For inspecting network requests in Logcat)
- Asynchronous Processing: Kotlin Coroutines (Non-blocking network requests)
- Jetpack Components:
ViewModel(Retains UI data through configuration changes)LiveData(Lifecycle-aware data observation)View Binding(Null-safe UI component interaction)
The code-base follows a strict layer-by-feature / layer-by-type separation to ensure clean boundaries, scalability, and ease of testing.
com.example.weatherapp/
β
βββ data/ # Data Layer (Network, Models, Repositories)
β βββ model/ # Pure Kotlin Data Classes mapped from JSON Response
β β βββ Clouds.kt
β β βββ Coord.kt
β β βββ Main.kt
β β βββ Sys.kt
β β βββ Weather.kt
β β βββ WeatherResponse.kt # Root API response model
β β βββ Wind.kt
β β
β βββ remote/ # Network Configuration Components
β β βββ WeatherApiService.kt # Retrofit Endpoint definitions interface
β β βββ RetrofitClient.kt # Singleton OkHttpClient & Retrofit provider
β β
β βββ repository/ # Single Source of Truth for Data Operations
β βββ WeatherRepository.kt # Handles API logic and maps responses to States
β
βββ ui/ # UI Layer (Activities, ViewModels, Adapters)
β βββ adapter/
β β βββ ForecastAdapter.kt # RecyclerView Adapter using View Binding for 7-day list
β β
β βββ weather/
β βββ WeatherActivity.kt # Renders UI, handles clicks, and observes ViewModel
β βββ WeatherViewModel.kt # Communicates with Repository using Coroutines & updates LiveData
β
βββ utils/ # Shared Helpers & Utility Components
βββ Constants.kt # App-wide fixed configurations (BASE_URL, API_KEY, Units)
βββ Resource.kt # Generic Sealed Class for managing API States (Loading, Success, Error)