本文整理汇总了Java中android.support.v7.util.DiffUtil类的典型用法代码示例。如果您正苦于以下问题:Java DiffUtil类的具体用法?Java DiffUtil怎么用?Java DiffUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiffUtil类属于android.support.v7.util包,在下文中一共展示了DiffUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleResult
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
/**
* 开始刷新
*
* @param diffResult 返回的diffResult
*/
protected final void handleResult(DiffUtil.DiffResult diffResult) {
checkAdapterBind();
diffResult.dispatchUpdatesTo(getListUpdateCallback(mAdapter));
mData.clear();
mData.addAll(mNewData);
HandleBase<T> pollData = mRefreshQueue.poll();
if (pollData != null) {
startRefresh(pollData);
} else {
onEnd();
}
}
示例2: startRefresh
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
@Override
protected void startRefresh(HandleBase<MultiHeaderEntity> refreshData) {
Flowable.just(refreshData)
.onBackpressureDrop()
.observeOn(Schedulers.computation())
.map(new Function<HandleBase<MultiHeaderEntity>, DiffUtil.DiffResult>() {
@Override
public DiffUtil.DiffResult apply(@NonNull HandleBase<MultiHeaderEntity> handleBase) throws Exception {
return handleRefresh(handleBase.getNewData(), handleBase.getNewHeader(), handleBase.getNewFooter(), handleBase.getType(), handleBase.getRefreshType());
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<DiffUtil.DiffResult>() {
@Override
public void accept(@NonNull DiffUtil.DiffResult diffResult) throws Exception {
handleResult(diffResult);
}
});
}
示例3: startRefresh
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
@Override
protected void startRefresh(HandleBase<T> refreshData) {
Flowable.just(refreshData)
.onBackpressureDrop()
.observeOn(Schedulers.computation())
.map(new Function<HandleBase<T>, DiffUtil.DiffResult>() {
@Override
public DiffUtil.DiffResult apply(@NonNull HandleBase<T> handleBase) throws Exception {
return handleRefresh(handleBase.getNewData(), handleBase.getNewHeader(), handleBase.getNewFooter(), handleBase.getType(), handleBase.getRefreshType());
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<DiffUtil.DiffResult>() {
@Override
public void accept(@NonNull DiffUtil.DiffResult diffResult) throws Exception {
handleResult(diffResult);
}
});
}
示例4: startRefresh
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
@Override
protected void startRefresh(HandleBase<StickyItem> refreshData) {
Flowable.just(refreshData)
.onBackpressureDrop()
.observeOn(Schedulers.computation())
.map(new Function<HandleBase<StickyItem>, DiffUtil.DiffResult>() {
@Override
public DiffUtil.DiffResult apply(@NonNull HandleBase<StickyItem> handleBase) throws Exception {
return handleRefresh(handleBase.getNewData(), handleBase.getNewHeader(), handleBase.getNewFooter(), handleBase.getType(), handleBase.getRefreshType());
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<DiffUtil.DiffResult>() {
@Override
public void accept(@NonNull DiffUtil.DiffResult diffResult) throws Exception {
handleResult(diffResult);
}
});
}
示例5: updateData
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
public SlimAdapter updateData(List<?> data) {
if (moreLoader != null) {
moreLoader.reset();
}
if (diffCallback == null || getItemCount() == 0 || data == null || data.size() == 0) {
this.data = data;
if (Looper.myLooper() == Looper.getMainLooper()) {
notifyDataSetChanged();
} else {
uiHandler.removeMessages(WHAT_NOTIFY_DATA_SET_CHANGED);
uiHandler.sendEmptyMessage(WHAT_NOTIFY_DATA_SET_CHANGED);
}
} else {
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new SlimDiffUtil(this.data, data, diffCallback));
this.data = data;
if (Looper.myLooper() == Looper.getMainLooper()) {
diffResult.dispatchUpdatesTo(this);
} else {
uiHandler.removeMessages(WHAT_NOTIFY_DATA_SET_CHANGED);
uiHandler.sendEmptyMessage(WHAT_NOTIFY_DATA_SET_CHANGED);
}
}
return this;
}
示例6: onDataLoaded
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
@Override
public void onDataLoaded(List<Message> messages) {
ChatContract.View view = getView();
if (view == null) {
return;
}
// 拿到老数据
@SuppressWarnings("unchecked")
List<Message> old = view.getRecyclerAdapter().getItems();
// 差异计算
DiffUiDataCallback<Message> callback = new DiffUiDataCallback<>(old, messages);
final DiffUtil.DiffResult result = DiffUtil.calculateDiff(callback);
// 进行界面刷新
refreshData(result,messages);
}
示例7: onDataLoaded
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
@Override
public void onDataLoaded(List<User> users) {
// 无论怎么操作,数据变更,最终都会通知到这里来
final ContactContract.View view = getView();
if (view == null)
return;
RecyclerAdapter<User> adapter = view.getRecyclerAdapter();
List<User> old = adapter.getItems();
// 进行数据对比
DiffUtil.Callback callback = new DiffUiDataCallback<>(old, users);
DiffUtil.DiffResult result = DiffUtil.calculateDiff(callback);
// 调用基类方法进行界面刷新
refreshData(result, users);
}
示例8: addDailyDate
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
public void addDailyDate(DailyListBean info) {
currentTitle = "今日热闻";
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new ZhihuDiffCallback(mList, info.getStories()), true);
mList = info.getStories();
mTopList = info.getTop_stories();
isBefore = false;
diffResult.dispatchUpdatesTo(this);
// notifyDataSetChanged();
}
示例9: addDailyBeforeDate
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
public void addDailyBeforeDate(DailyBeforeListBean info) {
currentTitle = info.getDate();
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new ZhihuDiffCallback(mList, info.getStories()), true);
mList = info.getStories();
isBefore = true;
diffResult.dispatchUpdatesTo(this);
// notifyDataSetChanged();
}
示例10: handleMessage
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
@Override
public void handleMessage(Message msg) {
if (msg.what == HANDLE_DATA_UPDATE) {
try {
DiffUtil.DiffResult diffResult = (DiffUtil.DiffResult) msg.obj;
handleResult(diffResult);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例11: run
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
@Override
public void run() {
List<T> newData = mHandleBase.getNewData();
T newHeader = mHandleBase.getNewHeader();
T newFooter = mHandleBase.getNewFooter();
int refreshType = mHandleBase.getRefreshType();
int type = mHandleBase.getType();
DiffUtil.DiffResult result = handleRefresh(newData, newHeader, newFooter, type, refreshType);
Message message = mHandler.obtainMessage(HANDLE_DATA_UPDATE);
message.obj = result;
message.sendToTarget();
}
示例12: animateDiff
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
@Deprecated //TODO: Call animateTo instead.
private synchronized void animateDiff(@Nullable List<T> newItems, Payload payloadChange) {
if (useDiffUtil) {
Log.v(TAG, "Animate changes with DiffUtils! oldSize=" + getItemCount() + " newSize=" + newItems.size());
if (diffUtilCallback == null) {
diffUtilCallback = new DiffUtilCallback();
}
diffUtilCallback.setItems(mItems, newItems);
diffResult = DiffUtil.calculateDiff(diffUtilCallback, notifyMoveOfFilteredItems);
} else {
animateTo(newItems, payloadChange);
}
}
示例13: RxDiffResult
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
/**
* Constructs a new instance of {@link RxDiffResult}.
*
* @param tag A {@link String} identifying the result.
* @param diffResult {@link android.support.v7.util.DiffUtil.DiffResult}.
*/
public RxDiffResult(@NonNull final String tag, @NonNull final DiffUtil.DiffResult diffResult) {
checkNotNull(diffResult, "diffResult must not be null!");
checkNotNull(tag, "tag string must not be null!");
checkArgument(!tag.isEmpty(), "tag string must not be empty!");
this.mTag = tag;
this.mDiffResult = diffResult;
}
示例14: single
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
/**
* Returns a new {@link Single} that emits the {@link RxDiffResult}.
*
* @param diffRequest {@link DiffRequest} holding all parameters to start the difference calculation.
* @return {@link Single}.
*/
static Single<RxDiffResult> single(@NonNull final DiffRequest diffRequest) {
return Single.fromCallable(new Callable<RxDiffResult>() {
@Override
public RxDiffResult call() throws Exception {
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffRequest.getDiffCallback(), diffRequest.isDetectingMoves());
return new RxDiffResult(diffRequest.getTag(), diffResult);
}
})
.cache()
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread());
}
示例15: update
import android.support.v7.util.DiffUtil; //导入依赖的package包/类
/**
* Updates data and visual representation of the adapter if the setNewData and the adapter is not null.
*
* @param diffResult The result of the difference calculation.
* @throws NullPointerException If the diffResult is null.
* @throws IllegalStateException If the current thread is not main thread.
*/
@UiThread
void update(@NonNull final DiffUtil.DiffResult diffResult) {
checkNotNull(diffResult, "diffResult must not be null!");
assertMainThread("The diff result must be obtained on the main thread");
if (mCurrentDiffRequest == null) {
return;
}
final List<D> newData = mCurrentDiffRequest.getNewData();
if (newData == null) {
return;
}
final A adapter = mAdapterWeakRef.get();
if (adapter == null) {
mPendingResult = diffResult;
return;
}
// Update data
adapter.swapData(newData);
// Update visual representation
diffResult.dispatchUpdatesTo(adapter);
// Clear all pending data
mCurrentDiffRequest = null;
mPendingResult = null;
}