Skip to content

Commit 9073f26

Browse files
authored
update readmde with Kotlin examples
1 parent ecb5367 commit 9073f26

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

README.md

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This library is available in **jCenter** which is the default Maven repository u
3434
```groovy
3535
dependencies {
3636
// other dependencies here
37-
implementation 'com.opensooq.android:pluto:1.2'
37+
implementation 'com.opensooq.android:pluto:1.4'
3838
}
3939
```
4040

@@ -49,6 +49,28 @@ Checkout the demo [here](https://github.com/OpenSooq/Pluto/tree/master/app/src/
4949
# Usage
5050
#### First create your own adapter extending the ``PlutoAdapter``
5151

52+
### Kotlin
53+
```kotlin
54+
class YourAdapter(items: MutableList<YourModel> , onItemClickListener: OnItemClickListener<Movie>? = null)
55+
: PlutoAdapter<YourModel, YourViewHolder>(items,onItemClickListener) {
56+
57+
override fun getViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
58+
return ViewHolder(parent, R.layout.item_your_layout)
59+
}
60+
61+
class YourViewHolder(parent: ViewGroup, itemLayoutId: Int) : PlutoViewHolder<YourModel>(parent, itemLayoutId) {
62+
private var ivPoster: ImageView = getView(R.id.iv_poster)
63+
private var tvRating: TextView = getView(R.id.tv_rating)
64+
65+
override fun set(item: YourModel, position: Int) {
66+
// yourImageLoader.with(mContext).load(item.getPosterId()).into(ivPoster);
67+
tvRating.text = item.imdbRating
68+
}
69+
}
70+
}
71+
```
72+
### Java
73+
5274
```java
5375
public class YourAdapter extends PlutoAdapter<YourModel, YourViewHolder> {
5476

@@ -91,14 +113,26 @@ public class YourAdapter extends PlutoAdapter<YourModel, YourViewHolder> {
91113
app:layout_constraintTop_toTopOf="parent"/>
92114
```
93115
### finaly attach the adapter to Pluto
116+
### Kotlin
117+
```kotlin
118+
val pluto = findViewById<PlutoView>(R.id.slider_view)
119+
val yourAdapter = YourAdapter(yourModelList, object : OnItemClickListener<Movie> {
120+
override fun onItemClicked(item: yourModel?, position: Int) {
121+
}
122+
})
123+
124+
pluto.create(adapter, lifecycle = lifecycle)//pass the lifecycle to make the slider aware of lifecycle to avoid memory leak and handling the pause/destroy/resume
125+
126+
```
127+
### Java
94128
```java
95129
PlutoView pluto = findViewById(R.id.slider_view);
96130
YourAdapter adapter = new YourAdapter(yourModelsList);
97-
pluto.create(adapter);
131+
pluto.create(adapter,getLifecycle()); //pass the lifecycle to make the slider aware of lifecycle to avoid memory leak and handling the pause/destroy/resume
98132
```
99133
| Method | usage |
100134
| ------ | ------ |
101-
| ``` create(PlutoAdapter adapter, long duration)``` | it is the initialization method it take your adapter and the duration of waiting between each slide |
135+
| ``` create(PlutoAdapter adapter, long duration,Lifecycle lifecyle)``` | it is the initialization method it take your adapter and the duration of waiting between each slide and lifecycle to make slider lifecylce-aware |
102136
| ``` startAutoCycle() ``` | by default the value of autocycle is true, it determine to start autocycling or not |
103137
| ``` stopAutoCycle() ``` | it stops the auto cycling of the view |
104138
| ``` moveNextPosition() ``` | if you are the auto cylce is off you can manually move next with this method |
@@ -109,19 +143,47 @@ public class YourAdapter extends PlutoAdapter<YourModel, YourViewHolder> {
109143
# Event Listeners
110144
### for item click listener its the responsibility of the ```PlutoAdapter``` to handle it,
111145
#### Example
146+
### Kotlin
147+
```kotlin
148+
val adapter = SliderAdapter(getAvenger(), object : OnItemClickListener<Movie> {
149+
override fun onItemClicked(item: Movie?, position: Int) {
150+
//handle click
151+
}
152+
153+
})
154+
//or
155+
adapter.setOnItemClickListener(object : OnItemClickListener<Movie> {
156+
override fun onItemClicked(item: Movie?, position: Int) {
157+
//handle click
158+
}
159+
})
160+
161+
```
162+
### Java
112163
```java
113164

114165
SliderAdapter adapter = new SliderAdapter(getAvengers(), (item, position) -> {
115166
//handle clickhere
116167
});
117-
168+
//or
118169
adapter.setOnItemClickListener((item, position) -> {
119170
//handle click here
120171
});
121172
```
122173
### you can attach listener to the ```PlutoView``` to listen for sliding event
123174
#### Example
124175

176+
### Kotlin
177+
```kotlin
178+
179+
pluto.setOnSlideChangeListener(object : OnSlideChangeListener {
180+
override fun onSlideChange(adapter: PlutoAdapter<*, *>, position: Int) {
181+
182+
}
183+
})
184+
```
185+
### Java
186+
125187
```java
126188

127189
pluto.setOnSlideChangeListener(new OnSlideChangeListener() {

0 commit comments

Comments
 (0)