-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite adapters without implementing DiffUtilItem
- Loading branch information
Showing
34 changed files
with
279 additions
and
828 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
delegateadapter/src/main/java/com/livermor/delegateadapter/delegate/AdaptersState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.livermor.delegateadapter.delegate | ||
|
||
/** | ||
* Class to hold [CompositeDelegateAdapter]'s adapters and data. | ||
*/ | ||
data class AdaptersState( | ||
private val adapters: List<DelegateAdapter>, | ||
val data: List<Any> = emptyList() | ||
) { | ||
|
||
private val adapterPositionsCache = Array<Int>(data.size) { -1 } | ||
|
||
fun getAdapterPosition(itemPosition: Int): Int = | ||
adapterPositionsCache[itemPosition].takeIf { it != -1 } | ||
?: adapters.indexOfFirst { it.isForViewType(data, itemPosition) } | ||
.takeIf { it != -1 } | ||
?.also { adapterPositionsCache[itemPosition] = it } | ||
?: error("Provide adapter for type ${data[itemPosition].javaClass} at position: $itemPosition") | ||
|
||
fun getAdapter(adapterPosition: Int): DelegateAdapter = adapters[adapterPosition] | ||
|
||
fun getAdapterByItemPosition(itemPosition: Int): DelegateAdapter = | ||
adapters[getAdapterPosition(itemPosition)] | ||
} |
59 changes: 0 additions & 59 deletions
59
delegateadapter/src/main/java/com/livermor/delegateadapter/delegate/BaseDelegateAdapter.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
delegateadapter/src/main/java/com/livermor/delegateadapter/delegate/BaseViewHolder.java
This file was deleted.
Oops, something went wrong.
92 changes: 0 additions & 92 deletions
92
...adapter/src/main/java/com/livermor/delegateadapter/delegate/CompositeDelegateAdapter.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.