Skip to content

Commit 806811a

Browse files
authored
Merge pull request #21 from SimpleAppProjects/develop
v5.11.1
2 parents e582ea5 + 0dadbbf commit 806811a

File tree

142 files changed

+5788
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+5788
-697
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ API_KEY.txt
3434
*.7z
3535
google-services.json
3636
/.privado/
37-
/.detekt
37+
/.detekt
38+
/.kotlin

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616
targetSdkVersion rootProject.targetSdkVersion
1717
// NOTE: Version Code Format (TargetSDK, Version Name, Build Number, Variant Code (Android: 0, WearOS: 1)
1818
// ex) 345100131 = (34, 5.10, 013, 0)
19-
versionCode 345100190
20-
versionName "5.10.4"
19+
versionCode 345110040
20+
versionName "5.11.1"
2121

2222
vectorDrawables {
2323
useSupportLibrary true
@@ -170,7 +170,7 @@ dependencies {
170170

171171
fullgmsImplementation "com.google.android.gms:play-services-base:$gms_base_version"
172172
fullgmsImplementation "com.google.android.gms:play-services-location:$gms_location_version"
173-
fullgmsImplementation 'com.google.android.gms:play-services-maps:19.0.0'
173+
fullgmsImplementation 'com.google.android.gms:play-services-maps:19.2.0'
174174
fullgmsImplementation "com.google.android.gms:play-services-wearable:$gms_wearable_version"
175175
fullgmsImplementation 'com.google.android.play:app-update-ktx:2.1.0'
176176
fullgmsImplementation 'com.google.android.play:feature-delivery-ktx:2.1.0'

app/src/androidTestFullgms/java/com/thewizrd/simpleweather/test/UnitTests.kt

Lines changed: 91 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.thewizrd.shared_resources.exceptions.WeatherException
1818
import com.thewizrd.shared_resources.locationdata.LocationData
1919
import com.thewizrd.shared_resources.locationdata.WeatherLocationProvider
2020
import com.thewizrd.shared_resources.locationdata.toLocationData
21+
import com.thewizrd.shared_resources.okhttp3.OkHttp3Utils.await
2122
import com.thewizrd.shared_resources.preferences.SettingsManager
2223
import com.thewizrd.shared_resources.remoteconfig.WeatherProviderConfig
2324
import com.thewizrd.shared_resources.utils.Coordinate
@@ -50,6 +51,7 @@ import com.thewizrd.weather_api.weatherkit.CurrentWeather
5051
import kotlinx.coroutines.Dispatchers
5152
import kotlinx.coroutines.runBlocking
5253
import kotlinx.coroutines.withContext
54+
import okhttp3.Request
5355
import org.junit.After
5456
import org.junit.Assert.*
5557
import org.junit.Before
@@ -105,17 +107,21 @@ class UnitTests {
105107
settingsManager.loadIfNeeded()
106108
}
107109

108-
if (settingsManager.usePersonalKey()) {
109-
settingsManager.setPersonalKey(false)
110-
wasUsingPersonalKey = true
110+
settingsManager.getAPI()?.let { api ->
111+
if (settingsManager.usePersonalKey(api)) {
112+
settingsManager.setPersonalKey(api, false)
113+
wasUsingPersonalKey = true
114+
}
111115
}
112116
}
113117

114118
@After
115119
fun destroy() {
116-
if (wasUsingPersonalKey) {
117-
settingsManager.setPersonalKey(true)
118-
wasUsingPersonalKey = false
120+
settingsManager.getAPI()?.let { api ->
121+
if (wasUsingPersonalKey) {
122+
settingsManager.setPersonalKey(api, true)
123+
wasUsingPersonalKey = false
124+
}
119125
}
120126
}
121127

@@ -263,7 +269,7 @@ class UnitTests {
263269
val json2 = withContext(Dispatchers.Default) {
264270
JSONParser.serializer(weather, Weather::class.java)
265271
}
266-
val desW2 = withContext(Dispatchers.Default) {
272+
withContext(Dispatchers.Default) {
267273
JSONParser.deserializer(json2, Weather::class.java)
268274
}
269275
val endTime2 = SystemClock.elapsedRealtimeNanos()
@@ -500,7 +506,9 @@ class UnitTests {
500506
@Throws(WeatherException::class)
501507
@Test
502508
fun getTomorrowIOWeather() {
503-
settingsManager.setPersonalKey(true)
509+
val originalKey = settingsManager.getAPIKey(WeatherAPI.TOMORROWIO)
510+
511+
settingsManager.setPersonalKey(WeatherAPI.TOMORROWIO, true)
504512
settingsManager.setAPIKey(WeatherAPI.TOMORROWIO, "TomorrowIo_REPLACE_VALUE")
505513

506514
runBlocking(Dispatchers.Default) {
@@ -510,14 +518,16 @@ class UnitTests {
510518
assertTrue(weather.isValid && WeatherUiModel(weather).isValid)
511519
}
512520

513-
settingsManager.setAPIKey(WeatherAPI.TOMORROWIO, null)
514-
settingsManager.setPersonalKey(false)
521+
settingsManager.setAPIKey(WeatherAPI.TOMORROWIO, originalKey)
522+
settingsManager.setPersonalKey(WeatherAPI.TOMORROWIO, false)
515523
}
516524

517525
@Throws(WeatherException::class)
518526
@Test
519527
fun getWeatherbitIOWeather() {
520-
settingsManager.setPersonalKey(true)
528+
val originalKey = settingsManager.getAPIKey(WeatherAPI.WEATHERBITIO)
529+
530+
settingsManager.setPersonalKey(WeatherAPI.WEATHERBITIO, true)
521531
settingsManager.setAPIKey(WeatherAPI.WEATHERBITIO, "WeatherBitIo_REPLACE_VALUE")
522532

523533
runBlocking(Dispatchers.Default) {
@@ -528,13 +538,15 @@ class UnitTests {
528538
assertTrue(weather.isValid && WeatherUiModel(weather).isValid)
529539
}
530540

531-
settingsManager.setAPIKey(WeatherAPI.WEATHERBITIO, null)
532-
settingsManager.setPersonalKey(false)
541+
settingsManager.setAPIKey(WeatherAPI.WEATHERBITIO, originalKey)
542+
settingsManager.setPersonalKey(WeatherAPI.WEATHERBITIO, false)
533543
}
534544

535545
@Test
536546
fun getPollenData() {
537-
settingsManager.setPersonalKey(true)
547+
val originalKey = settingsManager.getAPIKey(WeatherAPI.TOMORROWIO)
548+
549+
settingsManager.setPersonalKey(WeatherAPI.TOMORROWIO, true)
538550
settingsManager.setAPIKey(WeatherAPI.TOMORROWIO, "TomorrowIo_REPLACE_VALUE")
539551

540552
runBlocking(Dispatchers.Default) {
@@ -546,14 +558,16 @@ class UnitTests {
546558
assertNotNull(pollenData)
547559
}
548560

549-
settingsManager.setAPIKey(WeatherAPI.TOMORROWIO, null)
550-
settingsManager.setPersonalKey(false)
561+
settingsManager.setAPIKey(WeatherAPI.TOMORROWIO, originalKey)
562+
settingsManager.setPersonalKey(WeatherAPI.TOMORROWIO, false)
551563
}
552564

553565
@Throws(WeatherException::class)
554566
@Test
555567
fun getMeteomaticsWeather() {
556-
settingsManager.setPersonalKey(true)
568+
val originalKey = settingsManager.getAPIKey(WeatherAPI.METEOMATICS)
569+
570+
settingsManager.setPersonalKey(WeatherAPI.METEOMATICS, true)
557571
settingsManager.setAPIKey(
558572
WeatherAPI.METEOMATICS,
559573
BasicAuthProviderKey("username", "password").toString()
@@ -567,8 +581,8 @@ class UnitTests {
567581
assertTrue(weather.isValid && WeatherUiModel(weather).isValid)
568582
}
569583

570-
settingsManager.setAPIKey(WeatherAPI.METEOMATICS, null)
571-
settingsManager.setPersonalKey(false)
584+
settingsManager.setAPIKey(WeatherAPI.METEOMATICS, originalKey)
585+
settingsManager.setPersonalKey(WeatherAPI.METEOMATICS, false)
572586
}
573587

574588
@Test
@@ -641,6 +655,25 @@ class UnitTests {
641655
}
642656
}
643657

658+
@Throws(WeatherException::class)
659+
@Test
660+
fun getGoogleWeather() {
661+
val originalKey = settingsManager.getAPIKey(WeatherAPI.GOOGLE)
662+
663+
settingsManager.setPersonalKey(WeatherAPI.GOOGLE, true)
664+
settingsManager.setAPIKey(WeatherAPI.GOOGLE, "Google_REPLACE_VALUE")
665+
666+
runBlocking(Dispatchers.Default) {
667+
val provider = weatherModule.weatherManager.getWeatherProvider(WeatherAPI.GOOGLE)
668+
val weather =
669+
getWeather(provider, Coordinate(37.4220083, -122.0876528)) // ~ Mountain View
670+
assertTrue(weather.isValid && WeatherUiModel(weather).isValid)
671+
}
672+
673+
settingsManager.setAPIKey(WeatherAPI.GOOGLE, originalKey)
674+
settingsManager.setPersonalKey(WeatherAPI.GOOGLE, false)
675+
}
676+
644677
@Test
645678
fun moshiSerializeTest() {
646679
JSONParser.deserializer<WeatherProviderConfig>(
@@ -657,4 +690,43 @@ class UnitTests {
657690
UpdateInfo::class.java
658691
)
659692
}
693+
694+
@Test
695+
fun test500error() {
696+
val request = Request.Builder()
697+
.url("https://httpstat.us/500")
698+
.build()
699+
700+
val client = sharedDeps.httpClient
701+
702+
runBlocking {
703+
client.newCall(request).await()
704+
}
705+
}
706+
707+
@Test
708+
fun test502error() {
709+
val request = Request.Builder()
710+
.url("https://httpstat.us/502?sleep=1000")
711+
.build()
712+
713+
val client = sharedDeps.httpClient
714+
715+
runBlocking {
716+
client.newCall(request).await()
717+
}
718+
}
719+
720+
@Test
721+
fun test504error() {
722+
val request = Request.Builder()
723+
.url("https://httpstat.us/504?sleep=1000")
724+
.build()
725+
726+
val client = sharedDeps.httpClient
727+
728+
runBlocking {
729+
client.newCall(request).await()
730+
}
731+
}
660732
}

app/src/androidTestNongms/java/com/thewizrd/simpleweather/test/UnitTests.kt

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,27 @@ import android.util.Log
99
import androidx.preference.PreferenceManager
1010
import androidx.test.core.app.ApplicationProvider
1111
import androidx.test.ext.junit.runners.AndroidJUnit4
12-
import com.thewizrd.common.controls.WeatherNowViewModel
12+
import com.thewizrd.common.CommonModule
13+
import com.thewizrd.common.commonModule
14+
import com.thewizrd.common.controls.WeatherUiModel
1315
import com.thewizrd.shared_resources.*
16+
import com.thewizrd.shared_resources.di.settingsManager
1417
import com.thewizrd.shared_resources.exceptions.WeatherException
1518
import com.thewizrd.shared_resources.locationdata.LocationData
1619
import com.thewizrd.shared_resources.locationdata.WeatherLocationProvider
1720
import com.thewizrd.shared_resources.locationdata.toLocationData
21+
import com.thewizrd.shared_resources.preferences.SettingsManager
1822
import com.thewizrd.shared_resources.utils.Coordinate
1923
import com.thewizrd.shared_resources.utils.DateTimeUtils
2024
import com.thewizrd.shared_resources.utils.JSONParser
21-
import com.thewizrd.shared_resources.utils.SettingsManager
2225
import com.thewizrd.shared_resources.weatherdata.WeatherAPI
2326
import com.thewizrd.shared_resources.weatherdata.WeatherProvider
2427
import com.thewizrd.shared_resources.weatherdata.model.Weather
28+
import com.thewizrd.simpleweather.viewmodels.WeatherNowViewModel
2529
import com.thewizrd.weather_api.aqicn.AQICNProvider
30+
import com.thewizrd.weather_api.google.location.getFromLocationAsync
31+
import com.thewizrd.weather_api.google.location.getFromLocationNameAsync
32+
import com.thewizrd.weather_api.google.location.isGeocoderAvailable
2633
import com.thewizrd.weather_api.nws.SolCalcAstroProvider
2734
import com.thewizrd.weather_api.nws.alerts.NWSAlertProvider
2835
import com.thewizrd.weather_api.openweather.citydb.CityDBLocationProvider
@@ -33,6 +40,7 @@ import com.thewizrd.weather_api.weatherapi.location.WeatherApiLocationProvider
3340
import kotlinx.coroutines.Dispatchers
3441
import kotlinx.coroutines.runBlocking
3542
import kotlinx.coroutines.withContext
43+
import org.junit.After
3644
import org.junit.Assert.*
3745
import org.junit.Before
3846
import org.junit.Test
@@ -78,13 +86,29 @@ class UnitTests {
7886
}
7987
}
8088

89+
commonModule = object : CommonModule() {
90+
override val context = appLib.context
91+
}
92+
8193
runBlocking {
82-
appLib.settingsManager.loadIfNeeded()
94+
settingsManager.loadIfNeeded()
8395
}
8496

85-
if (appLib.settingsManager.usePersonalKey()) {
86-
appLib.settingsManager.setPersonalKey(false)
87-
wasUsingPersonalKey = true
97+
settingsManager.getAPI()?.let { api ->
98+
if (settingsManager.usePersonalKey(api)) {
99+
settingsManager.setPersonalKey(api, false)
100+
wasUsingPersonalKey = true
101+
}
102+
}
103+
}
104+
105+
@After
106+
fun destroy() {
107+
settingsManager.getAPI()?.let { api ->
108+
if (wasUsingPersonalKey) {
109+
settingsManager.setPersonalKey(api, true)
110+
wasUsingPersonalKey = false
111+
}
88112
}
89113
}
90114

@@ -191,7 +215,7 @@ class UnitTests {
191215
val json2 = withContext(Dispatchers.Default) {
192216
JSONParser.serializer(weather, Weather::class.java)
193217
}
194-
val desW2 = withContext(Dispatchers.Default) {
218+
withContext(Dispatchers.Default) {
195219
JSONParser.deserializer(json2, Weather::class.java)
196220
}
197221
val endTime2 = SystemClock.elapsedRealtimeNanos()
@@ -260,7 +284,7 @@ class UnitTests {
260284
val addressList = withContext(Dispatchers.IO) {
261285
geocoder.getFromLocationNameAsync("Redmond", 5) // Redmond
262286
}
263-
assertFalse(addressList.isNullOrEmpty())
287+
assertFalse(addressList.isEmpty())
264288
}
265289
}
266290

@@ -274,8 +298,8 @@ class UnitTests {
274298
val addressList = withContext(Dispatchers.IO) {
275299
geocoder.getFromLocationAsync(51.5073884, -0.1334347, 1) // London
276300
}
277-
assertFalse(addressList.isNullOrEmpty())
278-
val result = addressList!![0]
301+
assertFalse(addressList.isEmpty())
302+
val result = addressList[0]
279303
assertNotNull(result)
280304
}
281305
}
@@ -288,7 +312,7 @@ class UnitTests {
288312
val locations = withContext(Dispatchers.IO) {
289313
locationProvider.getLocations("Redmond, WA", WeatherAPI.WEATHERAPI)
290314
}
291-
assertFalse(locations.isNullOrEmpty())
315+
assertFalse(locations.isEmpty())
292316

293317
val queryVM = locations.find { it.locationName?.startsWith("Redmond") == true }
294318
assertNotNull(queryVM)
@@ -341,7 +365,7 @@ class UnitTests {
341365
runBlocking(Dispatchers.Default) {
342366
val provider = weatherModule.weatherManager.getWeatherProvider(WeatherAPI.WEATHERAPI)
343367
val weather = getWeather(provider)
344-
assertTrue(weather.isValid && WeatherNowViewModel(weather).isValid)
368+
assertTrue(weather.isValid && WeatherUiModel(weather).isValid)
345369
}
346370
}
347371

@@ -352,7 +376,7 @@ class UnitTests {
352376
val provider = weatherModule.weatherManager.getWeatherProvider(WeatherAPI.TOMORROWIO)
353377
val weather =
354378
getWeather(provider, Coordinate(34.0207305, -118.6919157)) // ~ Los Angeles
355-
assertTrue(weather.isValid && WeatherNowViewModel(weather).isValid)
379+
assertTrue(weather.isValid && WeatherUiModel(weather).isValid)
356380
}
357381
}
358382

@@ -364,7 +388,7 @@ class UnitTests {
364388
weatherModule.weatherManager.getWeatherProvider(WeatherAPI.WEATHERBITIO)
365389
val weather =
366390
getWeather(provider, Coordinate(39.9, -105.1)) // ~ Denver, CO
367-
assertTrue(weather.isValid && WeatherNowViewModel(weather).isValid)
391+
assertTrue(weather.isValid && WeatherUiModel(weather).isValid)
368392
}
369393
}
370394

@@ -376,7 +400,7 @@ class UnitTests {
376400
weatherModule.weatherManager.getWeatherProvider(WeatherAPI.METEOMATICS)
377401
val weather =
378402
getWeather(provider, Coordinate(52.22, 20.97))
379-
assertTrue(weather.isValid && WeatherNowViewModel(weather).isValid)
403+
assertTrue(weather.isValid && WeatherUiModel(weather).isValid)
380404
}
381405
}
382406

@@ -388,7 +412,7 @@ class UnitTests {
388412
val locations = withContext(Dispatchers.IO) {
389413
locationProvider.getLocations("Redmond", WeatherAPI.OPENWEATHERMAP)
390414
}
391-
assertFalse(locations.isNullOrEmpty())
415+
assertFalse(locations.isEmpty())
392416

393417
val queryVM = locations.find { it.locationName?.startsWith("Redmond") == true }
394418
assertNotNull(queryVM)
@@ -460,7 +484,7 @@ class UnitTests {
460484
val locations = withContext(Dispatchers.IO) {
461485
locationProvider.getLocations("Redmond", WeatherAPI.OPENWEATHERMAP)
462486
}
463-
assertFalse(locations.isNullOrEmpty())
487+
assertFalse(locations.isEmpty())
464488

465489
val queryVM = locations.find { it.locationName?.startsWith("Redmond, ") == true }
466490
assertNotNull(queryVM)

0 commit comments

Comments
 (0)