Skip to content

Commit dfdf616

Browse files
authored
Merge pull request #93 from odaridavid/bug-fix-ioexception
Fix known exceptions
2 parents 2e63e55 + 312c1d9 commit dfdf616

File tree

9 files changed

+51
-65
lines changed

9 files changed

+51
-65
lines changed

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ android {
4242
minifyEnabled false
4343
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
4444
manifestPlaceholders = [
45-
crashlyticsEnabled: true,
46-
appIcon : "@mipmap/ic_launcher",
47-
appIconRound : "@mipmap/ic_launcher_round"
45+
crashlyticsEnabled : true,
46+
appIcon : "@mipmap/ic_launcher",
47+
appIconRound : "@mipmap/ic_launcher_round"
4848
]
4949
}
5050
debug {
5151
applicationIdSuffix ".debug"
5252
versionNameSuffix "-debug"
5353
manifestPlaceholders = [
54-
crashlyticsEnabled: false,
55-
appIcon : "@mipmap/ic_debug_launcher",
56-
appIconRound : "@mipmap/ic_debug_launcher_round"
54+
crashlyticsEnabled : false,
55+
appIcon : "@mipmap/ic_debug_launcher",
56+
appIconRound : "@mipmap/ic_debug_launcher_round"
5757
]
5858
testCoverageEnabled true
5959
}

app/src/debug/AndroidManifest.xml

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:label="@string/app_name"
1010
android:roundIcon="${appIconRound}"
1111
android:supportsRtl="true"
12+
android:networkSecurityConfig="@xml/network_security_config"
1213
android:theme="@style/AppTheme">
1314
<activity
1415
android:name=".features.settings.AboutActivity"

app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailActivity.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,22 @@ class CharacterDetailActivity : AppCompatActivity() {
118118
onNetworkChange { isConnected ->
119119
characterDetailViewModel.detailViewState.value?.let { viewState ->
120120
if (isConnected && viewState.error != null) {
121-
binding.filmsLayout.filmsErrorTextView.remove()
122-
binding.planetLayout.planetErrorTextView.remove()
123-
binding.specieLayout.specieErrorTextView.remove()
124-
binding.filmsLayout.filmsProgressBar.show()
125-
binding.planetLayout.planetProgressBar.show()
126-
binding.specieLayout.speciesProgressBar.show()
121+
resolveErrorViewState()
127122
characterDetailViewModel.getCharacterDetails(characterUrl, isRetry = true)
128123
}
129124
}
130125
}
131126
}
132127

128+
private fun resolveErrorViewState() {
129+
binding.filmsLayout.filmsErrorTextView.remove()
130+
binding.planetLayout.planetErrorTextView.remove()
131+
binding.specieLayout.specieErrorTextView.remove()
132+
binding.filmsLayout.filmsProgressBar.show()
133+
binding.planetLayout.planetProgressBar.show()
134+
binding.specieLayout.speciesProgressBar.show()
135+
}
136+
133137
private fun onNetworkChange(block: (Boolean) -> Unit) {
134138
NetworkUtils.getNetworkStatus(this)
135139
.observe(this, Observer { isConnected ->

app/src/main/kotlin/com/k0d4black/theforce/features/character_details/CharacterDetailViewModel.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.k0d4black.theforce.features.character_details
22

3+
import android.util.Log
34
import androidx.annotation.StringRes
4-
import androidx.lifecycle.*
5+
import androidx.lifecycle.LiveData
6+
import androidx.lifecycle.MutableLiveData
7+
import androidx.lifecycle.ViewModel
8+
import androidx.lifecycle.viewModelScope
59
import com.k0d4black.theforce.commons.ExceptionHandler
610
import com.k0d4black.theforce.domain.usecases.FilmsUseCase
711
import com.k0d4black.theforce.domain.usecases.PlanetUseCase
@@ -27,6 +31,7 @@ internal class CharacterDetailViewModel(
2731
private var _detailViewState = MutableLiveData<CharacterDetailsViewState>()
2832

2933
private val characterDetailExceptionHandler = CoroutineExceptionHandler { _, exception ->
34+
Log.d("Character Detail VM", "$exception")
3035
val message = ExceptionHandler.parse(exception)
3136
_detailViewState.value = _detailViewState.value?.copy(error = Error(message))
3237
}
@@ -47,14 +52,10 @@ internal class CharacterDetailViewModel(
4752
_detailViewState.value = _detailViewState.value?.copy(error = null)
4853
}
4954
viewModelScope.launch(characterDetailExceptionHandler) {
50-
val planetRequest = async { loadPlanet(characterUrl) }
51-
val filmsRequest = async { loadFilms(characterUrl) }
52-
val speciesRequest = async { loadSpecies(characterUrl) }
53-
planetRequest.await()
54-
filmsRequest.await()
55-
speciesRequest.await()
55+
async { loadPlanet(characterUrl) }.await()
56+
async { loadFilms(characterUrl) }.await()
57+
async { loadSpecies(characterUrl) }.await()
5658
_detailViewState.value = _detailViewState.value?.copy(isComplete = true)
57-
5859
}
5960
}
6061

app/src/main/kotlin/com/k0d4black/theforce/features/character_search/CharacterSearchViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.k0d4black.theforce.features.character_search
22

3+
import android.util.Log
34
import androidx.annotation.StringRes
45
import androidx.lifecycle.*
56
import com.k0d4black.theforce.commons.ExceptionHandler

app/src/main/kotlin/com/k0d4black/theforce/mappers/DomainToPresentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fun Character.toPresentation(): CharacterPresentation {
2222
}
2323

2424
fun Planet.toPresentation(): PlanetPresentation {
25-
val populationAsLong = if (this.population.contains("Unknown")) 0L else this.population.toLong()
25+
val populationAsLong = if (this.population.contains("unknown")) 0L else this.population.toLong()
2626
return PlanetPresentation(this.name, populationAsLong)
2727
}
2828

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
3+
Copyright David Odari
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
in compliance with the License. You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software distributed under the License
9+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10+
or implied. See the License for the specific language governing permissions and limitations under
11+
the License.
12+
13+
-->
14+
<network-security-config>
15+
<domain-config cleartextTrafficPermitted="true">
16+
<domain includeSubdomains="true">swapi.dev</domain>
17+
</domain-config>
18+
<domain-config cleartextTrafficPermitted="true">
19+
<domain includeSubdomains="true">localhost</domain>
20+
</domain-config>
21+
</network-security-config>

dependencies.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ext {
66
buildToolsVersion = "29.0.2"
77

88
//App Versioning
9-
versionCodeMajor = 1
10-
versionCodeMinor = 3
9+
versionCodeMajor = 2
10+
versionCodeMinor = 0
1111
versionCodePatch = 0
1212
versionName = "$versionCodeMajor.$versionCodeMinor.$versionCodePatch"
1313

0 commit comments

Comments
 (0)