How maldonado20/countriesweathermvc works
Project Type and Purpose
• This is a native Android mobile application (Kotlin + XML) implementing an MVC architecture.
• It displays a list of world regions, then lists countries in a selected region (name, flag, capital), and finally shows details for one country including weather data for its capital.
• It consumes two external REST services: RestCountries and WeatherAPI.
File Structure Analysis
• Top-level “app/src/main/java/sv/edu/udb/countriesweather/…” is divided into three MVC folders:
• models/ — data classes reflecting JSON responses (CountryModels.kt, WeatherModels.kt)
• controllers/ — orchestrators (CountriesController, RegionsController, CountryDetailController)
• ui/ — Android UI components (MainActivity, Fragments, Adapters)
• network/ holds ApiClient, Retrofit service interfaces (RestCountriesService, WeatherApiService).
• utils/ contains Formatters.
• res/ holds XML layouts, drawables, navigation graph, resources.
README Insights
• Uses Retrofit2 + Gson, OkHttp interceptor, Coil for image loading, Android Navigation (without SafeArgs).
• Follows MVC: separation of data (models), coordination (controllers), presentation (ui).
Main Components
a. View Layer (UI)
• MainActivity
• RegionsFragment (list regions)
• CountriesFragment (list countries)
• CountryDetailFragment (show details + weather)
• Adapters: RegionsAdapter, CountriesAdapter
• Layout XMLs
b. Controller Layer
• RegionsController
• CountriesController
• CountryDetailController
c. Model Layer
• CountryModels
• WeatherModels
• Utility Formatters
d. Network Layer
• ApiClient (Retrofit builder)
• RestCountriesService (GET regions, countries)
• WeatherApiService (GET weather by capital)
e. External Services
• RestCountries API Endpoint
• WeatherAPI Endpoint
f. Image Loader
• Coil (loads flag URLs into ImageViews)
Relationships & Data Flow
• User taps in UI → Fragment calls its Controller
• Controller requests data via ApiClient → Retrofit service
• Service calls external API → Response mapped to Models
• Controller handles errors/loaders, transforms Models (via Formatters)
• Controller returns data to View (Fragment/Adapter) → UI updates
Architectural Patterns & Principles
• MVC: strict three-layer separation
• Single Responsibility: Controllers only coordinate, data classes only hold data, UI only renders
• Dependency Injection: ApiClient is singleton, controllers obtain services from it
• Asynchronous calls: Retrofit + OkHttp manage threads, callbacks or coroutines
Essential Elements
• Clear component names (e.g., CountriesController)
• Smartphone screen frames for UI