Skip to content

Commit

Permalink
adds complete project files
Browse files Browse the repository at this point in the history
  • Loading branch information
MamboBryan committed Feb 5, 2024
1 parent 38e7e97 commit bc921b3
Show file tree
Hide file tree
Showing 22 changed files with 201 additions and 40 deletions.
154 changes: 144 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,148 @@
This is a Kotlin Multiplatform project targeting Android, iOS.
# Weather

* `/composeApp` is for code that will be shared across your Compose Multiplatform applications.
It contains several subfolders:
- `commonMain` is for code that’s common for all targets.
- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
`iosMain` would be the right folder for such calls.
Weather is a simple Kotlin Multiplatform application built with Compose Multiplatform that gets
weather information data for a specific city.

* `/iosApp` contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform,
you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project.
## Features

- [X] user can get today's weather data
- [X] user can get weather data for the next 7 days
- [X] user can get the last 14 days weather data

Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html)
## Design

### android

| Loading | Today | More |
|:-----------------------------------------------------------------------------:|:---------------------------------------------------------------------------:|:--------------------------------------------------------------------------:|
| <img src="images/android/loading.png" width="200" hspace="2" alt="loading" /> | <img src="images/android/today.png" width="200" hspace="2" alt="calorie" /> | <img src="images/android/more.png" width="200" hspace="2" alt="calorie" /> |

### iOS

| Loading | Today | More |
|:-------------------------------------------------------------------------:|:-----------------------------------------------------------------------:|:----------------------------------------------------------------------:|
| <img src="images/ios/loading.png" width="200" hspace="2" alt="loading" /> | <img src="images/ios/today.png" width="200" hspace="2" alt="calorie" /> | <img src="images/ios/more.png" width="200" hspace="2" alt="calorie" /> |

## Architecture

This project uses the MVI(Model - View - Intent) architecture based on UDF(Unidirectional Data Flow)
and Reactive programming.

Why?

- more clear and intentional separation of concerns
- single source of truth for our UI state which can only be mutated by intent/actions
- simpler and more direct UI testability, since we can define how the UI should look like with our
state objects

### Packaging Structure

- `sources`
- `remotesource`
- handles getting data from any server/remote source
- `localsource`
- handles getting cached device data
- `data`
- handles getting and mutating data from needed sources
- `domain`
- handles encasing business logic for reuse
- `ui`
- handles displaying data on device

### Testing

The app includes both unit and instrumented tests.
#### Sources
---

- Remote

| WeatherRemoteSource |
|:----------------------------------------------------------------------------:|
| <img src="images/testing/remote.png" width="700" hspace="2" alt="loading" /> |

- Local

| WeatherLocalSource |
|:-------------------------------------------:|
| <div width="700"> <p>In Progress</p> </div> |

#### Data
---

- Repositories

| WeatherRepository |
|:--------------------------------------------------------------------------:|
| <img src="images/testing/repo.png" width="700" hspace="2" alt="loading" /> |

- Extensions

| DateTime |
|:-----------------------------------------------------------------------------------------:|
| <img src="images/testing/extensions/datetime.png" width="700" hspace="2" alt="loading" /> |

| String |
|:---------------------------------------------------------------------------------------:|
| <img src="images/testing/extensions/string.png" width="700" hspace="2" alt="loading" /> |

| Int |
|:------------------------------------------------------------------------------------:|
| <img src="images/testing/extensions/int.png" width="700" hspace="2" alt="loading" /> |

#### Domain
---

| GetCurrentWeatherDataUseCase |
|:------------------------------------------------------------------------------------:|
| <img src="images/testing/domain/current.png" width="700" hspace="2" alt="loading" /> |

| GetHistoryWeatherDataUseCase |
|:------------------------------------------------------------------------------------:|
| <img src="images/testing/domain/history.png" width="700" hspace="2" alt="loading" /> |

#### ui
---

- screen-model

| WeatherDetailScreenModel |
|:---------------------------------------------------------------------------------------:|
| <img src="images/testing/ui/models/details.png" width="700" hspace="2" alt="loading" /> |

| WeatherListScreenModel |
|:------------------------------------------------------------------------------------:|
| <img src="images/testing/ui/models/list.png" width="700" hspace="2" alt="loading" /> |

- screens

| WeatherDetailScreen |
|:---------------------------------------------------------------------------------------:|
| <img src="images/testing/ui/screens/detail.png" width="700" hspace="2" alt="loading" /> |

| WeatherListScreen |
|:-------------------------------------------:|
| <div width="700"> <p>In Progress</p> </div> |

## Stack

### Language & Framework

