|
|
@@ -4,7 +4,9 @@ import android.content.Context
|
|
|
import android.graphics.ColorMatrix
|
|
|
import android.graphics.ColorMatrixColorFilter
|
|
|
import android.graphics.drawable.Drawable
|
|
|
+import android.util.TypedValue
|
|
|
import android.widget.ImageView
|
|
|
+import androidx.annotation.AttrRes
|
|
|
import com.bumptech.glide.Glide
|
|
|
import com.bumptech.glide.load.DataSource
|
|
|
import com.bumptech.glide.load.engine.GlideException
|
|
|
@@ -16,23 +18,31 @@ import com.sirekanyan.knigopis.R
|
|
|
|
|
|
private const val DARK_SATURATION = 0.33f
|
|
|
|
|
|
-private fun ImageView.setImage(url: String?, requestOptions: RequestOptions, placeholder: Int) {
|
|
|
+private fun ImageView.setImage(
|
|
|
+ url: String?,
|
|
|
+ requestOptions: RequestOptions,
|
|
|
+ @AttrRes placeholderAttr: Int
|
|
|
+) {
|
|
|
if (isDarkTheme) {
|
|
|
val colorMatrix = ColorMatrix().apply { setSaturation(DARK_SATURATION) }
|
|
|
colorFilter = ColorMatrixColorFilter(colorMatrix)
|
|
|
}
|
|
|
+ val placeholder = TypedValue().let { typedValue ->
|
|
|
+ context.theme.resolveAttribute(placeholderAttr, typedValue, false)
|
|
|
+ typedValue.data
|
|
|
+ }
|
|
|
Glide.with(context)
|
|
|
.load(url)
|
|
|
- .apply(requestOptions.placeholder(placeholder).theme(context.theme))
|
|
|
+ .apply(requestOptions.placeholder(placeholder))
|
|
|
.transition(DrawableTransitionOptions.withCrossFade())
|
|
|
.into(this)
|
|
|
}
|
|
|
|
|
|
-fun ImageView.setCircleImage(url: String?, placeholder: Int? = null) {
|
|
|
+fun ImageView.setCircleImage(url: String?, @AttrRes placeholder: Int? = null) {
|
|
|
setImage(
|
|
|
url,
|
|
|
RequestOptions.circleCropTransform(),
|
|
|
- placeholder ?: R.drawable.oval_placeholder_background
|
|
|
+ placeholder ?: R.attr.oval_placeholder_drawable
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -40,7 +50,7 @@ fun ImageView.setSquareImage(url: String?) {
|
|
|
setImage(
|
|
|
url,
|
|
|
RequestOptions.centerCropTransform(),
|
|
|
- R.drawable.rectangle_placeholder_background
|
|
|
+ R.attr.rectangle_placeholder_drawable
|
|
|
)
|
|
|
}
|
|
|
|