@@ -23,6 +23,8 @@ import android.widget.TextView
2323import androidx.annotation.DrawableRes
2424import androidx.core.content.ContextCompat
2525import androidx.fragment.app.FragmentActivity
26+ import com.bumptech.glide.Glide
27+ import com.bumptech.glide.RequestBuilder
2628import com.bumptech.glide.load.DataSource
2729import com.bumptech.glide.load.engine.GlideException
2830import com.bumptech.glide.load.resource.bitmap.CenterCrop
@@ -38,8 +40,6 @@ import com.bumptech.glide.request.transition.Transition
3840import com.bumptech.glide.signature.ObjectKey
3941import kotlinx.coroutines.CoroutineScope
4042import org.wordpress.android.WordPress
41- import org.wordpress.android.modules.GlideApp
42- import org.wordpress.android.modules.GlideRequest
4343import org.wordpress.android.networking.MShot
4444import org.wordpress.android.ui.media.VideoLoader
4545import org.wordpress.android.util.AppLog
@@ -107,7 +107,7 @@ class ImageManager @Inject constructor(
107107 fun load (imageView : ImageView , imageType : ImageType , imgUrl : String = "", scaleType : ScaleType = CENTER ) {
108108 val context = imageView.context
109109 if (! context.isAvailable()) return
110- GlideApp .with (context)
110+ Glide .with (context)
111111 .load(imgUrl)
112112 .addFallback(imageType)
113113 .addPlaceholder(imageType)
@@ -137,7 +137,7 @@ class ImageManager @Inject constructor(
137137 videoUrl,
138138 loadAction = {
139139 if (! context.isAvailable()) return @runIfMediaNotTooBig
140- GlideApp .with (context)
140+ Glide .with (context)
141141 .load(videoUrl)
142142 .addFallback(imageType)
143143 .addPlaceholder(imageType)
@@ -152,7 +152,7 @@ class ImageManager @Inject constructor(
152152 val fallbackDrawable = placeholderManager.getErrorResource(imageType)?.let {
153153 ColorDrawable (ContextCompat .getColor(context, it))
154154 }
155- GlideApp .with (context)
155+ Glide .with (context)
156156 .load(fallbackDrawable)
157157 .addPlaceholder(imageType)
158158 .addFallback(imageType)
@@ -178,7 +178,7 @@ class ImageManager @Inject constructor(
178178 height : Int? = null
179179 ) {
180180 if (! context.isAvailable()) return
181- GlideApp .with (context)
181+ Glide .with (context)
182182 .asBitmap()
183183 .load(imgUrl)
184184 .addFallback(imageType)
@@ -202,7 +202,7 @@ class ImageManager @Inject constructor(
202202 ) {
203203 val context = imageView.context
204204 if (! context.isAvailable()) return
205- GlideApp .with (context)
205+ Glide .with (context)
206206 .load(imgUrl)
207207 .addFallback(imageType)
208208 .addPlaceholder(imageType)
@@ -236,7 +236,7 @@ class ImageManager @Inject constructor(
236236 return
237237 }
238238
239- GlideApp .with (context)
239+ Glide .with (context)
240240 .load(imageData)
241241 .addFallback(imageType)
242242 .addPlaceholder(imageType)
@@ -262,7 +262,7 @@ class ImageManager @Inject constructor(
262262 val context = imageView.context
263263 if (! context.isAvailable()) return
264264
265- GlideApp .with (context)
265+ Glide .with (context)
266266 .load(imgUrl)
267267 .transform(CenterCrop (), RoundedCorners (cornerRadius))
268268 .addFallback(imageType)
@@ -290,7 +290,7 @@ class ImageManager @Inject constructor(
290290 ) {
291291 val context = imageView.context
292292 if (! context.isAvailable()) return
293- GlideApp .with (context)
293+ Glide .with (context)
294294 .load(Uri .parse(imgUrl))
295295 .addFallback(imageType)
296296 .addPlaceholder(imageType)
@@ -310,7 +310,7 @@ class ImageManager @Inject constructor(
310310 fun preload (context : Context , design : MShot ) {
311311 if (! context.isAvailable()) return
312312 try {
313- GlideApp .with (context)
313+ Glide .with (context)
314314 .downloadOnly()
315315 .load(design)
316316 .submit()
@@ -330,7 +330,7 @@ class ImageManager @Inject constructor(
330330 fun loadWithResultListener (view : ImageView , design : MShot , requestListener : RequestListener <Drawable >) {
331331 val context = view.context
332332 if (! context.isAvailable()) return
333- GlideApp .with (context)
333+ Glide .with (context)
334334 .load(design)
335335 .addFallback(ImageType .THEME )
336336 .addPlaceholder(ImageType .THEME )
@@ -360,7 +360,7 @@ class ImageManager @Inject constructor(
360360 ) {
361361 val context = imageView.context
362362 if (! context.isAvailable()) return
363- GlideApp .with (context)
363+ Glide .with (context)
364364 .load(imgUri)
365365 .addFallback(imageType)
366366 .addPlaceholder(imageType)
@@ -384,7 +384,7 @@ class ImageManager @Inject constructor(
384384 ) {
385385 val context = WordPress .getContext()
386386 if (! context.isAvailable()) return
387- GlideApp .with (context)
387+ Glide .with (context)
388388 .asFile()
389389 .load(imgUri)
390390 .attachRequestListener(requestListener)
@@ -404,7 +404,7 @@ class ImageManager @Inject constructor(
404404 fun load (imageView : ImageView , bitmap : Bitmap , scaleType : ScaleType = CENTER ) {
405405 val context = imageView.context
406406 if (! context.isAvailable()) return
407- GlideApp .with (context)
407+ Glide .with (context)
408408 .load(bitmap)
409409 .applyScaleType(scaleType)
410410 .into(imageView)
@@ -418,7 +418,7 @@ class ImageManager @Inject constructor(
418418 fun load (imageView : ImageView , drawable : Drawable , scaleType : ScaleType = CENTER ) {
419419 val context = imageView.context
420420 if (! context.isAvailable()) return
421- GlideApp .with (context)
421+ Glide .with (context)
422422 .load(drawable)
423423 .applyScaleType(scaleType)
424424 .into(imageView)
@@ -432,7 +432,7 @@ class ImageManager @Inject constructor(
432432 fun load (imageView : ImageView , @DrawableRes resourceId : Int , scaleType : ScaleType = CENTER ) {
433433 val context = imageView.context
434434 if (! context.isAvailable()) return
435- GlideApp .with (context)
435+ Glide .with (context)
436436 .load(ContextCompat .getDrawable(context, resourceId))
437437 .applyScaleType(scaleType)
438438 .into(imageView)
@@ -450,7 +450,7 @@ class ImageManager @Inject constructor(
450450 fun loadIntoCustomTarget (viewTarget : ViewTarget <TextView , Drawable >, imageType : ImageType , imgUrl : String ) {
451451 val context = WordPress .getContext()
452452 if (! context.isAvailable()) return
453- GlideApp .with (context)
453+ Glide .with (context)
454454 .load(imgUrl)
455455 .addFallback(imageType)
456456 .addPlaceholder(imageType)
@@ -472,7 +472,7 @@ class ImageManager @Inject constructor(
472472 scaleType : ScaleType = CENTER
473473 ) {
474474 if (! context.isAvailable()) return
475- GlideApp .with (context)
475+ Glide .with (context)
476476 .asBitmap()
477477 .load(imgUrl)
478478 .applyScaleType(scaleType)
@@ -488,7 +488,7 @@ class ImageManager @Inject constructor(
488488 if (context is Activity && (context.isFinishing || context.isDestroyed)) {
489489 return
490490 }
491- GlideApp .with (imageView.context).clear(imageView)
491+ Glide .with (imageView.context).clear(imageView)
492492 }
493493
494494 /* *
@@ -497,12 +497,12 @@ class ImageManager @Inject constructor(
497497 */
498498 @Suppress(" DEPRECATION" )
499499 fun <T : Any > cancelRequest (context : Context , target : BaseTarget <T >? ) {
500- GlideApp .with (context).clear(target)
500+ Glide .with (context).clear(target)
501501 }
502502
503- private fun <T : Any > GlideRequest <T>.applyScaleType (
503+ private fun <T : Any > RequestBuilder <T>.applyScaleType (
504504 scaleType : ScaleType
505- ): GlideRequest <T > {
505+ ): RequestBuilder <T > {
506506 return when (scaleType) {
507507 ScaleType .CENTER_CROP -> this .centerCrop()
508508 ScaleType .CENTER_INSIDE -> this .centerInside()
@@ -521,15 +521,15 @@ class ImageManager @Inject constructor(
521521 }
522522 }
523523
524- private fun <T : Any > GlideRequest <T>.applySize (width : Int? , height : Int? ): GlideRequest <T > {
524+ private fun <T : Any > RequestBuilder <T>.applySize (width : Int? , height : Int? ): RequestBuilder <T > {
525525 return if (width != null && height != null ) {
526526 this .override (width, height)
527527 } else {
528528 this
529529 }
530530 }
531531
532- private fun <T : Any > GlideRequest <T>.addPlaceholder (imageType : ImageType ): GlideRequest <T > {
532+ private fun <T : Any > RequestBuilder <T>.addPlaceholder (imageType : ImageType ): RequestBuilder <T > {
533533 val placeholderImageRes = placeholderManager.getPlaceholderResource(imageType)
534534 return if (placeholderImageRes == null ) {
535535 this
@@ -538,7 +538,7 @@ class ImageManager @Inject constructor(
538538 }
539539 }
540540
541- private fun <T : Any > GlideRequest <T>.addFallback (imageType : ImageType ): GlideRequest <T > {
541+ private fun <T : Any > RequestBuilder <T>.addFallback (imageType : ImageType ): RequestBuilder <T > {
542542 val errorImageRes = placeholderManager.getErrorResource(imageType)
543543 return if (errorImageRes == null ) {
544544 this
@@ -550,23 +550,23 @@ class ImageManager @Inject constructor(
550550 /* *
551551 * Changing the signature invalidates cache.
552552 */
553- private fun <T : Any > GlideRequest <T>.addSignature (signature : Int? ): GlideRequest <T > {
553+ private fun <T : Any > RequestBuilder <T>.addSignature (signature : Int? ): RequestBuilder <T > {
554554 return if (signature == null ) {
555555 this
556556 } else {
557557 this .signature(ObjectKey (signature))
558558 }
559559 }
560560
561- private fun GlideRequest <Drawable>.addThumbnail (
561+ private fun RequestBuilder <Drawable>.addThumbnail (
562562 context : Context ,
563563 thumbnailUrl : String? ,
564564 listener : RequestListener <Drawable >
565- ): GlideRequest <Drawable > {
565+ ): RequestBuilder <Drawable > {
566566 return if (TextUtils .isEmpty(thumbnailUrl)) {
567567 this
568568 } else {
569- val thumbnailRequest = GlideApp
569+ val thumbnailRequest = Glide
570570 .with (context)
571571 .load(thumbnailUrl)
572572 .downsample(DownsampleStrategy .AT_MOST )
@@ -575,40 +575,34 @@ class ImageManager @Inject constructor(
575575 }
576576 }
577577
578- private fun <T : Any > GlideRequest <T>.attachRequestListener (
578+ private fun <T : Any > RequestBuilder <T>.attachRequestListener (
579579 requestListener : RequestListener <T >?
580- ): GlideRequest <T > {
580+ ): RequestBuilder <T > {
581581 return if (requestListener == null ) {
582582 this
583583 } else {
584584 this .listener(object : com.bumptech.glide.request.RequestListener <T > {
585585 override fun onLoadFailed (
586586 e : GlideException ? ,
587587 model : Any? ,
588- target : Target <T >? ,
588+ target : Target <T >,
589589 isFirstResource : Boolean
590590 ): Boolean {
591591 requestListener.onLoadFailed(e, model)
592592 return false
593593 }
594594
595595 override fun onResourceReady (
596- resource : T ? ,
597- model : Any? ,
596+ resource : T ,
597+ model : Any ,
598598 target : Target <T >? ,
599- dataSource : DataSource ? ,
599+ dataSource : DataSource ,
600600 isFirstResource : Boolean
601601 ): Boolean {
602- if (resource != null ) {
603- requestListener.onResourceReady(resource, model)
604- } else {
605- // according to the Glide's JavaDoc, this shouldn't happen
606- AppLog .e(AppLog .T .UTILS , " Resource in ImageManager.onResourceReady is null." )
607- requestListener.onLoadFailed(null , model)
608- }
602+ requestListener.onResourceReady(resource, model)
609603 return false
610604 }
611- })
605+ })
612606 }
613607 }
614608
0 commit comments