kopia lustrzana https://github.com/rt-bishop/Look4Sat
Added app-wide supervisor scope to CoroutinesModule.kt
rodzic
31fe18e4b5
commit
a15e789e70
|
@ -19,6 +19,7 @@
|
|||
|
||||
package com.rtbishop.look4sat.di
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.location.LocationManager
|
||||
|
@ -36,13 +37,19 @@ object ApplicationModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getLocationManager(@ApplicationContext context: Context): LocationManager {
|
||||
fun provideContentResolver(@ApplicationContext context: Context): ContentResolver {
|
||||
return context.contentResolver
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideLocationManager(@ApplicationContext context: Context): LocationManager {
|
||||
return context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
|
||||
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,24 +24,31 @@ import dagger.Provides
|
|||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import javax.inject.Qualifier
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object DispatchersModule {
|
||||
object CoroutinesModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideApplicationScope(): CoroutineScope = CoroutineScope(SupervisorJob())
|
||||
|
||||
@Provides
|
||||
@DefaultDispatcher
|
||||
fun getDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default
|
||||
fun provideDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default
|
||||
|
||||
@Provides
|
||||
@IoDispatcher
|
||||
fun getIoDispatcher(): CoroutineDispatcher = Dispatchers.IO
|
||||
fun provideIoDispatcher(): CoroutineDispatcher = Dispatchers.IO
|
||||
|
||||
@Provides
|
||||
@MainDispatcher
|
||||
fun getMainDispatcher(): CoroutineDispatcher = Dispatchers.Main
|
||||
fun provideMainDispatcher(): CoroutineDispatcher = Dispatchers.Main
|
||||
}
|
||||
|
||||
@Qualifier
|
|
@ -36,19 +36,19 @@ object NetworkModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getOkHttpClient(): OkHttpClient {
|
||||
fun provideOkHttpClient(): OkHttpClient {
|
||||
return OkHttpClient()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getMoshi(): Moshi {
|
||||
fun provideMoshi(): Moshi {
|
||||
return Moshi.Builder().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getTransmittersApi(): TransmittersApi {
|
||||
fun provideTransmittersApi(): TransmittersApi {
|
||||
return Retrofit.Builder()
|
||||
.baseUrl("https://db.satnogs.org/api/")
|
||||
.addConverterFactory(MoshiConverterFactory.create())
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package com.rtbishop.look4sat.di
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import com.rtbishop.look4sat.repository.localData.EntriesDao
|
||||
|
@ -41,31 +40,25 @@ object RepositoryModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getContentResolver(@ApplicationContext context: Context): ContentResolver {
|
||||
return context.contentResolver
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getEntriesDao(db: SatelliteDb): EntriesDao {
|
||||
fun provideEntriesDao(db: SatelliteDb): EntriesDao {
|
||||
return db.entriesDao()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getSourcesDao(db: SatelliteDb): SourcesDao {
|
||||
fun provideSourcesDao(db: SatelliteDb): SourcesDao {
|
||||
return db.sourcesDao()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getTransmittersDao(db: SatelliteDb): TransmittersDao {
|
||||
fun provideTransmittersDao(db: SatelliteDb): TransmittersDao {
|
||||
return db.transmittersDao()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
|
||||
fun provideSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
|
||||
RoomConverters.initialize(moshi)
|
||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb").build()
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue