本文整理汇总了Java中android.support.v7.util.DiffUtil.calculateDiff方法的典型用法代码示例。如果您正苦于以下问题:Java DiffUtil.calculateDiff方法的具体用法?Java DiffUtil.calculateDiff怎么用?Java DiffUtil.calculateDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.util.DiffUtil
的用法示例。
在下文中一共展示了DiffUtil.calculateDiff方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: getRootSuccess
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
@Override
public void getRootSuccess(List<AppInfo> apps, List<AppInfo> appsNew) {
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DiffCallBack(apps, appsNew), false);
diffResult.dispatchUpdatesTo(mDisableAppAdapter);
mAppList = appsNew;
mDisableAppAdapter.setData(mAppList);
for (int i = 0; i < mAppList.size(); i++) {
AppInfo info = mAppList.get(i);
if (mMainActivity.getSelection().contains(info)) {
mMainActivity.getSelection().remove(info);
mDisableAppAdapter.notifyItemChanged(i);
}
}
mMainActivity.checkSelection();
String str = mMainActivity.mRootStr;
if (!TextUtils.isEmpty(str)) {
snackBarShow(mMainActivity.mCoordinatorLayout, mMainActivity.mRootStr);
}
setRefreshing(false);
if (mAppList.isEmpty()) {
mDisableAppAdapter.showLoadFailed(R.drawable.empty, getResources().getString(R.string.no_disable_apps), "");
snackBarShow(mMainActivity.mCoordinatorLayout, getString(R.string.no_disable_apps));
}
}
示例3: setSuggestions
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
void setSuggestions(@NonNull List<String> newStrings) {
final SuggestionDiff suggestionDiff = new SuggestionDiff(suggestions, newStrings);
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(suggestionDiff, true);
suggestions.clear();
suggestions.addAll(newStrings);
diffResult.dispatchUpdatesTo(this);
}
示例4: 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();
}
示例5: 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);
}
}
示例6: onDataLoaded
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
@Override
public void onDataLoaded(List<Session> sessions) {
SessionContract.View view = getView();
if (view == null) {
return;
}
// 差异对比
List<Session> old = view.getRecyclerAdapter().getItems();
DiffUiDataCallback<Session> callback = new DiffUiDataCallback<>(old, sessions);
DiffUtil.DiffResult result = DiffUtil.calculateDiff(callback);
// 刷新界面
refreshData(result, sessions);
}
示例7: swapItems
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
public void swapItems(List<Watcher> watchers) {
final WatcherListDiffCallback callback = new WatcherListDiffCallback(this.watchers, watchers);
final DiffUtil.DiffResult result = DiffUtil.calculateDiff(callback);
this.watchers.clear();
this.watchers.addAll(watchers);
result.dispatchUpdatesTo(this);
}
示例8: updateEmployeeListItems
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
public void updateEmployeeListItems(List<BaseMessage> recentPhotoList) {
//final MessageListDiffCall diffCallback = new MessageListDiffCall(this.mBaseMessageList, recentPhotoList);
//final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffCallback);
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new MessageListDiffCall(this.mBaseMessageList, recentPhotoList));
diffResult.dispatchUpdatesTo(this);
/*
this.mBaseMessageList.removeAll(mBaseMessageList);
this.mBaseMessageList.addAll(recentPhotoList);
diffResult.dispatchUpdatesTo(RecentPhotoAdapter.this);*/
}
示例9: refresh
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
private void refresh() {
mNewDatas.clear();
mNewDatas.addAll(mDatas);
//改变第三个位置的对象
Item item = new Item(3, "zhang");
mNewDatas.remove(3);
mNewDatas.add(3, item);
DiffUtil.DiffResult diffResult =
DiffUtil.calculateDiff(new DiffCallback(mDatas, mNewDatas), true);
//将新数据给Adapter
mAdapter.setDatas(mNewDatas);
diffResult.dispatchUpdatesTo(mAdapter);
mDatas.clear();
mDatas.addAll(mNewDatas);
}
示例10: refreshItems
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
public void refreshItems(List<Recipe> recipeList) {
List<Recipe> newRecipeList = new ArrayList<>();
newRecipeList.addAll(recipeList);
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new RecipeDiffUtilCallback(this.recipeList, newRecipeList));
this.recipeList.clear();
this.recipeList.addAll(recipeList);
diffResult.dispatchUpdatesTo(this);
}
示例11: updateEmployeeListItems
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
public void updateEmployeeListItems(List<Employee> employees) {
final EmployeeDiffCallback diffCallback = new EmployeeDiffCallback(this.mEmployees, employees);
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffCallback);
this.mEmployees.clear();
this.mEmployees.addAll(employees);
diffResult.dispatchUpdatesTo(this);
}
示例12: swapItems
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
public void swapItems(List<User> users) {
String newActive = getContext().getSharedPreferences("settings", Context.MODE_PRIVATE).getString("userID", "");
final AccountListDiffCallback callback = new AccountListDiffCallback(this.users, users, oldActive, newActive);
final DiffUtil.DiffResult result = DiffUtil.calculateDiff(callback);
this.users.clear();
this.users.addAll(users);
result.dispatchUpdatesTo(this);
oldActive = newActive;
}
示例13: onNewData
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
public void onNewData(ArrayList<CategoryHolder> items) {
final CategoryDiffCallback callback = new CategoryDiffCallback(items, this.items);
final DiffUtil.DiffResult result = DiffUtil.calculateDiff(callback, true);
this.items.clear();
this.items.addAll(items);
result.dispatchUpdatesTo(this);
}
示例14: onNewData
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
public void onNewData(ArrayList<User> users) {
UserCallback callback = new UserCallback(users, this.users);
DiffUtil.DiffResult result = DiffUtil.calculateDiff(callback, true);
this.users.clear();
this.users.addAll(users);
result.dispatchUpdatesTo(this);
}
示例15: sort
import android.support.v7.util.DiffUtil; //导入方法依赖的package包/类
void sort() {
List<OpsInfo> mOld = new ArrayList<>(mOpsInfo);
Collections.sort(mOpsInfo, getSortMethod());
DiffUtil.DiffResult result = DiffUtil.calculateDiff(new DiffCallback(mOld, mOpsInfo));
result.dispatchUpdatesTo(this);
}