Extract RecipeImageLoader interface
This commit is contained in:
@@ -1,20 +1,7 @@
|
|||||||
package gq.kirmanak.mealie.data.recipes
|
package gq.kirmanak.mealie.data.recipes
|
||||||
|
|
||||||
import android.widget.ImageView
|
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(
|
interface RecipeImageLoader {
|
||||||
private val imageLoader: ImageLoader,
|
suspend fun loadRecipeImage(view: ImageView, slug: String?)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,4 +24,7 @@ interface RecipeModule {
|
|||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
fun provideRecipeRepo(recipeRepoImpl: RecipeRepoImpl): RecipeRepo
|
fun provideRecipeRepo(recipeRepoImpl: RecipeRepoImpl): RecipeRepo
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
fun provideRecipeImageLoader(recipeImageLoaderImpl: RecipeImageLoaderImpl): RecipeImageLoader
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user