Skip to content

Commit 465573c

Browse files
committed
Removed the unnecessary placeholder
1 parent d880d58 commit 465573c

File tree

6 files changed

+6
-98
lines changed

6 files changed

+6
-98
lines changed

app/src/main/java/com/limerse/sliding/KotlinActivity.kt

+4-9
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ class KotlinActivity : AppCompatActivity() {
6464
imageScaleType = ImageView.ScaleType.CENTER_CROP
6565

6666
carouselBackground = ColorDrawable(Color.parseColor("#333333"))
67-
imagePlaceholder = ContextCompat.getDrawable(
68-
this@KotlinActivity,
69-
R.drawable.carousel_default_placeholder
70-
)
7167

7268
carouselPadding = 0.dpToPx(context)
7369
carouselPaddingStart = 0.dpToPx(context)
@@ -153,8 +149,7 @@ class KotlinActivity : AppCompatActivity() {
153149

154150
currentBinding.imageView.apply {
155151
scaleType = imageScaleType
156-
157-
setImage(item, R.drawable.ic_wb_cloudy_with_padding)
152+
setImage(item)
158153
}
159154
}
160155
}
@@ -197,7 +192,7 @@ class KotlinActivity : AppCompatActivity() {
197192

198193
// carousel_default_placeholder is the default placeholder comes with
199194
// the library.
200-
setImage(item, R.drawable.carousel_default_placeholder)
195+
setImage(item)
201196
}
202197
}
203198
}
@@ -282,7 +277,7 @@ class KotlinActivity : AppCompatActivity() {
282277
currentBinding.imageView.apply {
283278
scaleType = imageScaleType
284279

285-
setImage(item, R.drawable.ic_wb_cloudy_with_padding)
280+
setImage(item)
286281
}
287282
}
288283
}
@@ -333,7 +328,7 @@ class KotlinActivity : AppCompatActivity() {
333328
currentBinding.imageView.apply {
334329
scaleType = imageScaleType
335330

336-
setImage(item, R.drawable.ic_wb_cloudy_with_padding)
331+
setImage(item)
337332
}
338333

339334
currentBinding.tvRating.text =

slider/src/main/java/com/limerse/slider/ImageCarousel.kt

-13
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,6 @@ class ImageCarousel(
263263
recyclerView.background = carouselBackground
264264
}
265265

266-
var imagePlaceholder: Drawable? = null
267-
set(value) {
268-
field = value
269-
270-
initAdapter()
271-
}
272-
273266
@Dimension(unit = Dimension.PX)
274267
var carouselPadding: Int = 0
275268
set(value) {
@@ -628,10 +621,6 @@ class ImageCarousel(
628621
R.styleable.ImageCarousel_carouselBackground
629622
) ?: ColorDrawable(Color.parseColor("#00000000"))
630623

631-
imagePlaceholder = getDrawable(
632-
R.styleable.ImageCarousel_imagePlaceholder
633-
) ?: ContextCompat.getDrawable(context, R.drawable.carousel_default_placeholder)
634-
635624
carouselPadding = getDimension(
636625
R.styleable.ImageCarousel_carouselPadding,
637626
0F
@@ -740,7 +729,6 @@ class ImageCarousel(
740729
carouselGravity = carouselGravity,
741730
autoWidthFixing = autoWidthFixing,
742731
imageScaleType = imageScaleType,
743-
imagePlaceholder = imagePlaceholder
744732
).apply {
745733
listener = carouselListener
746734
}
@@ -751,7 +739,6 @@ class ImageCarousel(
751739
carouselGravity = carouselGravity,
752740
autoWidthFixing = autoWidthFixing,
753741
imageScaleType = imageScaleType,
754-
imagePlaceholder = imagePlaceholder
755742
).apply {
756743
listener = carouselListener
757744
}

slider/src/main/java/com/limerse/slider/adapter/FiniteCarouselAdapter.kt

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.limerse.slider.adapter
22

3-
import android.graphics.drawable.Drawable
43
import android.view.LayoutInflater
54
import android.view.ViewGroup
65
import android.view.ViewTreeObserver
@@ -21,7 +20,6 @@ open class FiniteCarouselAdapter(
2120
private val carouselGravity: CarouselGravity,
2221
private val autoWidthFixing: Boolean,
2322
private val imageScaleType: ImageView.ScaleType,
24-
private val imagePlaceholder: Drawable?
2523
) : RecyclerView.Adapter<FiniteCarouselAdapter.MyViewHolder>() {
2624

2725
var listener: CarouselListener? = null
@@ -71,11 +69,7 @@ open class FiniteCarouselAdapter(
7169
if (holder.binding is ItemCarouselBinding) {
7270
holder.binding.img.scaleType = imageScaleType
7371

74-
if (imagePlaceholder != null) {
75-
holder.binding.img.setImage(item, imagePlaceholder)
76-
} else {
77-
holder.binding.img.setImage(item)
78-
}
72+
holder.binding.img.setImage(item)
7973

8074
listener?.apply {
8175
holder.itemView.setOnClickListener {

slider/src/main/java/com/limerse/slider/adapter/InfiniteCarouselAdapter.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.limerse.slider.adapter
22

3-
import android.graphics.drawable.Drawable
43
import android.widget.ImageView
54
import androidx.recyclerview.widget.RecyclerView
65
import com.limerse.slider.model.CarouselGravity
@@ -13,14 +12,12 @@ class InfiniteCarouselAdapter(
1312
carouselGravity: CarouselGravity,
1413
autoWidthFixing: Boolean,
1514
imageScaleType: ImageView.ScaleType,
16-
imagePlaceholder: Drawable?
1715
) : FiniteCarouselAdapter(
1816
recyclerView,
1917
carouselType,
2018
carouselGravity,
2119
autoWidthFixing,
22-
imageScaleType,
23-
imagePlaceholder
20+
imageScaleType
2421
) {
2522
override fun getItemCount(): Int {
2623
return if (dataList.isEmpty()) 0 else Integer.MAX_VALUE

slider/src/main/java/com/limerse/slider/utils/Extensions.kt

-41
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package com.limerse.slider.utils
44

55
import android.content.Context
6-
import android.graphics.drawable.Drawable
76
import android.util.DisplayMetrics
87
import android.util.TypedValue
98
import android.view.View
@@ -66,7 +65,6 @@ fun SnapHelper.getSnapPosition(layoutManager: RecyclerView.LayoutManager?): Int
6665
fun ImageView.setImage(item: CarouselItem) {
6766
this.setImage(
6867
item = item,
69-
placeholderDrawable = null,
7068
placeholderDrawableResourceId = null,
7169
)
7270
}
@@ -77,44 +75,8 @@ fun ImageView.setImage(item: CarouselItem) {
7775
* @param item The carousel item.
7876
* @param placeholderDrawableResourceId The id of the resource to use as a placeholder.
7977
*/
80-
fun ImageView.setImage(
81-
item: CarouselItem,
82-
@DrawableRes placeholderDrawableResourceId: Int
83-
) {
84-
this.setImage(
85-
item = item,
86-
placeholderDrawable = null,
87-
placeholderDrawableResourceId = placeholderDrawableResourceId,
88-
)
89-
}
90-
91-
/**
92-
* Set image to the carouse image view.
93-
*
94-
* @param item The carousel item.
95-
* @param placeholderDrawable The drawable to display as a placeholder.
96-
*/
97-
fun ImageView.setImage(
98-
item: CarouselItem,
99-
placeholderDrawable: Drawable? = null,
100-
) {
101-
this.setImage(
102-
item = item,
103-
placeholderDrawable = placeholderDrawable,
104-
placeholderDrawableResourceId = null,
105-
)
106-
}
107-
108-
/**
109-
* Set image to the carouse image view.
110-
*
111-
* @param item The carousel item.
112-
* @param placeholderDrawable The drawable to display as a placeholder.
113-
* @param placeholderDrawableResourceId The id of the resource to use as a placeholder.
114-
*/
11578
private fun ImageView.setImage(
11679
item: CarouselItem,
117-
placeholderDrawable: Drawable? = null,
11880
@DrawableRes placeholderDrawableResourceId: Int? = null
11981
) {
12082
val glide = Glide.with(context.applicationContext)
@@ -132,9 +94,6 @@ private fun ImageView.setImage(
13294
}
13395

13496
requestBuilder = when {
135-
placeholderDrawable != null -> {
136-
requestBuilder.placeholder(placeholderDrawable)
137-
}
13897
placeholderDrawableResourceId != null -> {
13998
requestBuilder.placeholder(placeholderDrawableResourceId)
14099
}

slider/src/main/res/drawable/carousel_default_placeholder.xml

-24
This file was deleted.

0 commit comments

Comments
 (0)