Extract RecipeImageLoader interface

This commit is contained in:
Kirill Kamakin
2021-11-13 09:52:01 +03:00
parent c22c544297
commit c081edbbbf
3 changed files with 25 additions and 15 deletions

View File

@@ -1,20 +1,7 @@
package gq.kirmanak.mealie.data.recipes
import android.widget.ImageView
import gq.kirmanak.mealie.R
import gq.kirmanak.mealie.data.auth.AuthRepo
import gq.kirmanak.mealie.ui.ImageLoader
import javax.inject.Inject
class RecipeImageLoader @Inject constructor(
private val imageLoader: ImageLoader,
private val authRepo: AuthRepo
) {
suspend fun loadRecipeImage(view: ImageView, slug: String?) {
val baseUrl = authRepo.getBaseUrl()
val recipeImageUrl =
if (baseUrl.isNullOrBlank()) null
else "$baseUrl/api/media/recipes/$slug/images/original.webp"
imageLoader.loadImage(recipeImageUrl, R.drawable.placeholder_recipe, view)
}
interface RecipeImageLoader {
suspend fun loadRecipeImage(view: ImageView, slug: String?)
}

View File

@@ -0,0 +1,20 @@
package gq.kirmanak.mealie.data.recipes
import android.widget.ImageView
import gq.kirmanak.mealie.R
import gq.kirmanak.mealie.data.auth.AuthRepo
import gq.kirmanak.mealie.ui.ImageLoader
import javax.inject.Inject
class RecipeImageLoaderImpl @Inject constructor(
private val imageLoader: ImageLoader,
private val authRepo: AuthRepo
): RecipeImageLoader {
override suspend fun loadRecipeImage(view: ImageView, slug: String?) {
val baseUrl = authRepo.getBaseUrl()
val recipeImageUrl =
if (baseUrl.isNullOrBlank()) null
else "$baseUrl/api/media/recipes/$slug/images/original.webp"
imageLoader.loadImage(recipeImageUrl, R.drawable.placeholder_recipe, view)
}
}

View File

@@ -24,4 +24,7 @@ interface RecipeModule {
@Binds
fun provideRecipeRepo(recipeRepoImpl: RecipeRepoImpl): RecipeRepo
@Binds
fun provideRecipeImageLoader(recipeImageLoaderImpl: RecipeImageLoaderImpl): RecipeImageLoader
}