| Title | Description |
|:-----------------------------------------------------------------------------------|:-----------------------------------|
| [Kotlin](https://kotlinlang.org/) | `fun` programming language |
| [KMP - Kotlin Multiplatform](https://www.jetbrains.com/kotlin-multiplatform/) | cross platform framework |
| [CMP - Compose Multiplatform](https://www.jetbrains.com/lp/compose-multiplatform/) | declarative UI rendering framework |
| [Ktor](https://github.com/ktorio/ktor) | networking client framework |

### Libraries

| Title | Description |
|:-------------------------------------------------------------------------|:------------------|
| [Kotlinx-DateTime](https://github.com/Kotlin/kotlinx-datetime) | date/time library |
| [Kotlinx-Coroutines](https://github.com/Kotlin/kotlinx.coroutines) | async programming |
| [Kotlinx-Serialization](https://github.com/Kotlin/kotlinx.serialization) | serialization |
| [Kamel](https://github.com/Kamel-Media/Kamel) | image loading |
| [Voyager](https://github.com/adrielcafe/voyager) | navigation |


Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun WeatherHourItem(
) {
Text(
text = buildAnnotatedString {
append("${item.temperatureInCelsius}")
append("${item.temperatureInCelsius.toInt()}")
withStyle(
style = SpanStyle(
fontSize = 12.sp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WeatherDetailScreenModel(
) : StatefulScreenModel<WeatherDetailScreenState>(initial = WeatherDetailScreenState()) {

fun getCurrentWeatherForecast() {
if (state.value.weatherData !is LoadState.Success)
screenModelScope.launch {
updateState { copy(weatherData = LoadState.Loading) }
when (val result = getCurrentWeatherDataUseCase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,34 @@ import kotlin.test.assertTrue
class FakeWeatherRepository : WeatherRepository {

private val data: MutableStateFlow<List<WeatherForecastData>?> = MutableStateFlow(emptyList())
private val fake = WeatherForecastData(
date = LocalDate(2024, 1, 1),
day = WeatherDayData(
maxTemperatureInCelsius = 35.0,
minTemperatureInCelsius = 24.0,
averageTemperatureInCelsius = 29.5,
averageHumidity = 24.0,
maxWindInKilometersPerHour = 40.0,
willRain = false,
chancesOfRainInPercentage = 25.0,
condition = WeatherConditionData("Sunny", "")
),
hours = listOf(
WeatherHourData(
time = LocalDateTime(2024, 2, 3, 6, 30, 0, 0),
temperatureInCelsius = 25.0,
isDaylight = true,
condition = WeatherConditionData("Sunny", "")
)
)
)

fun simulateError() {
data.value = null
}

fun simulateSuccess() {
data.value = listOf(
WeatherForecastData(
date = LocalDate(2024, 1, 1),
day = WeatherDayData(
maxTemperatureInCelsius = 35.0,
minTemperatureInCelsius = 24.0,
averageTemperatureInCelsius = 29.5,
averageHumidity = 24.0,
maxWindInKilometersPerHour = 40.0,
willRain = false,
chancesOfRainInPercentage = 25.0,
condition = WeatherConditionData("Sunny", "")
),
hours = listOf(
WeatherHourData(
time = LocalDateTime(2024, 2, 3, 6, 30, 0, 0),
temperatureInCelsius = 25.0,
isDaylight = true,
condition = WeatherConditionData("Sunny", "")
)
)
)
)
data.value = listOf(fake, fake)
}

override suspend fun getCurrentWeatherData(): DataResult<List<WeatherForecastData>> {
Expand Down Expand Up @@ -92,7 +91,7 @@ class WeatherRepositoryTest {
}

@Test
fun `given WeatherRepository - when fetching weather data - should return DataResult Error`() =
fun `given WeatherRepository - when fetching weather data - on failure should return DataResult Error`() =
runTest {
repository.simulateError()
val data = repository.getCurrentWeatherData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ui.screens.list.WeatherListScreenModel
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

/**
Expand Down Expand Up @@ -79,18 +80,19 @@ class WeatherListScreenModelTest {
@Test
fun `given WeatherListScreenModel - when updating futureState - should be ListState Success`() =
runTest {
weatherListScreenModel.updateFutureList(listOf())
weatherListScreenModel.updateFutureList(listOf(data))
val data = weatherListScreenModel.state.value.futureState
assertTrue { data is LoadState.Success }
}

@Test
fun `given WeatherListScreenModel - when updating futureState with data - state should contain data`() =
runTest {
weatherListScreenModel.updateFutureList(listOf(data))
val data = weatherListScreenModel.state.value.futureState
val value = (data as LoadState.Success).data
assertTrue { value.isNotEmpty() }
val list = listOf(data, data)
weatherListScreenModel.updateFutureList(list)
val state = weatherListScreenModel.state.value.futureState
val value = (state as LoadState.Success).data
assertEquals(listOf(data), value)
}

@Test
Expand Down
Binary file added images/android/loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/android/more.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/android/today.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ios/loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ios/more.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ios/today.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/domain/current.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/domain/history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/extensions/datetime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/extensions/int.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/extensions/string.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/remote.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/repo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/ui/models/details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/ui/models/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/testing/ui/screens/detail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,38 @@
name = Frameworks;
sourceTree = "<group>";
};
62DBF4183AB37B668A72A8E5 /* xcschemes */ = {
isa = PBXGroup;
children = (
);
path = xcschemes;
sourceTree = "<group>";
};
62DBF5F15D2B2366E4BAFF9A /* mambo.xcuserdatad */ = {
isa = PBXGroup;
children = (
62DBF4183AB37B668A72A8E5 /* xcschemes */,
);
path = mambo.xcuserdatad;
sourceTree = "<group>";
};
62DBF7D64596272A11ECB760 /* xcuserdata */ = {
isa = PBXGroup;
children = (
62DBF5F15D2B2366E4BAFF9A /* mambo.xcuserdatad */,
);
name = xcuserdata;
path = iosApp.xcodeproj/xcuserdata;
sourceTree = "<group>";
};
7555FF72242A565900829871 = {
isa = PBXGroup;
children = (
AB1DB47929225F7C00F7AF9C /* Configuration */,
7555FF7D242A565900829871 /* iosApp */,
7555FF7C242A565900829871 /* Products */,
42799AB246E5F90AF97AA0EF /* Frameworks */,
62DBF7D64596272A11ECB760 /* xcuserdata */,
);
sourceTree = "<group>";
};
Expand Down

0 comments on commit bc921b3

Please sign in to comment.