Skip to content

Commit

Permalink
Code review [#25] P1 - Retrofit creator.
Browse files Browse the repository at this point in the history
  • Loading branch information
E-D-W-I-N committed May 16, 2021
1 parent ac39fa0 commit 8660717
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ dependencies {
// Koin
implementation "io.insert-koin:koin-android:$koin_version"

// Retrofit + GSON
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

// Location
implementation "com.google.android.gms:play-services-location:$playServicesLocation_version"

Expand Down
19 changes: 8 additions & 11 deletions app/src/main/java/com/edwin/weatherapp/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.edwin.weatherapp.di
import android.location.Geocoder
import com.edwin.data.device.GetLocationDataSource
import com.edwin.data.network.GeocoderDataSource
import com.edwin.data.network.WeatherApiDataSource
import com.edwin.data.network.RetrofitClient
import com.edwin.data.repository.WeatherRepositoryImpl
import com.edwin.domain.WeatherRepository
import com.edwin.domain.usecase.GetAddressFromGeocoderUseCase
Expand All @@ -15,17 +15,8 @@ import com.google.android.gms.location.LocationServices
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

val dataModule = module {
// Retrofit API
single {
Retrofit.Builder()
.baseUrl("https://api.openweathermap.org/data/2.5/")
.addConverterFactory(GsonConverterFactory.create())
.build().create(WeatherApiDataSource::class.java)
}

// FusedLocationProvider
single { LocationServices.getFusedLocationProviderClient(androidContext()) }
Expand All @@ -40,7 +31,13 @@ val dataModule = module {
single { GeocoderDataSource(get()) }

// WeatherRepository
single<WeatherRepository> { WeatherRepositoryImpl(get(), get(), get()) }
single<WeatherRepository> {
WeatherRepositoryImpl(
RetrofitClient.weatherDataSource,
get(),
get()
)
}
}

val useCaseModule = module {
Expand Down
20 changes: 20 additions & 0 deletions data/src/main/java/com/edwin/data/network/RetrofitClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.edwin.data.network

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitClient {

private const val BASE_URL = "https://api.openweathermap.org/data/2.5/"

private val retrofit: Retrofit by lazy {
Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build()
}

val weatherDataSource: WeatherApiDataSource by lazy {
retrofit.create(WeatherApiDataSource::class.java)
}
}

0 comments on commit 8660717

Please sign in to comment.