Skip to content

Commit

Permalink
Merge pull request #93 from odaridavid/bug-fix-ioexception
Browse files Browse the repository at this point in the history
Fix known exceptions
  • Loading branch information
odaridavid committed May 31, 2020
2 parents 2e63e55 + 312c1d9 commit dfdf616
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 65 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ 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"
]
}
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
}
Expand Down
42 changes: 0 additions & 42 deletions app/src/debug/AndroidManifest.xml

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<activity
android:name=".features.settings.AboutActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,6 +31,7 @@ internal class CharacterDetailViewModel(
private var _detailViewState = MutableLiveData<CharacterDetailsViewState>()

private val characterDetailExceptionHandler = CoroutineExceptionHandler { _, exception ->
Log.d("Character Detail VM", "$exception")
val message = ExceptionHandler.parse(exception)
_detailViewState.value = _detailViewState.value?.copy(error = Error(message))
}
Expand All @@ -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)

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.k0d4black.theforce.features.character_search

import android.util.Log
import androidx.annotation.StringRes
import androidx.lifecycle.*
import com.k0d4black.theforce.commons.ExceptionHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 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.
-->
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">swapi.dev</domain>
</domain-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit dfdf616

Please sign in to comment.