Repository: odaridavid/WeatherApp Branch: develop Commit: 0e9641f3c9f0 Files: 128 Total size: 274.0 KB Directory structure: gitextract_68o3_ggl/ ├── .github/ │ └── workflows/ │ ├── code-analysis.yml │ └── update-dependencies-action.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app/ │ ├── .gitignore │ ├── build.gradle.kts │ ├── google-services.json │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── kotlin/ │ │ └── com/ │ │ └── github/ │ │ └── odaridavid/ │ │ └── weatherapp/ │ │ └── SettingsRepositoryTest.kt │ ├── debug/ │ │ └── res/ │ │ ├── drawable/ │ │ │ └── ic_launcher_background.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ └── mipmap-anydpi-v26/ │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── github/ │ │ │ └── odaridavid/ │ │ │ └── weatherapp/ │ │ │ ├── MainViewModel.kt │ │ │ ├── WeatherApp.kt │ │ │ ├── common/ │ │ │ │ ├── AndroidExtensions.kt │ │ │ │ └── LocationRequest.kt │ │ │ ├── data/ │ │ │ │ ├── Extensions.kt │ │ │ │ ├── settings/ │ │ │ │ │ └── DefaultSettingsRepository.kt │ │ │ │ └── weather/ │ │ │ │ ├── DefaultWeatherRepository.kt │ │ │ │ ├── FirebaseLogger.kt │ │ │ │ └── remote/ │ │ │ │ ├── DefaultRemoteWeatherDataSource.kt │ │ │ │ ├── Mappers.kt │ │ │ │ ├── OpenWeatherService.kt │ │ │ │ ├── RemoteWeatherDataSource.kt │ │ │ │ └── WeatherResponse.kt │ │ │ ├── designsystem/ │ │ │ │ ├── Theme.kt │ │ │ │ ├── atom/ │ │ │ │ │ ├── Color.kt │ │ │ │ │ ├── Dimensions.kt │ │ │ │ │ ├── Shape.kt │ │ │ │ │ └── Type.kt │ │ │ │ ├── molecule/ │ │ │ │ │ ├── Buttons.kt │ │ │ │ │ ├── Image.kt │ │ │ │ │ └── Text.kt │ │ │ │ ├── organism/ │ │ │ │ │ ├── BottomSheets.kt │ │ │ │ │ ├── Dialogs.kt │ │ │ │ │ ├── NavBars.kt │ │ │ │ │ ├── Row.kt │ │ │ │ │ └── TextWidgets.kt │ │ │ │ └── templates/ │ │ │ │ ├── ErrorScreen.kt │ │ │ │ ├── InfoScreens.kt │ │ │ │ └── ProgressScreens.kt │ │ │ ├── di/ │ │ │ │ ├── ClientModule.kt │ │ │ │ └── RepositoryModule.kt │ │ │ └── ui/ │ │ │ ├── AppNavGraph.kt │ │ │ ├── MainActivity.kt │ │ │ ├── about/ │ │ │ │ └── AboutScreen.kt │ │ │ ├── home/ │ │ │ │ ├── HomeScreen.kt │ │ │ │ ├── HomeScreenIntent.kt │ │ │ │ ├── HomeViewModel.kt │ │ │ │ └── Mappers.kt │ │ │ ├── settings/ │ │ │ │ ├── SettingsScreen.kt │ │ │ │ ├── SettingsScreenIntent.kt │ │ │ │ ├── SettingsViewModel.kt │ │ │ │ └── UIMapper.kt │ │ │ └── update/ │ │ │ ├── UpdateAppException.kt │ │ │ ├── UpdateManager.kt │ │ │ └── UpdateStateFactory.kt │ │ └── res/ │ │ ├── drawable/ │ │ │ ├── ic_arrow_back.xml │ │ │ ├── ic_exclude_24.xml │ │ │ ├── ic_info_24.xml │ │ │ ├── ic_language.xml │ │ │ ├── ic_launcher_background.xml │ │ │ ├── ic_settings.xml │ │ │ ├── ic_time_24.xml │ │ │ └── ic_units.xml │ │ ├── drawable-night/ │ │ │ ├── ic_arrow_back.xml │ │ │ ├── ic_exclude_24.xml │ │ │ ├── ic_info_24.xml │ │ │ ├── ic_language.xml │ │ │ ├── ic_settings.xml │ │ │ ├── ic_time_24.xml │ │ │ └── ic_units.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ ├── mipmap-anydpi-v26/ │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── values/ │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── themes.xml │ │ └── xml/ │ │ ├── backup_rules.xml │ │ └── data_extraction_rules.xml │ └── test/ │ └── java/ │ └── com/ │ └── github/ │ └── odaridavid/ │ └── weatherapp/ │ ├── HomeViewModelTest.kt │ ├── MainViewModelTest.kt │ ├── SettingsRepositoryTest.kt │ ├── SettingsViewModelTest.kt │ ├── UIMapperTest.kt │ ├── WeatherRepositoryTest.kt │ ├── fakes/ │ │ ├── FakeSettingsRepository.kt │ │ └── Fakes.kt │ └── rules/ │ └── MainCoroutineRule.kt ├── build.gradle.kts ├── gradle/ │ ├── libs.versions.toml │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── iOSApp/ │ ├── iOSApp/ │ │ ├── Assets.xcassets/ │ │ │ ├── AccentColor.colorset/ │ │ │ │ └── Contents.json │ │ │ ├── AppIcon.appiconset/ │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── ContentView.swift │ │ ├── Preview Content/ │ │ │ └── Preview Assets.xcassets/ │ │ │ └── Contents.json │ │ └── iOSAppApp.swift │ ├── iOSApp.xcodeproj/ │ │ ├── project.pbxproj │ │ ├── project.xcworkspace/ │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata/ │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata/ │ │ │ └── odari.xcuserdatad/ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata/ │ │ └── odari.xcuserdatad/ │ │ └── xcschemes/ │ │ └── xcschememanagement.plist │ ├── iOSAppTests/ │ │ └── iOSAppTests.swift │ └── iOSAppUITests/ │ ├── iOSAppUITests.swift │ └── iOSAppUITestsLaunchTests.swift ├── pull_request_template.md ├── settings.gradle.kts └── shared/ ├── build.gradle.kts └── src/ └── commonMain/ └── kotlin/ └── com/ └── github/ └── odaridavid/ └── weatherapp/ ├── api/ │ ├── Logger.kt │ ├── SettingsRepository.kt │ └── WeatherRepository.kt └── model/ ├── DefaultLocation.kt ├── ExcludedData.kt ├── Result.kt ├── SupportedLanguage.kt ├── Throwables.kt ├── TimeFormat.kt ├── Units.kt └── Weather.kt ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/code-analysis.yml ================================================ name: Code Analysis on: pull_request: branches: - develop jobs: code-analysis: runs-on: macos-latest environment: Dev steps: - name: Checkout code uses: actions/checkout@v4 - name: Download & Copy local.properties run: | curl -o local.properties "${{ secrets.LOCAL_PROPERTIES_URL }}" mv local.properties ./local.properties - name: Set up JDK uses: actions/setup-java@v4 with: distribution: 'oracle' java-version: '17' - name: Run Ktlint run: ./gradlew ktlintCheck continue-on-error: true - name: Run Detekt run: ./gradlew detekt continue-on-error: true ================================================ FILE: .github/workflows/update-dependencies-action.yml ================================================ name: Update Dependencies on: schedule: - cron: '00 08 * * 4' jobs: version-update: runs-on: macos-latest environment: Dev steps: - name: Checkout code uses: actions/checkout@v4 - name: Download & Copy local.properties run: | curl -o local.properties "${{ secrets.LOCAL_PROPERTIES_URL }}" mv local.properties ./local.properties - name: Set up JDK uses: actions/setup-java@v4 with: distribution: 'oracle' java-version: '17' - name: Version Update run: | ./gradlew versionCatalogUpdate - name: Open Pull Request uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.GITHUB_TOKEN }} title: "Update Version Catalog" body: "Automated version update using GitHub Actions." commit-message: "Update version catalog" ================================================ FILE: .gitignore ================================================ *.iml .gradle /local.properties /.idea/caches /.idea/libraries /.idea/modules.xml /.idea/workspace.xml /.idea/navEditor.xml /.idea/assetWizardSettings.xml .DS_Store /build /captures .externalNativeBuild .cxx local.properties /.idea/ ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing to Weather App 👍🎉 First off, thank you for taking the time to contribute! 🎉👍 The following is a set of guidelines for contributing to Weather App. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request. ## How Can I Contribute? ### Reporting Bugs Before submitting a bug report, please check if the issue has already been reported by searching through the [existing issues](https://github.com/odaridavid/weather-app/issues). If you can't find an existing issue addressing the problem, feel free to open a new one. When you report a bug, please include as much detail as possible, including: - Steps to reproduce the bug - Expected behavior - Actual behavior - Screenshots or code snippets, if applicable - Your Android Version. ### Suggesting Enhancements If you have an idea for an enhancement or new feature, we'd love to hear about it! You can submit your suggestion by opening a new issue. Please provide a clear description of the enhancement you're proposing and any relevant context or examples that might help us understand your idea better. ### Contributing Code We welcome contributions in the form of code improvements, bug fixes, or new features. To contribute code: 1. Fork the repository to your GitHub account. 2. Create a new branch for your feature or bug fix. 3. Make your changes and commit them with clear, descriptive messages. 4. Push your changes to your fork. 5. Submit a pull request to the main repository, explaining the changes you've made and why they're valuable. ### Code Style When contributing code, please adhere to the existing code style and formatting conventions used in the project. If you're unsure about the style or formatting, feel free to ask for guidance in your pull request. ### Code Review All contributions will go through a code review process before being merged. During the review, feedback may be provided to help improve the quality of the code. Please be receptive to feedback and be prepared to make any necessary changes to your code. ### Testing If you're adding new features or fixing bugs, please ensure that appropriate tests are included to cover the changes you've made. This helps maintain the overall quality and stability of the application. ## Questions If you have any questions about contributing or anything else related to the project, feel free to reach out to [maintainer's email or contact details](davidkibzodari@gmail.com). Once again, thank you for contributing to Weather App! Your support and contributions are greatly appreciated. 🌤️🌈 ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ ### Weather App [![Build Status](https://app.bitrise.io/app/80f9b4627fc90757/status.svg?token=3KnRQl0WRfDT5UTzPDiRgA&branch=develop)](https://app.bitrise.io/app/80f9b4627fc90757) [![codecov](https://codecov.io/gh/odaridavid/WeatherApp/branch/develop/graph/badge.svg?token=eZcGjGhF83)](https://codecov.io/gh/odaridavid/WeatherApp) *Summary* A simple weather app that gets your location and displays the forecast for the current day and a few days after that. *API :* [OpenWeatherMap](https://openweathermap.org/api) Reason for choosing mentioned API : - 1000 free api calls per day, good for a small project. - Ability to specify different units in requests and receive a formatted response based on the unit i.e imperial/metric etc. - Api response can also be modified to include the amount of needed data all with one call , contains icons for different conditions and has multilingual support if adopting for a wider audience is ever needed. - They have a large user base and handle millions of requests, if the app were ever to scale, there's confidence on the api providing high availability. - Has capabilities for alerts for severe weather conditions More info on how to make an api call [here](https://openweathermap.org/api/one-call-3#multi). # Pre-requisite 📝 In your `local.properties` you will need to add your Open Weather API key and copy the urls in. ```properties OPEN_WEATHER_API_KEY=YOUR KEY OPEN_WEATHER_BASE_URL=https://api.openweathermap.org OPEN_WEATHER_ICONS_URL=https://openweathermap.org/img/wn/ ``` Check for one under [`Api Keys`](https://home.openweathermap.org/api_keys) *Environment* - Built on A.S Hedgehog+ - JDK 17 # Design/Architectural decisions 📐 The project makes use of common android patterns in modern android codebases. **Project Structure** The folders are split into 4 boundaries:
Core Contains the models/data classes that are independent of any framework specific dependencies and represent the business logic. In a Clean Arch world you can consider these as your domain classes and interfaces.
Data Contains data sources , local or remote, this is where the implementation for such is kept. All data related actions and formatting happens in this layer as well. It may contain framework related dependencies to orchestrate and create instances of data stores like a database or shared preference etc. One common pattern used in this area is the repository pattern, which mediates data sources and acts as a source of truth to the consumer.
DI This acts as the glue between the core ,data and UI.The UI relies on the core models and interfaces which are implemented in data.
UI Contains the presentation layer of the app, the screen components and viewmodels. Framework specific dependencies are best suited for this layer. In this layer MVI is also used, it looks similar to MVVM but the difference is the actions from a screen a.k.a intents e.g ```HomeScreenIntent``` are predefined and are finite,making the the screen state a bit more predictable and it's easier to scan through what actions are possible from a given screen. The screen state e.g ```HomeScreenViewState``` is also modelled as a class with immutable properties and makes state management way easier by reducing the state whenever their is a new update received. Some design patterns that can be seen here are the Observer pattern when consuming the flow -> state flows in the composables and provides a reactive app.
![Add flow diagram here](/docs/MVI.png)
Testing The data layer is unit tested by mocking out external dependencies and the ui layer on the viewmodels, an integration test is written that makes use of fake,so as to mimic the real scenario as much as possible over using mocks, which would also turn it to a unit test.
# Other Stuff 📦 *Code style* For now there is no strict adherence to a code style, but the project is formatted using the default android studio formatter. You can run `./gradlew detekt` to check for any code smells and `./gradlew ktlint` to check for any linting issues. Alternatively for ktlint the [IDE plugin](https://pinterest.github.io/ktlint/latest/install/setup/#recommended-setup) might be a much better option :) Or setting up a [pre-commit/pre-push hook](https://pinterest.github.io/ktlint/latest/install/cli/#git-hooks) to run the checks before a commit is made or pushed. *CI/CD* The project is built on Bitrise and the workflow is maintained from its dashboard.Github actions are responsible for dependency updates and running code quality checks ,defined in the `.github/workflows` folder. *Design System* Under the `designsystem` package ,it follows a tiered approach to styling the app i.e
Atoms (Smallest Components) Typography: Define font styles, sizes, and weights for headers, paragraphs, and other text elements. Color Palette: Establish a color palette with primary, secondary, and accent colors. Specify their usage in different contexts. Icons: Design a set of basic icons that represent common actions or concepts. Ensure consistency in style and sizing. Buttons: Create button styles with variations for primary, secondary, and tertiary actions. Include states like hover and disabled. Input Fields: Design consistent styles for text inputs, checkboxes, radio buttons, and other form elements.
Molecules (Simple Components) Form Elements: Combine atoms to create complete form components. Ensure consistency in spacing and alignment. Cards: Combine text, images, and buttons to create card components. Define variations for different use cases. Badges: Assemble icons and text to create badge components for notifications or status indicators. Avatars: Design avatar components for user profiles, incorporating images or initials.
Organisms (Complex Components) Navigation Bars: Create a consistent navigation bar design that includes menus, icons, and navigation elements. Headers and Footers: Define headers and footers with appropriate spacing, logos, and navigation links. Lists: Assemble atoms and molecules to create list components, incorporating variations like simple lists, detailed lists, and nested lists. Modals: Design modal components for overlays or pop-ups, ensuring consistency in styles and behavior.
Templates (Page-Level Structures) Page Layouts: Establish consistent layouts for different types of pages (e.g., home page, product page, settings page). Grid Systems: Define grid systems that ensure alignment and consistency across various screen sizes.
*Performance* The app is monitored using Firebase Performance and Crashlytics,for performance it's using the default traces but can be extended as the app grows to monitor specific parts of the app that might be slow. LeakCanary is also used to monitor for any memory leaks that might occur in debug mode. *Build Times* The current CI build time , factoring in the project size, the number of tests etc. | Task | Avg Time | |-----------------------------------------|----------| | Build - Bitrise | 4m 30s | | Code Analysis - Github Actions | 6m 30s | | Update Dependencies - Github Actions | 8m 30s | # Technologies 🔨 **Language :** [Kotlin](https://github.com/JetBrains/kotlin) **Libraries :**
UI Compose
Coil
InAppUpdate
Data Retrofit
OkHTTP
kotlinx.serialization
Preference Data Store
Testing JUnit
Mockk
Truth
Turbine
Tooling/Project setup Gradle secrets plugin
Hilt (DI)
Firebase - Crashlytics, Performance
Bitrise
Codecov
Detekt
Ktlint
LeakCanary
About Libraries
KMM
# LICENSE ``` Copyright 2023 David Odari Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` # Screenshots 📱 | Light Theme | Dark Theme | |:------------------------------------------------------------------------:|:-----------------------------------------------------------------------:| | | | | | | | | | | | | | | | | | | | | | | | - | ![](https://media.giphy.com/media/hWvk9iUU4uBBeyBq0k/giphy.gif) ================================================ FILE: app/.gitignore ================================================ /build ================================================ FILE: app/build.gradle.kts ================================================ import com.google.firebase.perf.plugin.FirebasePerfExtension plugins { alias(libs.plugins.com.android.application) alias(libs.plugins.org.jetbrains.kotlin.android) alias(libs.plugins.mapsplatform.secrets.gradle.plugin) kotlin("kapt") alias(libs.plugins.dagger.hilt.android) alias(libs.plugins.org.jetbrains.kotlin.plugin.serialization) id("com.google.gms.google-services") id("com.google.firebase.crashlytics") id("io.gitlab.arturbosch.detekt") jacoco alias(libs.plugins.firebase.perf.plugin) alias(libs.plugins.about.lib.plugin) alias(libs.plugins.compose.compiler) } jacoco { toolVersion = "0.8.11" } project.afterEvaluate { setupAndroidReporting() } fun setupAndroidReporting() { val buildTypes = listOf("debug") buildTypes.forEach { buildTypeName -> val sourceName = buildTypeName val testTaskName = "test${sourceName.capitalize()}UnitTest" println("Task -> $testTaskName") tasks.register("${testTaskName}Coverage") { dependsOn(tasks.findByName(testTaskName)) group = "Reporting" description = "Generate Jacoco coverage reports on the ${sourceName.capitalize()} build." reports { xml.required.set(true) csv.required.set(false) html.required.set(true) } val fileFilter = listOf( // android "**/R.class", "**/R$*.class", "**/BuildConfig.*", "**/Manifest*.*", "**/*Test*.*", "android/**/*.*", // kotlin "**/*MapperImpl*.*", "**/*\$ViewInjector*.*", "**/*\$ViewBinder*.*", "**/BuildConfig.*", "**/*Component*.*", "**/*BR*.*", "**/Manifest*.*", "**/*\$Lambda$*.*", "**/*Companion*.*", "**/*Module*.*", "**/*Dagger*.*", "**/*Hilt*.*", "**/*MembersInjector*.*", "**/*_MembersInjector.class", "**/*_Factory*.*", "**/*_Provide*Factory*.*", // sealed and data classes "**/*\$Result.*", "**/*\$Result$*.*", // adapters generated by moshi "**/*JsonAdapter.*", "**/*Activity*", "**/di/**", "**/hilt*/**", // TODO Remove once UI and instrumented tests are added "**/entrypoint/**", "**/designsystem/**", "**/*Screen*.*", "**/*NavGraph*.*", "**/*Destinations*.*", "**/common/**", "**/*Extensions*.*", ) val javaTree = fileTree("${project.buildDir}/intermediates/javac/$sourceName/classes") { exclude(fileFilter) } val kotlinTree = fileTree("${project.buildDir}/tmp/kotlin-classes/$sourceName") { exclude(fileFilter) } classDirectories.setFrom(files(javaTree, kotlinTree)) executionData.setFrom(files("${project.buildDir}/jacoco/$testTaskName.exec")) val coverageSourceDirs = listOf( "${project.projectDir}/src/main/java", "${project.projectDir}/src/$buildTypeName/java" ) sourceDirectories.setFrom(files(coverageSourceDirs)) additionalSourceDirs.setFrom(files(coverageSourceDirs)) } } } android { namespace = "com.github.odaridavid.weatherapp" compileSdk = 35 defaultConfig { applicationId = "com.github.odaridavid.weatherapp" minSdk = 23 targetSdk = 35 versionCode = 1 versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary = true } } buildTypes { debug { applicationIdSuffix = ".debug" configure { // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for a specific build variant at compile time. // Breaks jacoco reporting if true see https://github.com/firebase/firebase-android-sdk/issues/3948 setInstrumentationEnabled(false) } enableAndroidTestCoverage = true } release { isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = JavaVersion.VERSION_17.toString() freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn" + listOf( "-P", // See https://github.com/androidx/androidx/blob/androidx-main/compose/compiler/design/compiler-metrics.md "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=${project.buildDir}/reports/kotlin-compile/compose" ) } buildFeatures { compose = true buildConfig = true } packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } } dependencies { implementation(project(":shared")) // Jetpack Core implementation(libs.bundles.androidx) implementation(platform(libs.compose.bom)) implementation(libs.bundles.compose) // Google Play Services implementation(libs.playservices.location) // Data & Async implementation(libs.retrofit) implementation(platform(libs.okhttp.bom)) implementation(libs.okhttp) implementation(libs.okhttp.logging.interceptor) implementation(libs.kotlinx.coroutines.android) implementation(libs.kotlinx.serialization.converter) implementation(libs.kotlinx.serialization) implementation(libs.coil) // DI implementation(libs.hilt.android) kapt(libs.hilt.compiler) // Firebase implementation(platform(libs.firebase.bom)) implementation(libs.bundles.firebase) // Test testImplementation(libs.junit) testImplementation(libs.turbine) testImplementation(libs.mock.android) testImplementation(libs.mock.agent) testImplementation(libs.truth) testImplementation(libs.coroutines.test) debugImplementation(libs.compose.ui.tooling) debugImplementation(libs.compose.ui.test.manifest) // Android Test androidTestImplementation(libs.bundles.android.test) androidTestImplementation(libs.coroutines.test) androidTestImplementation(libs.turbine) // Chucker debugImplementation(libs.chucker.debug) releaseImplementation(libs.chucker.release) // Memory Leak Detection debugImplementation(libs.leakcanary) // In-app update implementation(libs.bundles.google.play) // About implementation(libs.about.lib.core) implementation(libs.about.lib.compose.ui) } kapt { correctErrorTypes = true } ================================================ FILE: app/google-services.json ================================================ { "project_info": { "project_number": "610111461146", "project_id": "weatherapp-e7fb4", "storage_bucket": "weatherapp-e7fb4.appspot.com" }, "client": [ { "client_info": { "mobilesdk_app_id": "1:610111461146:android:93477e9051250424edbea3", "android_client_info": { "package_name": "com.github.odaridavid.weatherapp" } }, "oauth_client": [ { "client_id": "610111461146-na7se6v73h0i76v52d4g53snq48p9vi2.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { "current_key": "AIzaSyAZXonDiplhz8zSQJbC1JT0XiqVmtHbKy0" } ], "services": { "appinvite_service": { "other_platform_oauth_client": [ { "client_id": "610111461146-na7se6v73h0i76v52d4g53snq48p9vi2.apps.googleusercontent.com", "client_type": 3 } ] } } }, { "client_info": { "mobilesdk_app_id": "1:610111461146:android:1b766bcb5b1f3602edbea3", "android_client_info": { "package_name": "com.github.odaridavid.weatherapp.debug" } }, "oauth_client": [ { "client_id": "610111461146-na7se6v73h0i76v52d4g53snq48p9vi2.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { "current_key": "AIzaSyAZXonDiplhz8zSQJbC1JT0XiqVmtHbKy0" } ], "services": { "appinvite_service": { "other_platform_oauth_client": [ { "client_id": "610111461146-na7se6v73h0i76v52d4g53snq48p9vi2.apps.googleusercontent.com", "client_type": 3 } ] } } }, { "client_info": { "mobilesdk_app_id": "1:610111461146:android:c4a8151c04739b83edbea3", "android_client_info": { "package_name": "dev.davidodari.weatherupdates" } }, "oauth_client": [ { "client_id": "610111461146-na7se6v73h0i76v52d4g53snq48p9vi2.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { "current_key": "AIzaSyAZXonDiplhz8zSQJbC1JT0XiqVmtHbKy0" } ], "services": { "appinvite_service": { "other_platform_oauth_client": [ { "client_id": "610111461146-na7se6v73h0i76v52d4g53snq48p9vi2.apps.googleusercontent.com", "client_type": 3 } ] } } } ], "configuration_version": "1" } ================================================ FILE: app/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle.kts. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile ================================================ FILE: app/src/androidTest/kotlin/com/github/odaridavid/weatherapp/SettingsRepositoryTest.kt ================================================ package com.github.odaridavid.weatherapp import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.filters.SmallTest import app.cash.turbine.test import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.data.settings.DefaultSettingsRepository import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test @SmallTest class SettingsRepositoryTest { // TODO instrumentation test coverage private lateinit var settingsRepository: SettingsRepository @Before fun setup() { val context = ApplicationProvider.getApplicationContext() settingsRepository = DefaultSettingsRepository(context) } @Test fun when_we_update_language_then_we_get_the_updated_language() = runTest { settingsRepository.setLanguage(SupportedLanguage.FRENCH) val language = settingsRepository.getLanguage() language.test { awaitItem().also { language -> assert(language == SupportedLanguage.FRENCH) } } } @Test fun when_we_update_units_then_we_get_the_updated_units() = runTest { settingsRepository.setUnits(Units.IMPERIAL) val units = settingsRepository.getUnits() units.test { awaitItem().also { units -> assert(units == Units.IMPERIAL) } } } @Test fun when_we_update_time_format_then_we_get_the_updated_time_format() = runTest { settingsRepository.setFormat(TimeFormat.TWENTY_FOUR_HOUR) val timeFormat = settingsRepository.getFormat() timeFormat.test { awaitItem().also { timeFormat -> assert(timeFormat == TimeFormat.TWENTY_FOUR_HOUR) } } } @Test fun when_we_update_excluded_data_then_we_get_the_updated_excluded_data() = runTest { val excludedData = listOf(ExcludedData.MINUTELY, ExcludedData.ALERTS) settingsRepository.setExcludedData(excludedData) val data = settingsRepository.getExcludedData() data.test { awaitItem().also { data -> assert(data == "minutely,alerts") } } } @Test fun when_we_update_default_location_then_we_get_the_updated_default_location() = runTest { val defaultLocation = DefaultLocation(23.23, 34.12) settingsRepository.setDefaultLocation(defaultLocation) val location = settingsRepository.getDefaultLocation() location.test { awaitItem().also { location -> assert(location == defaultLocation) } } } } ================================================ FILE: app/src/debug/res/drawable/ic_launcher_background.xml ================================================ ================================================ FILE: app/src/debug/res/drawable-v24/ic_launcher_foreground.xml ================================================ ================================================ FILE: app/src/debug/res/mipmap-anydpi-v26/ic_launcher.xml ================================================ ================================================ FILE: app/src/debug/res/mipmap-anydpi-v26/ic_launcher_round.xml ================================================ ================================================ FILE: app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/MainViewModel.kt ================================================ package com.github.odaridavid.weatherapp import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.github.odaridavid.weatherapp.api.Logger import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.model.DefaultLocation import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class MainViewModel @Inject constructor( private val settingsRepository: SettingsRepository, private val logger: Logger ) : ViewModel() { private val _state = MutableStateFlow(MainViewState()) val state: StateFlow = _state.asStateFlow() private val _hasAppUpdate = MutableStateFlow(false) val hasAppUpdate: StateFlow = _hasAppUpdate.asStateFlow() fun processIntent(mainViewIntent: MainViewIntent) { when (mainViewIntent) { is MainViewIntent.GrantPermission -> { setState { copy(isPermissionGranted = mainViewIntent.isGranted) } } is MainViewIntent.CheckLocationSettings -> { setState { copy(isLocationSettingEnabled = mainViewIntent.isEnabled) } } is MainViewIntent.ReceiveLocation -> { val defaultLocation = DefaultLocation( longitude = mainViewIntent.longitude, latitude = mainViewIntent.latitude ) viewModelScope.launch { settingsRepository.setDefaultLocation(defaultLocation) } setState { copy(defaultLocation = defaultLocation) } } is MainViewIntent.LogException -> { logger.logException(mainViewIntent.throwable) } is MainViewIntent.UpdateApp -> { viewModelScope.launch { _hasAppUpdate.emit(true) } } } } private fun setState(stateReducer: MainViewState.() -> MainViewState) { viewModelScope.launch { _state.emit(stateReducer(state.value)) } } } data class MainViewState( val isPermissionGranted: Boolean = false, val isLocationSettingEnabled: Boolean = false, val defaultLocation: DefaultLocation? = DefaultLocation(longitude = 0.0, latitude = 0.0) ) sealed class MainViewIntent { data class GrantPermission(val isGranted: Boolean) : MainViewIntent() data class CheckLocationSettings(val isEnabled: Boolean) : MainViewIntent() data class ReceiveLocation(val latitude: Double, val longitude: Double) : MainViewIntent() data class LogException(val throwable: Throwable) : MainViewIntent() data object UpdateApp : MainViewIntent() } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/WeatherApp.kt ================================================ package com.github.odaridavid.weatherapp import android.app.Application import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp class WeatherApp : Application() // TODO Add global error handling // TODO Timber logging. ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/common/AndroidExtensions.kt ================================================ package com.github.odaridavid.weatherapp.common import android.Manifest import android.app.Activity import android.content.Context import android.content.pm.PackageManager import android.location.Address import android.location.Geocoder import android.os.Build import androidx.activity.result.ActivityResultLauncher import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.core.content.ContextCompat import com.github.odaridavid.weatherapp.designsystem.organism.PermissionRationaleDialog import java.util.Locale private const val NO_OF_ADDRESSES = 1 fun Context.getCityName(longitude: Double, latitude: Double, onAddressReceived: (Address) -> Unit) { val geoCoder = Geocoder(this, Locale.getDefault()) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { geoCoder.getFromLocation(latitude, longitude, NO_OF_ADDRESSES) { addresses -> if (addresses.isNotEmpty()) { onAddressReceived(addresses[0]) } } } else { try { val addresses = geoCoder.getFromLocation(latitude, longitude, NO_OF_ADDRESSES) if (addresses?.isNotEmpty() == true) { onAddressReceived(addresses[0]) } } catch (e: Exception) { e.printStackTrace() } } } @Composable fun Activity.OnPermissionDenied( activityPermissionResult: ActivityResultLauncher, ) { val showWeatherUI = remember { mutableStateOf(false) } if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_COARSE_LOCATION)) { val isDialogShown = remember { mutableStateOf(true) } if (isDialogShown.value) { PermissionRationaleDialog( isDialogShown, activityPermissionResult, showWeatherUI ) } } else { activityPermissionResult.launch(Manifest.permission.ACCESS_COARSE_LOCATION) } } @Composable fun Context.CheckForPermissions( onPermissionGranted: @Composable () -> Unit, onPermissionDenied: @Composable () -> Unit ) { when (ContextCompat.checkSelfPermission( this, Manifest.permission.ACCESS_COARSE_LOCATION )) { PackageManager.PERMISSION_GRANTED -> { onPermissionGranted() } PackageManager.PERMISSION_DENIED -> { onPermissionDenied() } } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/common/LocationRequest.kt ================================================ package com.github.odaridavid.weatherapp.common import android.app.Activity import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.IntentSenderRequest import com.google.android.gms.common.api.ApiException import com.google.android.gms.common.api.ResolvableApiException import com.google.android.gms.location.* import com.google.android.gms.tasks.Task fun createLocationRequest( activity: Activity, locationRequestLauncher: ActivityResultLauncher, onLocationRequestSuccessful: () -> Unit ) { val locationRequest = LocationRequest.Builder(30_000L) .setPriority(Priority.PRIORITY_BALANCED_POWER_ACCURACY) .build() val locationSettingsRequest = LocationSettingsRequest.Builder() .addLocationRequest(locationRequest) val task: Task = LocationServices.getSettingsClient(activity) .checkLocationSettings(locationSettingsRequest.build()) task.addOnCompleteListener { response -> try { val result = response.getResult(ApiException::class.java) val hasLocationAccess = result.locationSettingsStates?.isLocationUsable == true if (hasLocationAccess) { onLocationRequestSuccessful() } } catch (exception: ApiException) { when (exception.statusCode) { LocationSettingsStatusCodes.RESOLUTION_REQUIRED -> { val resolvable = exception as ResolvableApiException val intentSender = IntentSenderRequest.Builder(resolvable.resolution).build() locationRequestLauncher.launch(intentSender) } LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE -> { // Do nothing, location settings can't be changed } } } } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/Extensions.kt ================================================ package com.github.odaridavid.weatherapp.data import android.content.Context import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.preferencesDataStore val Context.dataStore: DataStore by preferencesDataStore(name = "settings") ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/settings/DefaultSettingsRepository.kt ================================================ package com.github.odaridavid.weatherapp.data.settings import android.content.Context import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.stringPreferencesKey import com.github.odaridavid.weatherapp.BuildConfig import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.data.dataStore import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import javax.inject.Inject class DefaultSettingsRepository @Inject constructor( @ApplicationContext private val context: Context ) : SettingsRepository { private val prefLanguage by lazy { stringPreferencesKey(KEY_LANGUAGE) } private val prefUnits by lazy { stringPreferencesKey(KEY_UNITS) } private val prefTimeFormat by lazy { stringPreferencesKey(KEY_TIME_FORMAT) } private val prefLatLng by lazy { stringPreferencesKey(KEY_LAT_LNG) } private val prefExcludedData by lazy { stringPreferencesKey(KEY_EXCLUDED_DATA) } override suspend fun setLanguage(language: SupportedLanguage) { set(key = prefLanguage, value = language.name) } override suspend fun getLanguage(): Flow { return get(key = prefLanguage, default = SupportedLanguage.ENGLISH.name).map { SupportedLanguage.valueOf(it) } } override suspend fun setUnits(units: Units) { set(key = prefUnits, value = units.name) } override suspend fun getUnits(): Flow { return get(key = prefUnits, default = Units.METRIC.name).map { Units.valueOf(it) } } override fun getAppVersion(): String = "Version : ${BuildConfig.VERSION_NAME}-${BuildConfig.BUILD_TYPE}" override suspend fun setDefaultLocation(defaultLocation: DefaultLocation) { set(key = prefLatLng, value = "${defaultLocation.latitude}/${defaultLocation.longitude}") } override suspend fun getDefaultLocation(): Flow { return get( key = prefLatLng, default = "$DEFAULT_LATITUDE/$DEFAULT_LONGITUDE" ).map { latlng -> val latLngList = latlng.split("/").map { it.toDouble() } DefaultLocation(latitude = latLngList[0], longitude = latLngList[1]) } } override suspend fun getFormat(): Flow { return get(key = prefTimeFormat, default = TimeFormat.TWENTY_FOUR_HOUR.name).map { TimeFormat.valueOf(it) } } override suspend fun setFormat(format: TimeFormat) { set(key = prefTimeFormat, value = format.name) } // TODO Refactor to flow of list of excluded data override suspend fun getExcludedData(): Flow = get( key = prefExcludedData, default = "${ExcludedData.MINUTELY.value},${ExcludedData.ALERTS.value}" ) override suspend fun setExcludedData(excludedData: List) { val formattedData = excludedData.joinToString(separator = ",") { it.value } set(key = prefExcludedData, value = formattedData) } private suspend fun set(key: Preferences.Key, value: T) { context.dataStore.edit { settings -> settings[key] = value } } private fun get(key: Preferences.Key, default: T): Flow { return context.dataStore.data.map { settings -> settings[key] ?: default } } companion object { // Düsseldorf const val DEFAULT_LONGITUDE = 6.773456 const val DEFAULT_LATITUDE = 51.227741 const val KEY_LANGUAGE = "language" const val KEY_UNITS = "units" const val KEY_LAT_LNG = "lat_lng" const val KEY_TIME_FORMAT = "time_formats" const val KEY_EXCLUDED_DATA = "excluded_data" } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/weather/DefaultWeatherRepository.kt ================================================ package com.github.odaridavid.weatherapp.data.weather import com.github.odaridavid.weatherapp.api.Logger import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.api.WeatherRepository import com.github.odaridavid.weatherapp.data.weather.remote.RemoteWeatherDataSource import com.github.odaridavid.weatherapp.data.weather.remote.mapThrowableToErrorType import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.Result import com.github.odaridavid.weatherapp.model.Result.Error import com.github.odaridavid.weatherapp.model.Weather import kotlinx.coroutines.flow.first import javax.inject.Inject class DefaultWeatherRepository @Inject constructor( private val remoteWeatherDataSource: RemoteWeatherDataSource, private val logger: Logger, private val settingsRepository: SettingsRepository, ) : WeatherRepository { override suspend fun fetchWeatherData( defaultLocation: DefaultLocation, language: String, units: String, ): Result = try { val format = settingsRepository.getFormat().first().value val excludedData = settingsRepository .getExcludedData() .first() .replace(ExcludedData.NONE.value, "") remoteWeatherDataSource.fetchWeatherData( defaultLocation = defaultLocation, units = units, language = language, format = format, excludedData = excludedData ) } catch (throwable: Throwable) { val errorType = mapThrowableToErrorType(throwable) logger.logException(throwable) Error(errorType) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/weather/FirebaseLogger.kt ================================================ package com.github.odaridavid.weatherapp.data.weather import com.github.odaridavid.weatherapp.api.Logger import com.google.firebase.crashlytics.ktx.crashlytics import com.google.firebase.ktx.Firebase import javax.inject.Inject class FirebaseLogger @Inject constructor() : Logger { override fun logException(throwable: Throwable) { Firebase.crashlytics.recordException(throwable) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/weather/remote/DefaultRemoteWeatherDataSource.kt ================================================ package com.github.odaridavid.weatherapp.data.weather.remote import com.github.odaridavid.weatherapp.BuildConfig import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.Result import com.github.odaridavid.weatherapp.model.Weather import javax.inject.Inject class DefaultRemoteWeatherDataSource @Inject constructor( private val openWeatherService: OpenWeatherService, ) : RemoteWeatherDataSource { override suspend fun fetchWeatherData( defaultLocation: DefaultLocation, language: String, units: String, format: String, excludedData: String, ): Result = try { val response = openWeatherService.getWeatherData( longitude = defaultLocation.longitude, latitude = defaultLocation.latitude, excludedInfo = excludedData, units = units, language = language, appid = BuildConfig.OPEN_WEATHER_API_KEY, ) if (response.isSuccessful && response.body() != null) { val weatherData = response.body()!!.toCoreModel(unit = units, format = format) Result.Success(data = weatherData) } else { val throwable = mapResponseCodeToThrowable(response.code()) throw throwable } } catch (e: Exception) { throw e } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/weather/remote/Mappers.kt ================================================ package com.github.odaridavid.weatherapp.data.weather.remote import com.github.odaridavid.weatherapp.BuildConfig import com.github.odaridavid.weatherapp.model.ClientException import com.github.odaridavid.weatherapp.model.CurrentWeather import com.github.odaridavid.weatherapp.model.DailyWeather import com.github.odaridavid.weatherapp.model.ErrorType import com.github.odaridavid.weatherapp.model.GenericException import com.github.odaridavid.weatherapp.model.HourlyWeather import com.github.odaridavid.weatherapp.model.ServerException import com.github.odaridavid.weatherapp.model.Temperature import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import com.github.odaridavid.weatherapp.model.Weather import com.github.odaridavid.weatherapp.model.WeatherInfo import java.io.IOException import java.net.HttpURLConnection import java.text.SimpleDateFormat import java.util.Date import java.util.Locale import kotlin.math.roundToInt fun WeatherResponse.toCoreModel(unit: String, format: String): Weather = Weather( current = current?.toCoreModel(unit = unit), daily = daily?.map { it.toCoreModel(unit = unit) }, hourly = hourly?.map { it.toCoreModel(unit = unit, format = format) } ) fun CurrentWeatherResponse.toCoreModel(unit: String): CurrentWeather = CurrentWeather( temperature = formatTemperatureValue(temperature, unit), feelsLike = formatTemperatureValue(feelsLike, unit), weather = weather.map { it.toCoreModel() } ) fun DailyWeatherResponse.toCoreModel(unit: String): DailyWeather = DailyWeather( forecastedTime = getDate(forecastedTime, "EEEE dd/M"), temperature = temperature.toCoreModel(unit = unit), weather = weather.map { it.toCoreModel() } ) fun HourlyWeatherResponse.toCoreModel(unit: String, format: String): HourlyWeather { val formatPattern = when (format) { TimeFormat.TWELVE_HOUR.value -> "h:mm a" TimeFormat.TWENTY_FOUR_HOUR.value -> "HH:SS" else -> "HH:SS" } return HourlyWeather( forecastedTime = getDate(forecastedTime, formatPattern), temperature = formatTemperatureValue(temperature, unit), weather = weather.map { it.toCoreModel() } ) } fun WeatherInfoResponse.toCoreModel(): WeatherInfo = WeatherInfo( id = id, main = main, description = description, icon = "${BuildConfig.OPEN_WEATHER_ICONS_URL}$icon@2x.png" ) fun TemperatureResponse.toCoreModel(unit: String): Temperature = Temperature( min = formatTemperatureValue(min, unit), max = formatTemperatureValue(max, unit) ) private fun formatTemperatureValue(temperature: Float, unit: String): String = "${temperature.roundToInt()}${getUnitSymbols(unit = unit)}" private fun getUnitSymbols(unit: String) = when (unit) { Units.METRIC.value -> Units.METRIC.tempLabel Units.IMPERIAL.value -> Units.IMPERIAL.tempLabel Units.STANDARD.value -> Units.STANDARD.tempLabel else -> "N/A" } private fun getDate(utcInMillis: Long, formatPattern: String): String { // TODO use locale from supported languages val sdf = SimpleDateFormat(formatPattern, Locale.ENGLISH) val dateFormat = Date(utcInMillis * 1000) return sdf.format(dateFormat) } fun mapResponseCodeToThrowable(code: Int): Throwable = when (code) { HttpURLConnection.HTTP_BAD_REQUEST -> ClientException("Bad request : $code: Check request parameters") HttpURLConnection.HTTP_UNAUTHORIZED -> ClientException("Unauthorized access : $code: Check API Token") HttpURLConnection.HTTP_NOT_FOUND -> ClientException("Resource not found : $code: Check parameters") TOO_MANY_REQUESTS -> ClientException("Too many requests : $code: Rate limit exceeded") in CLIENT_ERRORS -> ClientException("Client error : $code") in SERVER_ERRORS -> ServerException("Server error : $code") else -> GenericException("Generic error : $code") } fun mapThrowableToErrorType(throwable: Throwable): ErrorType { val errorType = when (throwable) { is IOException -> ErrorType.IO_CONNECTION is ClientException -> ErrorType.CLIENT is ServerException -> ErrorType.SERVER else -> ErrorType.GENERIC } return errorType } private val SERVER_ERRORS = 500..600 private val CLIENT_ERRORS = 400..499 private const val TOO_MANY_REQUESTS = 429 ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/weather/remote/OpenWeatherService.kt ================================================ package com.github.odaridavid.weatherapp.data.weather.remote import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Query interface OpenWeatherService { @GET("/data/3.0/onecall") suspend fun getWeatherData( @Query("lat") latitude: Double, @Query("lon") longitude: Double, @Query("appid") appid: String, @Query("exclude") excludedInfo: String, @Query("units") units: String, @Query("lang") language: String ): Response } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/weather/remote/RemoteWeatherDataSource.kt ================================================ package com.github.odaridavid.weatherapp.data.weather.remote import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.Result import com.github.odaridavid.weatherapp.model.Weather interface RemoteWeatherDataSource { suspend fun fetchWeatherData( defaultLocation: DefaultLocation, language: String, units: String, format: String, excludedData: String ): Result } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/data/weather/remote/WeatherResponse.kt ================================================ package com.github.odaridavid.weatherapp.data.weather.remote import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class WeatherResponse( @SerialName("current") val current: CurrentWeatherResponse? = null, @SerialName("hourly") val hourly: List? = null, @SerialName("daily") val daily: List? = null, ) @Serializable data class CurrentWeatherResponse( @SerialName("temp") val temperature: Float, @SerialName("feels_like") val feelsLike: Float, @SerialName("weather") val weather: List ) @Serializable data class HourlyWeatherResponse( @SerialName("dt") val forecastedTime: Long, @SerialName("temp") val temperature: Float, @SerialName("weather") val weather: List ) @Serializable data class DailyWeatherResponse( @SerialName("dt") val forecastedTime: Long, @SerialName("temp") val temperature: TemperatureResponse, @SerialName("weather") val weather: List ) @Serializable data class WeatherInfoResponse( val id: Int, val main: String, val description: String, val icon: String ) @Serializable data class TemperatureResponse( @SerialName("min") val min: Float, @SerialName("max") val max: Float, ) ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/Theme.kt ================================================ package com.github.odaridavid.weatherapp.designsystem import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import com.github.odaridavid.weatherapp.designsystem.atom.DarkColorPalette import com.github.odaridavid.weatherapp.designsystem.atom.Dimensions import com.github.odaridavid.weatherapp.designsystem.atom.LightColorPalette import com.github.odaridavid.weatherapp.designsystem.atom.LocalDimens import com.github.odaridavid.weatherapp.designsystem.atom.LocalWeight import com.github.odaridavid.weatherapp.designsystem.atom.Weight import com.github.odaridavid.weatherapp.designsystem.atom.shapes import com.github.odaridavid.weatherapp.designsystem.atom.typography // TODO Debug menu or app to preview design system components @Composable fun WeatherAppTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) { val colors = if (darkTheme) { DarkColorPalette } else { LightColorPalette } MaterialTheme( colorScheme = colors, typography = typography, shapes = shapes, content = content ) } object WeatherAppTheme { val dimens: Dimensions @Composable get() = LocalDimens.current val weight: Weight @Composable get() = LocalWeight.current } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/atom/Color.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.atom import androidx.compose.material3.darkColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.ui.graphics.Color // TODO Expand color range val pink50 = Color(0xffffE9F7) val pink200 = Color(0xffff7597) val pinkA200 = Color(0xffff3886) val pink500 = Color(0xffff0266) val pink600 = Color(0xffd8004d) val black = Color(0xff24191c) val darkBlue = Color(0xff1976D2) val blue500 = Color(0xff448aff) val blue200 = Color(0xff92Aeff) val lightBlue = Color(0xffbbdefb) val grey = Color(0xff757575) val lightGrey = Color(0xffBDBDBD) val white = Color(0xffffffff) val LightColorPalette = lightColorScheme( primary = pink500, secondary = blue500, onPrimary = pink50, onSecondary = black, primaryContainer = pink200, onPrimaryContainer = black, secondaryContainer = blue200, onSecondaryContainer = black, surface = white ) val DarkColorPalette = darkColorScheme( primary = blue500, secondary = pinkA200, surface = black, onPrimary = black, onSecondary = white, primaryContainer = blue200, onPrimaryContainer = black, secondaryContainer = pink200, onSecondaryContainer = black ) ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/atom/Dimensions.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.atom import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.unit.dp object Dimensions { val none = 0.dp val extraSmall = 4.dp val small = 8.dp val medium = 16.dp val large = 24.dp val extraLarge = 32.dp } object Weight { const val NONE = 0f const val HALF = 0.5f const val FULL = 1f } val LocalDimens = staticCompositionLocalOf { Dimensions } val LocalWeight = staticCompositionLocalOf { Weight } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/atom/Shape.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.atom import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Shapes import androidx.compose.ui.unit.dp val shapes = Shapes( extraSmall = RoundedCornerShape(4.dp), small = RoundedCornerShape(8.dp), medium = RoundedCornerShape(size = 0f), large = RoundedCornerShape( topStart = 16.dp, topEnd = 0.dp, bottomEnd = 0.dp, bottomStart = 16.dp ) ) ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/atom/Type.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.atom import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.LineHeightStyle import androidx.compose.ui.text.style.LineHeightStyle.Alignment import androidx.compose.ui.text.style.LineHeightStyle.Trim import androidx.compose.ui.unit.sp import com.github.odaridavid.weatherapp.R private val fonts = FontFamily( Font(R.font.rubik_regular), Font(R.font.rubik_medium, FontWeight.W500), Font(R.font.rubik_bold, FontWeight.Bold) ) // typography adapted from NIA Design System, to be improved and tweaked later. val typography = typographyFromDefaults( displayLarge = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Bold, fontSize = 64.sp, lineHeight = 64.sp, letterSpacing = (-0.25).sp, ), displayMedium = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Bold, fontSize = 48.sp, lineHeight = 52.sp, letterSpacing = 0.sp, ), displaySmall = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Normal, fontSize = 36.sp, lineHeight = 44.sp, letterSpacing = 0.sp, ), headlineLarge = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Normal, fontSize = 32.sp, lineHeight = 40.sp, letterSpacing = 0.sp, ), headlineMedium = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Normal, fontSize = 28.sp, lineHeight = 36.sp, letterSpacing = 0.sp, ), headlineSmall = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Normal, fontSize = 24.sp, lineHeight = 32.sp, letterSpacing = 0.sp, lineHeightStyle = LineHeightStyle( alignment = Alignment.Bottom, trim = Trim.None, ), ), titleLarge = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Bold, fontSize = 22.sp, lineHeight = 28.sp, letterSpacing = 0.sp, lineHeightStyle = LineHeightStyle( alignment = Alignment.Bottom, trim = Trim.LastLineBottom, ), ), titleMedium = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Bold, fontSize = 18.sp, lineHeight = 24.sp, letterSpacing = 0.1.sp, ), titleSmall = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Medium, fontSize = 14.sp, lineHeight = 20.sp, letterSpacing = 0.1.sp, ), // Default text style bodyLarge = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Normal, fontSize = 16.sp, lineHeight = 24.sp, letterSpacing = 0.5.sp, lineHeightStyle = LineHeightStyle( alignment = Alignment.Center, trim = Trim.None, ), ), bodyMedium = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Normal, fontSize = 14.sp, lineHeight = 20.sp, letterSpacing = 0.25.sp, ), bodySmall = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Normal, fontSize = 12.sp, lineHeight = 16.sp, letterSpacing = 0.4.sp, ), labelLarge = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Medium, fontSize = 14.sp, lineHeight = 20.sp, letterSpacing = 0.1.sp, lineHeightStyle = LineHeightStyle( alignment = Alignment.Center, trim = Trim.LastLineBottom, ), ), labelMedium = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Medium, fontSize = 12.sp, lineHeight = 16.sp, letterSpacing = 0.5.sp, lineHeightStyle = LineHeightStyle( alignment = Alignment.Center, trim = Trim.LastLineBottom, ), ), labelSmall = TextStyle( fontFamily = fonts, fontWeight = FontWeight.Medium, fontSize = 10.sp, lineHeight = 14.sp, letterSpacing = 0.sp, lineHeightStyle = LineHeightStyle( alignment = Alignment.Center, trim = Trim.LastLineBottom, ), ), ) fun typographyFromDefaults( displayLarge: TextStyle?, displayMedium: TextStyle?, displaySmall: TextStyle?, headlineLarge: TextStyle?, headlineMedium: TextStyle?, headlineSmall: TextStyle?, titleLarge: TextStyle?, titleMedium: TextStyle?, titleSmall: TextStyle?, bodyLarge: TextStyle?, bodyMedium: TextStyle?, bodySmall: TextStyle?, labelLarge: TextStyle?, labelMedium: TextStyle?, labelSmall: TextStyle?, ): Typography { val defaults = Typography() return Typography( displayLarge = defaults.displayLarge.merge(displayLarge), displayMedium = defaults.displayMedium.merge(displayMedium), displaySmall = defaults.displaySmall.merge(displaySmall), headlineLarge = defaults.headlineLarge.merge(headlineLarge), headlineMedium = defaults.headlineMedium.merge(headlineMedium), headlineSmall = defaults.headlineSmall.merge(headlineSmall), titleLarge = defaults.titleLarge.merge(titleLarge), titleMedium = defaults.titleMedium.merge(titleMedium), titleSmall = defaults.titleSmall.merge(titleSmall), bodyLarge = defaults.bodyLarge.merge(bodyLarge), bodyMedium = defaults.bodyMedium.merge(bodyMedium), bodySmall = defaults.bodySmall.merge(bodySmall), labelLarge = defaults.labelLarge.merge(labelLarge), labelMedium = defaults.labelMedium.merge(labelMedium), labelSmall = defaults.labelSmall.merge(labelSmall) ) } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/molecule/Buttons.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.molecule import androidx.compose.foundation.background import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @Composable fun PositiveButton( text: String, modifier: Modifier = Modifier, onClick: () -> Unit ) { Button( modifier = modifier.background( color = MaterialTheme.colorScheme.primaryContainer, shape = MaterialTheme.shapes.small ), onClick = { onClick() }, colors = ButtonDefaults.buttonColors( containerColor = MaterialTheme.colorScheme.primaryContainer, contentColor = MaterialTheme.colorScheme.onPrimaryContainer ) ) { LargeLabel(text = text) } } @Composable fun NegativeButton( text: String, modifier: Modifier = Modifier, onClick: () -> Unit ) { Button( modifier = modifier.background( color = MaterialTheme.colorScheme.secondaryContainer, shape = MaterialTheme.shapes.small ), onClick = { onClick() }, colors = ButtonDefaults.buttonColors( containerColor = MaterialTheme.colorScheme.secondaryContainer, contentColor = MaterialTheme.colorScheme.onSecondaryContainer ) ) { LargeLabel(text = text) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/molecule/Image.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.molecule import androidx.compose.foundation.Image import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.defaultMinSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.unit.dp import coil.compose.AsyncImage // todo check with 48 private val ICON_SIZE = 40.dp @Composable fun RemoteImage( url: String, contentDescription: String, modifier: Modifier = Modifier ) { AsyncImage( model = url, contentDescription = contentDescription, modifier = modifier, ) } @Composable fun ActionIcon( painter: Painter, contentDescription: String, modifier: Modifier = Modifier, onClicked: () -> Unit ) { Image( painter = painter, contentDescription = contentDescription, modifier = modifier .defaultMinSize(ICON_SIZE) .clickable { onClicked() } ) } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/molecule/Text.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.molecule import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign @Composable fun LargeDisplay(text: String, modifier: Modifier = Modifier) { Text( text = text, modifier = modifier, style = MaterialTheme.typography.displayLarge ) } @Composable fun MediumDisplay(text: String, modifier: Modifier = Modifier) { Text( text = text, modifier = modifier, style = MaterialTheme.typography.displayMedium ) } @Composable fun SmallDisplay(text: String, modifier: Modifier = Modifier) { Text( text = text, modifier = modifier, style = MaterialTheme.typography.displaySmall ) } @Composable fun LargeLabel( text: String, modifier: Modifier = Modifier, color: Color = Color.Unspecified, fontWeight: FontWeight = FontWeight.Medium ) { Text( text = text, style = MaterialTheme.typography.labelLarge.copy(fontWeight = fontWeight), modifier = modifier, color = color ) } @Composable fun MediumLabel( text: String, modifier: Modifier = Modifier, color: Color = Color.Unspecified, textAlign: TextAlign = TextAlign.Start ) { Text( text = text, style = MaterialTheme.typography.labelMedium, modifier = modifier, color = color, textAlign = textAlign ) } @Composable fun MediumHeadline( text: String, modifier: Modifier = Modifier, color: Color = Color.Unspecified, textAlign: TextAlign? = null, ) { Text( text = text, style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold), color = color, modifier = modifier, textAlign = textAlign, ) } @Composable fun SmallHeadline( text: String, modifier: Modifier = Modifier, ) { Text( text = text, style = MaterialTheme.typography.headlineSmall.copy(fontWeight = FontWeight.Bold), modifier = modifier, ) } @Composable fun LargeBody( text: String, modifier: Modifier = Modifier, ) { Text( text = text, style = MaterialTheme.typography.bodyLarge, modifier = modifier, ) } @Composable fun SmallBody( text: String, modifier: Modifier = Modifier, ) { Text( text = text, style = MaterialTheme.typography.bodySmall, modifier = modifier, ) } @Composable fun MediumBody( text: String, modifier: Modifier = Modifier, color: Color = Color.Unspecified, textAlign: TextAlign? = null, ) { Text( text = text, style = MaterialTheme.typography.bodyMedium, color = color, modifier = modifier, textAlign = textAlign ) } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/organism/BottomSheets.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.organism import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material3.Checkbox import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.RadioButton import androidx.compose.material3.SheetState import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.molecule.MediumBody import com.github.odaridavid.weatherapp.designsystem.molecule.PositiveButton import com.github.odaridavid.weatherapp.designsystem.molecule.SmallHeadline import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch // todo reuse some logic for single select and multi select @OptIn(ExperimentalMaterial3Api::class) @Composable fun MultiSelectBottomSheet( title: String, items: List, selectedItems: List, sheetState: SheetState, onSaveState: (List) -> Unit, onDismiss: (() -> Unit)? = null, ) { val scope = rememberCoroutineScope() ModalBottomSheet( onDismissRequest = { scope.launch { sheetState.hide() } if (onDismiss != null) { onDismiss() } }, sheetState = sheetState, // windowInsets = WindowInsets.navigationBars, ) { Column( modifier = Modifier .fillMaxWidth() ) { SmallHeadline( text = title, modifier = Modifier.padding( vertical = WeatherAppTheme.dimens.small, horizontal = WeatherAppTheme.dimens.medium ) ) val selectedItemsState = remember { mutableStateListOf(*selectedItems.toTypedArray()) } LazyColumn() { items(items) { item -> Row { Checkbox( checked = selectedItemsState.count { it.id == item.id } > 0, onCheckedChange = { isSelected -> if (isSelected) { if (item.id == NONE_ID) selectedItemsState.clear() // TODO use removeIf once min sdk is 24 else selectedItemsState.removeAll { it.id == NONE_ID } selectedItemsState.add(item.copy(isSelected = true)) } else { selectedItemsState.removeAll { it.id == item.id } } } ) MediumBody( text = item.name, modifier = Modifier.padding( horizontal = WeatherAppTheme.dimens.small, vertical = WeatherAppTheme.dimens.medium ) ) } } } MultiSelectSaveButtonSection( sheetState = sheetState, coroutineScope = scope, onSaveState = onSaveState, selectedItemsState = selectedItemsState, ) } } } @OptIn(ExperimentalMaterial3Api::class) @Composable fun SingleSelectBottomSheet( title: String, items: List, selectedItem: BottomSheetItem, sheetState: SheetState, onSaveState: (BottomSheetItem) -> Unit, onDismiss: (() -> Unit)? = null, ) { val scope = rememberCoroutineScope() ModalBottomSheet( onDismissRequest = { scope.launch { sheetState.hide() } if (onDismiss != null) { onDismiss() } }, sheetState = sheetState, // windowInsets = WindowInsets.navigationBars, ) { Column( modifier = Modifier.fillMaxWidth() ) { SmallHeadline( text = title, modifier = Modifier.padding( vertical = WeatherAppTheme.dimens.small, horizontal = WeatherAppTheme.dimens.medium ) ) val selectedItemsState = remember { mutableStateOf(selectedItem) } LazyColumn(Modifier.weight(1f, false)) { items(items) { item -> Row { RadioButton( selected = selectedItemsState.value.id == item.id, onClick = { selectedItemsState.value = item.copy(isSelected = true) } ) MediumBody( text = item.name, modifier = Modifier.padding( horizontal = WeatherAppTheme.dimens.small, vertical = WeatherAppTheme.dimens.medium ) ) } } } SingleSelectSaveButtonSection( sheetState = sheetState, coroutineScope = scope, onSaveState = onSaveState, selectedItemState = selectedItemsState, ) } } } @OptIn(ExperimentalMaterial3Api::class) @Composable fun SingleSelectSaveButtonSection( sheetState: SheetState, coroutineScope: CoroutineScope, onSaveState: (BottomSheetItem) -> Unit, selectedItemState: MutableState, ) { SaveButton( sheetState = sheetState, coroutineScope = coroutineScope, ) { onSaveState(selectedItemState.value) } } @OptIn(ExperimentalMaterial3Api::class) @Composable fun MultiSelectSaveButtonSection( sheetState: SheetState, coroutineScope: CoroutineScope, onSaveState: (List) -> Unit, selectedItemsState: SnapshotStateList, ) { SaveButton( sheetState = sheetState, coroutineScope = coroutineScope, ) { onSaveState(selectedItemsState) } } @OptIn(ExperimentalMaterial3Api::class) @Composable private fun SaveButton( sheetState: SheetState, coroutineScope: CoroutineScope, onSaveState: () -> Unit, ) { Box( contentAlignment = Alignment.BottomEnd, modifier = Modifier .fillMaxWidth() ) { PositiveButton( text = stringResource(id = R.string.settings_save), modifier = Modifier .fillMaxWidth() .padding(WeatherAppTheme.dimens.medium) ) { coroutineScope.launch { sheetState.hide() } onSaveState() } } } data class BottomSheetItem( val name: String, val id: Int, val isSelected: Boolean = false, ) const val NONE_ID = -1 ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/organism/Dialogs.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.organism import android.Manifest import androidx.activity.result.ActivityResultLauncher import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding import androidx.compose.material3.BasicAlertDialog import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.window.Dialog import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.molecule.LargeLabel import com.github.odaridavid.weatherapp.designsystem.molecule.MediumBody import com.github.odaridavid.weatherapp.designsystem.molecule.NegativeButton import com.github.odaridavid.weatherapp.designsystem.molecule.PositiveButton @OptIn(ExperimentalMaterial3Api::class) @Composable fun PermissionRationaleDialog( isDialogShown: MutableState, activityPermissionResult: ActivityResultLauncher, showWeatherUI: MutableState ) { BasicAlertDialog( onDismissRequest = { isDialogShown.value = false }, modifier = Modifier .background(MaterialTheme.colorScheme.surface) ) { Column { LargeLabel( text = stringResource(R.string.location_rationale_title), modifier = Modifier.padding( horizontal = WeatherAppTheme.dimens.medium, vertical = WeatherAppTheme.dimens.small ) ) MediumBody( text = stringResource(R.string.location_rationale_description), modifier = Modifier.padding(WeatherAppTheme.dimens.medium) ) Row(modifier = Modifier.padding(WeatherAppTheme.dimens.medium)) { PositiveButton( text = stringResource(R.string.location_rationale_button_grant), onClick = { isDialogShown.value = false activityPermissionResult.launch(Manifest.permission.ACCESS_COARSE_LOCATION) } ) Spacer(modifier = Modifier.weight(1f)) NegativeButton( text = stringResource(R.string.location_rationale_button_deny), onClick = { isDialogShown.value = false showWeatherUI.value = false } ) } } } } @Composable fun UpdateDialog( onDismiss: () -> Unit, onConfirm: () -> Unit, ) { Dialog(onDismissRequest = { onDismiss() }) { Box { MediumBody(text = stringResource(R.string.update_available)) PositiveButton( text = stringResource(R.string.install_update), onClick = { onConfirm() } ) } } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/organism/NavBars.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.organism import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.molecule.ActionIcon import com.github.odaridavid.weatherapp.designsystem.molecule.MediumHeadline // TODO Create a navbar factory when more screens are added @Composable fun HomeTopBar(cityName: String, onSettingClicked: () -> Unit) { Row( modifier = Modifier .padding(WeatherAppTheme.dimens.medium) .fillMaxWidth() ) { MediumHeadline(text = cityName) Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.FULL)) ActionIcon( painter = painterResource(id = R.drawable.ic_settings), contentDescription = stringResource(R.string.home_content_description_setting_icon), modifier = Modifier.padding(WeatherAppTheme.dimens.small), onClicked = { onSettingClicked() } ) } } @Composable fun TopNavigationBar(onBackButtonClicked: () -> Unit, title: String) { Row(modifier = Modifier.padding(WeatherAppTheme.dimens.medium)) { ActionIcon( painter = painterResource(id = R.drawable.ic_arrow_back), contentDescription = stringResource(R.string.back_button_content_description_icon), modifier = Modifier.padding(WeatherAppTheme.dimens.small), onClicked = { onBackButtonClicked() } ) MediumHeadline( text = title, modifier = Modifier.align(Alignment.CenterVertically), textAlign = TextAlign.Center, ) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/organism/Row.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.organism import androidx.annotation.DrawableRes import androidx.compose.foundation.Image import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.molecule.LargeBody import com.github.odaridavid.weatherapp.designsystem.molecule.LargeLabel @Composable fun SettingOptionRow( optionLabel: String, optionValue: String? = null, @DrawableRes optionIcon: Int, optionIconContentDescription: String, modifier: Modifier = Modifier, onOptionClicked: () -> Unit ) { Row( modifier = modifier .fillMaxWidth() .clickable { onOptionClicked() } .padding(WeatherAppTheme.dimens.medium) ) { Image( painter = painterResource(id = optionIcon), contentDescription = optionIconContentDescription, modifier = Modifier.padding(WeatherAppTheme.dimens.small) ) LargeLabel( text = optionLabel, modifier = Modifier.padding(WeatherAppTheme.dimens.small), fontWeight = FontWeight.Bold ) Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.FULL)) optionValue?.let { LargeBody( text = it, modifier = Modifier.padding(WeatherAppTheme.dimens.extraSmall) ) } } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/organism/TextWidgets.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.organism import androidx.annotation.StringRes import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.molecule.LargeDisplay import com.github.odaridavid.weatherapp.designsystem.molecule.MediumBody import com.github.odaridavid.weatherapp.designsystem.molecule.MediumLabel import com.github.odaridavid.weatherapp.designsystem.molecule.PositiveButton // TODO These components still feel meh. They could be better or maybe they are too specfic @Composable fun Temperature(text: String) { MediumBody( text = text, modifier = Modifier.padding(WeatherAppTheme.dimens.extraSmall) ) } @Composable fun ForecastedTime(text: String, modifier: Modifier = Modifier) { MediumBody( text = text, modifier = modifier.padding(WeatherAppTheme.dimens.extraSmall) ) } @Composable fun VersionInfoText(versionInfo: String, modifier: Modifier) { MediumLabel( text = versionInfo, modifier = modifier .fillMaxWidth() .padding(WeatherAppTheme.dimens.medium), textAlign = TextAlign.Center ) } @Composable fun TemperatureHeadline(temperature: String, modifier: Modifier = Modifier) { LargeDisplay( text = temperature, modifier = modifier .padding(horizontal = WeatherAppTheme.dimens.medium) .padding(vertical = WeatherAppTheme.dimens.small) ) } @Composable fun ActionErrorMessage( @StringRes errorMessageId: Int, modifier: Modifier, onTryAgainClicked: () -> Unit, ) { Column(modifier = Modifier.fillMaxWidth()) { MediumBody( text = stringResource(id = errorMessageId), textAlign = TextAlign.Center, modifier = modifier.align(Alignment.CenterHorizontally), ) PositiveButton( text = stringResource(id = R.string.home_error_try_again), onClick = { onTryAgainClicked() }, modifier = Modifier .padding(WeatherAppTheme.dimens.medium) .align(Alignment.CenterHorizontally) ) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/templates/ErrorScreen.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.templates import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.organism.ActionErrorMessage @Composable fun ColumnScope.ErrorScreen(errorMsgId: Int, onTryAgainClicked: () -> Unit) { Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.HALF)) ActionErrorMessage( errorMessageId = errorMsgId, modifier = Modifier.padding(WeatherAppTheme.dimens.medium) ) { onTryAgainClicked() } Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.HALF)) } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/templates/InfoScreens.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.templates import androidx.annotation.StringRes import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.molecule.MediumBody @Composable fun InfoScreen(@StringRes message: Int) { Column( modifier = Modifier .fillMaxWidth() .padding(WeatherAppTheme.dimens.medium) ) { Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.HALF)) MediumBody( text = stringResource(message), modifier = Modifier .padding(WeatherAppTheme.dimens.medium) .align(Alignment.CenterHorizontally) ) Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.HALF)) } } @Composable fun RequiresPermissionsScreen() { InfoScreen(message = R.string.location_no_permission_screen_description) } @Composable fun EnableLocationSettingScreen() { InfoScreen(message = R.string.location_settings_not_enabled) } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/designsystem/templates/ProgressScreens.kt ================================================ package com.github.odaridavid.weatherapp.designsystem.templates import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme @Composable fun LoadingScreen() { Column(modifier = Modifier.fillMaxSize()) { Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.FULL)) CircularProgressIndicator( modifier = Modifier .padding(WeatherAppTheme.dimens.medium) .align(Alignment.CenterHorizontally) ) Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.FULL)) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/di/ClientModule.kt ================================================ package com.github.odaridavid.weatherapp.di import android.content.Context import com.chuckerteam.chucker.api.ChuckerCollector import com.chuckerteam.chucker.api.ChuckerInterceptor import com.github.odaridavid.weatherapp.BuildConfig import com.github.odaridavid.weatherapp.data.weather.remote.OpenWeatherService import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import java.util.concurrent.TimeUnit import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object ClientModule { @OptIn(ExperimentalSerializationApi::class) @Provides @Singleton fun provideRetrofit( @ApplicationContext context: Context, ): Retrofit { val okHttpClient = provideOkhttpClient(context = context) val json = providesJson() val contentType = "application/json".toMediaType() return Retrofit.Builder() .baseUrl(BuildConfig.OPEN_WEATHER_BASE_URL) .client(okHttpClient) .addConverterFactory(json.asConverterFactory(contentType)) .build() } @Provides @Singleton fun provideOpenWeatherService(retrofit: Retrofit): OpenWeatherService = retrofit.create(OpenWeatherService::class.java) private fun providesJson(): Json = Json { ignoreUnknownKeys = true } private fun provideOkhttpClient( context: Context ): OkHttpClient { val loggingInterceptor = provideLoggingInterceptor() val chuckerInterceptor = provideChuckerInterceptor(context) return OkHttpClient.Builder() .connectTimeout(60L, TimeUnit.SECONDS) .addInterceptor(loggingInterceptor) .addInterceptor(chuckerInterceptor) .build() } private fun provideLoggingInterceptor(): HttpLoggingInterceptor { val level = if (BuildConfig.DEBUG) { HttpLoggingInterceptor.Level.BODY } else HttpLoggingInterceptor.Level.NONE return HttpLoggingInterceptor().also { it.level = level } } private fun provideChuckerInterceptor( context: Context ): ChuckerInterceptor = ChuckerInterceptor.Builder(context = context) .collector(ChuckerCollector(context = context)) .maxContentLength(length = 250000L) .redactHeaders(headerNames = emptySet()) .alwaysReadResponseBody(enable = false) .build() } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/di/RepositoryModule.kt ================================================ package com.github.odaridavid.weatherapp.di import com.github.odaridavid.weatherapp.api.Logger import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.api.WeatherRepository import com.github.odaridavid.weatherapp.data.settings.DefaultSettingsRepository import com.github.odaridavid.weatherapp.data.weather.DefaultWeatherRepository import com.github.odaridavid.weatherapp.data.weather.FirebaseLogger import com.github.odaridavid.weatherapp.data.weather.remote.DefaultRemoteWeatherDataSource import com.github.odaridavid.weatherapp.data.weather.remote.RemoteWeatherDataSource import dagger.Binds import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.android.components.ViewModelComponent @Module @InstallIn(ViewModelComponent::class) interface RepositoryModule { @Binds fun bindWeatherRepository(weatherRepository: DefaultWeatherRepository): WeatherRepository @Binds fun bindSettingsRepository(settingsRepository: DefaultSettingsRepository): SettingsRepository @Binds fun bindFirebaseLogger(logger: FirebaseLogger): Logger @Binds fun bindRemoteWeatherDataSource(remoteWeatherDataSource: DefaultRemoteWeatherDataSource): RemoteWeatherDataSource } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/AppNavGraph.kt ================================================ package com.github.odaridavid.weatherapp.ui import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import com.github.odaridavid.weatherapp.ui.about.AboutScreen import com.github.odaridavid.weatherapp.ui.home.HomeScreen import com.github.odaridavid.weatherapp.ui.home.HomeScreenIntent import com.github.odaridavid.weatherapp.ui.home.HomeViewModel import com.github.odaridavid.weatherapp.ui.settings.SettingsScreen import com.github.odaridavid.weatherapp.ui.settings.SettingsScreenIntent import com.github.odaridavid.weatherapp.ui.settings.SettingsScreenViewState import com.github.odaridavid.weatherapp.ui.settings.SettingsViewModel @Composable fun WeatherAppScreensConfig( navController: NavHostController ) { NavHost(navController = navController, startDestination = Destinations.HOME.route) { composable(Destinations.HOME.route) { val homeViewModel = hiltViewModel() val state = homeViewModel .state .collectAsState() .value HomeScreen( state = state, onSettingClicked = { navController.navigate(Destinations.SETTINGS.route) }, onTryAgainClicked = { homeViewModel.processIntent(HomeScreenIntent.LoadWeatherData) }, onCityNameReceived = { cityName -> homeViewModel.processIntent(HomeScreenIntent.DisplayCityName(cityName = cityName)) } ) } composable(Destinations.SETTINGS.route) { val settingsViewModel = hiltViewModel() val state = settingsViewModel .state .collectAsState(initial = SettingsScreenViewState()) .value settingsViewModel.processIntent(SettingsScreenIntent.LoadSettingScreenData) SettingsScreen( state = state, onBackButtonClicked = { navController.navigateUp() }, onLanguageChanged = { selectedLanguage -> settingsViewModel.processIntent( SettingsScreenIntent.ChangeLanguage( selectedLanguage ) ) }, onUnitChanged = { selectedUnit -> settingsViewModel.processIntent(SettingsScreenIntent.ChangeUnits(selectedUnit)) }, onTimeFormatChanged = { selectedFormat -> settingsViewModel.processIntent( SettingsScreenIntent.ChangeTimeFormat(selectedFormat) ) }, onAboutClicked = { navController.navigate(Destinations.ABOUT.route) }, onExcludedDataChanged = { excludeData -> settingsViewModel.processIntent( SettingsScreenIntent.ChangeExcludedData(excludeData) ) } ) } composable(Destinations.ABOUT.route) { AboutScreen { navController.navigateUp() } } } } enum class Destinations(val route: String) { HOME("home"), SETTINGS("settings"), ABOUT("about") } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/MainActivity.kt ================================================ package com.github.odaridavid.weatherapp.ui import android.annotation.SuppressLint import android.location.Location import android.os.Bundle import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.ui.Modifier import androidx.navigation.compose.rememberNavController import com.github.odaridavid.weatherapp.MainViewIntent import com.github.odaridavid.weatherapp.MainViewModel import com.github.odaridavid.weatherapp.MainViewState import com.github.odaridavid.weatherapp.common.CheckForPermissions import com.github.odaridavid.weatherapp.common.OnPermissionDenied import com.github.odaridavid.weatherapp.common.createLocationRequest import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.organism.UpdateDialog import com.github.odaridavid.weatherapp.designsystem.templates.EnableLocationSettingScreen import com.github.odaridavid.weatherapp.designsystem.templates.LoadingScreen import com.github.odaridavid.weatherapp.designsystem.templates.RequiresPermissionsScreen import com.github.odaridavid.weatherapp.ui.update.UpdateManager import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @AndroidEntryPoint class MainActivity : ComponentActivity() { private val mainViewModel: MainViewModel by viewModels() @Inject lateinit var updateManager: UpdateManager private val locationRequestLauncher = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result -> if (result.resultCode == RESULT_OK) { mainViewModel.processIntent(MainViewIntent.CheckLocationSettings(isEnabled = true)) } else { mainViewModel.processIntent(MainViewIntent.CheckLocationSettings(isEnabled = false)) } } private val permissionRequestLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted -> mainViewModel.processIntent(MainViewIntent.GrantPermission(isGranted = isGranted)) } private val updateRequestLauncher = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result -> if (result.resultCode == RESULT_OK) { // TODO Trigger a UI event ,is this even necessary since we already have a listener? Log.d("MainActivity", "Update successful") } else { Log.e("MainActivity", "Update failed") } } private lateinit var fusedLocationProviderClient: FusedLocationProviderClient override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() updateManager.checkForUpdates( activityResultLauncher = updateRequestLauncher, onUpdateDownloaded = { mainViewModel.processIntent(MainViewIntent.UpdateApp) }, onUpdateFailure = { exception -> mainViewModel.processIntent(MainViewIntent.LogException(throwable = exception)) } ) createLocationRequest( activity = this@MainActivity, locationRequestLauncher = locationRequestLauncher ) { mainViewModel.processIntent(MainViewIntent.CheckLocationSettings(isEnabled = true)) } fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this) setContent { WeatherAppTheme { Surface( modifier = Modifier.fillMaxSize().safeDrawingPadding(), color = MaterialTheme.colorScheme.background ) { val state = mainViewModel.state.collectAsState().value // TODO test this with internal testing track mainViewModel.hasAppUpdate.collectAsState().value.let { hasAppUpdate -> if (hasAppUpdate) { UpdateDialog( onDismiss = { // TODO dismiss it }, onConfirm = { updateManager.completeUpdate() } ) } } CheckForPermissions( onPermissionGranted = { mainViewModel.processIntent(MainViewIntent.GrantPermission(isGranted = true)) }, onPermissionDenied = { OnPermissionDenied(activityPermissionResult = permissionRequestLauncher) } ) InitMainScreen(state) } } } } @SuppressLint("MissingPermission") @Composable private fun InitMainScreen(state: MainViewState) { when { state.isLocationSettingEnabled && state.isPermissionGranted -> { fusedLocationProviderClient.lastLocation .addOnSuccessListener { location: Location? -> location?.run { mainViewModel.processIntent( MainViewIntent.ReceiveLocation( longitude = location.longitude, latitude = location.latitude ) ) } }.addOnFailureListener { exception -> mainViewModel.processIntent(MainViewIntent.LogException(throwable = exception)) } WeatherAppScreensConfig(navController = rememberNavController()) } state.isLocationSettingEnabled && !state.isPermissionGranted -> { RequiresPermissionsScreen() } !state.isLocationSettingEnabled && !state.isPermissionGranted -> { EnableLocationSettingScreen() } else -> LoadingScreen() } } override fun onDestroy() { super.onDestroy() updateManager.unregisterListeners() } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/about/AboutScreen.kt ================================================ package com.github.odaridavid.weatherapp.ui.about import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.designsystem.organism.TopNavigationBar import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer @Composable fun AboutScreen( onBackButtonClicked: () -> Unit, ) { Column { TopNavigationBar( onBackButtonClicked = onBackButtonClicked, title = stringResource(R.string.about_screen_title), ) LibrariesContainer( Modifier.fillMaxSize() ) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/home/HomeScreen.kt ================================================ package com.github.odaridavid.weatherapp.ui.home import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.common.getCityName import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.molecule.LargeLabel import com.github.odaridavid.weatherapp.designsystem.molecule.MediumBody import com.github.odaridavid.weatherapp.designsystem.molecule.RemoteImage import com.github.odaridavid.weatherapp.designsystem.organism.ForecastedTime import com.github.odaridavid.weatherapp.designsystem.organism.HomeTopBar import com.github.odaridavid.weatherapp.designsystem.organism.Temperature import com.github.odaridavid.weatherapp.designsystem.organism.TemperatureHeadline import com.github.odaridavid.weatherapp.designsystem.templates.ErrorScreen import com.github.odaridavid.weatherapp.designsystem.templates.LoadingScreen import com.github.odaridavid.weatherapp.model.CurrentWeather import com.github.odaridavid.weatherapp.model.DailyWeather import com.github.odaridavid.weatherapp.model.HourlyWeather @Composable fun HomeScreen( state: HomeScreenViewState, onSettingClicked: () -> Unit, onTryAgainClicked: () -> Unit, onCityNameReceived: (String) -> Unit ) { Column(modifier = Modifier.fillMaxSize()) { LocalContext.current.getCityName( latitude = state.defaultLocation.latitude, longitude = state.defaultLocation.longitude ) { address -> val cityName = address.locality onCityNameReceived(cityName) } HomeTopBar(cityName = state.locationName, onSettingClicked) if (state.isLoading) { LoadingScreen() } if (state.errorMessageId != null) { ErrorScreen(state.errorMessageId, onTryAgainClicked) } else { state.weather?.current?.let { currentWeather -> CurrentWeatherWidget(currentWeather = currentWeather) } ?: run { EmptySectionWidget( label = stringResource(id = R.string.home_title_currently), weatherType = stringResource(id = R.string.home_weather_type_currently) ) } state.weather?.hourly?.let { hourlyWeather -> HourlyWeatherWidget(hourlyWeatherList = hourlyWeather) } ?: run { EmptySectionWidget( label = stringResource(id = R.string.home_today_forecast_title), weatherType = stringResource(id = R.string.home_weather_type_hourly) ) } state.weather?.daily?.let { dailyWeather -> DailyWeatherWidget(dailyWeatherList = dailyWeather) } ?: run { EmptySectionWidget( label = stringResource(id = R.string.home_weekly_forecast_title), weatherType = stringResource(id = R.string.home_weather_type_daily) ) } } } } @Composable private fun EmptySectionWidget(label: String, weatherType: String) { Column { LargeLabel( text = label, modifier = Modifier.padding( horizontal = WeatherAppTheme.dimens.medium, vertical = WeatherAppTheme.dimens.small ) ) MediumBody( text = stringResource(R.string.home_enable_weather_in_settings, weatherType), modifier = Modifier .fillMaxWidth() .padding(WeatherAppTheme.dimens.medium), textAlign = TextAlign.Center ) } } @Composable private fun CurrentWeatherWidget(currentWeather: CurrentWeather) { Column { LargeLabel( text = stringResource(id = R.string.home_title_currently), modifier = Modifier.padding( horizontal = WeatherAppTheme.dimens.medium, vertical = WeatherAppTheme.dimens.small ) ) TemperatureHeadline(temperature = currentWeather.temperature) LargeLabel( text = stringResource( id = R.string.home_feels_like_description, currentWeather.feelsLike ), color = MaterialTheme.colorScheme.secondary, modifier = Modifier.padding( horizontal = WeatherAppTheme.dimens.medium, vertical = WeatherAppTheme.dimens.small ) ) } } @OptIn(ExperimentalFoundationApi::class) @Composable private fun HourlyWeatherWidget(hourlyWeatherList: List) { LargeLabel( text = stringResource(id = R.string.home_today_forecast_title), modifier = Modifier.padding( horizontal = WeatherAppTheme.dimens.medium, vertical = WeatherAppTheme.dimens.small ) ) LazyRow(modifier = Modifier.padding(WeatherAppTheme.dimens.medium)) { items(hourlyWeatherList) { hourlyWeather -> HourlyWeatherRow( hourlyWeather = hourlyWeather, modifier = Modifier.animateItemPlacement() ) } } } @Composable private fun HourlyWeatherRow(hourlyWeather: HourlyWeather, modifier: Modifier) { Row(modifier = modifier) { RemoteImage( url = hourlyWeather.weather.first().icon, contentDescription = hourlyWeather.weather.first().description, modifier = Modifier .padding(WeatherAppTheme.dimens.extraSmall) .align(Alignment.CenterVertically), ) Column( modifier = Modifier .padding(WeatherAppTheme.dimens.extraSmall) .align(Alignment.CenterVertically) ) { Temperature(text = hourlyWeather.temperature) ForecastedTime(text = hourlyWeather.forecastedTime) } } } @OptIn(ExperimentalFoundationApi::class) @Composable private fun DailyWeatherWidget(dailyWeatherList: List) { LargeLabel( text = stringResource(id = R.string.home_weekly_forecast_title), modifier = Modifier.padding( horizontal = WeatherAppTheme.dimens.medium, vertical = WeatherAppTheme.dimens.small ) ) LazyColumn(modifier = Modifier.padding(WeatherAppTheme.dimens.medium)) { items(dailyWeatherList) { dailyWeather -> DailyWeatherRow(dailyWeather = dailyWeather, modifier = Modifier.animateItemPlacement()) } } } @Composable private fun DailyWeatherRow(dailyWeather: DailyWeather, modifier: Modifier) { Row( modifier = modifier .padding(WeatherAppTheme.dimens.small) .fillMaxWidth() ) { RemoteImage( url = dailyWeather.weather.first().icon, contentDescription = dailyWeather.weather.first().description, modifier = Modifier .padding(WeatherAppTheme.dimens.extraSmall) .align(Alignment.CenterVertically), ) ForecastedTime( text = dailyWeather.forecastedTime, modifier = Modifier .align(Alignment.CenterVertically) ) Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.FULL)) Column(modifier = Modifier.align(Alignment.CenterVertically)) { Temperature( text = stringResource( id = R.string.home_max_temp, dailyWeather.temperature.max ) ) Temperature( text = stringResource( id = R.string.home_min_temp, dailyWeather.temperature.min ) ) } } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/home/HomeScreenIntent.kt ================================================ package com.github.odaridavid.weatherapp.ui.home sealed class HomeScreenIntent { data object LoadWeatherData : HomeScreenIntent() data class DisplayCityName(val cityName: String) : HomeScreenIntent() } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/home/HomeViewModel.kt ================================================ package com.github.odaridavid.weatherapp.ui.home import androidx.annotation.StringRes import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.api.WeatherRepository import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.Result import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.Units import com.github.odaridavid.weatherapp.model.Weather import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( private val weatherRepository: WeatherRepository, private val settingsRepository: SettingsRepository ) : ViewModel() { private val _state = MutableStateFlow(HomeScreenViewState(isLoading = true)) val state: StateFlow = _state.asStateFlow() init { viewModelScope.launch { combine( settingsRepository.getLanguage(), settingsRepository.getUnits(), settingsRepository.getDefaultLocation() ) { language, units, defaultLocation -> Triple(language, units, defaultLocation) }.collect { (language, units, defaultLocation) -> setState { copy( language = language, units = units, defaultLocation = defaultLocation ) }.also { processIntent(HomeScreenIntent.LoadWeatherData) } } } } fun processIntent(homeScreenIntent: HomeScreenIntent) { when (homeScreenIntent) { is HomeScreenIntent.LoadWeatherData -> { viewModelScope.launch { val result = weatherRepository.fetchWeatherData( language = state.value.language.languageValue, defaultLocation = state.value.defaultLocation, units = state.value.units.value ) processResult(result) } } is HomeScreenIntent.DisplayCityName -> { setState { copy(locationName = homeScreenIntent.cityName) } } } } private fun processResult(result: Result) { when (result) { is Result.Success -> { val weatherData = result.data setState { copy( weather = weatherData, isLoading = false, errorMessageId = null ) } } is Result.Error -> { setState { copy( isLoading = false, errorMessageId = result.errorType.toResourceId() ) } } } } private fun setState(stateReducer: HomeScreenViewState.() -> HomeScreenViewState) { viewModelScope.launch { _state.emit(stateReducer(state.value)) } } } data class HomeScreenViewState( val units: Units = Units.METRIC, val defaultLocation: DefaultLocation = DefaultLocation(0.0, 0.0), val locationName: String = "-", val language: SupportedLanguage = SupportedLanguage.ENGLISH, val weather: Weather? = null, val isLoading: Boolean = false, @StringRes val errorMessageId: Int? = null ) ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/home/Mappers.kt ================================================ package com.github.odaridavid.weatherapp.ui.home import androidx.annotation.StringRes import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.model.ErrorType @StringRes fun ErrorType.toResourceId(): Int = when (this) { ErrorType.SERVER -> R.string.error_server ErrorType.GENERIC -> R.string.error_generic ErrorType.IO_CONNECTION -> R.string.error_connection ErrorType.CLIENT -> R.string.error_client } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/settings/SettingsScreen.kt ================================================ package com.github.odaridavid.weatherapp.ui.settings import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.SheetState import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.github.odaridavid.weatherapp.R import com.github.odaridavid.weatherapp.designsystem.WeatherAppTheme import com.github.odaridavid.weatherapp.designsystem.organism.MultiSelectBottomSheet import com.github.odaridavid.weatherapp.designsystem.organism.SettingOptionRow import com.github.odaridavid.weatherapp.designsystem.organism.SingleSelectBottomSheet import com.github.odaridavid.weatherapp.designsystem.organism.TopNavigationBar import com.github.odaridavid.weatherapp.designsystem.organism.VersionInfoText import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import kotlinx.coroutines.launch @OptIn(ExperimentalMaterial3Api::class) @Composable fun SettingsScreen( state: SettingsScreenViewState, onBackButtonClicked: () -> Unit, onLanguageChanged: (SupportedLanguage) -> Unit, onUnitChanged: (Units) -> Unit, onTimeFormatChanged: (TimeFormat) -> Unit, onAboutClicked: () -> Unit, onExcludedDataChanged: (List) -> Unit, ) { Column { TopNavigationBar( onBackButtonClicked = onBackButtonClicked, title = stringResource(R.string.settings_screen_title), ) val scope = rememberCoroutineScope() val languageSheetState = rememberModalBottomSheetState( skipPartiallyExpanded = true ) SettingOptionRow( optionLabel = stringResource(R.string.settings_language_label), optionValue = state.selectedLanguage.languageName, optionIcon = R.drawable.ic_language, optionIconContentDescription = stringResource(R.string.settings_content_description_lang_icon) ) { scope.launch { languageSheetState.show() } } val unitsSheetState = rememberModalBottomSheetState() SettingOptionRow( optionLabel = stringResource(R.string.settings_unit_label), optionValue = state.selectedUnit.value, optionIcon = R.drawable.ic_units, optionIconContentDescription = stringResource(R.string.settings_content_description_unit_icon) ) { scope.launch { unitsSheetState.show() } } val timeFormatSheetState = rememberModalBottomSheetState() SettingOptionRow( optionLabel = stringResource(R.string.settings_time_format), optionValue = state.selectedTimeFormat.value, optionIcon = R.drawable.ic_time_24, optionIconContentDescription = stringResource(R.string.settings_content_description_time_icon) ) { scope.launch { timeFormatSheetState.show() } } val excludeSheetState = rememberModalBottomSheetState( skipPartiallyExpanded = true ) SettingOptionRow( optionLabel = stringResource(id = R.string.settings_exclude_label), optionIcon = R.drawable.ic_exclude_24, optionValue = state.selectedExcludedDataDisplayValue, optionIconContentDescription = stringResource(R.string.settings_content_description_exclude_icon), ) { scope.launch { excludeSheetState.show() } } SettingOptionRow( optionLabel = stringResource(R.string.settings_about), optionIcon = R.drawable.ic_info_24, optionIconContentDescription = stringResource(R.string.settings_content_description_about_icon) ) { onAboutClicked() } SetupBottomSheets( state = state, onLanguageChanged = onLanguageChanged, onUnitChanged = onUnitChanged, onTimeFormatChanged = onTimeFormatChanged, onExcludedDataChanged = onExcludedDataChanged, languageSheetState = languageSheetState, unitsSheetState = unitsSheetState, timeFormatSheetState = timeFormatSheetState, excludeSheetState = excludeSheetState, ) Spacer(modifier = Modifier.weight(WeatherAppTheme.weight.FULL)) VersionInfoText( versionInfo = state.versionInfo, modifier = Modifier.align(Alignment.CenterHorizontally), ) } } @OptIn(ExperimentalMaterial3Api::class) @Composable private fun SetupBottomSheets( state: SettingsScreenViewState, onLanguageChanged: (SupportedLanguage) -> Unit, onUnitChanged: (Units) -> Unit, onTimeFormatChanged: (TimeFormat) -> Unit, onExcludedDataChanged: (List) -> Unit, languageSheetState: SheetState, unitsSheetState: SheetState, timeFormatSheetState: SheetState, excludeSheetState: SheetState ) { if (languageSheetState.isVisible) { SingleSelectBottomSheet( title = stringResource(id = R.string.settings_language_label), sheetState = languageSheetState, selectedItem = state.selectedLanguage.toBottomSheetModel(isSelected = true), items = state.availableLanguages.map { it.toBottomSheetModel(isSelected = false) }, onSaveState = { bottomSheet -> onLanguageChanged(bottomSheet.toSupportedLanguage()) } ) } if (unitsSheetState.isVisible) { SingleSelectBottomSheet( title = stringResource(id = R.string.settings_unit_label), sheetState = unitsSheetState, selectedItem = state.selectedUnit.toBottomSheetModel(isSelected = true), items = state.availableUnits.map { it.toBottomSheetModel(isSelected = false) }, onSaveState = { bottomSheet -> onUnitChanged(bottomSheet.toUnits()) } ) } if (timeFormatSheetState.isVisible) { SingleSelectBottomSheet( title = stringResource(id = R.string.settings_time_format), sheetState = timeFormatSheetState, selectedItem = state.selectedTimeFormat.toBottomSheetModel(isSelected = true), items = state.availableFormats.map { it.toBottomSheetModel(isSelected = false) }, onSaveState = { bottomSheet -> onTimeFormatChanged(bottomSheet.toTimeFormat()) } ) } if (excludeSheetState.isVisible) { MultiSelectBottomSheet( title = stringResource(id = R.string.settings_exclude_label), sheetState = excludeSheetState, selectedItems = state.selectedExcludedData.map { it.toBottomSheetModel(isSelected = true) }, items = state.excludedData.map { it.toBottomSheetModel(isSelected = false) }, onSaveState = { bottomSheet -> onExcludedDataChanged(bottomSheet.map { it.toExcludedData() }) } ) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/settings/SettingsScreenIntent.kt ================================================ package com.github.odaridavid.weatherapp.ui.settings import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units sealed class SettingsScreenIntent { data object LoadSettingScreenData : SettingsScreenIntent() data class ChangeLanguage(val selectedLanguage: SupportedLanguage) : SettingsScreenIntent() data class ChangeUnits(val selectedUnits: Units) : SettingsScreenIntent() data class ChangeTimeFormat(val selectedTimeFormat: TimeFormat) : SettingsScreenIntent() data class ChangeExcludedData(val selectedExcludedData: List) : SettingsScreenIntent() } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/settings/SettingsViewModel.kt ================================================ package com.github.odaridavid.weatherapp.ui.settings import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.github.odaridavid.weatherapp.api.Logger import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class SettingsViewModel @Inject constructor( private val settingsRepository: SettingsRepository, private val logger: Logger, ) : ViewModel() { private val _state = MutableStateFlow(SettingsScreenViewState()) val state: StateFlow = _state.asStateFlow() fun processIntent(settingsScreenIntent: SettingsScreenIntent) { when (settingsScreenIntent) { SettingsScreenIntent.LoadSettingScreenData -> { viewModelScope.launch { combine( settingsRepository.getLanguage(), settingsRepository.getUnits(), settingsRepository.getFormat(), settingsRepository.getExcludedData() ) { language, units, format, excludedData -> SettingsScreenViewState( selectedLanguage = language, selectedUnit = units, selectedTimeFormat = format, selectedExcludedData = mapStringToExcludedData(excludedData), selectedExcludedDataDisplayValue = excludedData, versionInfo = settingsRepository.getAppVersion(), availableLanguages = SupportedLanguage.entries, availableUnits = Units.entries, availableFormats = TimeFormat.entries, excludedData = ExcludedData.entries, ) }.collect { state -> setState { state } } } } is SettingsScreenIntent.ChangeLanguage -> { viewModelScope.launch { settingsRepository.setLanguage(settingsScreenIntent.selectedLanguage) setState { copy(selectedLanguage = settingsScreenIntent.selectedLanguage) } } } is SettingsScreenIntent.ChangeUnits -> { viewModelScope.launch { settingsRepository.setUnits(settingsScreenIntent.selectedUnits) setState { copy(selectedUnit = settingsScreenIntent.selectedUnits) } } } is SettingsScreenIntent.ChangeTimeFormat -> { viewModelScope.launch { val format = settingsScreenIntent.selectedTimeFormat settingsRepository.setFormat(format) setState { copy(selectedTimeFormat = format) } } } is SettingsScreenIntent.ChangeExcludedData -> { viewModelScope.launch { settingsRepository.setExcludedData(settingsScreenIntent.selectedExcludedData) setState { copy( selectedExcludedData = settingsScreenIntent.selectedExcludedData, selectedExcludedDataDisplayValue = mapExcludedDataToDisplayValue( settingsScreenIntent.selectedExcludedData ), ) } } } } } private fun setState(stateReducer: SettingsScreenViewState.() -> SettingsScreenViewState) { viewModelScope.launch { _state.emit(stateReducer(state.value)) } } private fun mapExcludedDataToDisplayValue(excludedData: List): String = excludedData.joinToString(separator = ",") { it.value.trim() } private fun mapStringToExcludedData(excludedData: String): List { return excludedData.split(",").map { when (it.trim()) { ExcludedData.CURRENT.value -> ExcludedData.CURRENT ExcludedData.HOURLY.value -> ExcludedData.HOURLY ExcludedData.DAILY.value -> ExcludedData.DAILY ExcludedData.MINUTELY.value -> ExcludedData.MINUTELY ExcludedData.ALERTS.value -> ExcludedData.ALERTS ExcludedData.NONE.value -> ExcludedData.NONE else -> { logger.logException(IllegalArgumentException("Invalid excluded data")) ExcludedData.NONE } } } } } data class SettingsScreenViewState( val selectedUnit: Units = Units.METRIC, val selectedLanguage: SupportedLanguage = SupportedLanguage.ENGLISH, val selectedTimeFormat: TimeFormat = TimeFormat.TWENTY_FOUR_HOUR, val selectedExcludedData: List = emptyList(), val selectedExcludedDataDisplayValue: String = "", val availableLanguages: List = emptyList(), val availableUnits: List = emptyList(), val availableFormats: List = emptyList(), val excludedData: List = emptyList(), val versionInfo: String = "", val error: Throwable? = null ) ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/settings/UIMapper.kt ================================================ package com.github.odaridavid.weatherapp.ui.settings import com.github.odaridavid.weatherapp.designsystem.organism.BottomSheetItem import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units // TODO Fix repetition of mapping fun ExcludedData.toBottomSheetModel(isSelected: Boolean = false): BottomSheetItem { return BottomSheetItem( id = this.id, name = this.name, isSelected = isSelected ) } fun BottomSheetItem.toExcludedData(): ExcludedData { return ExcludedData.entries.first { it.id == this.id } } fun TimeFormat.toBottomSheetModel(isSelected: Boolean = false): BottomSheetItem { return BottomSheetItem( id = this.ordinal, name = this.value, isSelected = isSelected ) } fun BottomSheetItem.toTimeFormat(): TimeFormat { return TimeFormat.entries.first { it.ordinal == this.id } } fun Units.toBottomSheetModel(isSelected: Boolean = false): BottomSheetItem { return BottomSheetItem( id = this.ordinal, name = this.value, isSelected = isSelected ) } fun BottomSheetItem.toUnits(): Units { return Units.entries.first { it.ordinal == this.id } } fun SupportedLanguage.toBottomSheetModel(isSelected: Boolean = false): BottomSheetItem { return BottomSheetItem( id = this.ordinal, name = this.languageName, isSelected = isSelected ) } fun BottomSheetItem.toSupportedLanguage(): SupportedLanguage { return SupportedLanguage.entries.first { it.ordinal == this.id } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/update/UpdateAppException.kt ================================================ package com.github.odaridavid.weatherapp.ui.update data class UpdateAppException(val throwable: Throwable) : Exception() ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/update/UpdateManager.kt ================================================ package com.github.odaridavid.weatherapp.ui.update import android.content.Context import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.IntentSenderRequest import com.google.android.play.core.appupdate.AppUpdateInfo import com.google.android.play.core.appupdate.AppUpdateManager import com.google.android.play.core.appupdate.AppUpdateManagerFactory import com.google.android.play.core.appupdate.AppUpdateOptions import com.google.android.play.core.install.model.AppUpdateType import com.google.android.play.core.install.model.UpdateAvailability import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject class UpdateManager @Inject constructor( @ApplicationContext private val context: Context, private val updateStateFactory: UpdateStateFactory, ) { private val appUpdateManager: AppUpdateManager by lazy { AppUpdateManagerFactory.create(context) } fun checkForUpdates( activityResultLauncher: ActivityResultLauncher, onUpdateDownloaded: () -> Unit, onUpdateFailure: (Throwable) -> Unit, ) { val appUpdateInfoTask = appUpdateManager.appUpdateInfo appUpdateManager.registerListener( updateStateFactory.getUpdateStateListener( onDownloaded = { onUpdateDownloaded() } ) ) appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE) ) { update( appUpdateManager = appUpdateManager, appUpdateInfo = appUpdateInfo, activityResultLauncher = activityResultLauncher, ) } }.addOnFailureListener { exception -> onUpdateFailure(UpdateAppException(exception)) } } fun unregisterListeners() { appUpdateManager.unregisterListener(updateStateFactory.getUpdateStateListener()) } fun completeUpdate() { appUpdateManager.completeUpdate() } private fun update( appUpdateManager: AppUpdateManager, appUpdateInfo: AppUpdateInfo, activityResultLauncher: ActivityResultLauncher ) { appUpdateManager.startUpdateFlowForResult( appUpdateInfo, activityResultLauncher, AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build() ) } } ================================================ FILE: app/src/main/java/com/github/odaridavid/weatherapp/ui/update/UpdateStateFactory.kt ================================================ package com.github.odaridavid.weatherapp.ui.update import com.google.android.play.core.install.InstallStateUpdatedListener import com.google.android.play.core.install.model.InstallStatus import javax.inject.Inject class UpdateStateFactory @Inject constructor() { fun getUpdateStateListener( onDownloading: ((bytesDownloaded: Long, totalBytesToDownload: Long) -> Unit)? = null, onDownloaded: (() -> Unit)? = null, ) = InstallStateUpdatedListener { state -> when (state.installStatus()) { InstallStatus.DOWNLOADING -> { val bytesDownloaded = state.bytesDownloaded() val totalBytesToDownload = state.totalBytesToDownload() if (onDownloading != null) { onDownloading(bytesDownloaded, totalBytesToDownload) } // Show update progress bar. } InstallStatus.DOWNLOADED -> { // Notify the user that the update is ready to be installed. if (onDownloaded != null) { onDownloaded() } } InstallStatus.INSTALLING, InstallStatus.INSTALLED, InstallStatus.FAILED, InstallStatus.CANCELED, InstallStatus.PENDING, InstallStatus.UNKNOWN -> { // No-op } else -> { // No-op } } } } ================================================ FILE: app/src/main/res/drawable/ic_arrow_back.xml ================================================ ================================================ FILE: app/src/main/res/drawable/ic_exclude_24.xml ================================================ ================================================ FILE: app/src/main/res/drawable/ic_info_24.xml ================================================ ================================================ FILE: app/src/main/res/drawable/ic_language.xml ================================================ ================================================ FILE: app/src/main/res/drawable/ic_launcher_background.xml ================================================ ================================================ FILE: app/src/main/res/drawable/ic_settings.xml ================================================ ================================================ FILE: app/src/main/res/drawable/ic_time_24.xml ================================================ ================================================ FILE: app/src/main/res/drawable/ic_units.xml ================================================ ================================================ FILE: app/src/main/res/drawable-night/ic_arrow_back.xml ================================================ ================================================ FILE: app/src/main/res/drawable-night/ic_exclude_24.xml ================================================ ================================================ FILE: app/src/main/res/drawable-night/ic_info_24.xml ================================================ ================================================ FILE: app/src/main/res/drawable-night/ic_language.xml ================================================ ================================================ FILE: app/src/main/res/drawable-night/ic_settings.xml ================================================ ================================================ FILE: app/src/main/res/drawable-night/ic_time_24.xml ================================================ ================================================ FILE: app/src/main/res/drawable-night/ic_units.xml ================================================ ================================================ FILE: app/src/main/res/drawable-v24/ic_launcher_foreground.xml ================================================ ================================================ FILE: app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml ================================================ ================================================ FILE: app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml ================================================ ================================================ FILE: app/src/main/res/values/colors.xml ================================================ #33000000 @color/immersive_sys_ui ================================================ FILE: app/src/main/res/values/strings.xml ================================================ WeatherApp Setting Icon Currently Feels like %1$s Today\'s Forecast Weekly Forecast Min %1$s Max %1$s An issue occurred Try Again Enable %1$s weather in settings to see data. Hourly Daily Current Settings Back Button Language Units Time Format About Exclude Language Icon Units Icon Time Icon About Icon Exclude icon Confirm Save About Permission Request Hey there, we need location permission to show you relevant / accurate weather information. Allow Deny You need to grant location access to use the app Check your location settings and enable them You may need to log in or sign up to see this :) Oops,something fishy is up on your end :) Oops! Something is wrong on our end :( Something is happening that\'s disturbing the force :( Check your internet connection and try again Update is available for install Install ================================================ FILE: app/src/main/res/values/themes.xml ================================================ ================================================ FILE: app/src/main/res/xml/backup_rules.xml ================================================ ================================================ FILE: app/src/main/res/xml/data_extraction_rules.xml ================================================ ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/HomeViewModelTest.kt ================================================ package com.github.odaridavid.weatherapp import app.cash.turbine.test import com.github.odaridavid.weatherapp.api.Logger import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.api.WeatherRepository import com.github.odaridavid.weatherapp.data.weather.DefaultWeatherRepository import com.github.odaridavid.weatherapp.data.weather.remote.DefaultRemoteWeatherDataSource import com.github.odaridavid.weatherapp.data.weather.remote.OpenWeatherService import com.github.odaridavid.weatherapp.data.weather.remote.WeatherResponse import com.github.odaridavid.weatherapp.fakes.FakeSettingsRepository import com.github.odaridavid.weatherapp.fakes.fakeSuccessMappedWeatherResponse import com.github.odaridavid.weatherapp.fakes.fakeSuccessWeatherResponse import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import com.github.odaridavid.weatherapp.rules.MainCoroutineRule import com.github.odaridavid.weatherapp.ui.home.HomeScreenIntent import com.github.odaridavid.weatherapp.ui.home.HomeScreenViewState import com.github.odaridavid.weatherapp.ui.home.HomeViewModel import com.google.common.truth.Truth import io.mockk.coEvery import io.mockk.impl.annotations.MockK import io.mockk.mockk import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.runBlocking import okhttp3.ResponseBody.Companion.toResponseBody import org.junit.Before import org.junit.Rule import org.junit.Test import retrofit2.Response import java.util.TimeZone @OptIn(ExperimentalCoroutinesApi::class) class HomeViewModelTest { @MockK val mockOpenWeatherService = mockk(relaxed = true) @MockK val mockLogger = mockk(relaxed = true) private val settingsRepository: SettingsRepository by lazy { FakeSettingsRepository() } @get:Rule val coroutineRule = MainCoroutineRule() @Before fun setup() { TimeZone.setDefault(TimeZone.getTimeZone("UTC")) } @Test fun `when fetching weather data is successful, then display correct data`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.success( fakeSuccessWeatherResponse ) settingsRepository.setFormat(TimeFormat.TWELVE_HOUR) val weatherRepository = createWeatherRepository() val viewModel = createViewModel( weatherRepository = weatherRepository ) viewModel.processIntent(HomeScreenIntent.LoadWeatherData) val expectedState = HomeScreenViewState( units = Units.METRIC, defaultLocation = DefaultLocation( longitude = 0.0, latitude = 0.0 ), locationName = "-", language = SupportedLanguage.ENGLISH, weather = fakeSuccessMappedWeatherResponse, isLoading = false, errorMessageId = null ) viewModel.state.test { awaitItem().also { state -> Truth.assertThat(state).isEqualTo(expectedState) } } } @Test fun `when fetching weather data is unsuccessful, then display correct error state`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.error( 404, "{}".toResponseBody() ) val weatherRepository = createWeatherRepository() val viewModel = createViewModel(weatherRepository = weatherRepository) viewModel.processIntent(HomeScreenIntent.LoadWeatherData) val expectedState = HomeScreenViewState( units = Units.METRIC, defaultLocation = DefaultLocation( longitude = 0.0, latitude = 0.0 ), locationName = "-", language = SupportedLanguage.ENGLISH, weather = null, isLoading = false, errorMessageId = R.string.error_client ) viewModel.state.test { awaitItem().also { state -> Truth.assertThat(state).isEqualTo(expectedState) } } } @Test fun `when we init the screen, then update the state`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.success( fakeSuccessWeatherResponse ) val settingsRepository = mockk() { coEvery { getDefaultLocation() } returns flowOf(DefaultLocation(0.0, 0.0)) coEvery { getLanguage() } returns flowOf(SupportedLanguage.ENGLISH) coEvery { getUnits() } returns flowOf(Units.METRIC) coEvery { getFormat() } returns flowOf(TimeFormat.TWELVE_HOUR) coEvery { getExcludedData() } returns flowOf("minutely,alerts") } val viewModel = createViewModel( settingsRepository = settingsRepository, weatherRepository = createWeatherRepository( settingsRepository = settingsRepository ) ) val expectedState = HomeScreenViewState( units = Units.METRIC, defaultLocation = DefaultLocation( longitude = 0.0, latitude = 0.0 ), locationName = "-", language = SupportedLanguage.ENGLISH, weather = fakeSuccessMappedWeatherResponse, isLoading = false, errorMessageId = null ) viewModel.state.test { awaitItem().also { state -> Truth.assertThat(state).isEqualTo(expectedState) } } } @Test fun `when we receive a city name, the state is updated with it`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.success( fakeSuccessWeatherResponse ) val settingsRepository = mockk() { coEvery { getDefaultLocation() } returns flowOf(DefaultLocation(0.0, 0.0)) coEvery { getLanguage() } returns flowOf(SupportedLanguage.ENGLISH) coEvery { getUnits() } returns flowOf(Units.METRIC) coEvery { getFormat() } returns flowOf(TimeFormat.TWELVE_HOUR) coEvery { getExcludedData() } returns flowOf("minutely,alerts") } val viewModel = createViewModel( settingsRepository = settingsRepository, weatherRepository = createWeatherRepository( settingsRepository = settingsRepository ) ) viewModel.processIntent(HomeScreenIntent.DisplayCityName(cityName = "Paradise")) val expectedState = HomeScreenViewState( units = Units.METRIC, defaultLocation = DefaultLocation( longitude = 0.0, latitude = 0.0 ), locationName = "Paradise", language = SupportedLanguage.ENGLISH, weather = fakeSuccessMappedWeatherResponse, isLoading = false, errorMessageId = null ) viewModel.state.test { awaitItem().also { state -> Truth.assertThat(state).isEqualTo(expectedState) } } } private fun createViewModel( weatherRepository: WeatherRepository, settingsRepository: SettingsRepository = this.settingsRepository ): HomeViewModel = HomeViewModel( weatherRepository = weatherRepository, settingsRepository = settingsRepository ) private fun createWeatherRepository( settingsRepository: SettingsRepository = this.settingsRepository ) = DefaultWeatherRepository( remoteWeatherDataSource = DefaultRemoteWeatherDataSource( mockOpenWeatherService ), logger = mockLogger, settingsRepository = settingsRepository, ) } ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/MainViewModelTest.kt ================================================ package com.github.odaridavid.weatherapp import app.cash.turbine.test import com.github.odaridavid.weatherapp.api.Logger import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.fakes.FakeSettingsRepository import com.github.odaridavid.weatherapp.rules.MainCoroutineRule import io.mockk.every import io.mockk.impl.annotations.MockK import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.Rule import org.junit.Test class MainViewModelTest { @OptIn(ExperimentalCoroutinesApi::class) @get:Rule val coroutineRule = MainCoroutineRule() @MockK val logger = mockk().apply { every { logException(any()) } returns Unit } private val settingsRepository: SettingsRepository by lazy { FakeSettingsRepository() } @Test fun `when we grant permission, then the state is updated as expected`() = runTest { val viewModel = createMainViewModel() viewModel.processIntent(MainViewIntent.GrantPermission(true)) viewModel.state.test { awaitItem().also { state -> assert(state.isPermissionGranted) } } } @Test fun `when we check location settings, then the state is updated as expected`() = runTest { val viewModel = createMainViewModel() viewModel.processIntent(MainViewIntent.CheckLocationSettings(true)) viewModel.state.test { awaitItem().also { state -> assert(state.isLocationSettingEnabled) } } } // TODO Use parameterized tests @Test fun `when we deny permission, then the state is updated as expected`() = runTest { val viewModel = createMainViewModel() viewModel.processIntent(MainViewIntent.GrantPermission(false)) viewModel.state.test { awaitItem().also { state -> assert(!state.isPermissionGranted) } } } @Test fun `when we log an exception,then the right methods are called`() = runTest { val viewModel = createMainViewModel( logger = logger, ) viewModel.state.test { viewModel.processIntent(MainViewIntent.LogException(Exception("Test"))) awaitItem() } verify { logger.logException(any()) } } @Test fun `when we receive a location, then the state is updated as expected`() = runTest { val viewModel = createMainViewModel( settingsRepository = settingsRepository, ) viewModel.state.test { viewModel.processIntent(MainViewIntent.ReceiveLocation(0.0, 0.0)) awaitItem().also { state -> assert(state.defaultLocation?.latitude == 0.0) assert(state.defaultLocation?.longitude == 0.0) } } } private fun createMainViewModel( settingsRepository: SettingsRepository = this.settingsRepository, logger: Logger = mockk(), ): MainViewModel { return MainViewModel(settingsRepository = settingsRepository, logger = logger) } } ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/SettingsRepositoryTest.kt ================================================ package com.github.odaridavid.weatherapp import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.data.settings.DefaultSettingsRepository import com.github.odaridavid.weatherapp.fakes.FakeSettingsRepository import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import kotlinx.coroutines.flow.map import kotlinx.coroutines.runBlocking import org.junit.Test class SettingsRepositoryTest { @Test fun `when we update language, then we get the updated language`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.setLanguage(SupportedLanguage.FRENCH) settingsRepo.getLanguage().map { language -> assert(language == SupportedLanguage.FRENCH) } } } @Test fun `when we fetch the language, then we get the default language`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.getLanguage().map { language -> assert(language == SupportedLanguage.ENGLISH) } } } @Test fun `when we update units, then we get the updated units`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.setUnits(Units.IMPERIAL) settingsRepo.getUnits().map { units -> assert(units == Units.IMPERIAL) } } } @Test fun `when we fetch the units, then we get the default units`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.getUnits().map { units -> assert(units == Units.METRIC) } } } @Test fun `when we update time format, then we get the updated time format`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.setFormat(TimeFormat.TWELVE_HOUR) settingsRepo.getFormat().map { format -> assert(format == TimeFormat.TWELVE_HOUR) } } } @Test fun `when we fetch the time format, then we get the default time format`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.getFormat().map { format -> assert(format == TimeFormat.TWENTY_FOUR_HOUR) } } } @Test fun `when we fetch the location, then we get the default location`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.getDefaultLocation().map { location -> assert(location.latitude == DefaultSettingsRepository.DEFAULT_LATITUDE) assert(location.longitude == DefaultSettingsRepository.DEFAULT_LONGITUDE) } } } @Test fun `when we update the location, then we get the correct location`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.setDefaultLocation(DefaultLocation(0.0, 0.0)) settingsRepo.getDefaultLocation().map { location -> assert(location.latitude == 0.0) assert(location.longitude == 0.0) } } } @Test fun `when we update excluded data, then we get the updated excluded data`() { val settingsRepo = createSettingsRepository() runBlocking { settingsRepo.setExcludedData( listOf( ExcludedData.ALERTS, ExcludedData.MINUTELY, ExcludedData.DAILY ) ) settingsRepo.getExcludedData().map { excludedData -> assert(excludedData == "${ExcludedData.ALERTS.value},${ExcludedData.MINUTELY.value},${ExcludedData.DAILY.value}") } } } private fun createSettingsRepository(): SettingsRepository = FakeSettingsRepository() } ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/SettingsViewModelTest.kt ================================================ package com.github.odaridavid.weatherapp import app.cash.turbine.test import com.github.odaridavid.weatherapp.api.Logger import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.fakes.FakeSettingsRepository import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import com.github.odaridavid.weatherapp.rules.MainCoroutineRule import com.github.odaridavid.weatherapp.ui.settings.SettingsScreenIntent import com.github.odaridavid.weatherapp.ui.settings.SettingsScreenViewState import com.github.odaridavid.weatherapp.ui.settings.SettingsViewModel import io.mockk.impl.annotations.MockK import io.mockk.mockk import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import org.junit.Rule import org.junit.Test @OptIn(ExperimentalCoroutinesApi::class) class SettingsViewModelTest { private val settingsRepository: SettingsRepository = FakeSettingsRepository() @MockK private val logger: Logger = mockk() @get:Rule val coroutineRule = MainCoroutineRule() @Test fun `when we load screen data, then the state is updated as expected`() = runBlocking { val settingsViewModel = createSettingsScreenViewModel() settingsViewModel.processIntent(SettingsScreenIntent.LoadSettingScreenData) val expectedState = SettingsScreenViewState( selectedUnit = Units.METRIC, selectedLanguage = SupportedLanguage.ENGLISH, availableLanguages = SupportedLanguage.entries, availableUnits = Units.entries, selectedTimeFormat = TimeFormat.TWENTY_FOUR_HOUR, availableFormats = TimeFormat.entries, versionInfo = "1.0.0", selectedExcludedData = listOf(ExcludedData.MINUTELY, ExcludedData.ALERTS), excludedData = ExcludedData.entries, selectedExcludedDataDisplayValue = "minutely,alerts" ) settingsViewModel.state.test { awaitItem().also { state -> assert(state.error == null) assert(state == expectedState) } } } @Test fun `when we change units, then the units are updated`() = runBlocking { val settingsViewModel = createSettingsScreenViewModel() settingsViewModel.processIntent(SettingsScreenIntent.ChangeUnits(selectedUnits = Units.STANDARD)) settingsViewModel.state.test { awaitItem().also { state -> assert(state.error == null) assert(state.selectedUnit == Units.STANDARD) } } } @Test fun `when we change language, then the language is updated `() = runBlocking { val settingsViewModel = createSettingsScreenViewModel() settingsViewModel.processIntent(SettingsScreenIntent.ChangeLanguage(selectedLanguage = SupportedLanguage.AFRIKAANS)) settingsViewModel.state.test { awaitItem().also { state -> assert(state.error == null) assert(state.selectedLanguage == SupportedLanguage.AFRIKAANS) } } } @Test fun `when we change time format, then the format is updated `() = runBlocking { val settingsViewModel = createSettingsScreenViewModel() settingsViewModel.processIntent(SettingsScreenIntent.ChangeTimeFormat(selectedTimeFormat = TimeFormat.TWENTY_FOUR_HOUR)) settingsViewModel.state.test { awaitItem().also { state -> assert(state.error == null) assert(state.selectedTimeFormat == TimeFormat.TWENTY_FOUR_HOUR) } } } @Test fun `when we change excluded data, then the excluded data is updated `() = runBlocking { val settingsViewModel = createSettingsScreenViewModel() settingsViewModel.processIntent( SettingsScreenIntent.ChangeExcludedData( selectedExcludedData = listOf( ExcludedData.CURRENT, ExcludedData.DAILY, ExcludedData.NONE ) ) ) settingsViewModel.state.test { awaitItem().also { state -> assert(state.error == null) assert( state.selectedExcludedData == listOf( ExcludedData.CURRENT, ExcludedData.DAILY, ExcludedData.NONE ) ) assert(state.selectedExcludedDataDisplayValue == "current,daily,none") } } } private fun createSettingsScreenViewModel(): SettingsViewModel = SettingsViewModel( settingsRepository = settingsRepository, logger = logger, ) } ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/UIMapperTest.kt ================================================ package com.github.odaridavid.weatherapp import com.github.odaridavid.weatherapp.designsystem.organism.BottomSheetItem import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import com.github.odaridavid.weatherapp.ui.settings.toBottomSheetModel import com.github.odaridavid.weatherapp.ui.settings.toExcludedData import com.github.odaridavid.weatherapp.ui.settings.toSupportedLanguage import com.github.odaridavid.weatherapp.ui.settings.toTimeFormat import com.github.odaridavid.weatherapp.ui.settings.toUnits import org.junit.Test class UIMapperTest { @Test fun `when we map units to bottom sheet items, then we get the expected items`() { val expectedItems = listOf( BottomSheetItem( id = 0, name = "standard", isSelected = false ), BottomSheetItem( id = 1, name = "metric", isSelected = false ), BottomSheetItem( id = 2, name = "imperial", isSelected = false ), ) val actual = Units.entries.map { it.toBottomSheetModel() } assert(actual == expectedItems) { "Expected $expectedItems but was $actual" } } @Test fun `when we map time format to bottom sheet items, then we get the expected items`() { val expectedItems = listOf( BottomSheetItem( id = 0, name = "24 hours", isSelected = false ), BottomSheetItem( id = 1, name = "12 hours", isSelected = false ), ) val actual = TimeFormat.entries.map { it.toBottomSheetModel() } assert(actual == expectedItems) { "Expected $expectedItems but was $actual" } } @Test fun `when we map excluded data to bottom sheet items, then we get the expected items`() { val expectedItems = listOf( BottomSheetItem( id = 0, name = "CURRENT", isSelected = false ), BottomSheetItem( id = 1, name = "HOURLY", isSelected = false ), BottomSheetItem( id = 2, name = "DAILY", isSelected = false ), BottomSheetItem( id = 3, name = "MINUTELY", isSelected = false ), BottomSheetItem( id = 4, name = "ALERTS", isSelected = false ), BottomSheetItem( id = -1, name = "NONE", isSelected = false ), ) val actual = ExcludedData.entries.map { it.toBottomSheetModel() } assert(actual == expectedItems) { "Expected $expectedItems but was $actual" } } @Test fun `when we map supported language to bottom sheet items, then we get the expected items`() { val expectedItems = listOf( BottomSheetItem( id = 0, name = "Afrikaans", isSelected = false ), BottomSheetItem( id = 1, name = "Albanian", isSelected = false ), BottomSheetItem( id = 2, name = "Arabic", isSelected = false ), BottomSheetItem( id = 3, name = "Azerbaijani", isSelected = false ), ) val actual = SupportedLanguage.entries.take(4).map { it.toBottomSheetModel() } assert(actual == expectedItems) { "Expected: $expectedItems \n Actual: $actual" } } @Test fun `when we map bottom sheet item to supported language, then we get the expected language`() { val expectedLanguage = SupportedLanguage.AFRIKAANS val bottomSheetItem = BottomSheetItem( id = 0, name = "Afrikaans", isSelected = false ) val actual = bottomSheetItem.toSupportedLanguage() assert(actual == expectedLanguage) { "Expected: $expectedLanguage \n Actual: $actual" } } @Test fun `when we map bottom sheet item to units, then we get the expected units`() { val expectedUnits = Units.METRIC val bottomSheetItem = BottomSheetItem( id = 1, name = "metric", isSelected = false ) val actual = bottomSheetItem.toUnits() assert(actual == expectedUnits) { "Expected: $expectedUnits \n Actual: $actual" } } @Test fun `when we map bottom sheet item to time format, then we get the expected time format`() { val expectedTimeFormat = TimeFormat.TWENTY_FOUR_HOUR val bottomSheetItem = BottomSheetItem( id = 0, name = "24 hours", isSelected = false ) val actual = bottomSheetItem.toTimeFormat() assert(actual == expectedTimeFormat) { "Expected: $expectedTimeFormat \n Actual: $actual" } } @Test fun `when we map bottom sheet item to excluded data, then we get the expected excluded data`() { val expectedExcludedData = ExcludedData.CURRENT val bottomSheetItem = BottomSheetItem( id = 0, name = "CURRENT", isSelected = false ) val actual = bottomSheetItem.toExcludedData() assert(actual == expectedExcludedData) { "Expected: $expectedExcludedData \n Actual: $actual" } } } ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/WeatherRepositoryTest.kt ================================================ package com.github.odaridavid.weatherapp import com.github.odaridavid.weatherapp.api.Logger import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.api.WeatherRepository import com.github.odaridavid.weatherapp.data.weather.DefaultWeatherRepository import com.github.odaridavid.weatherapp.data.weather.remote.DefaultRemoteWeatherDataSource import com.github.odaridavid.weatherapp.data.weather.remote.OpenWeatherService import com.github.odaridavid.weatherapp.data.weather.remote.RemoteWeatherDataSource import com.github.odaridavid.weatherapp.data.weather.remote.WeatherResponse import com.github.odaridavid.weatherapp.fakes.FakeSettingsRepository import com.github.odaridavid.weatherapp.fakes.fakeSuccessMappedWeatherResponse import com.github.odaridavid.weatherapp.fakes.fakeSuccessWeatherResponse import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.ErrorType import com.github.odaridavid.weatherapp.model.Result import com.github.odaridavid.weatherapp.model.TimeFormat import com.google.common.truth.Truth import io.mockk.coEvery import io.mockk.impl.annotations.MockK import io.mockk.mockk import kotlinx.coroutines.runBlocking import okhttp3.ResponseBody.Companion.toResponseBody import org.junit.Before import org.junit.Test import retrofit2.Response import java.io.IOException import java.util.TimeZone class WeatherRepositoryTest { @MockK val mockOpenWeatherService = mockk(relaxed = true) private val settingsRepository: SettingsRepository by lazy { FakeSettingsRepository() } @MockK val mockLogger = mockk(relaxed = true) // TODO Look into parameterized testing to cover different mapper scenarios @Before fun setup() { TimeZone.setDefault(TimeZone.getTimeZone("UTC")) } @Test fun `when we fetch weather data successfully, then a successfully mapped result is emitted`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.success( fakeSuccessWeatherResponse ) settingsRepository.setFormat(TimeFormat.TWELVE_HOUR) val weatherRepository = createWeatherRepository() val expectedResult = fakeSuccessMappedWeatherResponse val actualResults = weatherRepository.fetchWeatherData( defaultLocation = DefaultLocation( longitude = 10.0, latitude = 12.90 ), language = "English", units = "metric" ) Truth.assertThat(actualResults).isInstanceOf(Result.Success::class.java) Truth.assertThat((actualResults as Result.Success).data).isEqualTo(expectedResult) } @Test fun `when we fetch weather data and a server error occurs, then a server error is emitted`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.error( 500, "{}".toResponseBody() ) val weatherRepository = createWeatherRepository() val actualResults = weatherRepository.fetchWeatherData( defaultLocation = DefaultLocation( longitude = 10.0, latitude = 12.90 ), language = "English", units = "metric" ) Truth.assertThat(actualResults).isInstanceOf(Result.Error::class.java) Truth.assertThat((actualResults as Result.Error).errorType).isEqualTo(ErrorType.SERVER) } @Test fun `when we fetch weather data and a client error occurs, then a client error is emitted`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.error( 404, "{}".toResponseBody() ) val weatherRepository = createWeatherRepository() val actualResults = weatherRepository.fetchWeatherData( defaultLocation = DefaultLocation( longitude = 10.0, latitude = 12.90 ), language = "English", units = "metric" ) Truth.assertThat(actualResults).isInstanceOf(Result.Error::class.java) Truth.assertThat((actualResults as Result.Error).errorType).isEqualTo(ErrorType.CLIENT) } @Test fun `when we fetch weather data and an unauthorized error occurs, then a client error is emitted`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.error( 401, "{}".toResponseBody() ) val weatherRepository = createWeatherRepository() val actualResults = weatherRepository.fetchWeatherData( defaultLocation = DefaultLocation( longitude = 10.0, latitude = 12.90 ), language = "English", units = "metric" ) Truth.assertThat(actualResults).isInstanceOf(Result.Error::class.java) Truth.assertThat((actualResults as Result.Error).errorType) .isEqualTo(ErrorType.CLIENT) } @Test fun `when we fetch weather data and a generic error occurs, then a generic error is emitted`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } returns Response.error( 800, "{}".toResponseBody() ) val weatherRepository = createWeatherRepository() val actualResults = weatherRepository.fetchWeatherData( defaultLocation = DefaultLocation( longitude = 10.0, latitude = 12.90 ), language = "English", units = "metric" ) Truth.assertThat(actualResults).isInstanceOf(Result.Error::class.java) Truth.assertThat((actualResults as Result.Error).errorType) .isEqualTo(ErrorType.GENERIC) } @Test fun `when we fetch weather data and an IOException is thrown, then a connection error is emitted`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } throws IOException() val weatherRepository = createWeatherRepository() val actualResults = weatherRepository.fetchWeatherData( defaultLocation = DefaultLocation( longitude = 10.0, latitude = 12.90 ), language = "English", units = "metric" ) Truth.assertThat(actualResults).isInstanceOf(Result.Error::class.java) Truth.assertThat((actualResults as Result.Error).errorType) .isEqualTo(ErrorType.IO_CONNECTION) } @Test fun `when we fetch weather data and an unknown Exception is thrown, then a generic error is emitted`() = runBlocking { coEvery { mockOpenWeatherService.getWeatherData( any(), any(), any(), any(), any(), any() ) } throws Exception() val weatherRepository = createWeatherRepository() val actualResults = weatherRepository.fetchWeatherData( defaultLocation = DefaultLocation( longitude = 10.0, latitude = 12.90 ), language = "English", units = "metric" ) Truth.assertThat(actualResults).isInstanceOf(Result.Error::class.java) Truth.assertThat((actualResults as Result.Error).errorType) .isEqualTo(ErrorType.GENERIC) } private fun createWeatherRepository( logger: Logger = mockLogger, remoteWeatherDataSource: RemoteWeatherDataSource = DefaultRemoteWeatherDataSource( openWeatherService = mockOpenWeatherService ), settingsRepository: SettingsRepository = this.settingsRepository, ): WeatherRepository = DefaultWeatherRepository( remoteWeatherDataSource = remoteWeatherDataSource, logger = logger, settingsRepository = settingsRepository, ) } ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/fakes/FakeSettingsRepository.kt ================================================ package com.github.odaridavid.weatherapp.fakes import com.github.odaridavid.weatherapp.api.SettingsRepository import com.github.odaridavid.weatherapp.data.settings.DefaultSettingsRepository.Companion.KEY_EXCLUDED_DATA import com.github.odaridavid.weatherapp.data.settings.DefaultSettingsRepository.Companion.KEY_LANGUAGE import com.github.odaridavid.weatherapp.data.settings.DefaultSettingsRepository.Companion.KEY_LAT_LNG import com.github.odaridavid.weatherapp.data.settings.DefaultSettingsRepository.Companion.KEY_TIME_FORMAT import com.github.odaridavid.weatherapp.data.settings.DefaultSettingsRepository.Companion.KEY_UNITS import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow class FakeSettingsRepository : SettingsRepository { private val settingsMap = mutableMapOf() override suspend fun setLanguage(language: SupportedLanguage) { settingsMap[KEY_LANGUAGE] = language } override suspend fun getLanguage(): Flow = flow { emit(settingsMap[KEY_LANGUAGE] as? SupportedLanguage ?: SupportedLanguage.ENGLISH) } override suspend fun setUnits(units: Units) { settingsMap[KEY_UNITS] = units } override suspend fun getUnits(): Flow = flow { emit(settingsMap[KEY_UNITS] as? Units ?: Units.METRIC) } override fun getAppVersion(): String = "1.0.0" override suspend fun setDefaultLocation(defaultLocation: DefaultLocation) { settingsMap[KEY_LAT_LNG] = "${defaultLocation.latitude}/${defaultLocation.longitude}" } override suspend fun getDefaultLocation(): Flow = flow { val latLng = settingsMap[KEY_LAT_LNG] as? String ?: "0.0/0.0" val latLngList = latLng.split("/") DefaultLocation(latitude = latLngList[0].toDouble(), longitude = latLngList[1].toDouble()) } override suspend fun getFormat(): Flow = flow { emit(settingsMap[KEY_TIME_FORMAT] as? TimeFormat ?: TimeFormat.TWENTY_FOUR_HOUR) } override suspend fun setFormat(format: TimeFormat) { settingsMap[KEY_TIME_FORMAT] = format } override suspend fun getExcludedData(): Flow = flow { emit( settingsMap[KEY_EXCLUDED_DATA] as? String ?: "${ExcludedData.MINUTELY.value},${ExcludedData.ALERTS.value}" ) } override suspend fun setExcludedData(excludedData: List) { val formattedData = excludedData.joinToString(separator = ",") { it.value } settingsMap[KEY_EXCLUDED_DATA] = formattedData } } ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/fakes/Fakes.kt ================================================ package com.github.odaridavid.weatherapp.fakes import com.github.odaridavid.weatherapp.data.weather.remote.CurrentWeatherResponse import com.github.odaridavid.weatherapp.data.weather.remote.DailyWeatherResponse import com.github.odaridavid.weatherapp.data.weather.remote.HourlyWeatherResponse import com.github.odaridavid.weatherapp.data.weather.remote.TemperatureResponse import com.github.odaridavid.weatherapp.data.weather.remote.WeatherResponse import com.github.odaridavid.weatherapp.model.CurrentWeather import com.github.odaridavid.weatherapp.model.DailyWeather import com.github.odaridavid.weatherapp.model.HourlyWeather import com.github.odaridavid.weatherapp.model.Temperature import com.github.odaridavid.weatherapp.model.Weather // TODO Populate the responses with more data to test the mappers val fakeSuccessWeatherResponse = WeatherResponse( current = CurrentWeatherResponse( temperature = 3.0f, feelsLike = 2.0f, weather = listOf() ), hourly = listOf( HourlyWeatherResponse( forecastedTime = 1618310400, temperature = 3.0f, weather = listOf() ) ), daily = listOf( DailyWeatherResponse( forecastedTime = 1618310400, temperature = TemperatureResponse(min = 0.0f, max = 10.0f), weather = listOf() ) ) ) val fakeSuccessMappedWeatherResponse = Weather( current = CurrentWeather( temperature = "3°C", feelsLike = "2°C", weather = listOf() ), hourly = listOf( HourlyWeather( forecastedTime = "10:40 AM", temperature = "3°C", weather = listOf() ) ), daily = listOf( DailyWeather( forecastedTime = "Tuesday 13/4", temperature = Temperature(min = "0°C", max = "10°C"), weather = listOf(), ) ) ) // TODO Parameterized tests to cover different formattings, time/date formats, temperature specifically. ================================================ FILE: app/src/test/java/com/github/odaridavid/weatherapp/rules/MainCoroutineRule.kt ================================================ package com.github.odaridavid.weatherapp.rules import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestDispatcher import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.setMain import org.junit.rules.TestWatcher import org.junit.runner.Description @ExperimentalCoroutinesApi class MainCoroutineRule( private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher(), ) : TestWatcher() { override fun starting(description: Description) { Dispatchers.setMain(testDispatcher) } override fun finished(description: Description) { Dispatchers.resetMain() } } ================================================ FILE: build.gradle.kts ================================================ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask plugins { alias(libs.plugins.com.android.application) apply false alias(libs.plugins.com.android.library) apply false alias(libs.plugins.org.jetbrains.kotlin.android) apply false alias(libs.plugins.mapsplatform.secrets.gradle.plugin) apply false alias(libs.plugins.dagger.hilt.android) apply false alias(libs.plugins.org.jetbrains.kotlin.plugin.serialization) apply false alias(libs.plugins.kotlinMultiplatform) apply false alias(libs.plugins.about.lib.plugin) apply false alias(libs.plugins.firebase.perf.plugin) apply false alias(libs.plugins.compose.compiler) apply false // TODO Move some of these to toml file id("com.github.ben-manes.versions") version "0.41.0" id("nl.littlerobots.version-catalog-update") version "0.8.4" id("io.gitlab.arturbosch.detekt") version "1.23.3" id("org.jlleitschuh.gradle.ktlint") version "12.1.1" } buildscript { dependencies { classpath(libs.com.google.services) classpath(libs.com.firebase.crashlytics.plugin) classpath(libs.gradle.versions.plugin) classpath(libs.littlerobots.plugin) classpath(libs.detekt.gradle.plugin) classpath(libs.gradle) } } versionCatalogUpdate { pin { versions.addAll("kotlin-android") } } fun isNonStable(version: String): Boolean { val nonStableKeyword = listOf("BETA", "ALPHA", "DEV").any { version.uppercase().contains(it) } val regex = "^[0-9,.v-]+(-r)?$".toRegex() val isStable = nonStableKeyword.not() || regex.matches(version) return isStable.not() } tasks.withType { rejectVersionIf { isNonStable(candidate.version) } } ================================================ FILE: gradle/libs.versions.toml ================================================ [versions] about-lib = "12.0.0-a04" activity-compose = "1.10.1" android-gradle-plugin = "8.9.0" androidx-test-rules = "1.6.1" androidx-test-runner = "1.6.2" chucker = "4.1.0" coil-compose = "2.7.0" com-google-services = "4.4.2" compose-bom = "2025.03.00" compose-constraint = "1.1.1" compose-material3 = "1.3.1" compose-navigation = "2.8.9" core-ktx = "1.6.1" core-ktx-version = "1.15.0" coroutines = "1.10.1" coroutines-test = "1.10.1" crashlytics-plugin = "3.0.3" datastore = "1.1.3" detekt-gradle-plugin = "1.23.8" firebase-bom = "33.10.0" firebase-perf = "1.4.2" gradle = "8.9.0" gradle-versions-plugin = "0.52.0" hilt = "2.55" hilt-nav-compose = "1.2.0" inappupdate = "2.1.0" junit = "4.13.2" kotlin = "2.1.20-RC2" kotlin-serialization = "2.1.20-RC2" kotlinx-coroutines-android = "1.10.1" kotlinx-serialization = "1.8.0" kotlinx-serialization-converter = "1.0.0" leakcanary = "2.14" lifecycle-runtime-ktx = "2.8.7" lifecycle-viewmodel-compose = "2.8.7" mapsplatform-secrets = "2.0.1" mockk = "1.13.17" okhttp = "4.12.0" play-services-location = "21.3.0" plugin = "0.8.5" retrofit = "2.11.0" truth = "1.4.4" turbine = "1.2.0" [libraries] about-lib-compose-ui = { module = "com.mikepenz:aboutlibraries-compose-m3", version.ref = "about-lib" } about-lib-core = { module = "com.mikepenz:aboutlibraries-core", version.ref = "about-lib" } activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity-compose" } android-test-rules = { module = "androidx.test:rules", version.ref = "androidx-test-rules" } android-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" } chucker-debug = { module = "com.github.chuckerteam.chucker:library", version.ref = "chucker" } chucker-release = { module = "com.github.chuckerteam.chucker:library-no-op", version.ref = "chucker" } coil = { module = "io.coil-kt:coil-compose", version.ref = "coil-compose" } com-firebase-crashlytics-plugin = { module = "com.google.firebase:firebase-crashlytics-gradle", version.ref = "crashlytics-plugin" } com-google-services = { module = "com.google.gms:google-services", version.ref = "com-google-services" } compose-bom = { module = "androidx.compose:compose-bom", version.ref = "compose-bom" } compose-constraint = { module = "androidx.constraintlayout:constraintlayout-compose", version.ref = "compose-constraint" } compose-material3 = { module = "androidx.compose.material3:material3-android", version.ref = "compose-material3" } compose-navigation = { module = "androidx.navigation:navigation-compose", version.ref = "compose-navigation" } compose-preview = { module = "androidx.compose.ui:ui-tooling-preview" } compose-ui = { module = "androidx.compose.ui:ui" } compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } compose-viewmodel-lifecycle = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle-viewmodel-compose" } core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx-version" } coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines-test" } datastore = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" } detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt-gradle-plugin" } firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" } firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebase-bom" } firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-ktx" } firebase-perfomance-monitoring = { module = "com.google.firebase:firebase-perf" } gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" } gradle-versions-plugin = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "gradle-versions-plugin" } hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" } hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt" } hilt-nav-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hilt-nav-compose" } inapp-update = { module = "com.google.android.play:app-update", version.ref = "inappupdate" } inapp-update-ktx = { module = "com.google.android.play:app-update-ktx", version.ref = "inappupdate" } junit = { module = "junit:junit", version.ref = "junit" } kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines-android" } kotlinx-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } kotlinx-serialization-converter = { module = "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter", version.ref = "kotlinx-serialization-converter" } leakcanary = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakcanary" } lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-ktx" } littlerobots-plugin = { module = "nl.littlerobots.vcu:plugin", version.ref = "plugin" } mock-agent = { module = "io.mockk:mockk-agent", version.ref = "mockk" } mock-android = { module = "io.mockk:mockk-android", version.ref = "mockk" } okhttp = { module = "com.squareup.okhttp3:okhttp" } okhttp-bom = { module = "com.squareup.okhttp3:okhttp-bom", version.ref = "okhttp" } okhttp-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor" } playservices-location = { module = "com.google.android.gms:play-services-location", version.ref = "play-services-location" } retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" } test-core-ktx = { module = "androidx.test:core-ktx", version.ref = "core-ktx" } truth = { module = "com.google.truth:truth", version.ref = "truth" } turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" } [plugins] about-lib-plugin = { id = "com.mikepenz.aboutlibraries.plugin", version.ref = "about-lib" } com-android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" } com-android-library = { id = "com.android.library", version.ref = "android-gradle-plugin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } dagger-hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } firebase-perf-plugin = { id = "com.google.firebase.firebase-perf", version.ref = "firebase-perf" } kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } mapsplatform-secrets-gradle-plugin = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "mapsplatform-secrets" } org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } org-jetbrains-kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-serialization" } [bundles] android-test = [ "android-test-rules", "android-test-runner", "test-core-ktx", ] androidx = [ "activity-compose", "core-ktx", "datastore", "hilt-nav-compose", "lifecycle-runtime-ktx", ] compose = [ "compose-constraint", "compose-material3", "compose-navigation", "compose-preview", "compose-ui", "compose-viewmodel-lifecycle", ] firebase = [ "firebase-analytics", "firebase-crashlytics", "firebase-perfomance-monitoring", ] google-play = [ "inapp-update", "inapp-update-ktx", ] ================================================ FILE: gradle/wrapper/gradle-wrapper.properties ================================================ #Tue Jan 14 09:55:22 CET 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists ================================================ FILE: gradle.properties ================================================ # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true # AndroidX package structure to make it clearer which packages are bundled with the # Android operating system, and which are packaged with your app's APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true android.defaults.buildfeatures.buildconfig=true android.nonFinalResIds=false ================================================ FILE: gradlew ================================================ #!/usr/bin/env bash # # Copyright 2015 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn () { echo "$*" } die () { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin or MSYS, switch paths to Windows format before running java if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=`expr $i + 1` done case $i in 0) set -- ;; 1) set -- "$args0" ;; 2) set -- "$args0" "$args1" ;; 3) set -- "$args0" "$args1" "$args2" ;; 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Escape application args save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" exec "$JAVACMD" "$@" ================================================ FILE: gradlew.bat ================================================ @rem @rem Copyright 2015 the original author or authors. @rem @rem Licensed under the Apache License, Version 2.0 (the "License"); @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem @rem https://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Resolve any "." and ".." in APP_HOME to make it shorter. for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: iOSApp/iOSApp/Assets.xcassets/AccentColor.colorset/Contents.json ================================================ { "colors" : [ { "idiom" : "universal" } ], "info" : { "author" : "xcode", "version" : 1 } } ================================================ FILE: iOSApp/iOSApp/Assets.xcassets/AppIcon.appiconset/Contents.json ================================================ { "images" : [ { "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" } ], "info" : { "author" : "xcode", "version" : 1 } } ================================================ FILE: iOSApp/iOSApp/Assets.xcassets/Contents.json ================================================ { "info" : { "author" : "xcode", "version" : 1 } } ================================================ FILE: iOSApp/iOSApp/ContentView.swift ================================================ // // ContentView.swift // iOSApp // // Created by David Odari Kiribwa on 07.03.24. // import SwiftUI import shared struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) } .padding() } } #Preview { ContentView() } ================================================ FILE: iOSApp/iOSApp/Preview Content/Preview Assets.xcassets/Contents.json ================================================ { "info" : { "author" : "xcode", "version" : 1 } } ================================================ FILE: iOSApp/iOSApp/iOSAppApp.swift ================================================ // // iOSAppApp.swift // iOSApp // // Created by David Odari Kiribwa on 07.03.24. // import SwiftUI @main struct iOSAppApp: App { var body: some Scene { WindowGroup { ContentView() } } } ================================================ FILE: iOSApp/iOSApp.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 56; objects = { /* Begin PBXBuildFile section */ 666856C12B993D62003C0CC3 /* iOSAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 666856C02B993D62003C0CC3 /* iOSAppApp.swift */; }; 666856C32B993D62003C0CC3 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 666856C22B993D62003C0CC3 /* ContentView.swift */; }; 666856C52B993D66003C0CC3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 666856C42B993D66003C0CC3 /* Assets.xcassets */; }; 666856C82B993D66003C0CC3 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 666856C72B993D66003C0CC3 /* Preview Assets.xcassets */; }; 666856D22B993D66003C0CC3 /* iOSAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 666856D12B993D66003C0CC3 /* iOSAppTests.swift */; }; 666856DC2B993D66003C0CC3 /* iOSAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 666856DB2B993D66003C0CC3 /* iOSAppUITests.swift */; }; 666856DE2B993D66003C0CC3 /* iOSAppUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 666856DD2B993D66003C0CC3 /* iOSAppUITestsLaunchTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ 666856CE2B993D66003C0CC3 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 666856B52B993D62003C0CC3 /* Project object */; proxyType = 1; remoteGlobalIDString = 666856BC2B993D62003C0CC3; remoteInfo = iOSApp; }; 666856D82B993D66003C0CC3 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 666856B52B993D62003C0CC3 /* Project object */; proxyType = 1; remoteGlobalIDString = 666856BC2B993D62003C0CC3; remoteInfo = iOSApp; }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ 666856BD2B993D62003C0CC3 /* iOSApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 666856C02B993D62003C0CC3 /* iOSAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSAppApp.swift; sourceTree = ""; }; 666856C22B993D62003C0CC3 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 666856C42B993D66003C0CC3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 666856C72B993D66003C0CC3 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 666856CD2B993D66003C0CC3 /* iOSAppTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSAppTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 666856D12B993D66003C0CC3 /* iOSAppTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSAppTests.swift; sourceTree = ""; }; 666856D72B993D66003C0CC3 /* iOSAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 666856DB2B993D66003C0CC3 /* iOSAppUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSAppUITests.swift; sourceTree = ""; }; 666856DD2B993D66003C0CC3 /* iOSAppUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSAppUITestsLaunchTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 666856BA2B993D62003C0CC3 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; 666856CA2B993D66003C0CC3 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; 666856D42B993D66003C0CC3 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 666856B42B993D62003C0CC3 = { isa = PBXGroup; children = ( 666856BF2B993D62003C0CC3 /* iOSApp */, 666856D02B993D66003C0CC3 /* iOSAppTests */, 666856DA2B993D66003C0CC3 /* iOSAppUITests */, 666856BE2B993D62003C0CC3 /* Products */, ); sourceTree = ""; }; 666856BE2B993D62003C0CC3 /* Products */ = { isa = PBXGroup; children = ( 666856BD2B993D62003C0CC3 /* iOSApp.app */, 666856CD2B993D66003C0CC3 /* iOSAppTests.xctest */, 666856D72B993D66003C0CC3 /* iOSAppUITests.xctest */, ); name = Products; sourceTree = ""; }; 666856BF2B993D62003C0CC3 /* iOSApp */ = { isa = PBXGroup; children = ( 666856C02B993D62003C0CC3 /* iOSAppApp.swift */, 666856C22B993D62003C0CC3 /* ContentView.swift */, 666856C42B993D66003C0CC3 /* Assets.xcassets */, 666856C62B993D66003C0CC3 /* Preview Content */, ); path = iOSApp; sourceTree = ""; }; 666856C62B993D66003C0CC3 /* Preview Content */ = { isa = PBXGroup; children = ( 666856C72B993D66003C0CC3 /* Preview Assets.xcassets */, ); path = "Preview Content"; sourceTree = ""; }; 666856D02B993D66003C0CC3 /* iOSAppTests */ = { isa = PBXGroup; children = ( 666856D12B993D66003C0CC3 /* iOSAppTests.swift */, ); path = iOSAppTests; sourceTree = ""; }; 666856DA2B993D66003C0CC3 /* iOSAppUITests */ = { isa = PBXGroup; children = ( 666856DB2B993D66003C0CC3 /* iOSAppUITests.swift */, 666856DD2B993D66003C0CC3 /* iOSAppUITestsLaunchTests.swift */, ); path = iOSAppUITests; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 666856BC2B993D62003C0CC3 /* iOSApp */ = { isa = PBXNativeTarget; buildConfigurationList = 666856E12B993D66003C0CC3 /* Build configuration list for PBXNativeTarget "iOSApp" */; buildPhases = ( 666856EB2B993F81003C0CC3 /* ShellScript */, 666856B92B993D62003C0CC3 /* Sources */, 666856BA2B993D62003C0CC3 /* Frameworks */, 666856BB2B993D62003C0CC3 /* Resources */, ); buildRules = ( ); dependencies = ( ); name = iOSApp; productName = iOSApp; productReference = 666856BD2B993D62003C0CC3 /* iOSApp.app */; productType = "com.apple.product-type.application"; }; 666856CC2B993D66003C0CC3 /* iOSAppTests */ = { isa = PBXNativeTarget; buildConfigurationList = 666856E42B993D66003C0CC3 /* Build configuration list for PBXNativeTarget "iOSAppTests" */; buildPhases = ( 666856C92B993D66003C0CC3 /* Sources */, 666856CA2B993D66003C0CC3 /* Frameworks */, 666856CB2B993D66003C0CC3 /* Resources */, ); buildRules = ( ); dependencies = ( 666856CF2B993D66003C0CC3 /* PBXTargetDependency */, ); name = iOSAppTests; productName = iOSAppTests; productReference = 666856CD2B993D66003C0CC3 /* iOSAppTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; 666856D62B993D66003C0CC3 /* iOSAppUITests */ = { isa = PBXNativeTarget; buildConfigurationList = 666856E72B993D66003C0CC3 /* Build configuration list for PBXNativeTarget "iOSAppUITests" */; buildPhases = ( 666856D32B993D66003C0CC3 /* Sources */, 666856D42B993D66003C0CC3 /* Frameworks */, 666856D52B993D66003C0CC3 /* Resources */, ); buildRules = ( ); dependencies = ( 666856D92B993D66003C0CC3 /* PBXTargetDependency */, ); name = iOSAppUITests; productName = iOSAppUITests; productReference = 666856D72B993D66003C0CC3 /* iOSAppUITests.xctest */; productType = "com.apple.product-type.bundle.ui-testing"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 666856B52B993D62003C0CC3 /* Project object */ = { isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = 1; LastSwiftUpdateCheck = 1520; LastUpgradeCheck = 1520; TargetAttributes = { 666856BC2B993D62003C0CC3 = { CreatedOnToolsVersion = 15.2; }; 666856CC2B993D66003C0CC3 = { CreatedOnToolsVersion = 15.2; TestTargetID = 666856BC2B993D62003C0CC3; }; 666856D62B993D66003C0CC3 = { CreatedOnToolsVersion = 15.2; TestTargetID = 666856BC2B993D62003C0CC3; }; }; }; buildConfigurationList = 666856B82B993D62003C0CC3 /* Build configuration list for PBXProject "iOSApp" */; compatibilityVersion = "Xcode 14.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, Base, ); mainGroup = 666856B42B993D62003C0CC3; productRefGroup = 666856BE2B993D62003C0CC3 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 666856BC2B993D62003C0CC3 /* iOSApp */, 666856CC2B993D66003C0CC3 /* iOSAppTests */, 666856D62B993D66003C0CC3 /* iOSAppUITests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ 666856BB2B993D62003C0CC3 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 666856C82B993D66003C0CC3 /* Preview Assets.xcassets in Resources */, 666856C52B993D66003C0CC3 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; 666856CB2B993D66003C0CC3 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; 666856D52B993D66003C0CC3 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ 666856EB2B993F81003C0CC3 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( ); inputPaths = ( ); outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "cd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode\n"; }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 666856B92B993D62003C0CC3 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 666856C32B993D62003C0CC3 /* ContentView.swift in Sources */, 666856C12B993D62003C0CC3 /* iOSAppApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 666856C92B993D66003C0CC3 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 666856D22B993D66003C0CC3 /* iOSAppTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 666856D32B993D66003C0CC3 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 666856DE2B993D66003C0CC3 /* iOSAppUITestsLaunchTests.swift in Sources */, 666856DC2B993D66003C0CC3 /* iOSAppUITests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ 666856CF2B993D66003C0CC3 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 666856BC2B993D62003C0CC3 /* iOSApp */; targetProxy = 666856CE2B993D66003C0CC3 /* PBXContainerItemProxy */; }; 666856D92B993D66003C0CC3 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 666856BC2B993D62003C0CC3 /* iOSApp */; targetProxy = 666856D82B993D66003C0CC3 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ 666856DF2B993D66003C0CC3 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu17; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 17.2; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; }; 666856E02B993D66003C0CC3 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu17; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 17.2; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; VALIDATE_PRODUCT = YES; }; name = Release; }; 666856E22B993D66003C0CC3 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"iOSApp/Preview Content\""; DEVELOPMENT_TEAM = 7NFZ339747; ENABLE_PREVIEWS = YES; ENABLE_USER_SCRIPT_SANDBOXING = NO; FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)"; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.odaridavid.github.weatherapp.iOSApp; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; 666856E32B993D66003C0CC3 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"iOSApp/Preview Content\""; DEVELOPMENT_TEAM = 7NFZ339747; ENABLE_PREVIEWS = YES; ENABLE_USER_SCRIPT_SANDBOXING = NO; FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)"; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.odaridavid.github.weatherapp.iOSApp; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; 666856E52B993D66003C0CC3 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; IPHONEOS_DEPLOYMENT_TARGET = 17.2; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.odaridavid.github.weatherapp.iOSAppTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/iOSApp"; }; name = Debug; }; 666856E62B993D66003C0CC3 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; IPHONEOS_DEPLOYMENT_TARGET = 17.2; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.odaridavid.github.weatherapp.iOSAppTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/iOSApp"; }; name = Release; }; 666856E82B993D66003C0CC3 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.odaridavid.github.weatherapp.iOSAppUITests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_TARGET_NAME = iOSApp; }; name = Debug; }; 666856E92B993D66003C0CC3 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.odaridavid.github.weatherapp.iOSAppUITests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_TARGET_NAME = iOSApp; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 666856B82B993D62003C0CC3 /* Build configuration list for PBXProject "iOSApp" */ = { isa = XCConfigurationList; buildConfigurations = ( 666856DF2B993D66003C0CC3 /* Debug */, 666856E02B993D66003C0CC3 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 666856E12B993D66003C0CC3 /* Build configuration list for PBXNativeTarget "iOSApp" */ = { isa = XCConfigurationList; buildConfigurations = ( 666856E22B993D66003C0CC3 /* Debug */, 666856E32B993D66003C0CC3 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 666856E42B993D66003C0CC3 /* Build configuration list for PBXNativeTarget "iOSAppTests" */ = { isa = XCConfigurationList; buildConfigurations = ( 666856E52B993D66003C0CC3 /* Debug */, 666856E62B993D66003C0CC3 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 666856E72B993D66003C0CC3 /* Build configuration list for PBXNativeTarget "iOSAppUITests" */ = { isa = XCConfigurationList; buildConfigurations = ( 666856E82B993D66003C0CC3 /* Debug */, 666856E92B993D66003C0CC3 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 666856B52B993D62003C0CC3 /* Project object */; } ================================================ FILE: iOSApp/iOSApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: iOSApp/iOSApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist ================================================ IDEDidComputeMac32BitWarning ================================================ FILE: iOSApp/iOSApp.xcodeproj/xcuserdata/odari.xcuserdatad/xcschemes/xcschememanagement.plist ================================================ SchemeUserState iOSApp.xcscheme_^#shared#^_ orderHint 0 ================================================ FILE: iOSApp/iOSAppTests/iOSAppTests.swift ================================================ // // iOSAppTests.swift // iOSAppTests // // Created by David Odari Kiribwa on 07.03.24. // import XCTest @testable import iOSApp final class iOSAppTests: XCTestCase { override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. } override func tearDownWithError() throws { // Put teardown code here. This method is called after the invocation of each test method in the class. } func testExample() throws { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. // Any test you write for XCTest can be annotated as throws and async. // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. } func testPerformanceExample() throws { // This is an example of a performance test case. self.measure { // Put the code you want to measure the time of here. } } } ================================================ FILE: iOSApp/iOSAppUITests/iOSAppUITests.swift ================================================ // // iOSAppUITests.swift // iOSAppUITests // // Created by David Odari Kiribwa on 07.03.24. // import XCTest final class iOSAppUITests: XCTestCase { override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. // In UI tests it is usually best to stop immediately when a failure occurs. continueAfterFailure = false // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. } override func tearDownWithError() throws { // Put teardown code here. This method is called after the invocation of each test method in the class. } func testExample() throws { // UI tests must launch the application that they test. let app = XCUIApplication() app.launch() // Use XCTAssert and related functions to verify your tests produce the correct results. } func testLaunchPerformance() throws { if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { // This measures how long it takes to launch your application. measure(metrics: [XCTApplicationLaunchMetric()]) { XCUIApplication().launch() } } } } ================================================ FILE: iOSApp/iOSAppUITests/iOSAppUITestsLaunchTests.swift ================================================ // // iOSAppUITestsLaunchTests.swift // iOSAppUITests // // Created by David Odari Kiribwa on 07.03.24. // import XCTest final class iOSAppUITestsLaunchTests: XCTestCase { override class var runsForEachTargetApplicationUIConfiguration: Bool { true } override func setUpWithError() throws { continueAfterFailure = false } func testLaunch() throws { let app = XCUIApplication() app.launch() // Insert steps here to perform after app launch but before taking a screenshot, // such as logging into a test account or navigating somewhere in the app let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = "Launch Screen" attachment.lifetime = .keepAlways add(attachment) } } ================================================ FILE: pull_request_template.md ================================================ ## Related Issue ## Description ## How Can It Be Tested ## Screenshots (If Applicable) ## Additional Comments ## Checklist - [ ] New tests were added/Existing Modified ================================================ FILE: settings.gradle.kts ================================================ pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } } dependencyResolutionManagement { repositories { google() mavenCentral() } } rootProject.name = "WeatherApp" include(":app") include(":shared") ================================================ FILE: shared/build.gradle.kts ================================================ plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.com.android.library) } kotlin { androidTarget { compilations.all { kotlinOptions { jvmTarget = "1.8" } } } listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { it.binaries.framework { baseName = "shared" isStatic = true } } sourceSets { commonMain.dependencies { implementation(libs.coroutines) } commonTest.dependencies { // TODO Add common test dependencies } } } android { namespace = "com.github.odaridavid.weatherapp.shared" compileSdk = 34 defaultConfig { minSdk = 23 } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/api/Logger.kt ================================================ package com.github.odaridavid.weatherapp.api interface Logger { fun logException(throwable: Throwable) } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/api/SettingsRepository.kt ================================================ package com.github.odaridavid.weatherapp.api import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.ExcludedData import com.github.odaridavid.weatherapp.model.SupportedLanguage import com.github.odaridavid.weatherapp.model.TimeFormat import com.github.odaridavid.weatherapp.model.Units import kotlinx.coroutines.flow.Flow interface SettingsRepository { suspend fun setLanguage(language: SupportedLanguage) suspend fun getLanguage(): Flow suspend fun setUnits(units: Units) suspend fun getUnits(): Flow fun getAppVersion(): String suspend fun setDefaultLocation(defaultLocation: DefaultLocation) suspend fun getDefaultLocation(): Flow suspend fun getFormat(): Flow suspend fun setFormat(format: TimeFormat) suspend fun getExcludedData(): Flow suspend fun setExcludedData(excludedData: List) } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/api/WeatherRepository.kt ================================================ package com.github.odaridavid.weatherapp.api import com.github.odaridavid.weatherapp.model.DefaultLocation import com.github.odaridavid.weatherapp.model.Result import com.github.odaridavid.weatherapp.model.Weather interface WeatherRepository { suspend fun fetchWeatherData( defaultLocation: DefaultLocation, language: String, units: String ) : Result } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/model/DefaultLocation.kt ================================================ package com.github.odaridavid.weatherapp.model data class DefaultLocation(val longitude: Double, val latitude: Double) ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/model/ExcludedData.kt ================================================ package com.github.odaridavid.weatherapp.model enum class ExcludedData(val value: String, val id: Int) { CURRENT("current", 0), HOURLY("hourly", 1), DAILY("daily", 2), MINUTELY("minutely", 3), ALERTS("alerts", 4), NONE("none", -1), } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/model/Result.kt ================================================ package com.github.odaridavid.weatherapp.model sealed class Result { data class Success(val data: T) : Result() data class Error(val errorType: ErrorType) : Result() } enum class ErrorType { CLIENT, SERVER, GENERIC, IO_CONNECTION, } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/model/SupportedLanguage.kt ================================================ package com.github.odaridavid.weatherapp.model enum class SupportedLanguage(val languageName: String, val languageValue: String) { AFRIKAANS("Afrikaans", "af"), ALBANIAN("Albanian", "al"), ARABIC("Arabic", "ar"), AZERBAIJANI("Azerbaijani", "az"), BULGARIAN("Bulgarian", "bg"), CATALAN("Catalan", "ca"), CZECH("Czech", "cz"), DANISH("Danish", "da"), GERMAN("German", "de"), GREEK("Greek", "el"), ENGLISH("English", "en"), BASQUE("Basque", "eu"), PERSIAN("Persian (Farsi)", "fa"), FINNISH("Finnish", "fi"), FRENCH("French", "fr"), GALICIAN("Galician", "gl"), HEBREW("Hebrew", "he"), HINDI("Hindi", "hi"), CROATIAN("Croatian", "hr"), HUNGARIAN("Hungarian", "hu"), INDONESIAN("Indonesian", "id"), ITALIAN("Italian", "it"), JAPANESE("Japanese", "ja"), KOREAN("Korean", "kr"), LATVIAN("Latvian", "la"), LITHUANIAN("Lithuanian", "lt"), MACEDONIAN("Macedonian", "mk"), NORWEGIAN("Norwegian", "no"), DUTCH("Dutch", "nl"), POLISH("Polish", "pl"), PORTUGUESE("Portuguese", "pt"), PORTUGUESE_BRAZIL("Português Brasil", "pt_br"), ROMANIAN("Romanian", "ro"), RUSSIAN("Russian", "ru"), SWEDISH("Swedish", "sv, se"), SLOVAK("Slovak", "sk"), SLOVANIAN("Slovenian", "sl"), SPANISH("Spanish", "sp, es"), SERBIAN("Serbian", "sr"), THAI("Thai", "th"), TURKISH("Turkish", "tr"), UKRAINIAN("Ukrainian", "ua, uk"), VIETNAMESE("Vietnamese", "vi"), CHINESE_SIMPLIFIED("Chinese Simplified", "zh_cn"), CHINESE_TRADITIONAL("Chinese Traditional", "zh_tw"), ZULU("Zulu", "zu") } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/model/Throwables.kt ================================================ package com.github.odaridavid.weatherapp.model data class ClientException(override val message: String) : Throwable(message = message) data class ServerException(override val message: String) : Throwable(message = message) data class GenericException(override val message: String) : Throwable(message = message) ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/model/TimeFormat.kt ================================================ package com.github.odaridavid.weatherapp.model enum class TimeFormat(val value: String) { TWENTY_FOUR_HOUR("24 hours"), TWELVE_HOUR("12 hours") } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/model/Units.kt ================================================ package com.github.odaridavid.weatherapp.model enum class Units(val value: String, val tempLabel: String) { STANDARD("standard","°F"), METRIC("metric","°C"), IMPERIAL("imperial","°F"), } ================================================ FILE: shared/src/commonMain/kotlin/com/github/odaridavid/weatherapp/model/Weather.kt ================================================ package com.github.odaridavid.weatherapp.model data class Weather( val current: CurrentWeather?, val hourly: List?, val daily: List? ) data class CurrentWeather( val temperature: String, val feelsLike: String, val weather: List ) data class HourlyWeather( val forecastedTime: String, val temperature: String, val weather: List ) data class DailyWeather( val forecastedTime: String, val temperature: Temperature, val weather: List ) data class WeatherInfo( val id: Int, val main: String, val description: String, val icon: String ) data class Temperature( val min: String, val max: String, )