-
Notifications
You must be signed in to change notification settings - Fork 7
kotlin/recyclerview-adapters #92
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
base: feature/kotlin
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| <manifest | ||
| package="ru.touchin.adapters"/> | ||
| package="ru.touchin.roboswag.recyclerview_adapters"/> |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package ru.touchin.roboswag.recyclerview_adapters | ||
|
|
||
| import androidx.recyclerview.widget.RecyclerView | ||
|
|
||
| /** | ||
| * Objects of such class controls creation and binding of specific type of RecyclerView's ViewHolders. | ||
| * Such delegates are creating and binding ViewHolders for specific items. | ||
| * Default [.getItemViewType] is generating on construction of object. | ||
| * | ||
| * @param <TViewHolder> Type of [RecyclerView.ViewHolder] of delegate; | ||
| * @param <TItem> Type of items to bind to [RecyclerView.ViewHolder]s. | ||
| </TItem></TViewHolder> */ | ||
| abstract class ItemAdapterDelegate<TViewHolder : RecyclerView.ViewHolder, TItem> : AdapterDelegate<TViewHolder>() { | ||
|
|
||
| override fun isForViewType(items: List<*>, adapterPosition: Int, collectionPosition: Int): Boolean { | ||
| return (collectionPosition >= 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Скобки лишние |
||
| && collectionPosition < items.size | ||
| && isForViewType(items[collectionPosition]!!, adapterPosition, collectionPosition)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. force unwrap |
||
| } | ||
|
|
||
| /** | ||
| * Returns if object is processable by this delegate. | ||
| * This item will be casted to [TItem] and passes to [.onBindViewHolder]. | ||
| * | ||
| * @param item Item to check; | ||
| * @param adapterPosition Position of item in adapter; | ||
| * @param collectionPosition Position of item in collection that contains item; | ||
| * @return True if item is processable by this delegate. | ||
| */ | ||
| open fun isForViewType(item: Any, adapterPosition: Int, collectionPosition: Int): Boolean { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without return
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Везде |
||
| return true | ||
| } | ||
|
|
||
| override fun getItemId(items: List<*>, adapterPosition: Int, collectionPosition: Int): Long = | ||
| getItemId(items[collectionPosition] as TItem, adapterPosition, collectionPosition) | ||
|
|
||
| /** | ||
| * Returns unique ID of item to support stable ID's logic of RecyclerView's adapter. | ||
| * | ||
| * @param item Item in adapter; | ||
| * @param adapterPosition Position of item in adapter; | ||
| * @param collectionPosition Position of item in collection that contains item; | ||
| * @return Unique item ID. | ||
| */ | ||
| fun getItemId(item: TItem, adapterPosition: Int, collectionPosition: Int): Long = 0 | ||
|
|
||
| override fun onBindViewHolder( | ||
| holder: RecyclerView.ViewHolder, | ||
| items: List<*>, | ||
| adapterPosition: Int, | ||
| collectionPosition: Int, | ||
| payloads: List<*> | ||
| ) { | ||
| onBindViewHolder(holder as TViewHolder, items[collectionPosition] as TItem, adapterPosition, collectionPosition, payloads) | ||
| } | ||
|
|
||
| /** | ||
| * Binds item with payloads to created by this object ViewHolder. | ||
| * | ||
| * @param holder ViewHolder to bind item to; | ||
| * @param item Item in adapter; | ||
| * @param adapterPosition Position of item in adapter; | ||
| * @param collectionPosition Position of item in collection that contains item; | ||
| * @param payloads Payloads; | ||
| */ | ||
| abstract fun onBindViewHolder( | ||
| holder: TViewHolder, | ||
| item: TItem, | ||
| adapterPosition: Int, | ||
| collectionPosition: Int, | ||
| payloads: List<*> | ||
| ) | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without return