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