├── debug.keystore
├── settings.gradle
├── results
├── video.mp4
├── screenshot_1.png
├── screenshot_2.png
├── screenshot_3.png
├── screenshot_4.png
├── screenshot_5.png
└── screenshot_6.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── app
├── src
│ ├── main
│ │ ├── ic_launcher-playstore.png
│ │ ├── res
│ │ │ ├── font
│ │ │ │ ├── roboto_black.ttf
│ │ │ │ ├── roboto_bold.ttf
│ │ │ │ ├── roboto_medium.ttf
│ │ │ │ └── roboto_regular.ttf
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── themes.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_settingsn.xml
│ │ │ │ ├── ic_settingsd.xml
│ │ │ │ ├── ic_searchn.xml
│ │ │ │ ├── ic_searchd.xml
│ │ │ │ ├── ic_03d.xml
│ │ │ │ ├── ic_03n.xml
│ │ │ │ ├── ic_04n.xml
│ │ │ │ ├── ic_04d.xml
│ │ │ │ ├── ic_11n.xml
│ │ │ │ ├── ic_11d.xml
│ │ │ │ ├── ic_01n.xml
│ │ │ │ ├── ic_01d.xml
│ │ │ │ ├── ic_02n.xml
│ │ │ │ ├── ic_02d.xml
│ │ │ │ ├── ic_50n.xml
│ │ │ │ ├── ic_50d.xml
│ │ │ │ ├── ic_09n.xml
│ │ │ │ ├── ic_09d.xml
│ │ │ │ ├── ic_10d.xml
│ │ │ │ ├── ic_10n.xml
│ │ │ │ ├── ic_launcher_foreground.xml
│ │ │ │ ├── ic_13n.xml
│ │ │ │ └── ic_13d.xml
│ │ │ └── values-night
│ │ │ │ └── themes.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── androiddevchallenge
│ │ │ │ ├── domain
│ │ │ │ ├── model
│ │ │ │ │ ├── City.kt
│ │ │ │ │ ├── Weather.kt
│ │ │ │ │ ├── FeelsLike.kt
│ │ │ │ │ ├── Alert.kt
│ │ │ │ │ ├── Temp.kt
│ │ │ │ │ ├── WeatherData.kt
│ │ │ │ │ ├── Current.kt
│ │ │ │ │ ├── Daily.kt
│ │ │ │ │ └── WWWeather.kt
│ │ │ │ └── GetWeatherData.kt
│ │ │ │ ├── presentation
│ │ │ │ ├── cb
│ │ │ │ │ └── WeatherDataEvent.kt
│ │ │ │ └── WeatherViewModel.kt
│ │ │ │ ├── ui
│ │ │ │ ├── theme
│ │ │ │ │ ├── Shape.kt
│ │ │ │ │ ├── Color.kt
│ │ │ │ │ ├── Type.kt
│ │ │ │ │ └── Theme.kt
│ │ │ │ ├── MainScreen.kt
│ │ │ │ └── SettingsScreen.kt
│ │ │ │ ├── data
│ │ │ │ └── OpenWeatherAPI.kt
│ │ │ │ ├── utils
│ │ │ │ ├── SingleLiveEvent.kt
│ │ │ │ └── Utils.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── androiddevchallenge
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── androiddevchallenge
│ │ └── ExampleInstrumentedTest.kt
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── .gitignore
├── spotless
└── copyright.kt
├── .github
├── ci-gradle.properties
└── workflows
│ └── Check.yaml
├── CONTRIBUTING.md
├── gradle.properties
├── README.md
├── gradlew.bat
├── gradlew
└── LICENSE
/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/debug.keystore
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = "AndroidDevChallenge"
2 | include ':app'
3 |
--------------------------------------------------------------------------------
/results/video.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/results/video.mp4
--------------------------------------------------------------------------------
/results/screenshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/results/screenshot_1.png
--------------------------------------------------------------------------------
/results/screenshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/results/screenshot_2.png
--------------------------------------------------------------------------------
/results/screenshot_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/results/screenshot_3.png
--------------------------------------------------------------------------------
/results/screenshot_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/results/screenshot_4.png
--------------------------------------------------------------------------------
/results/screenshot_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/results/screenshot_5.png
--------------------------------------------------------------------------------
/results/screenshot_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/results/screenshot_6.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/app/src/main/res/font/roboto_black.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/font/roboto_black.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/roboto_bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/font/roboto_bold.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/roboto_medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/font/roboto_medium.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/roboto_regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/font/roboto_regular.ttf
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cmota/wwweather/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000000
4 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | # Gradle
2 | .gradle
3 | build/
4 |
5 | captures
6 |
7 | /local.properties
8 |
9 | # IntelliJ .idea folder
10 | /.idea
11 | *.iml
12 |
13 | # General
14 | .DS_Store
15 | .externalNativeBuild
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Feb 24 18:05:51 CET 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_settingsn.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_settingsd.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_searchn.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_searchd.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_03d.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_03n.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Mac files
6 | .DS_Store
7 |
8 | # files for the dex VM
9 | *.dex
10 |
11 | # Java class files
12 | *.class
13 |
14 | # generated files
15 | bin/
16 | gen/
17 |
18 | # Ignore gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 | proguard-project.txt
28 |
29 | # Eclipse files
30 | .project
31 | .classpath
32 | .settings/
33 |
34 | # Android Studio/IDEA
35 | *.iml
36 | .idea
--------------------------------------------------------------------------------
/spotless/copyright.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright $YEAR The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 | #FF000000
14 | #FFFFFFFF
15 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/City.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | data class City(val name: String, val lat: String, val lon: String)
19 |
--------------------------------------------------------------------------------
/.github/ci-gradle.properties:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # Copyright 2020 The Android Open Source Project
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | org.gradle.daemon=false
19 | org.gradle.parallel=true
20 | org.gradle.jvmargs=-Xmx5120m
21 | org.gradle.workers.max=2
22 |
23 | kotlin.incremental=false
24 | kotlin.compiler.execution.strategy=in-process
25 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_04n.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_04d.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/Weather.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | import kotlinx.serialization.Serializable
19 |
20 | @Serializable
21 | data class Weather(
22 | val description: String = "",
23 | val icon: String = "",
24 | val id: Int = 0,
25 | val main: String = ""
26 | )
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/presentation/cb/WeatherDataEvent.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.presentation.cb
17 |
18 | import com.example.androiddevchallenge.domain.model.WeatherData
19 |
20 | interface WeatherDataEvent {
21 |
22 | fun onWeatherDataFetched(data: WeatherData)
23 |
24 | fun onWeatherDataFailed()
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/FeelsLike.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | import kotlinx.serialization.Serializable
19 |
20 | @Serializable
21 | data class FeelsLike(
22 | val day: Double = 0.0,
23 | val eve: Double = 0.0,
24 | val morn: Double = 0.0,
25 | val night: Double = 0.0
26 | )
27 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_11n.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/androiddevchallenge/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge
17 |
18 | /**
19 | * Example local unit test, which will execute on the development machine (host).
20 | *
21 | * See [testing documentation](http://d.android.com/tools/testing).
22 | */
23 | class ExampleUnitTest {
24 | // Add unit tests here
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/Alert.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | import kotlinx.serialization.Serializable
19 |
20 | @Serializable
21 | data class Alert(
22 | val description: String,
23 | val end: Int,
24 | val event: String,
25 | val sender_name: String,
26 | val start: Int
27 | )
28 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_11d.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_01n.xml:
--------------------------------------------------------------------------------
1 |
6 |
11 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_01d.xml:
--------------------------------------------------------------------------------
1 |
6 |
11 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/Temp.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | import kotlinx.serialization.Serializable
19 |
20 | @Serializable
21 | data class Temp(
22 | val day: Double = 0.0,
23 | val eve: Double = 0.0,
24 | val max: Double = 0.0,
25 | val min: Double = 0.0,
26 | val morn: Double = 0.0,
27 | val night: Double = 0.0
28 | )
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/ui/theme/Shape.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.ui.theme
17 |
18 | import androidx.compose.foundation.shape.RoundedCornerShape
19 | import androidx.compose.material.Shapes
20 | import androidx.compose.ui.unit.dp
21 |
22 | val shapes = Shapes(
23 | small = RoundedCornerShape(4.dp),
24 | medium = RoundedCornerShape(4.dp),
25 | large = RoundedCornerShape(0.dp)
26 | )
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/WeatherData.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | import kotlinx.serialization.Serializable
19 |
20 | @Serializable
21 | data class WeatherData(
22 | val alerts: List = emptyList(),
23 | val current: Current,
24 | val daily: List,
25 | val lat: Double,
26 | val lon: Double,
27 | val timezone: String,
28 | val timezone_offset: Int
29 | )
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_02n.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_02d.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_50n.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_50d.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution,
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google.com/conduct/).
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_09n.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/Current.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | import kotlinx.serialization.Serializable
19 |
20 | @Serializable
21 | data class Current(
22 | val clouds: Int,
23 | val dew_point: Double,
24 | val dt: Int,
25 | val feels_like: Double,
26 | val humidity: Int,
27 | val pressure: Int,
28 | val sunrise: Int,
29 | val sunset: Int,
30 | val temp: Double,
31 | val uvi: Double,
32 | val visibility: Int,
33 | val weather: List,
34 | val wind_deg: Int,
35 | val wind_speed: Double
36 | )
37 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_09d.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/Daily.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | import kotlinx.serialization.Serializable
19 |
20 | @Serializable
21 | data class Daily(
22 | val clouds: Int = 0,
23 | val dew_point: Double = 0.0,
24 | val dt: Int = 0,
25 | val feels_like: FeelsLike = FeelsLike(),
26 | val humidity: Int = 0,
27 | val pop: Double = 0.0,
28 | val pressure: Int = 0,
29 | val rain: Double? = 0.0,
30 | val sunrise: Int = 0,
31 | val sunset: Int = 0,
32 | val temp: Temp = Temp(),
33 | val uvi: Double = 0.0,
34 | val weather: List = listOf(Weather()),
35 | val wind_deg: Int = 0,
36 | val wind_speed: Double = 0.0
37 | )
38 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/androiddevchallenge/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge
17 |
18 | import androidx.compose.ui.test.junit4.createAndroidComposeRule
19 | import androidx.test.ext.junit.runners.AndroidJUnit4
20 | import org.junit.Rule
21 | import org.junit.Test
22 | import org.junit.runner.RunWith
23 |
24 | /**
25 | * Instrumented test, which will execute on an Android device.
26 | *
27 | * See [testing documentation](http://d.android.com/tools/testing).
28 | */
29 | @RunWith(AndroidJUnit4::class)
30 | class ExampleInstrumentedTest {
31 | @get:Rule
32 | val composeTestRule = createAndroidComposeRule()
33 |
34 | @Test
35 | fun sampleTest() {
36 | // Add instrumented tests here
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.ui.theme
17 |
18 | import androidx.compose.ui.graphics.Color
19 |
20 | val darkBackground = Color(0xFF000000)
21 | val darkBackgroundField = Color(0xFF121212)
22 | val darkText = Color(0xFFFFFFFF)
23 | val darkTextSecondary = Color(0xFF546E7A)
24 | val darkSelected = Color(0xFFFFFFFF)
25 | val darkNotSelected = Color(0xFF212121)
26 | val darkSingleOption = Color(0xFF546E7A)
27 |
28 | val lightBackground = Color(0xFFFFFFFF)
29 | val lightBackgroundField = Color(0xFFF4F4F4)
30 | val lightText = Color(0xFF000000)
31 | val lightTextSecondary = Color(0xFFE0E0E0)
32 | val lightSelected = Color(0xFF292E3C)
33 | val lightNotSelected = Color(0xFFE0E0E0)
34 | val lightSingleOption = Color(0xFF546E7A)
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # wwweather
2 |
3 | 
4 |
5 |
6 | ## :scroll: Description
7 | A simple, yet beautiful weather app done with Jetpack Compose.
8 |
9 | A special thank you to [@henrikemacedo](https://twitter.com/henrikemacedo) who designed this beautiful UI.
10 |
11 |
12 | ## :bulb: Motivation and Context
13 | Played with Jetpack Compose to create a simple, yet beautiful weather app made entirely with Jetpack Compose. The app supports two theme modes: light and night which can be changed by either activiating the night mode on the device or changing it on runtime inside the app settings.
14 |
15 | ## :camera_flash: Screenshots
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | ## License
24 | ```
25 | Copyright 2020 The Android Open Source Project
26 |
27 | Licensed under the Apache License, Version 2.0 (the "License");
28 | you may not use this file except in compliance with the License.
29 | You may obtain a copy of the License at
30 |
31 | https://www.apache.org/licenses/LICENSE-2.0
32 |
33 | Unless required by applicable law or agreed to in writing, software
34 | distributed under the License is distributed on an "AS IS" BASIS,
35 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 | See the License for the specific language governing permissions and
37 | limitations under the License.
38 | ```
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
15 |
16 |
17 |
18 |
25 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/model/WWWeather.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain.model
17 |
18 | data class WWWeather(
19 | val icon: String = "",
20 | val feelsLike: Double = 0.0,
21 | val now: Double = 0.0,
22 | val min: Double = 0.0,
23 | val max: Double = 0.0,
24 | val wind: Double = 0.0,
25 | val humidity: Int = 0,
26 | val daily: List = emptyList()
27 | )
28 |
29 | fun mapper(weatherData: WeatherData?, index: Int): WWWeather {
30 | if (weatherData == null) {
31 | return WWWeather()
32 | }
33 |
34 | val daily = if (weatherData.daily.size > index) {
35 | weatherData.daily[index]
36 | } else {
37 | Daily()
38 | }
39 |
40 | return WWWeather(
41 | icon = daily.weather[0].icon,
42 | feelsLike = daily.feels_like.day,
43 | now = daily.temp.day,
44 | min = daily.temp.min,
45 | max = daily.temp.max,
46 | wind = daily.wind_speed,
47 | humidity = daily.humidity,
48 | daily = weatherData.daily
49 | )
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_10d.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_10n.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/domain/GetWeatherData.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.domain
17 |
18 | import android.util.Log
19 | import com.example.androiddevchallenge.data.OpenWeatherAPI
20 | import com.example.androiddevchallenge.data.UNITS
21 | import com.example.androiddevchallenge.domain.model.City
22 | import com.example.androiddevchallenge.presentation.cb.WeatherDataEvent
23 | import kotlinx.coroutines.coroutineScope
24 |
25 | private const val TAG = "GetWeatherData"
26 |
27 | class GetWeatherData {
28 |
29 | suspend fun invoke(city: City, units: UNITS, event: WeatherDataEvent) {
30 | try {
31 |
32 | val result = OpenWeatherAPI.getWeather(city.lat, city.lon, units)
33 |
34 | Log.d(TAG, "Result=$result")
35 |
36 | coroutineScope {
37 | event.onWeatherDataFetched(result)
38 | }
39 | } catch (e: Exception) {
40 | Log.d(TAG, "Unable to get data for city=$city. Reason=$e")
41 |
42 | coroutineScope {
43 | event.onWeatherDataFailed()
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
11 |
13 |
16 |
19 |
22 |
25 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 | wwweather
13 |
14 | Feels like
15 |
16 | Now
17 | Min / Max
18 | Wind
19 | Humidity
20 |
21 | %sº
22 | %sº
23 | %s Km/h
24 | %s mph
25 | %
26 |
27 | Today
28 |
29 | Settings
30 | Units
31 | Metric (ºC, Km/h)
32 | Imperial (ºF, mph)
33 | Theme
34 | Light
35 | Dark
36 |
37 | Search
38 | Recent Searches
39 |
40 |
41 | Weather image
42 | Open settings
43 | Open search for location
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/presentation/WeatherViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.presentation
17 |
18 | import androidx.lifecycle.ViewModel
19 | import com.example.androiddevchallenge.data.UNITS
20 | import com.example.androiddevchallenge.domain.GetWeatherData
21 | import com.example.androiddevchallenge.domain.model.City
22 | import com.example.androiddevchallenge.domain.model.WeatherData
23 | import com.example.androiddevchallenge.presentation.cb.WeatherDataEvent
24 | import com.example.androiddevchallenge.utils.SingleLiveEvent
25 | import kotlinx.coroutines.CoroutineScope
26 | import kotlinx.coroutines.Dispatchers
27 | import kotlinx.coroutines.Job
28 | import kotlinx.coroutines.launch
29 |
30 | class WeatherViewModel : ViewModel(), WeatherDataEvent {
31 |
32 | private val _weather = SingleLiveEvent()
33 | val weather: SingleLiveEvent = _weather
34 |
35 | private val scope = CoroutineScope(Job() + Dispatchers.Main)
36 |
37 | fun getWeather(city: City, units: UNITS) {
38 | val event = this
39 | scope.launch {
40 | GetWeatherData().invoke(city, units, event)
41 | }
42 | }
43 |
44 | //region WeatherDataEvent
45 |
46 | override fun onWeatherDataFetched(data: WeatherData) {
47 | weather.postValue(data)
48 | }
49 |
50 | override fun onWeatherDataFailed() {
51 | weather.postValue(null)
52 | }
53 |
54 | //endregion
55 | }
56 |
--------------------------------------------------------------------------------
/.github/workflows/Check.yaml:
--------------------------------------------------------------------------------
1 | name: Check
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 | timeout-minutes: 30
12 |
13 | steps:
14 | - name: Checkout
15 | uses: actions/checkout@v2
16 |
17 | - name: Copy CI gradle.properties
18 | run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
19 |
20 | - name: Set up JDK 11
21 | uses: actions/setup-java@v1
22 | with:
23 | java-version: 11
24 |
25 | - name: Build project
26 | run: ./gradlew spotlessCheck assembleDebug lintDebug --stacktrace
27 |
28 | - name: Upload build outputs (APKs)
29 | uses: actions/upload-artifact@v2
30 | with:
31 | name: build-outputs
32 | path: app/build/outputs
33 |
34 | - name: Upload build reports
35 | if: always()
36 | uses: actions/upload-artifact@v2
37 | with:
38 | name: build-reports
39 | path: app/build/reports
40 |
41 | test:
42 | needs: build
43 | runs-on: macOS-latest # enables hardware acceleration in the virtual machine
44 | timeout-minutes: 30
45 | strategy:
46 | matrix:
47 | api-level: [23, 26, 29]
48 |
49 | steps:
50 | - name: Checkout
51 | uses: actions/checkout@v2
52 |
53 | - name: Copy CI gradle.properties
54 | run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
55 |
56 | - name: Set up JDK 11
57 | uses: actions/setup-java@v1
58 | with:
59 | java-version: 11
60 |
61 | - name: Run instrumentation tests
62 | uses: reactivecircus/android-emulator-runner@v2
63 | with:
64 | api-level: ${{ matrix.api-level }}
65 | arch: x86
66 | disable-animations: true
67 | script: ./gradlew connectedCheck --stacktrace
68 |
69 | - name: Upload test reports
70 | if: always()
71 | uses: actions/upload-artifact@v2
72 | with:
73 | name: test-reports
74 | path: app/build/reports
75 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
29 |
30 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/data/OpenWeatherAPI.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.data
17 |
18 | import com.example.androiddevchallenge.domain.model.WeatherData
19 | import io.ktor.client.HttpClient
20 | import io.ktor.client.features.json.JsonFeature
21 | import io.ktor.client.features.json.serializer.KotlinxSerializer
22 | import io.ktor.client.request.get
23 | import kotlinx.serialization.json.Json
24 |
25 | private const val API_KEY = "3404b86afb31bf57ef44a72bc8f12405"
26 |
27 | private const val BASE_URL = "https://api.openweathermap.org/data/2.5/onecall"
28 | private const val PARAM_LAT = "?lat="
29 | private const val PARAM_LON = "&lon="
30 | private const val PARAM_UNITS = "&units="
31 | private const val PARAM_EXCLUDE = "&exclude=minutely,hourly"
32 | private const val PARAM_KEY = "&appid=$API_KEY"
33 |
34 | private const val METRIC = "metric"
35 | private const val IMPERIAL = "imperial"
36 |
37 | enum class UNITS { METRIC, IMPERIAL }
38 |
39 | object OpenWeatherAPI {
40 |
41 | private val nonStrictJson = Json { isLenient = true; ignoreUnknownKeys = true }
42 |
43 | private val client = HttpClient {
44 | install(JsonFeature) {
45 | serializer = KotlinxSerializer(nonStrictJson)
46 | }
47 | }
48 |
49 | suspend fun getWeather(lat: String, lon: String, units: UNITS): WeatherData = client.get(
50 | BASE_URL +
51 | "$PARAM_LAT$lat" +
52 | "$PARAM_LON$lon" +
53 | "$PARAM_UNITS$units" +
54 | PARAM_EXCLUDE +
55 | PARAM_KEY
56 | )
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.ui.theme
17 |
18 | import androidx.compose.material.Typography
19 | import androidx.compose.ui.text.TextStyle
20 | import androidx.compose.ui.text.font.Font
21 | import androidx.compose.ui.text.font.FontFamily
22 | import androidx.compose.ui.text.font.FontWeight
23 | import androidx.compose.ui.unit.sp
24 | import com.example.androiddevchallenge.R
25 |
26 | // Set of Material typography styles to start with
27 | val RobotoFontFamily = FontFamily(
28 | Font(R.font.roboto_bold, FontWeight.Bold),
29 | Font(R.font.roboto_black, FontWeight.Black),
30 | Font(R.font.roboto_medium, FontWeight.Medium),
31 | Font(R.font.roboto_regular)
32 | )
33 |
34 | // Set of Material typography styles to start with
35 | val typography = Typography(
36 | h1 = TextStyle(
37 | fontFamily = RobotoFontFamily,
38 | fontWeight = FontWeight.Black,
39 | fontSize = 18.sp,
40 | ),
41 |
42 | h2 = TextStyle(
43 | fontFamily = RobotoFontFamily,
44 | fontWeight = FontWeight.Black,
45 | fontSize = 80.sp,
46 | letterSpacing = (-9.6).sp
47 | ),
48 |
49 | h3 = TextStyle(
50 | fontFamily = RobotoFontFamily,
51 | fontSize = 16.sp,
52 | ),
53 |
54 | h4 = TextStyle(
55 | fontFamily = RobotoFontFamily,
56 | fontWeight = FontWeight.Black,
57 | fontSize = 16.sp,
58 | ),
59 |
60 | h5 = TextStyle(
61 | fontFamily = RobotoFontFamily,
62 | fontWeight = FontWeight.Medium,
63 | fontSize = 16.sp,
64 | ),
65 |
66 | h6 = TextStyle(
67 | fontFamily = RobotoFontFamily,
68 | fontWeight = FontWeight.Medium,
69 | fontSize = 20.sp,
70 | letterSpacing = (0.15).sp
71 | )
72 | )
73 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/utils/SingleLiveEvent.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.utils
17 |
18 | import android.util.Log
19 | import androidx.annotation.MainThread
20 | import androidx.lifecycle.LifecycleOwner
21 | import androidx.lifecycle.MutableLiveData
22 | import androidx.lifecycle.Observer
23 | import java.util.concurrent.atomic.AtomicBoolean
24 |
25 | /**
26 | * A lifecycle-aware observable that sends only new updates after subscription, used for events like
27 | * navigation and Snackbar messages.
28 | *
29 | *
30 | * This avoids a common problem with events: on configuration change (like rotation) an update
31 | * can be emitted if the observer is active. This LiveData only calls the observable if there's an
32 | * explicit call to setValue() or call().
33 | *
34 | *
35 | * Note that only one observer is going to be notified of changes.
36 | */
37 | class SingleLiveEvent : MutableLiveData() {
38 | private val pending = AtomicBoolean(false)
39 | @MainThread
40 | override fun observe(owner: LifecycleOwner, observer: Observer) {
41 | if (hasActiveObservers()) {
42 | Log.w(TAG, "Multiple observers registered but only one will be notified of changes.")
43 | }
44 | // Observe the internal MutableLiveData
45 | super.observe(
46 | owner,
47 | { t ->
48 | if (pending.compareAndSet(true, false)) {
49 | observer.onChanged(t)
50 | }
51 | }
52 | )
53 | }
54 |
55 | @MainThread
56 | override fun setValue(t: T?) {
57 | pending.set(true)
58 | super.setValue(t)
59 | }
60 | /**
61 | * Used for cases where T is Void, to make calls cleaner.
62 | */
63 | @MainThread
64 | fun call() {
65 | value = null
66 | }
67 | companion object {
68 | private const val TAG = "SingleLiveEvent"
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | id "kotlinx-serialization"
5 | }
6 |
7 | android {
8 | compileSdkVersion 30
9 |
10 | defaultConfig {
11 | applicationId "com.example.androiddevchallenge"
12 | minSdkVersion 23
13 | targetSdkVersion 30
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | signingConfigs {
21 | // We use a bundled debug keystore, to allow debug builds from CI to be upgradable
22 | debug {
23 | storeFile rootProject.file('debug.keystore')
24 | storePassword 'android'
25 | keyAlias 'androiddebugkey'
26 | keyPassword 'android'
27 | }
28 | }
29 |
30 | buildTypes {
31 | debug {
32 | signingConfig signingConfigs.debug
33 | }
34 | release {
35 | minifyEnabled false
36 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
37 | }
38 | }
39 |
40 | kotlinOptions {
41 | jvmTarget = "1.8"
42 | }
43 |
44 | buildFeatures {
45 | compose true
46 |
47 | // Disable unused AGP features
48 | buildConfig false
49 | aidl false
50 | renderScript false
51 | resValues false
52 | shaders false
53 | }
54 |
55 | composeOptions {
56 | kotlinCompilerExtensionVersion compose_version
57 | }
58 |
59 | packagingOptions {
60 | // Multiple dependency bring these files in. Exclude them to enable
61 | // our test APK to build (has no effect on our AARs)
62 | excludes += "/META-INF/AL2.0"
63 | excludes += "/META-INF/LGPL2.1"
64 | }
65 | }
66 |
67 | dependencies {
68 | implementation 'androidx.core:core-ktx:1.3.2'
69 | implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
70 | implementation 'com.google.android.material:material:1.3.0'
71 | implementation "androidx.activity:activity-compose:1.3.0-alpha04"
72 | implementation "androidx.compose.ui:ui:$compose_version"
73 | implementation "androidx.compose.material:material:$compose_version"
74 | implementation "androidx.compose.material:material-icons-extended:$compose_version"
75 | implementation("androidx.compose.runtime:runtime-livedata:$compose_version")
76 | implementation "androidx.compose.ui:ui-tooling:$compose_version"
77 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
78 |
79 | implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1'
80 |
81 | implementation 'io.ktor:ktor-client-json:1.5.0'
82 | implementation 'io.ktor:ktor-client-serialization:1.5.0'
83 | implementation 'io.ktor:ktor-client-android:1.5.2'
84 |
85 | implementation 'dev.chrisbanes.accompanist:accompanist-coil:0.6.2'
86 |
87 | testImplementation 'junit:junit:4.13.2'
88 |
89 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
90 | androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
91 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_13n.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_13d.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/utils/Utils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.utils
17 |
18 | import android.content.Context
19 | import com.example.androiddevchallenge.R
20 | import com.example.androiddevchallenge.data.UNITS
21 | import com.example.androiddevchallenge.ui.theme.DarkImages
22 | import com.example.androiddevchallenge.ui.theme.LightImages
23 | import java.util.Calendar
24 | import java.util.Locale
25 |
26 | fun roundUp(value: Double?): String? {
27 | if (value == null) {
28 | return null
29 | }
30 |
31 | return "${Math.round(value)}"
32 | }
33 |
34 | fun roundUp(value: Int?): String? {
35 | return roundUp(value?.toDouble())
36 | }
37 |
38 | fun formatUnit(context: Context, value: String?, unit: UNITS, temp: Boolean): String {
39 | if (value == null || value.isEmpty()) {
40 | return "-"
41 | }
42 |
43 | return when (unit) {
44 | UNITS.METRIC -> {
45 | if (temp) {
46 | context.getString(R.string.unit_celsius, value)
47 | } else {
48 | context.getString(R.string.unit_kmh, value)
49 | }
50 | }
51 | UNITS.IMPERIAL -> {
52 | if (temp) {
53 | context.getString(R.string.unit_imperial, value)
54 | } else {
55 | context.getString(R.string.unit_mph, value)
56 | }
57 | }
58 | }
59 | }
60 |
61 | fun getDayOfWeek(context: Context, index: Int): String {
62 | val calendar = Calendar.getInstance()
63 | calendar.add(Calendar.DAY_OF_MONTH, index)
64 |
65 | return if (index == 0) {
66 | context.getString(R.string.today)
67 | } else {
68 | calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault())!!
69 | }
70 | }
71 |
72 | fun getWeatherIcon(icon: String, darkTheme: Boolean): Int {
73 | if (icon.isNotEmpty()) {
74 | when (icon) {
75 | "01d", "01n" -> { return if (darkTheme) DarkImages[0] else LightImages[0] }
76 | "02d", "02n" -> { return if (darkTheme) DarkImages[1] else LightImages[1] }
77 | "03d", "03n" -> { return if (darkTheme) DarkImages[2] else LightImages[2] }
78 | "04d", "04n" -> { return if (darkTheme) DarkImages[3] else LightImages[3] }
79 | "09d", "09n" -> { return if (darkTheme) DarkImages[4] else LightImages[4] }
80 | "10d", "10n" -> { return if (darkTheme) DarkImages[5] else LightImages[5] }
81 | "11d", "11n" -> { return if (darkTheme) DarkImages[6] else LightImages[6] }
82 | "13d", "13n" -> { return if (darkTheme) DarkImages[7] else LightImages[7] }
83 | "50d", "50n" -> { return if (darkTheme) DarkImages[8] else LightImages[8] }
84 | }
85 | }
86 |
87 | return if (darkTheme) DarkImages[1] else LightImages[1]
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.ui.theme
17 |
18 | import android.os.Build
19 | import android.util.Log
20 | import android.view.View
21 | import android.view.Window
22 | import androidx.compose.foundation.isSystemInDarkTheme
23 | import androidx.compose.material.MaterialTheme
24 | import androidx.compose.material.darkColors
25 | import androidx.compose.material.lightColors
26 | import androidx.compose.runtime.Composable
27 | import androidx.compose.ui.graphics.toArgb
28 | import com.example.androiddevchallenge.R
29 |
30 | private const val TAG = "Theme"
31 |
32 | val LightImages = listOf(
33 | R.drawable.ic_01d,
34 | R.drawable.ic_02d,
35 | R.drawable.ic_03d,
36 | R.drawable.ic_04d,
37 | R.drawable.ic_09d,
38 | R.drawable.ic_10d,
39 | R.drawable.ic_11d,
40 | R.drawable.ic_13d,
41 | R.drawable.ic_50d
42 | )
43 |
44 | val DarkImages = listOf(
45 | R.drawable.ic_01n,
46 | R.drawable.ic_02n,
47 | R.drawable.ic_03n,
48 | R.drawable.ic_04n,
49 | R.drawable.ic_09n,
50 | R.drawable.ic_10n,
51 | R.drawable.ic_11n,
52 | R.drawable.ic_13n,
53 | R.drawable.ic_50n
54 | )
55 |
56 | @Composable
57 | fun MyTheme(window: Window, darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
58 |
59 | val colors = if (darkTheme) {
60 | darkColors(
61 | primary = darkBackground,
62 | primaryVariant = darkSelected,
63 | secondary = darkTextSecondary,
64 | secondaryVariant = darkNotSelected,
65 | onPrimary = darkText,
66 | onSecondary = darkSingleOption,
67 | surface = darkBackgroundField
68 | )
69 | } else {
70 | lightColors(
71 | primary = lightBackground,
72 | primaryVariant = lightSelected,
73 | secondary = lightTextSecondary,
74 | secondaryVariant = lightNotSelected,
75 | onPrimary = lightText,
76 | onSecondary = lightSingleOption,
77 | surface = lightBackgroundField
78 | )
79 | }
80 |
81 | Log.d(TAG, "Current theme | dark=$darkTheme")
82 |
83 | window.statusBarColor = colors.primary.toArgb()
84 | window.navigationBarColor = colors.primary.toArgb()
85 |
86 | @Suppress("DEPRECATION")
87 | if (darkTheme) {
88 | window.decorView.systemUiVisibility =
89 | window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
90 |
91 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
92 | window.decorView.systemUiVisibility = window.decorView.systemUiVisibility and
93 | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv()
94 | }
95 | } else {
96 | window.decorView.systemUiVisibility =
97 | window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
98 |
99 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
100 | window.decorView.systemUiVisibility = window.decorView.systemUiVisibility or
101 | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
102 | }
103 | }
104 |
105 | MaterialTheme(
106 | colors = colors,
107 | typography = typography,
108 | shapes = shapes,
109 | content = content
110 | )
111 | }
112 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge
17 |
18 | import android.os.Bundle
19 | import android.os.Handler
20 | import android.util.Log
21 | import androidx.activity.compose.setContent
22 | import androidx.activity.viewModels
23 | import androidx.appcompat.app.AppCompatActivity
24 | import androidx.compose.foundation.clickable
25 | import androidx.compose.foundation.isSystemInDarkTheme
26 | import androidx.compose.foundation.layout.Arrangement
27 | import androidx.compose.foundation.layout.Row
28 | import androidx.compose.foundation.layout.fillMaxWidth
29 | import androidx.compose.foundation.layout.padding
30 | import androidx.compose.foundation.layout.width
31 | import androidx.compose.material.BottomSheetScaffold
32 | import androidx.compose.material.BottomSheetValue
33 | import androidx.compose.material.ExperimentalMaterialApi
34 | import androidx.compose.material.Icon
35 | import androidx.compose.material.MaterialTheme
36 | import androidx.compose.material.Scaffold
37 | import androidx.compose.material.Text
38 | import androidx.compose.material.rememberBottomSheetScaffoldState
39 | import androidx.compose.material.rememberBottomSheetState
40 | import androidx.compose.runtime.Composable
41 | import androidx.compose.runtime.MutableState
42 | import androidx.compose.runtime.mutableStateOf
43 | import androidx.compose.runtime.remember
44 | import androidx.compose.runtime.rememberCoroutineScope
45 | import androidx.compose.ui.Modifier
46 | import androidx.compose.ui.res.painterResource
47 | import androidx.compose.ui.res.stringResource
48 | import androidx.compose.ui.unit.dp
49 | import com.example.androiddevchallenge.data.UNITS
50 | import com.example.androiddevchallenge.domain.model.City
51 | import com.example.androiddevchallenge.presentation.WeatherViewModel
52 | import com.example.androiddevchallenge.ui.MainScreen
53 | import com.example.androiddevchallenge.ui.OPTIONS
54 | import com.example.androiddevchallenge.ui.SearchScreen
55 | import com.example.androiddevchallenge.ui.SettingsScreen
56 | import com.example.androiddevchallenge.ui.theme.MyTheme
57 | import com.example.androiddevchallenge.ui.theme.typography
58 | import kotlinx.coroutines.launch
59 |
60 | private const val TAG = "MainActivity"
61 |
62 | private val DEFAULT_CITY = City("Coimbra, PT", "40.2089113", "-8.4263396")
63 | private lateinit var bottomSheetOption: MutableState
64 |
65 | class MainActivity : AppCompatActivity() {
66 |
67 | private val viewModel: WeatherViewModel by viewModels()
68 |
69 | @ExperimentalMaterialApi
70 | override fun onCreate(savedInstanceState: Bundle?) {
71 | super.onCreate(savedInstanceState)
72 |
73 | setContent {
74 |
75 | val units = remember { mutableStateOf(UNITS.METRIC) }
76 | viewModel.getWeather(DEFAULT_CITY, units.value)
77 |
78 | val isDarkThemeActive = isSystemInDarkTheme()
79 | val darkTheme = remember { mutableStateOf(isDarkThemeActive) }
80 |
81 | MyTheme(window, darkTheme.value) {
82 |
83 | bottomSheetOption = remember { mutableStateOf(OPTIONS.SEARCH) }
84 |
85 | MyApp(viewModel, units, darkTheme)
86 | }
87 | }
88 | }
89 | }
90 |
91 | // Start building your app here!
92 | @ExperimentalMaterialApi
93 | @Composable
94 | fun MyApp(
95 | viewModel: WeatherViewModel,
96 | units: MutableState,
97 | darkTheme: MutableState
98 | ) {
99 |
100 | Log.d(TAG, "MyApp")
101 |
102 | val coroutineScope = rememberCoroutineScope()
103 |
104 | val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
105 | bottomSheetState = rememberBottomSheetState(
106 | initialValue = BottomSheetValue.Collapsed
107 | )
108 | )
109 |
110 | BottomSheetScaffold(
111 | sheetContent = {
112 | if (bottomSheetOption.value == OPTIONS.SEARCH) {
113 | SearchScreen(viewModel, units.value, coroutineScope, bottomSheetScaffoldState)
114 | } else {
115 | SettingsScreen(units, darkTheme)
116 | }
117 | },
118 | sheetBackgroundColor = MaterialTheme.colors.primary,
119 | scaffoldState = bottomSheetScaffoldState, sheetPeekHeight = 0.dp
120 | ) {
121 |
122 | Scaffold(
123 | topBar = {
124 | Row(
125 | modifier = Modifier
126 | .fillMaxWidth()
127 | .padding(start = 16.dp, top = 8.dp, end = 16.dp),
128 | horizontalArrangement = Arrangement.SpaceBetween
129 | ) {
130 |
131 | val settingsIcon = painterResource(R.drawable.ic_settingsd)
132 | val settingsDescription = stringResource(id = R.string.description_settings)
133 |
134 | Icon(
135 | painter = settingsIcon,
136 | contentDescription = settingsDescription,
137 | modifier = Modifier
138 | .width(25.dp)
139 | .clickable {
140 | bottomSheetOption.value = OPTIONS.SETTINGS
141 |
142 | @Suppress("DEPRECATION")
143 | Handler().postDelayed(
144 | {
145 | coroutineScope.launch {
146 | if (bottomSheetScaffoldState.bottomSheetState.isCollapsed) {
147 | Log.d(TAG, "Opening settings")
148 | bottomSheetScaffoldState.bottomSheetState.expand()
149 | } else {
150 | Log.d(TAG, "Collapsing settings")
151 | bottomSheetScaffoldState.bottomSheetState.collapse()
152 | }
153 | }
154 | },
155 | 250
156 | )
157 | }
158 | )
159 |
160 | Text(
161 | text = "Coimbra, PT",
162 | style = typography.h6
163 | )
164 |
165 | val searchIcon = painterResource(R.drawable.ic_searchd)
166 | val searchDescription = stringResource(id = R.string.description_search)
167 |
168 | Icon(
169 | painter = searchIcon,
170 | contentDescription = searchDescription,
171 | modifier = Modifier
172 | .width(25.dp)
173 | .clickable {
174 | bottomSheetOption.value = OPTIONS.SEARCH
175 |
176 | @Suppress("DEPRECATION")
177 | Handler().postDelayed(
178 | {
179 | coroutineScope.launch {
180 | if (bottomSheetScaffoldState.bottomSheetState.isCollapsed) {
181 | bottomSheetScaffoldState.bottomSheetState.expand()
182 | } else {
183 | bottomSheetScaffoldState.bottomSheetState.collapse()
184 | }
185 | }
186 | },
187 | 250
188 | )
189 | }
190 | )
191 | }
192 | },
193 | content = {
194 | MainScreen(viewModel, darkTheme.value, units.value)
195 | }
196 | )
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/ui/MainScreen.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.ui
17 |
18 | import android.util.Log
19 | import androidx.annotation.StringRes
20 | import androidx.compose.foundation.Image
21 | import androidx.compose.foundation.clickable
22 | import androidx.compose.foundation.layout.Arrangement
23 | import androidx.compose.foundation.layout.Column
24 | import androidx.compose.foundation.layout.Row
25 | import androidx.compose.foundation.layout.Spacer
26 | import androidx.compose.foundation.layout.fillMaxHeight
27 | import androidx.compose.foundation.layout.fillMaxSize
28 | import androidx.compose.foundation.layout.fillMaxWidth
29 | import androidx.compose.foundation.layout.height
30 | import androidx.compose.foundation.layout.padding
31 | import androidx.compose.foundation.layout.size
32 | import androidx.compose.foundation.layout.width
33 | import androidx.compose.foundation.lazy.LazyRow
34 | import androidx.compose.foundation.lazy.itemsIndexed
35 | import androidx.compose.foundation.shape.RoundedCornerShape
36 | import androidx.compose.material.Card
37 | import androidx.compose.material.MaterialTheme
38 | import androidx.compose.material.Text
39 | import androidx.compose.runtime.Composable
40 | import androidx.compose.runtime.MutableState
41 | import androidx.compose.runtime.getValue
42 | import androidx.compose.runtime.livedata.observeAsState
43 | import androidx.compose.runtime.mutableStateOf
44 | import androidx.compose.runtime.remember
45 | import androidx.compose.ui.Alignment
46 | import androidx.compose.ui.Modifier
47 | import androidx.compose.ui.draw.clip
48 | import androidx.compose.ui.layout.ContentScale
49 | import androidx.compose.ui.platform.LocalContext
50 | import androidx.compose.ui.res.painterResource
51 | import androidx.compose.ui.res.stringResource
52 | import androidx.compose.ui.unit.dp
53 | import com.example.androiddevchallenge.R
54 | import com.example.androiddevchallenge.data.UNITS
55 | import com.example.androiddevchallenge.domain.model.Daily
56 | import com.example.androiddevchallenge.domain.model.mapper
57 | import com.example.androiddevchallenge.presentation.WeatherViewModel
58 | import com.example.androiddevchallenge.ui.theme.typography
59 | import com.example.androiddevchallenge.utils.formatUnit
60 | import com.example.androiddevchallenge.utils.getDayOfWeek
61 | import com.example.androiddevchallenge.utils.getWeatherIcon
62 | import com.example.androiddevchallenge.utils.roundUp
63 | import java.util.Calendar
64 |
65 | private const val TAG = "MainScreen"
66 |
67 | @Composable
68 | fun MainScreen(
69 | viewModel: WeatherViewModel,
70 | darkTheme: Boolean,
71 | units: UNITS,
72 | ) {
73 |
74 | val weatherData by viewModel.weather.observeAsState()
75 |
76 | val selection = remember { mutableStateOf(0) }
77 |
78 | val weather = mapper(weatherData, selection.value)
79 |
80 | Column(horizontalAlignment = Alignment.CenterHorizontally) {
81 |
82 | Spacer(modifier = Modifier.height(60.dp))
83 |
84 | Log.d(TAG, "Icon=${weather.icon} | now=${weather.now} | selected=${selection.value}")
85 |
86 | val icon = painterResource(getWeatherIcon(weather.icon, darkTheme))
87 | val description = stringResource(id = R.string.description_weather)
88 |
89 | Image(
90 | painter = icon,
91 | contentDescription = description,
92 | modifier = Modifier.size(150.dp),
93 | contentScale = ContentScale.Fit
94 | )
95 |
96 | Text(
97 | text = stringResource(id = R.string.feels_like),
98 | style = typography.h1
99 | )
100 |
101 | val context = LocalContext.current
102 |
103 | Text(
104 | text = formatUnit(context, roundUp(weather.feelsLike), units, true),
105 | style = typography.h2
106 | )
107 |
108 | Column(
109 | modifier = Modifier.fillMaxHeight(),
110 | verticalArrangement = Arrangement.Bottom
111 | ) {
112 |
113 | AddMoreInformation(R.string.temperature_now, formatUnit(context, roundUp(weather.now), units, true))
114 |
115 | val min = formatUnit(context, roundUp(weather.min), units, true)
116 | val max = formatUnit(context, roundUp(weather.max), units, true)
117 | AddMoreInformation(R.string.temperature_min_max, "$min / $max")
118 |
119 | AddMoreInformation(R.string.temperature_wind, formatUnit(context, roundUp(weather.wind), units, false))
120 |
121 | val value = roundUp(weather.humidity)
122 | val humidity = if (value != null) {
123 | value + stringResource(id = R.string.unit_percentage)
124 | } else {
125 | "-"
126 | }
127 | AddMoreInformation(
128 | R.string.temperature_humidity,
129 | humidity
130 | )
131 |
132 | Spacer(modifier = Modifier.height(40.dp))
133 |
134 | val forecast = if (weather.daily.isEmpty()) {
135 | val daily = Daily()
136 | listOf(daily, daily, daily, daily, daily)
137 | } else {
138 | weather.daily.subList(0, 5)
139 | }
140 |
141 | LazyRow(modifier = Modifier.padding(start = 8.dp, end = 8.dp)) {
142 |
143 | itemsIndexed(forecast) { index, item ->
144 | AddForecast(item, index, selection, darkTheme, units)
145 | }
146 | }
147 | }
148 | }
149 | }
150 |
151 | @Composable
152 | fun AddMoreInformation(@StringRes resId: Int, value: String?) {
153 | Row {
154 |
155 | Row(
156 | modifier = Modifier
157 | .fillMaxWidth()
158 | .weight(1.0f)
159 | .padding(end = 10.dp),
160 | horizontalArrangement = Arrangement.End
161 | ) {
162 | Text(
163 | text = stringResource(id = resId),
164 | style = typography.h3
165 | )
166 | }
167 |
168 | Row(
169 | modifier = Modifier
170 | .fillMaxWidth()
171 | .weight(1.0f)
172 | .padding(start = 10.dp),
173 | horizontalArrangement = Arrangement.Start
174 | ) {
175 | Text(
176 | text = value ?: "-",
177 | style = typography.h4
178 | )
179 | }
180 | }
181 | }
182 |
183 | @Composable
184 | fun AddForecast(temp: Daily, index: Int, selection: MutableState, darkTheme: Boolean, units: UNITS) {
185 | val selected = index == selection.value
186 |
187 | val background = if (selected) {
188 | MaterialTheme.colors.primaryVariant
189 | } else {
190 | MaterialTheme.colors.secondaryVariant
191 | }
192 |
193 | val textColor = if (selected) {
194 | MaterialTheme.colors.secondaryVariant
195 | } else {
196 | MaterialTheme.colors.primaryVariant
197 | }
198 |
199 | Card(
200 | modifier = Modifier
201 | .width(90.dp)
202 | .height(145.dp)
203 | .padding(start = 8.dp, bottom = 16.dp, end = 8.dp)
204 | .clip(RoundedCornerShape(20.dp))
205 | .clickable {
206 | selection.value = index
207 | },
208 | backgroundColor = background,
209 | shape = RoundedCornerShape(20.dp),
210 | elevation = 0.dp
211 | ) {
212 | Column(
213 | modifier = Modifier.fillMaxSize(),
214 | verticalArrangement = Arrangement.SpaceEvenly,
215 | horizontalAlignment = Alignment.CenterHorizontally
216 | ) {
217 |
218 | val calendar = Calendar.getInstance()
219 | calendar.add(Calendar.DAY_OF_MONTH, index)
220 |
221 | Text(
222 | text = getDayOfWeek(LocalContext.current, index),
223 | style = typography.h5,
224 | color = textColor
225 | )
226 |
227 | val dailyIcon = painterResource(getWeatherIcon(temp.weather[0].icon, if (selected) !darkTheme else darkTheme))
228 | val description = stringResource(id = R.string.description_weather)
229 |
230 | Image(
231 | painter = dailyIcon,
232 | contentDescription = description,
233 | modifier = Modifier.width(45.dp)
234 | )
235 |
236 | val context = LocalContext.current
237 | Text(
238 | text = formatUnit(context, roundUp(temp.temp.day), units, true),
239 | style = typography.h5,
240 | color = textColor
241 | )
242 | }
243 | }
244 | }
245 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/androiddevchallenge/ui/SettingsScreen.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.androiddevchallenge.ui
17 |
18 | import androidx.annotation.StringRes
19 | import androidx.compose.foundation.clickable
20 | import androidx.compose.foundation.layout.Arrangement
21 | import androidx.compose.foundation.layout.Column
22 | import androidx.compose.foundation.layout.Row
23 | import androidx.compose.foundation.layout.Spacer
24 | import androidx.compose.foundation.layout.fillMaxWidth
25 | import androidx.compose.foundation.layout.height
26 | import androidx.compose.foundation.layout.padding
27 | import androidx.compose.foundation.layout.width
28 | import androidx.compose.foundation.lazy.LazyColumn
29 | import androidx.compose.foundation.lazy.itemsIndexed
30 | import androidx.compose.foundation.shape.RoundedCornerShape
31 | import androidx.compose.material.BottomSheetScaffoldState
32 | import androidx.compose.material.Divider
33 | import androidx.compose.material.ExperimentalMaterialApi
34 | import androidx.compose.material.Icon
35 | import androidx.compose.material.MaterialTheme
36 | import androidx.compose.material.RadioButton
37 | import androidx.compose.material.RadioButtonDefaults
38 | import androidx.compose.material.Text
39 | import androidx.compose.material.TextField
40 | import androidx.compose.material.TextFieldDefaults
41 | import androidx.compose.runtime.Composable
42 | import androidx.compose.runtime.MutableState
43 | import androidx.compose.runtime.mutableStateOf
44 | import androidx.compose.runtime.remember
45 | import androidx.compose.ui.Alignment
46 | import androidx.compose.ui.Modifier
47 | import androidx.compose.ui.graphics.Color
48 | import androidx.compose.ui.res.painterResource
49 | import androidx.compose.ui.res.stringResource
50 | import androidx.compose.ui.unit.dp
51 | import com.example.androiddevchallenge.R
52 | import com.example.androiddevchallenge.data.UNITS
53 | import com.example.androiddevchallenge.domain.model.City
54 | import com.example.androiddevchallenge.presentation.WeatherViewModel
55 | import com.example.androiddevchallenge.ui.theme.typography
56 | import kotlinx.coroutines.CoroutineScope
57 | import kotlinx.coroutines.launch
58 |
59 | enum class SELECTION { OPTION_1, OPTION_2 }
60 | enum class OPTIONS { SETTINGS, SEARCH }
61 |
62 | @Composable
63 | fun SettingsScreen(units: MutableState, darkTheme: MutableState) {
64 |
65 | Column(horizontalAlignment = Alignment.CenterHorizontally) {
66 |
67 | Spacer(modifier = Modifier.height(30.dp))
68 |
69 | Text(
70 | text = stringResource(id = R.string.settings),
71 | style = typography.h4
72 | )
73 |
74 | Spacer(modifier = Modifier.height(40.dp))
75 |
76 | val metricSelected = remember { mutableStateOf(SELECTION.OPTION_1) }
77 | units.value = if (metricSelected.value == SELECTION.OPTION_1) {
78 | UNITS.METRIC
79 | } else {
80 | UNITS.IMPERIAL
81 | }
82 |
83 | SelectOption(
84 | R.string.units,
85 | R.string.units_metric,
86 | R.string.units_imperial,
87 | metricSelected
88 | ) {}
89 |
90 | Spacer(modifier = Modifier.height(40.dp))
91 |
92 | val option = if (darkTheme.value) {
93 | SELECTION.OPTION_2
94 | } else {
95 | SELECTION.OPTION_1
96 | }
97 |
98 | val themeSelected = remember { mutableStateOf(option) }
99 |
100 | SelectOption(
101 | R.string.theme,
102 | R.string.theme_light,
103 | R.string.theme_dark,
104 | themeSelected
105 | ) {
106 | darkTheme.value = themeSelected.value != SELECTION.OPTION_1
107 | }
108 |
109 | Spacer(modifier = Modifier.height(40.dp))
110 | }
111 | }
112 |
113 | @Composable
114 | fun SelectOption(
115 | @StringRes label: Int,
116 | @StringRes option1: Int,
117 | @StringRes option2: Int,
118 | selected: MutableState,
119 | action: () -> Unit
120 | ) {
121 |
122 | Row {
123 |
124 | Row(
125 | modifier = Modifier
126 | .fillMaxWidth()
127 | .weight(1.0f),
128 | horizontalArrangement = Arrangement.End
129 | ) {
130 |
131 | Text(
132 | text = stringResource(id = label),
133 | style = typography.h4
134 | )
135 | }
136 |
137 | Row(
138 | modifier = Modifier
139 | .fillMaxWidth()
140 | .weight(2.0f)
141 | .padding(start = 30.dp),
142 | horizontalArrangement = Arrangement.Start
143 | ) {
144 |
145 | Column {
146 |
147 | Row {
148 |
149 | RadioButton(
150 | selected = selected.value == SELECTION.OPTION_1,
151 | onClick = {
152 | selected.value = SELECTION.OPTION_1
153 | action()
154 | },
155 | colors = RadioButtonDefaults.colors(
156 | selectedColor = MaterialTheme.colors.onSecondary,
157 | unselectedColor = MaterialTheme.colors.onSecondary
158 | )
159 | )
160 |
161 | Spacer(modifier = Modifier.width(8.dp))
162 |
163 | Text(
164 | text = stringResource(id = option1),
165 | style = typography.h3
166 | )
167 | }
168 |
169 | Spacer(modifier = Modifier.height(16.dp))
170 |
171 | Row {
172 | RadioButton(
173 | selected = selected.value == SELECTION.OPTION_2,
174 | onClick = {
175 | selected.value = SELECTION.OPTION_2
176 | action()
177 | },
178 | colors = RadioButtonDefaults.colors(
179 | selectedColor = MaterialTheme.colors.onSecondary,
180 | unselectedColor = MaterialTheme.colors.onSecondary
181 | )
182 | )
183 |
184 | Spacer(modifier = Modifier.width(8.dp))
185 |
186 | Text(
187 | text = stringResource(id = option2),
188 | style = typography.h3
189 | )
190 | }
191 | }
192 | }
193 | }
194 | }
195 |
196 | @ExperimentalMaterialApi
197 | @Composable
198 | fun SearchScreen(viewModel: WeatherViewModel, units: UNITS, coroutineScope: CoroutineScope, bottomSheetScaffoldState: BottomSheetScaffoldState) {
199 |
200 | Column(
201 | modifier = Modifier.padding(30.dp)
202 | ) {
203 |
204 | val city = remember { mutableStateOf("") }
205 | TextField(
206 | value = city.value,
207 | onValueChange = { value ->
208 | city.value = value
209 | },
210 | leadingIcon = {
211 | val searchIcon = painterResource(R.drawable.ic_searchd)
212 | Icon(searchIcon, stringResource(id = R.string.description_search))
213 | },
214 | shape = RoundedCornerShape(4.dp),
215 | modifier = Modifier.fillMaxWidth(),
216 | colors = TextFieldDefaults.textFieldColors(
217 | backgroundColor = MaterialTheme.colors.surface,
218 | focusedIndicatorColor = MaterialTheme.colors.primaryVariant,
219 | unfocusedIndicatorColor = Color.Transparent,
220 | cursorColor = MaterialTheme.colors.primaryVariant
221 | )
222 | )
223 |
224 | Spacer(modifier = Modifier.height(30.dp))
225 |
226 | Text(
227 | text = stringResource(id = R.string.search_recent),
228 | style = typography.h3,
229 | color = MaterialTheme.colors.secondary
230 | )
231 |
232 | Spacer(modifier = Modifier.height(4.dp))
233 |
234 | Divider(
235 | color = MaterialTheme.colors.secondary,
236 | thickness = 1.dp
237 | )
238 |
239 | Spacer(modifier = Modifier.height(16.dp))
240 |
241 | val recents = listOf(
242 | City("Coimbra, Portugal", "40.2089113", "-8.4263396"),
243 | City("Mountain View, California, US", "37.4134508", "-122.1513074"),
244 | City("London, United Kingdom", "51.5287352", "-0.3817816"),
245 | City("Lisboa, Portugal", "38.7437396", "-9.2302436")
246 | )
247 |
248 | LazyColumn {
249 |
250 | itemsIndexed(recents) { _, value ->
251 |
252 | Text(
253 | text = value.name,
254 | style = typography.h3,
255 | modifier = Modifier.clickable {
256 | viewModel.getWeather(value, units)
257 | coroutineScope.launch {
258 | bottomSheetScaffoldState.bottomSheetState.collapse()
259 | }
260 | }
261 | )
262 |
263 | Spacer(modifier = Modifier.height(8.dp))
264 | }
265 | }
266 | }
267 | }
268 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------