From 465573c165a2043e6de2a0a0107a9500a40ea53a Mon Sep 17 00:00:00 2001 From: akshaaatt Date: Sun, 30 May 2021 01:16:36 +0530 Subject: [PATCH] Removed the unnecessary placeholder --- .../com/limerse/sliding/KotlinActivity.kt | 13 ++---- .../java/com/limerse/slider/ImageCarousel.kt | 13 ------ .../slider/adapter/FiniteCarouselAdapter.kt | 8 +--- .../slider/adapter/InfiniteCarouselAdapter.kt | 5 +-- .../com/limerse/slider/utils/Extensions.kt | 41 ------------------- .../drawable/carousel_default_placeholder.xml | 24 ----------- 6 files changed, 6 insertions(+), 98 deletions(-) delete mode 100644 slider/src/main/res/drawable/carousel_default_placeholder.xml diff --git a/app/src/main/java/com/limerse/sliding/KotlinActivity.kt b/app/src/main/java/com/limerse/sliding/KotlinActivity.kt index dbe65f8..34f1099 100644 --- a/app/src/main/java/com/limerse/sliding/KotlinActivity.kt +++ b/app/src/main/java/com/limerse/sliding/KotlinActivity.kt @@ -64,10 +64,6 @@ class KotlinActivity : AppCompatActivity() { imageScaleType = ImageView.ScaleType.CENTER_CROP carouselBackground = ColorDrawable(Color.parseColor("#333333")) - imagePlaceholder = ContextCompat.getDrawable( - this@KotlinActivity, - R.drawable.carousel_default_placeholder - ) carouselPadding = 0.dpToPx(context) carouselPaddingStart = 0.dpToPx(context) @@ -153,8 +149,7 @@ class KotlinActivity : AppCompatActivity() { currentBinding.imageView.apply { scaleType = imageScaleType - - setImage(item, R.drawable.ic_wb_cloudy_with_padding) + setImage(item) } } } @@ -197,7 +192,7 @@ class KotlinActivity : AppCompatActivity() { // carousel_default_placeholder is the default placeholder comes with // the library. - setImage(item, R.drawable.carousel_default_placeholder) + setImage(item) } } } @@ -282,7 +277,7 @@ class KotlinActivity : AppCompatActivity() { currentBinding.imageView.apply { scaleType = imageScaleType - setImage(item, R.drawable.ic_wb_cloudy_with_padding) + setImage(item) } } } @@ -333,7 +328,7 @@ class KotlinActivity : AppCompatActivity() { currentBinding.imageView.apply { scaleType = imageScaleType - setImage(item, R.drawable.ic_wb_cloudy_with_padding) + setImage(item) } currentBinding.tvRating.text = diff --git a/slider/src/main/java/com/limerse/slider/ImageCarousel.kt b/slider/src/main/java/com/limerse/slider/ImageCarousel.kt index ed6e433..445cb19 100644 --- a/slider/src/main/java/com/limerse/slider/ImageCarousel.kt +++ b/slider/src/main/java/com/limerse/slider/ImageCarousel.kt @@ -263,13 +263,6 @@ class ImageCarousel( recyclerView.background = carouselBackground } - var imagePlaceholder: Drawable? = null - set(value) { - field = value - - initAdapter() - } - @Dimension(unit = Dimension.PX) var carouselPadding: Int = 0 set(value) { @@ -628,10 +621,6 @@ class ImageCarousel( R.styleable.ImageCarousel_carouselBackground ) ?: ColorDrawable(Color.parseColor("#00000000")) - imagePlaceholder = getDrawable( - R.styleable.ImageCarousel_imagePlaceholder - ) ?: ContextCompat.getDrawable(context, R.drawable.carousel_default_placeholder) - carouselPadding = getDimension( R.styleable.ImageCarousel_carouselPadding, 0F @@ -740,7 +729,6 @@ class ImageCarousel( carouselGravity = carouselGravity, autoWidthFixing = autoWidthFixing, imageScaleType = imageScaleType, - imagePlaceholder = imagePlaceholder ).apply { listener = carouselListener } @@ -751,7 +739,6 @@ class ImageCarousel( carouselGravity = carouselGravity, autoWidthFixing = autoWidthFixing, imageScaleType = imageScaleType, - imagePlaceholder = imagePlaceholder ).apply { listener = carouselListener } diff --git a/slider/src/main/java/com/limerse/slider/adapter/FiniteCarouselAdapter.kt b/slider/src/main/java/com/limerse/slider/adapter/FiniteCarouselAdapter.kt index c4d2dc5..119727a 100644 --- a/slider/src/main/java/com/limerse/slider/adapter/FiniteCarouselAdapter.kt +++ b/slider/src/main/java/com/limerse/slider/adapter/FiniteCarouselAdapter.kt @@ -1,6 +1,5 @@ package com.limerse.slider.adapter -import android.graphics.drawable.Drawable import android.view.LayoutInflater import android.view.ViewGroup import android.view.ViewTreeObserver @@ -21,7 +20,6 @@ open class FiniteCarouselAdapter( private val carouselGravity: CarouselGravity, private val autoWidthFixing: Boolean, private val imageScaleType: ImageView.ScaleType, - private val imagePlaceholder: Drawable? ) : RecyclerView.Adapter() { var listener: CarouselListener? = null @@ -71,11 +69,7 @@ open class FiniteCarouselAdapter( if (holder.binding is ItemCarouselBinding) { holder.binding.img.scaleType = imageScaleType - if (imagePlaceholder != null) { - holder.binding.img.setImage(item, imagePlaceholder) - } else { - holder.binding.img.setImage(item) - } + holder.binding.img.setImage(item) listener?.apply { holder.itemView.setOnClickListener { diff --git a/slider/src/main/java/com/limerse/slider/adapter/InfiniteCarouselAdapter.kt b/slider/src/main/java/com/limerse/slider/adapter/InfiniteCarouselAdapter.kt index d343106..95a4bc2 100644 --- a/slider/src/main/java/com/limerse/slider/adapter/InfiniteCarouselAdapter.kt +++ b/slider/src/main/java/com/limerse/slider/adapter/InfiniteCarouselAdapter.kt @@ -1,6 +1,5 @@ package com.limerse.slider.adapter -import android.graphics.drawable.Drawable import android.widget.ImageView import androidx.recyclerview.widget.RecyclerView import com.limerse.slider.model.CarouselGravity @@ -13,14 +12,12 @@ class InfiniteCarouselAdapter( carouselGravity: CarouselGravity, autoWidthFixing: Boolean, imageScaleType: ImageView.ScaleType, - imagePlaceholder: Drawable? ) : FiniteCarouselAdapter( recyclerView, carouselType, carouselGravity, autoWidthFixing, - imageScaleType, - imagePlaceholder + imageScaleType ) { override fun getItemCount(): Int { return if (dataList.isEmpty()) 0 else Integer.MAX_VALUE diff --git a/slider/src/main/java/com/limerse/slider/utils/Extensions.kt b/slider/src/main/java/com/limerse/slider/utils/Extensions.kt index b6b4d73..1b1a935 100644 --- a/slider/src/main/java/com/limerse/slider/utils/Extensions.kt +++ b/slider/src/main/java/com/limerse/slider/utils/Extensions.kt @@ -3,7 +3,6 @@ package com.limerse.slider.utils import android.content.Context -import android.graphics.drawable.Drawable import android.util.DisplayMetrics import android.util.TypedValue import android.view.View @@ -66,7 +65,6 @@ fun SnapHelper.getSnapPosition(layoutManager: RecyclerView.LayoutManager?): Int fun ImageView.setImage(item: CarouselItem) { this.setImage( item = item, - placeholderDrawable = null, placeholderDrawableResourceId = null, ) } @@ -77,44 +75,8 @@ fun ImageView.setImage(item: CarouselItem) { * @param item The carousel item. * @param placeholderDrawableResourceId The id of the resource to use as a placeholder. */ -fun ImageView.setImage( - item: CarouselItem, - @DrawableRes placeholderDrawableResourceId: Int -) { - this.setImage( - item = item, - placeholderDrawable = null, - placeholderDrawableResourceId = placeholderDrawableResourceId, - ) -} - -/** - * Set image to the carouse image view. - * - * @param item The carousel item. - * @param placeholderDrawable The drawable to display as a placeholder. - */ -fun ImageView.setImage( - item: CarouselItem, - placeholderDrawable: Drawable? = null, -) { - this.setImage( - item = item, - placeholderDrawable = placeholderDrawable, - placeholderDrawableResourceId = null, - ) -} - -/** - * Set image to the carouse image view. - * - * @param item The carousel item. - * @param placeholderDrawable The drawable to display as a placeholder. - * @param placeholderDrawableResourceId The id of the resource to use as a placeholder. - */ private fun ImageView.setImage( item: CarouselItem, - placeholderDrawable: Drawable? = null, @DrawableRes placeholderDrawableResourceId: Int? = null ) { val glide = Glide.with(context.applicationContext) @@ -132,9 +94,6 @@ private fun ImageView.setImage( } requestBuilder = when { - placeholderDrawable != null -> { - requestBuilder.placeholder(placeholderDrawable) - } placeholderDrawableResourceId != null -> { requestBuilder.placeholder(placeholderDrawableResourceId) } diff --git a/slider/src/main/res/drawable/carousel_default_placeholder.xml b/slider/src/main/res/drawable/carousel_default_placeholder.xml deleted file mode 100644 index 6daf639..0000000 --- a/slider/src/main/res/drawable/carousel_default_placeholder.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - -