From 6185c1ccfe27da5431b799a7944dbe4680027dc7 Mon Sep 17 00:00:00 2001 From: Davidodari Date: Sun, 31 May 2020 08:49:54 +0300 Subject: [PATCH 1/4] fix clear text issues on release and tests --- app/build.gradle | 22 +++++++--- app/src/debug/AndroidManifest.xml | 42 ------------------- app/src/main/AndroidManifest.xml | 1 + .../CharacterSearchViewModel.kt | 2 + .../main/res/xml/network_security_config.xml | 21 ++++++++++ .../com/k0d4black/theforce/domain/Utils.kt | 23 ++++++++++ .../domain/usecases/GetFilmsUseCase.kt | 3 +- .../domain/usecases/GetPlanetUseCase.kt | 3 +- .../domain/usecases/GetSpeciesUseCase.kt | 3 +- 9 files changed, 69 insertions(+), 51 deletions(-) delete mode 100644 app/src/debug/AndroidManifest.xml create mode 100644 app/src/main/res/xml/network_security_config.xml create mode 100644 domain/src/main/kotlin/com/k0d4black/theforce/domain/Utils.kt diff --git a/app/build.gradle b/app/build.gradle index d6384df2..7015a55b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,6 +26,15 @@ jacocoAndroidUnitTestReport { android { + signingConfigs { + release { + keyAlias "theforcekey" + keyPassword "theforce2020" + storeFile file("../theforce.jks") + storePassword "theforce2020" + } + } + compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion @@ -42,18 +51,19 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' manifestPlaceholders = [ - crashlyticsEnabled: true, - appIcon : "@mipmap/ic_launcher", - appIconRound : "@mipmap/ic_launcher_round" + crashlyticsEnabled : true, + appIcon : "@mipmap/ic_launcher", + appIconRound : "@mipmap/ic_launcher_round" ] + signingConfig signingConfigs.release } debug { applicationIdSuffix ".debug" versionNameSuffix "-debug" manifestPlaceholders = [ - crashlyticsEnabled: false, - appIcon : "@mipmap/ic_debug_launcher", - appIconRound : "@mipmap/ic_debug_launcher_round" + crashlyticsEnabled : false, + appIcon : "@mipmap/ic_debug_launcher", + appIconRound : "@mipmap/ic_debug_launcher_round" ] testCoverageEnabled true } diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml deleted file mode 100644 index d5980b7b..00000000 --- a/app/src/debug/AndroidManifest.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a95d6191..3536fecb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ android:label="@string/app_name" android:roundIcon="${appIconRound}" android:supportsRtl="true" + android:networkSecurityConfig="@xml/network_security_config" android:theme="@style/AppTheme"> () private val searchExceptionHandler = CoroutineExceptionHandler { _, exception -> + Log.d("Vm","$exception") val message = ExceptionHandler.parse(exception) _searchViewState.value = Error(message) } diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 00000000..30d83e35 --- /dev/null +++ b/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,21 @@ + + + + swapi.dev + + + localhost + + \ No newline at end of file diff --git a/domain/src/main/kotlin/com/k0d4black/theforce/domain/Utils.kt b/domain/src/main/kotlin/com/k0d4black/theforce/domain/Utils.kt new file mode 100644 index 00000000..a2554601 --- /dev/null +++ b/domain/src/main/kotlin/com/k0d4black/theforce/domain/Utils.kt @@ -0,0 +1,23 @@ +/** + * + * Copyright 2020 David Odari + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + **/ +package com.k0d4black.theforce.domain + + +fun String.toHttps(): String { + return if (this.contains("https")) { + this + } else { + this.replace("http", "https") + } +} \ No newline at end of file diff --git a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetFilmsUseCase.kt b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetFilmsUseCase.kt index ec1198d0..daaaacb5 100644 --- a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetFilmsUseCase.kt +++ b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetFilmsUseCase.kt @@ -2,6 +2,7 @@ package com.k0d4black.theforce.domain.usecases import com.k0d4black.theforce.domain.models.Film import com.k0d4black.theforce.domain.repository.ICharacterDetailsRepository +import com.k0d4black.theforce.domain.toHttps import kotlinx.coroutines.flow.Flow typealias FilmsUseCase = BaseUseCase>> @@ -11,5 +12,5 @@ class GetFilmsUseCase( ) : FilmsUseCase { override suspend operator fun invoke(params: String) = - characterDetailsRepository.getCharacterFilms(params) + characterDetailsRepository.getCharacterFilms(params.toHttps()) } \ No newline at end of file diff --git a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetPlanetUseCase.kt b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetPlanetUseCase.kt index 287cf257..a85fa23a 100644 --- a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetPlanetUseCase.kt +++ b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetPlanetUseCase.kt @@ -2,6 +2,7 @@ package com.k0d4black.theforce.domain.usecases import com.k0d4black.theforce.domain.models.Planet import com.k0d4black.theforce.domain.repository.ICharacterDetailsRepository +import com.k0d4black.theforce.domain.toHttps import kotlinx.coroutines.flow.Flow typealias PlanetUseCase = BaseUseCase> @@ -11,5 +12,5 @@ class GetPlanetUseCase( ) : PlanetUseCase { override suspend operator fun invoke(params: String) = - characterDetailsRepository.getCharacterPlanet(params) + characterDetailsRepository.getCharacterPlanet(params.toHttps()) } \ No newline at end of file diff --git a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetSpeciesUseCase.kt b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetSpeciesUseCase.kt index 92a159c0..a16a4350 100644 --- a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetSpeciesUseCase.kt +++ b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetSpeciesUseCase.kt @@ -2,6 +2,7 @@ package com.k0d4black.theforce.domain.usecases import com.k0d4black.theforce.domain.models.Specie import com.k0d4black.theforce.domain.repository.ICharacterDetailsRepository +import com.k0d4black.theforce.domain.toHttps import kotlinx.coroutines.flow.Flow typealias SpeciesUseCase = BaseUseCase>> @@ -11,6 +12,6 @@ class GetSpeciesUseCase( ) : SpeciesUseCase { override suspend operator fun invoke(params: String) = - characterDetailsRepository.getCharacterSpecies(params) + characterDetailsRepository.getCharacterSpecies(params.toHttps()) } \ No newline at end of file From 7236f76ada591b19f99bff14adf2c030c2399204 Mon Sep 17 00:00:00 2001 From: Davidodari Date: Sun, 31 May 2020 08:52:18 +0300 Subject: [PATCH 2/4] cleanup --- .../com/k0d4black/theforce/domain/Utils.kt | 23 ------------------- .../domain/usecases/GetFilmsUseCase.kt | 3 +-- .../domain/usecases/GetPlanetUseCase.kt | 3 +-- .../domain/usecases/GetSpeciesUseCase.kt | 3 +-- 4 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 domain/src/main/kotlin/com/k0d4black/theforce/domain/Utils.kt diff --git a/domain/src/main/kotlin/com/k0d4black/theforce/domain/Utils.kt b/domain/src/main/kotlin/com/k0d4black/theforce/domain/Utils.kt deleted file mode 100644 index a2554601..00000000 --- a/domain/src/main/kotlin/com/k0d4black/theforce/domain/Utils.kt +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * Copyright 2020 David Odari - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - **/ -package com.k0d4black.theforce.domain - - -fun String.toHttps(): String { - return if (this.contains("https")) { - this - } else { - this.replace("http", "https") - } -} \ No newline at end of file diff --git a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetFilmsUseCase.kt b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetFilmsUseCase.kt index daaaacb5..ec1198d0 100644 --- a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetFilmsUseCase.kt +++ b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetFilmsUseCase.kt @@ -2,7 +2,6 @@ package com.k0d4black.theforce.domain.usecases import com.k0d4black.theforce.domain.models.Film import com.k0d4black.theforce.domain.repository.ICharacterDetailsRepository -import com.k0d4black.theforce.domain.toHttps import kotlinx.coroutines.flow.Flow typealias FilmsUseCase = BaseUseCase>> @@ -12,5 +11,5 @@ class GetFilmsUseCase( ) : FilmsUseCase { override suspend operator fun invoke(params: String) = - characterDetailsRepository.getCharacterFilms(params.toHttps()) + characterDetailsRepository.getCharacterFilms(params) } \ No newline at end of file diff --git a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetPlanetUseCase.kt b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetPlanetUseCase.kt index a85fa23a..287cf257 100644 --- a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetPlanetUseCase.kt +++ b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetPlanetUseCase.kt @@ -2,7 +2,6 @@ package com.k0d4black.theforce.domain.usecases import com.k0d4black.theforce.domain.models.Planet import com.k0d4black.theforce.domain.repository.ICharacterDetailsRepository -import com.k0d4black.theforce.domain.toHttps import kotlinx.coroutines.flow.Flow typealias PlanetUseCase = BaseUseCase> @@ -12,5 +11,5 @@ class GetPlanetUseCase( ) : PlanetUseCase { override suspend operator fun invoke(params: String) = - characterDetailsRepository.getCharacterPlanet(params.toHttps()) + characterDetailsRepository.getCharacterPlanet(params) } \ No newline at end of file diff --git a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetSpeciesUseCase.kt b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetSpeciesUseCase.kt index a16a4350..92a159c0 100644 --- a/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetSpeciesUseCase.kt +++ b/domain/src/main/kotlin/com/k0d4black/theforce/domain/usecases/GetSpeciesUseCase.kt @@ -2,7 +2,6 @@ package com.k0d4black.theforce.domain.usecases import com.k0d4black.theforce.domain.models.Specie import com.k0d4black.theforce.domain.repository.ICharacterDetailsRepository -import com.k0d4black.theforce.domain.toHttps import kotlinx.coroutines.flow.Flow typealias SpeciesUseCase = BaseUseCase>> @@ -12,6 +11,6 @@ class GetSpeciesUseCase( ) : SpeciesUseCase { override suspend operator fun invoke(params: String) = - characterDetailsRepository.getCharacterSpecies(params.toHttps()) + characterDetailsRepository.getCharacterSpecies(params) } \ No newline at end of file From 520ab98c4aecd5c13162471e21e971495ea2ded1 Mon Sep 17 00:00:00 2001 From: Davidodari Date: Sun, 31 May 2020 10:15:44 +0300 Subject: [PATCH 3/4] fix number format exception --- app/build.gradle | 9 --------- .../CharacterDetailActivity.kt | 16 ++++++++++------ .../CharacterDetailViewModel.kt | 17 +++++++++-------- .../CharacterSearchViewModel.kt | 1 - .../theforce/mappers/DomainToPresentation.kt | 2 +- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7015a55b..aef3bbdc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,15 +26,6 @@ jacocoAndroidUnitTestReport { android { - signingConfigs { - release { - keyAlias "theforcekey" - keyPassword "theforce2020" - storeFile file("../theforce.jks") - storePassword "theforce2020" - } - } - compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion diff --git a/app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailActivity.kt b/app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailActivity.kt index 39b4e26f..c992d7fc 100644 --- a/app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailActivity.kt +++ b/app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailActivity.kt @@ -118,18 +118,22 @@ class CharacterDetailActivity : AppCompatActivity() { onNetworkChange { isConnected -> characterDetailViewModel.detailViewState.value?.let { viewState -> if (isConnected && viewState.error != null) { - binding.filmsLayout.filmsErrorTextView.remove() - binding.planetLayout.planetErrorTextView.remove() - binding.specieLayout.specieErrorTextView.remove() - binding.filmsLayout.filmsProgressBar.show() - binding.planetLayout.planetProgressBar.show() - binding.specieLayout.speciesProgressBar.show() + resolveErrorViewState() characterDetailViewModel.getCharacterDetails(characterUrl, isRetry = true) } } } } + private fun resolveErrorViewState() { + binding.filmsLayout.filmsErrorTextView.remove() + binding.planetLayout.planetErrorTextView.remove() + binding.specieLayout.specieErrorTextView.remove() + binding.filmsLayout.filmsProgressBar.show() + binding.planetLayout.planetProgressBar.show() + binding.specieLayout.speciesProgressBar.show() + } + private fun onNetworkChange(block: (Boolean) -> Unit) { NetworkUtils.getNetworkStatus(this) .observe(this, Observer { isConnected -> diff --git a/app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailViewModel.kt b/app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailViewModel.kt index 958ef634..d98ec7e9 100644 --- a/app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailViewModel.kt +++ b/app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailViewModel.kt @@ -1,7 +1,11 @@ package com.k0d4black.theforce.features.character_details +import android.util.Log import androidx.annotation.StringRes -import androidx.lifecycle.* +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.k0d4black.theforce.commons.ExceptionHandler import com.k0d4black.theforce.domain.usecases.FilmsUseCase import com.k0d4black.theforce.domain.usecases.PlanetUseCase @@ -27,6 +31,7 @@ internal class CharacterDetailViewModel( private var _detailViewState = MutableLiveData() private val characterDetailExceptionHandler = CoroutineExceptionHandler { _, exception -> + Log.d("Character Detail VM", "$exception") val message = ExceptionHandler.parse(exception) _detailViewState.value = _detailViewState.value?.copy(error = Error(message)) } @@ -47,14 +52,10 @@ internal class CharacterDetailViewModel( _detailViewState.value = _detailViewState.value?.copy(error = null) } viewModelScope.launch(characterDetailExceptionHandler) { - val planetRequest = async { loadPlanet(characterUrl) } - val filmsRequest = async { loadFilms(characterUrl) } - val speciesRequest = async { loadSpecies(characterUrl) } - planetRequest.await() - filmsRequest.await() - speciesRequest.await() + async { loadPlanet(characterUrl) }.await() + async { loadFilms(characterUrl) }.await() + async { loadSpecies(characterUrl) }.await() _detailViewState.value = _detailViewState.value?.copy(isComplete = true) - } } diff --git a/app/src/main/kotlin/com/k0d4black/theforce/features/character_search/CharacterSearchViewModel.kt b/app/src/main/kotlin/com/k0d4black/theforce/features/character_search/CharacterSearchViewModel.kt index d2840c34..efe56544 100644 --- a/app/src/main/kotlin/com/k0d4black/theforce/features/character_search/CharacterSearchViewModel.kt +++ b/app/src/main/kotlin/com/k0d4black/theforce/features/character_search/CharacterSearchViewModel.kt @@ -21,7 +21,6 @@ internal class CharacterSearchViewModel( private var _searchViewState = MutableLiveData() private val searchExceptionHandler = CoroutineExceptionHandler { _, exception -> - Log.d("Vm","$exception") val message = ExceptionHandler.parse(exception) _searchViewState.value = Error(message) } diff --git a/app/src/main/kotlin/com/k0d4black/theforce/mappers/DomainToPresentation.kt b/app/src/main/kotlin/com/k0d4black/theforce/mappers/DomainToPresentation.kt index 7b6e87e7..e501046f 100644 --- a/app/src/main/kotlin/com/k0d4black/theforce/mappers/DomainToPresentation.kt +++ b/app/src/main/kotlin/com/k0d4black/theforce/mappers/DomainToPresentation.kt @@ -22,7 +22,7 @@ fun Character.toPresentation(): CharacterPresentation { } fun Planet.toPresentation(): PlanetPresentation { - val populationAsLong = if (this.population.contains("Unknown")) 0L else this.population.toLong() + val populationAsLong = if (this.population.contains("unknown")) 0L else this.population.toLong() return PlanetPresentation(this.name, populationAsLong) } From 312c1d9d1bde1161d9dbc8a5edc59537d09f93b4 Mon Sep 17 00:00:00 2001 From: Davidodari Date: Sun, 31 May 2020 10:16:57 +0300 Subject: [PATCH 4/4] version bumpt to 2.0.0 --- app/build.gradle | 1 - dependencies.gradle | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index aef3bbdc..633f3d15 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,6 @@ android { appIcon : "@mipmap/ic_launcher", appIconRound : "@mipmap/ic_launcher_round" ] - signingConfig signingConfigs.release } debug { applicationIdSuffix ".debug" diff --git a/dependencies.gradle b/dependencies.gradle index efecba19..05c83dbc 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -6,8 +6,8 @@ ext { buildToolsVersion = "29.0.2" //App Versioning - versionCodeMajor = 1 - versionCodeMinor = 3 + versionCodeMajor = 2 + versionCodeMinor = 0 versionCodePatch = 0 versionName = "$versionCodeMajor.$versionCodeMinor.$versionCodePatch"