This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module(includes = [InterceptorModule::class]) | |
class NetworkModule { | |
@Provides | |
@ApplicationScope | |
fun provideTreasureApi(retrofit: Retrofit): TreasureApi = retrofit.create(TreasureApi::class.java) | |
@Provides | |
@ApplicationScope | |
fun provideRetrofit(client: OkHttpClient): Retrofit = Retrofit.Builder() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Scope | |
@Retention(AnnotationRetention.RUNTIME) | |
annotation class ApplicationScope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class InterceptorModule { | |
@Provides | |
@ApplicationScope | |
fun provideOkHttpClient(interceptor: HttpLoggingInterceptor): OkHttpClient { | |
return OkHttpClient.Builder() | |
.addInterceptor(interceptor) | |
.build() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationScope | |
@Component(modules = [NetworkModule::class, SchedulersModule::class]) | |
interface PocketTreasureComponent { | |
fun getTreasureApi(): TreasureApi | |
fun getSchedulers(): CoroutineDispatcher | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PocketTreasureApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PocketTreasureApplication : Application() { | |
private lateinit var pocketTreasureComponent: PocketTreasureComponent | |
override fun onCreate() { | |
super.onCreate() | |
pocketTreasureComponent = DaggerPocketTreasureComponent.builder().build() | |
} | |
fun getPocketTreasureComponent() = pocketTreasureComponent | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Scope | |
@Retention(AnnotationRetention.RUNTIME) | |
annotation class FragmentScope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class NamesFragmentModule(private val context: Context) { | |
@Provides | |
@FragmentScope | |
fun provideNamesFragmentContext(): Context = context | |
@Provides | |
@FragmentScope | |
fun provideViewModelFactory( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FragmentScope | |
@Component(modules = [NamesFragmentModule::class], dependencies = [PocketTreasureComponent::class]) | |
interface NamesFragmentComponent { | |
fun inject(namesFragment: NamesFragment) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NamesViewModelProviderFactory( | |
private val repository: NamesRepository, | |
private val coroutineDispatcher: CoroutineDispatcher | |
) : ViewModelProvider.Factory { | |
override fun <T : ViewModel?> create(modelClass: Class<T>): T = NamesViewModel(repository, coroutineDispatcher) as T | |
} |
OlderNewer