-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from AlanCheen/feature/differ
Feature/differ
- Loading branch information
Showing
10 changed files
with
174 additions
and
86 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
14 changes: 10 additions & 4 deletions
14
app/src/main/java/me/yifeiyuan/flapdev/showcase/DiffAdapterTestcase.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
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package me.yifeiyuan.flap.differ | ||
|
||
/** | ||
* | ||
* 实现 IDiffer 接口,可以高效刷新 | ||
* | ||
* @see FlapDifferAdapter | ||
* @see androidx.recyclerview.widget.AsyncListDiffer | ||
* | ||
* Created by 程序亦非猿 on 2021/9/22. | ||
* | ||
* Flap Github: <a>https://github.com/AlanCheen/Flap</a> | ||
* @author 程序亦非猿 [Follow me](<a> https://github.com/AlanCheen</a>) | ||
* @since 2020/9/22 | ||
* @since 3.0.0 | ||
*/ | ||
interface IDiffer { | ||
|
||
/** | ||
* 是否是同一个 item,如果有 id 之类的属性,就比较它们是否相等 | ||
* this.id == newItem.id | ||
* | ||
* 当返回 true,则会继续调用 areContentsTheSame | ||
* | ||
* @see androidx.recyclerview.widget.DiffUtil.ItemCallback.areItemsTheSame | ||
*/ | ||
fun areItemsTheSame(newItem: Any): Boolean { | ||
return this.javaClass == newItem.javaClass | ||
} | ||
|
||
/** | ||
* | ||
* equals | ||
* 当 areItemsTheSame 返回 true 的时候会调用这个方法 | ||
* | ||
* @see androidx.recyclerview.widget.DiffUtil.ItemCallback.areContentsTheSame | ||
*/ | ||
fun areContentsTheSame(newItem: Any): Boolean { | ||
return equals(newItem) | ||
} | ||
|
||
/** | ||
* 当 areItemsTheSame 返回 true , 并且 areContentsTheSame 返回 false, 就会调用该方法 | ||
* | ||
* @see androidx.recyclerview.widget.DiffUtil.ItemCallback.getChangePayload | ||
*/ | ||
fun getChangePayload(newItem: Any): Any? = null | ||
} |
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
Oops, something went wrong.