当前位置: 首页>>代码示例>>Java>>正文


Java DiffUtil类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:RecyclerViewAdapterHelper.java

示例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);
                }
            });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:RxAdapterHelper.java

示例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);
                }
            });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:SimpleRxAdapterHelper.java

示例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);
                }
            });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:ErrorAndEmptyAdapterHelper.java

示例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;
}
 
开发者ID:MEiDIK,项目名称:SlimAdapter,代码行数:25,代码来源:SlimAdapter.java

示例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);
}
 
开发者ID:FZZFVII,项目名称:pipe,代码行数:20,代码来源:ChatPresenter.java

示例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);
}
 
开发者ID:FZZFVII,项目名称:pipe,代码行数:18,代码来源:ContactPresenter.java

示例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();
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:DailyAdapter.java

示例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();
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:DailyAdapter.java

示例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();
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:AsynAdapterHelper.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:AsynAdapterHelper.java

示例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);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:FlexibleAdapter.java

示例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;
}
 
开发者ID:storix,项目名称:RxDiffUtil,代码行数:15,代码来源:RxDiffResult.java

示例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());
}
 
开发者ID:storix,项目名称:RxDiffUtil,代码行数:19,代码来源:DiffRequestManager.java

示例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;
}
 
开发者ID:storix,项目名称:RxDiffUtil,代码行数:38,代码来源:DiffRequestManager.java


注:本文中的android.support.v7.util.DiffUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。