當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。