-
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 #16 from AlanCheen/develop
Support AsyncListDiffer feature
- Loading branch information
Showing
7 changed files
with
102 additions
and
45 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
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 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
50 changes: 50 additions & 0 deletions
50
flap/src/main/java/me/yifeiyuan/flap/extensions/DifferFlapAdapter.java
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,50 @@ | ||
package me.yifeiyuan.flap.extensions; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.v7.recyclerview.extensions.AsyncDifferConfig; | ||
import android.support.v7.recyclerview.extensions.AsyncListDiffer; | ||
import android.support.v7.util.AdapterListUpdateCallback; | ||
import android.support.v7.util.DiffUtil; | ||
|
||
import java.util.List; | ||
|
||
import me.yifeiyuan.flap.FlapAdapter; | ||
|
||
/** | ||
* Created by 程序亦非猿 on 2019/1/4. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public class DifferFlapAdapter<T> extends FlapAdapter { | ||
|
||
private AsyncListDiffer<T> differ; | ||
|
||
public DifferFlapAdapter(final @NonNull DiffUtil.ItemCallback<T> itemCallback) { | ||
differ = new AsyncListDiffer(this, itemCallback); | ||
} | ||
|
||
public DifferFlapAdapter(@NonNull AsyncDifferConfig<T> config) { | ||
differ = new AsyncListDiffer(new AdapterListUpdateCallback(this), config); | ||
} | ||
|
||
@Override | ||
public DifferFlapAdapter setData(@NonNull final List<?> data) { | ||
differ.submitList((List<T>) data); | ||
return this; | ||
} | ||
|
||
@Override | ||
protected T getItem(int position) { | ||
return differ.getCurrentList().get(position); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return differ.getCurrentList().size(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<T> getData() { | ||
return differ.getCurrentList(); | ||
} | ||
} |