Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/228 #258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"java.completion.enabled": false,
"java.debug.settings.enableRunDebugCodeLens": false,
"java.test.editor.enableShortcuts": false
}
72 changes: 71 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Or you can put it inside the cardView to look more beautiful :
## Next step

The new version requires an slider adapter plus your custom layout for slider items, Although its very similar to RecyclerView & RecyclerAdapter, and it's familiar and easy to implement this adapter... here is an example for adapter implementation :

### Java
```java
public class SliderAdapterExample extends
SliderViewAdapter<SliderAdapterExample.SliderAdapterVH> {
Expand Down Expand Up @@ -167,6 +167,76 @@ public class SliderAdapterExample extends
}
```

###Kotlin
```kotlin
class ImageSliderAdapter(context: Context) :
SliderViewAdapter<ImageSliderAdapter.SliderAdapterVH>() {
private val context: Context
private var mSliderItems: MutableList<SliderItem> = ArrayList()
fun renewItems(sliderItems: MutableList<SliderItem>) {
mSliderItems = sliderItems
notifyDataSetChanged()
}

fun deleteItem(position: Int) {
mSliderItems.removeAt(position)
notifyDataSetChanged()
}

fun addItem(sliderItem: SliderItem) {
mSliderItems.add(sliderItem)
notifyDataSetChanged()
}

override fun onCreateViewHolder(parent: ViewGroup): SliderAdapterVH {
val inflate: View =
LayoutInflater.from(parent.context).inflate(R.layout.image_slider_layout_item, null)
return SliderAdapterVH(inflate)
}

override fun onBindViewHolder(viewHolder: SliderAdapterVH, position: Int) {
val sliderItem: SliderItem = mSliderItems[position]
viewHolder.textViewDescription.setText("Demo Description")
viewHolder.textViewDescription.textSize = 16f
viewHolder.textViewDescription.setTextColor(Color.WHITE)
// Glide.with(viewHolder.itemView)
// .load(sliderItem.image)
// .fitCenter()
// .into(viewHolder.imageViewBackground)

viewHolder.imageViewBackground.load(sliderItem.image_url)

viewHolder.itemView.setOnClickListener {
Toast.makeText(context, "This is item in position $position", Toast.LENGTH_SHORT)
.show()
}
}

override fun getCount(): Int {
//slider view count could be dynamic size
return mSliderItems.size
}

inner class SliderAdapterVH(itemView: View) : ViewHolder(itemView) {
var _itemView: View
var imageViewBackground: ImageView
var imageGifContainer: ImageView
var textViewDescription: TextView

init {
imageViewBackground = itemView.findViewById(R.id.iv_auto_image_slider)
imageGifContainer = itemView.findViewById(R.id.iv_gif_container)
textViewDescription = itemView.findViewById(R.id.tv_auto_image_slider)
_itemView = itemView
}
}

init {
this.context = context
}
}
```

## Custom Slider Image Layout

you can make your own layout for slider view
Expand Down