Skip to content

Commit

Permalink
Removed the unnecessary placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaaatt committed May 29, 2021
1 parent d880d58 commit 465573c
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 98 deletions.
13 changes: 4 additions & 9 deletions app/src/main/java/com/limerse/sliding/KotlinActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -153,8 +149,7 @@ class KotlinActivity : AppCompatActivity() {

currentBinding.imageView.apply {
scaleType = imageScaleType

setImage(item, R.drawable.ic_wb_cloudy_with_padding)
setImage(item)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -282,7 +277,7 @@ class KotlinActivity : AppCompatActivity() {
currentBinding.imageView.apply {
scaleType = imageScaleType

setImage(item, R.drawable.ic_wb_cloudy_with_padding)
setImage(item)
}
}
}
Expand Down Expand Up @@ -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 =
Expand Down
13 changes: 0 additions & 13 deletions slider/src/main/java/com/limerse/slider/ImageCarousel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -740,7 +729,6 @@ class ImageCarousel(
carouselGravity = carouselGravity,
autoWidthFixing = autoWidthFixing,
imageScaleType = imageScaleType,
imagePlaceholder = imagePlaceholder
).apply {
listener = carouselListener
}
Expand All @@ -751,7 +739,6 @@ class ImageCarousel(
carouselGravity = carouselGravity,
autoWidthFixing = autoWidthFixing,
imageScaleType = imageScaleType,
imagePlaceholder = imagePlaceholder
).apply {
listener = carouselListener
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<FiniteCarouselAdapter.MyViewHolder>() {

var listener: CarouselListener? = null
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
41 changes: 0 additions & 41 deletions slider/src/main/java/com/limerse/slider/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,7 +65,6 @@ fun SnapHelper.getSnapPosition(layoutManager: RecyclerView.LayoutManager?): Int
fun ImageView.setImage(item: CarouselItem) {
this.setImage(
item = item,
placeholderDrawable = null,
placeholderDrawableResourceId = null,
)
}
Expand All @@ -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)
Expand All @@ -132,9 +94,6 @@ private fun ImageView.setImage(
}

requestBuilder = when {
placeholderDrawable != null -> {
requestBuilder.placeholder(placeholderDrawable)
}
placeholderDrawableResourceId != null -> {
requestBuilder.placeholder(placeholderDrawableResourceId)
}
Expand Down
24 changes: 0 additions & 24 deletions slider/src/main/res/drawable/carousel_default_placeholder.xml

This file was deleted.

0 comments on commit 465573c

Please sign in to comment.