Skip to content

Commit c670d96

Browse files
author
Sergi Llamas
committedMay 10, 2020
Update gradle and refactor
1 parent 38dfbc8 commit c670d96

File tree

9 files changed

+27
-56
lines changed

9 files changed

+27
-56
lines changed
 

‎.idea/gradle.xml

-19
This file was deleted.

‎.idea/misc.xml

-15
This file was deleted.

‎app/build.gradle

+11-9
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ dependencies {
3535
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
3636
implementation 'androidx.appcompat:appcompat:1.1.0'
3737
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
38-
implementation 'androidx.core:core-ktx:1.1.0'
39-
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
38+
implementation 'androidx.core:core-ktx:1.2.0'
39+
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
4040
implementation 'androidx.recyclerview:recyclerview:1.1.0'
41-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1'
42-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'
43-
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
44-
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
41+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'
42+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
43+
implementation 'com.squareup.retrofit2:retrofit:2.8.0'
44+
implementation 'com.squareup.retrofit2:converter-gson:2.8.0'
4545
implementation 'com.github.bumptech.glide:glide:4.10.0'
46+
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
47+
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
48+
4649
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
47-
testImplementation 'junit:junit:4.12'
50+
51+
testImplementation 'junit:junit:4.13'
4852
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
4953
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
50-
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
51-
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
5254
}

‎app/src/main/java/com/slg/pokeonary/data/repository/common/ServiceResultWrapper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ suspend fun <T : Any> safeApiCall(call: suspend () -> T): ServiceResultWrapper<T
1111
ServiceResultWrapper.Success(call())
1212
} catch (e: Exception) {
1313
ServiceResultWrapper.Error(e)
14-
}
14+
}

‎app/src/main/java/com/slg/pokeonary/mobile/pokemonDetail/PokemonDetailFragment.kt

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
7-
import android.widget.Toast
87
import androidx.fragment.app.Fragment
98
import androidx.navigation.fragment.navArgs
109
import com.slg.pokeonary.R

‎app/src/main/java/com/slg/pokeonary/mobile/pokemonList/PokemonListFragment.kt

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import android.view.ViewGroup
77
import androidx.core.content.ContextCompat
88
import androidx.fragment.app.Fragment
99
import androidx.lifecycle.Observer
10-
import androidx.lifecycle.ViewModelProviders
10+
import androidx.lifecycle.ViewModelProvider
1111
import androidx.navigation.NavController
1212
import androidx.navigation.findNavController
1313
import androidx.recyclerview.widget.DividerItemDecoration
@@ -36,17 +36,17 @@ class PokemonListFragment : Fragment() {
3636

3737
navController = view.findNavController()
3838

39-
viewModel = ViewModelProviders.of(
39+
viewModel = ViewModelProvider(
4040
this,
41-
PokemonListViewModel.PokemonListViewModelFactory(activity!!.application)
41+
PokemonListViewModel.PokemonListViewModelFactory(requireActivity().application)
4242
)[PokemonListViewModel::class.java]
4343

4444
pokemonsAdapter = PokemonsAdapter(viewModel::onPokemonClicked)
4545

4646
initializeRecyclerView()
4747

48-
viewModel.model.observe(this, Observer(::updateUi))
49-
viewModel.navigation.observe(this, Observer { event ->
48+
viewModel.model.observe(viewLifecycleOwner, Observer(::updateUi))
49+
viewModel.navigation.observe(viewLifecycleOwner, Observer { event ->
5050
event.getContentIfNotHandled()?.let { pokemon ->
5151
val action = PokemonListFragmentDirections
5252
.actionPokemonListFragmentToPokemonDetailFragment(pokemon)
@@ -57,7 +57,8 @@ class PokemonListFragment : Fragment() {
5757

5858
private fun initializeRecyclerView() {
5959
recyclerView.adapter = pokemonsAdapter
60-
val dividerDrawable = ContextCompat.getDrawable(context!!, R.drawable.recycler_view_divider)
60+
val dividerDrawable =
61+
ContextCompat.getDrawable(requireContext(), R.drawable.recycler_view_divider)
6162
recyclerView.addItemDecoration(
6263
DividerItemDecoration(
6364
context,

‎app/src/main/java/com/slg/pokeonary/mobile/pokemonList/PokemonListViewModel.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ class PokemonListViewModel(private val context: Context) : CoroutineScope, ViewM
4646
GetPokemonList(PokemonDataRepository(PokemonRemoteDataSource(context)))
4747
launch {
4848
_model.value = UiModel.Loading
49-
when (val pokemons = getPokemonListUseCase.buildAsync(GetPokemonListParams(START, COUNT))) {
50-
is ServiceResultWrapper.Success -> _model.value = pokemons.data?.transformToUi()?.let { UiModel.Content(it) }
49+
val pokemons = getPokemonListUseCase.buildAsync(GetPokemonListParams(START, COUNT))
50+
when (pokemons) {
51+
is ServiceResultWrapper.Success -> {
52+
_model.value = pokemons.data?.transformToUi()?.let { UiModel.Content(it) }
53+
}
5154
is ServiceResultWrapper.Error -> _model.value = UiModel.Content(listOf())
5255
}
5356
}

‎build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88

99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.5.3'
11+
classpath 'com.android.tools.build:gradle:3.6.3'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0"
1414

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sun Nov 17 10:49:14 CET 2019
1+
#Sun May 10 12:29:55 CEST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 commit comments

Comments
 (0)
Please sign in to comment.