Skip to content

Commit 3b64978

Browse files
committed
provide getDefaultCarouselViewHolder() and update README accordingly
1 parent efcb307 commit 3b64978

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ and attach it. Everything else is handled for you.
1818

1919
Implementations of `CarouselAdapter` have a default / standard `ViewHolder` baked
2020
in for use if desired - called `DefaultCarouselViewHolder`. It has a simple
21-
indeterminate loading circle . If you are not interested in this pre-packaged ViewHolder,
22-
`onCreateViewHolder` and `onBindViewHolder` should return and work with your own
23-
implementation of a `CarouselAdapter.CarouselViewHolder`.
21+
indeterminate loading circle . You can get an instance of this ViewHolder by calling
22+
`CarouselAdapter.getDefaultCarouselViewHolder(parentView)`
23+
24+
If you are not interested in this pre-packaged ViewHolder, `onCreateViewHolder`
25+
and `onBindViewHolder` should return and work with your own implementation of
26+
a `CarouselAdapter.CarouselViewHolder`.
2427

2528
Currently active item indicators are also automatically created and kept in sync
2629
with the carousel's ViewPager.
@@ -39,7 +42,7 @@ the AndroidX RecyclerView package or the ViewPager2 package.
3942
=> See [ViewPager2 Releases](https://developer.android.com/jetpack/androidx/releases/viewpager2) for the latest ViewPager2 version(s)
4043

4144
```
42-
implementation 'com.meetarp:carousel:1.0.4'
45+
implementation 'com.meetarp:carousel:1.0.5'
4346
4447
// and one of...
4548
implementation 'androidx.viewpager2:viewpager2:$viewPager2_version'
@@ -147,7 +150,7 @@ override fun onBindViewHolder(holder: CarouselViewHolder, position: Int) {
147150
}
148151
```
149152

150-
## Working with data
153+
## Working with changing data
151154

152155
If you find that you need to update your carousel items after its initial population,
153156
you will have to call `adapter.setItems(newList)` with the new data.
@@ -165,9 +168,8 @@ Please see `CarouselAdapter.setItems()` if this is unclear.
165168

166169
## DefaultCarouselViewHolder
167170

168-
The default implementations of `onCreateViewHolder` and `onBindViewHolder` for the
169-
`CarouselAdapter` abstract class provide an instance of `DefaultCarouselViewHolder`
170-
with publicly exposed members:
171+
`CarouselAdapter.getDefaultCarouselViewHolder(parentView)` provides an instance
172+
of `DefaultCarouselViewHolder` with publicly exposed members:
171173

172174
* container (ViewGroup - RelativeLayout)
173175
* progressBar (ProgressBar)

app/src/main/java/com/example/meetarp/carousel/CarouselImagesAdapter.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class CarouselImagesAdapter : CarouselAdapter<CarouselImage>() {
1313

1414
// Default gravity is START and TOP. This adapter wants the views CENTER in the container.
1515
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CarouselViewHolder {
16-
return super.onCreateViewHolder(parent, viewType)
17-
.also { vh -> (vh as DefaultCarouselViewHolder).container.gravity = Gravity.CENTER }
16+
return getDefaultCarouselViewHolder(parent)
17+
.also { vh -> vh.container.gravity = Gravity.CENTER }
1818
}
1919

2020
override fun onBindViewHolder(holder: CarouselViewHolder, position: Int) {

app/src/main/java/com/example/meetarp/carousel/CarouselViewsAdapter.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class CarouselViewsAdapter : CarouselAdapter<View>() {
99

1010
// Default gravity is START and TOP. This adapter wants the views CENTER in the container.
1111
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CarouselViewHolder {
12-
return super.onCreateViewHolder(parent, viewType)
13-
.also { vh -> (vh as DefaultCarouselViewHolder).container.gravity = Gravity.CENTER }
12+
return getDefaultCarouselViewHolder(parent)
13+
.also { vh -> vh.container.gravity = Gravity.CENTER }
1414
}
1515

1616
override fun onBindViewHolder(holder: CarouselViewHolder, position: Int) {

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
ext.kotlin_version = '1.3.50'
4-
ext.libVersionCode = 6
5-
ext.libVersion = '1.0.4'
4+
ext.libVersionCode = 7
5+
ext.libVersion = '1.0.5'
66

77
repositories {
88
google()

carousel/src/main/java/com/meetarp/carousel/CarouselAdapter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ abstract class CarouselAdapter<ItemType>
5151
return carouselItems.size
5252
}
5353

54-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CarouselViewHolder {
54+
fun getDefaultCarouselViewHolder(parent: ViewGroup): DefaultCarouselViewHolder {
5555
return DefaultCarouselViewHolder(
5656
LayoutInflater.from(parent.context)
5757
.inflate(R.layout.carousel_viewholder, parent, false)

0 commit comments

Comments
 (0)