Skip to content

Commit

Permalink
added dagger-hilt
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzcetinbas committed May 25, 2023
1 parent 2d63f81 commit c02ba01
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.fragment:fragment-ktx:1.5.6'
implementation 'androidx.fragment:fragment-ktx:1.5.7'

// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'

// okHttp
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.10.0")
implementation("com.squareup.okhttp3:okhttp:5.0.0-alpha.2")
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2")

// Gson
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.example.hw13_weatherapp.R
object Consts{

// Base Url tanımlandı
//const val BASE_URL = "https://api.open-meteo.com/"
const val BASE_URL = "https://api.open-meteo.com/"

// ViewType layoutları için sabit değişkenler tanımlandı
const val VIEW_TYPE_CURRENT_DAY = 0
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/example/hw13_weatherapp/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Environment
import androidx.room.Room
import com.example.hw13_weatherapp.constants.Consts
import com.example.hw13_weatherapp.db.WeatherPropertyDatabase
import com.example.hw13_weatherapp.model.api.WeatherApiService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -23,20 +24,23 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class AppModule {
object AppModule {

@Provides
@Singleton
fun provideRetrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl(provideBaseUrl())
.baseUrl(Consts.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(provideOkHttp())
.build()
}

@Provides
fun provideBaseUrl() = "https://api.open-meteo.com/"
@Singleton
fun provideWeatherApiService(retrofit: Retrofit): WeatherApiService {
return retrofit.create(WeatherApiService::class.java)
}

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.hw13_weatherapp.view.homeFragment
package com.example.hw13_weatherapp.di

import android.content.Context
import com.example.hw13_weatherapp.db.WeatherPropertyDao
Expand All @@ -16,12 +16,7 @@ import retrofit2.Retrofit

@Module
@InstallIn(ViewModelComponent::class)
class MainModule {

@Provides
fun provideWeatherApiService(retrofit: Retrofit): WeatherApiService {
return retrofit.create(WeatherApiService::class.java)
}
object MainModule {

@Provides
fun provideWeatherPropertyDao(database: WeatherPropertyDatabase): WeatherPropertyDao {
Expand All @@ -46,5 +41,4 @@ class MainModule {
): WeatherPropertyRepository {
return WeatherPropertyRepository(context,remoteDataSource,localDataSource)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MainActivity : AppCompatActivity() {
val view = binding.root
setContentView(view)
createNotificationChannel()

}

private val requestPermissionLauncher = registerForActivityResult(
Expand Down

0 comments on commit c02ba01

Please sign in to comment.