-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(di): Add new di ImageModule for the Coil + use in UI
- Loading branch information
1 parent
4d3281a
commit c017325
Showing
3 changed files
with
56 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.mooncascade.di | ||
|
||
import android.content.Context | ||
import coil.ImageLoader | ||
import com.mooncascade.R | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.OkHttpClient | ||
import javax.inject.Singleton | ||
|
||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ImageModule { | ||
|
||
/** | ||
* provides [ImageLoader] to use in application | ||
* @param context: [ApplicationContext] | ||
* @param okHttpClient: [OkHttpClient] in [NetworkModule] | ||
*/ | ||
@Provides | ||
@Singleton | ||
fun provideImageLoader( | ||
okHttpClient: OkHttpClient, | ||
@ApplicationContext context: Context, | ||
): ImageLoader = | ||
ImageLoader.Builder(context) | ||
.okHttpClient { okHttpClient } | ||
.crossfade(true) | ||
.placeholder(R.drawable.ic_placeholder) | ||
.error(R.drawable.ic_placeholder) | ||
//.diskCache(DiskCache.Builder().build()) | ||
.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
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