Implement Glide image preload in RecyclerView
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package gq.kirmanak.mealient.di
|
||||
|
||||
import com.bumptech.glide.load.model.ModelLoaderFactory
|
||||
import dagger.hilt.EntryPoint
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import gq.kirmanak.mealient.data.recipes.db.entity.RecipeSummaryEntity
|
||||
import okhttp3.OkHttpClient
|
||||
import java.io.InputStream
|
||||
import javax.inject.Named
|
||||
|
||||
@EntryPoint
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface GlideModuleEntryPoint {
|
||||
|
||||
@Named(AUTH_OK_HTTP)
|
||||
fun provideOkHttp(): OkHttpClient
|
||||
|
||||
fun provideRecipeLoaderFactory(): ModelLoaderFactory<RecipeSummaryEntity, InputStream>
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package gq.kirmanak.mealient.di
|
||||
|
||||
import androidx.paging.InvalidatingPagingSourceFactory
|
||||
import com.bumptech.glide.load.model.ModelLoaderFactory
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import gq.kirmanak.mealient.R
|
||||
import gq.kirmanak.mealient.data.baseurl.BaseURLStorage
|
||||
import gq.kirmanak.mealient.data.network.RetrofitBuilder
|
||||
import gq.kirmanak.mealient.data.network.ServiceFactory
|
||||
@@ -13,12 +16,17 @@ import gq.kirmanak.mealient.data.network.createServiceFactory
|
||||
import gq.kirmanak.mealient.data.recipes.RecipeRepo
|
||||
import gq.kirmanak.mealient.data.recipes.db.RecipeStorage
|
||||
import gq.kirmanak.mealient.data.recipes.db.RecipeStorageImpl
|
||||
import gq.kirmanak.mealient.data.recipes.db.entity.RecipeSummaryEntity
|
||||
import gq.kirmanak.mealient.data.recipes.impl.RecipeImageUrlProvider
|
||||
import gq.kirmanak.mealient.data.recipes.impl.RecipeImageUrlProviderImpl
|
||||
import gq.kirmanak.mealient.data.recipes.impl.RecipeRepoImpl
|
||||
import gq.kirmanak.mealient.data.recipes.network.RecipeDataSource
|
||||
import gq.kirmanak.mealient.data.recipes.network.RecipeDataSourceImpl
|
||||
import gq.kirmanak.mealient.data.recipes.network.RecipeService
|
||||
import gq.kirmanak.mealient.ui.recipes.images.RecipeModelLoaderFactory
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.OkHttpClient
|
||||
import java.io.InputStream
|
||||
import javax.inject.Named
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -38,6 +46,14 @@ interface RecipeModule {
|
||||
@Singleton
|
||||
fun provideRecipeRepo(recipeRepoImpl: RecipeRepoImpl): RecipeRepo
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindImageUrlProvider(recipeImageUrlProviderImpl: RecipeImageUrlProviderImpl): RecipeImageUrlProvider
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindModelLoaderFactory(recipeModelLoaderFactory: RecipeModelLoaderFactory): ModelLoaderFactory<RecipeSummaryEntity, InputStream>
|
||||
|
||||
companion object {
|
||||
|
||||
@Provides
|
||||
@@ -55,5 +71,10 @@ interface RecipeModule {
|
||||
fun provideRecipePagingSourceFactory(
|
||||
recipeStorage: RecipeStorage
|
||||
) = InvalidatingPagingSourceFactory { recipeStorage.queryRecipes() }
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGlideRequestOptions(): RequestOptions = RequestOptions.centerCropTransform()
|
||||
.placeholder(R.drawable.placeholder_recipe)
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@ import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.FragmentComponent
|
||||
import dagger.hilt.android.scopes.FragmentScoped
|
||||
import gq.kirmanak.mealient.data.recipes.impl.RecipeImageLoaderImpl
|
||||
import gq.kirmanak.mealient.ui.images.ImageLoader
|
||||
import gq.kirmanak.mealient.ui.images.ImageLoaderGlide
|
||||
import gq.kirmanak.mealient.ui.recipes.RecipeImageLoader
|
||||
import gq.kirmanak.mealient.ui.recipes.images.RecipeImageLoader
|
||||
import gq.kirmanak.mealient.ui.recipes.images.RecipeImageLoaderImpl
|
||||
import gq.kirmanak.mealient.ui.recipes.images.RecipePreloaderFactory
|
||||
import gq.kirmanak.mealient.ui.recipes.images.RecipePreloaderFactoryImpl
|
||||
|
||||
@Module
|
||||
@InstallIn(FragmentComponent::class)
|
||||
@@ -16,10 +16,10 @@ interface UiModule {
|
||||
|
||||
@Binds
|
||||
@FragmentScoped
|
||||
fun bindImageLoader(imageLoaderGlide: ImageLoaderGlide): ImageLoader
|
||||
fun provideRecipeImageLoader(recipeImageLoaderImpl: RecipeImageLoaderImpl): RecipeImageLoader
|
||||
|
||||
@Binds
|
||||
@FragmentScoped
|
||||
fun provideRecipeImageLoader(recipeImageLoaderImpl: RecipeImageLoaderImpl): RecipeImageLoader
|
||||
fun bindRecipePreloaderFactory(recipePreloaderFactoryImpl: RecipePreloaderFactoryImpl): RecipePreloaderFactory
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user