Comments (9)
你好,不好意思我没有太理解你的意思:
但是因为DiffUtil.ItemCallback中的areContentsTheSame(oldItem: Repo, newItem: Repo)方法返回的oldItem和newItem是相同的,导致点赞状态不会被更新。
这时的对象为何会是相同的呢,我的理解是item.forksCount
发生了变化,Paging内部会自动执行onItemChanged的更新逻辑呀。
from mvvm-architecture.
@qingmei2 我的想法是和你一样的,我也认为Paging内部应该会自动执行onItemChanged的更新逻辑才对,所以我就一直寻找问题的原因,直到打印areContentsTheSame(oldItem: Repo, newItem: Repo)中的log时才发现:点击同一个item时,返回的oldItem和newItem是相同的。
我也看了一下DiffUtil的相关源码,也没有什么收获。你之前有用paging实现过类似的功能吗?是怎么处理的呢?
from mvvm-architecture.
下面是连续点击同一个item时输出的log:
submitList是提交给PageList的数据,areContentsTheSame 是DiffUtil打印的数据
2019-08-14 16:07:56.312 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:07:56.314 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1
2019-08-14 16:07:59.610 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:07:59.612 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1000
2019-08-14 16:08:12.650 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:08:12.652 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1
2019-08-14 16:08:21.999 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:08:22.003 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1000
`
from mvvm-architecture.
快速点击item的log,快速点击同一个item的时候,forksCount在界面上的显示有时会变化:
2019-08-14 16:13:07.925 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:13:07.928 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1
2019-08-14 16:13:15.385 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:13:15.387 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1000
2019-08-14 16:13:16.361 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:13:16.364 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1
2019-08-14 16:13:17.043 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:13:17.045 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1000
2019-08-14 16:13:17.747 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:13:17.749 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1
2019-08-14 16:13:18.325 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:13:18.327 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1 == newItem: 1000
2019-08-14 16:13:19.511 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:13:19.512 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1000 == newItem: 1000
2019-08-14 16:13:21.042 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:13:21.044 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1000 == newItem: 1
2019-08-14 16:13:21.844 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:13:21.846 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1000 == newItem: 1000
2019-08-14 16:13:23.058 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:13:23.060 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1000 == newItem: 1
2019-08-14 16:13:23.959 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:13:23.961 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1000 == newItem: 1000
2019-08-14 16:13:24.545 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:13:24.547 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1000 == newItem: 1
2019-08-14 16:13:25.030 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1000
2019-08-14 16:13:25.031 29145-29759/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1000 == newItem: 1000
2019-08-14 16:13:25.663 29145-29145/com.qingmei2.sample E/ReposFragment$override: =============submitList id: 200820107 count: 1
2019-08-14 16:13:25.666 29145-29904/com.qingmei2.sample E/ReposPagedAdapter$Companion$diffCallback$1$override: =============areContentsTheSame id: 200820107 == oldItem: 1000 == newItem: 1
from mvvm-architecture.
1和1000本质没有区别,既然点赞能够响应在ui上,取消点赞也能响应在ui上。
会不会是哪里代码实现有问题呢(比如为Dao的接口上试试为@update配置下冲突策略如OnConflictStrategy.REPLACE
)?公司的项目是有实现点赞功能的,但合同约定不能放代码,这个只能靠个人debug了。
from mvvm-architecture.
Room的Insert和Update以及冲突策略OnConflictStrategy.REPLACE,我都试过了,没有什么变化。我之前是在我自己的代码上操作的,我觉得可能是我某些代码的原因,但是我把上面的代码放到clone下来的MVVM-Rhine中也是同样的问题?
另外开始我怀疑可能是AutoDisposeViewHolder问题,所以也尝试把AutoDisposeViewHolder替换成RecyclerView.ViewHolder,可是问题依然存在。
from mvvm-architecture.
感谢你的反馈,个人的想法是,尝试一下在源码中打一下断点呢,或者使用相关工具查询一下数据库最新的数据?
from mvvm-architecture.
@qingmei2
谢谢你的提议,我查看了每次写入后的数据库,发现数据是有正常写入的。
然后我断点看了submitList的源码,发现mPagedList 会在某个时间被赋值为当前状态的PagedList,进而导致oldSnapshot 和newSnapshot 一致。
AsyncPagedListDiffer的submitList代码:
public void submitList(@Nullable final PagedList<T> pagedList,
@Nullable final Runnable commitCallback) {
......
if (mPagedList != null) {
// first update scheduled on this list, so capture mPages as a snapshot, removing
// callbacks so we don't have resolve updates against a moving target
mPagedList.removeWeakCallback(mPagedListCallback);
mSnapshot = (PagedList<T>) mPagedList.snapshot();
mPagedList = null;
}
if (mSnapshot == null || mPagedList != null) {
throw new IllegalStateException("must be in snapshot state to diff");
}
final PagedList<T> oldSnapshot = mSnapshot;
final PagedList<T> newSnapshot = (PagedList<T>) pagedList.snapshot();
mConfig.getBackgroundThreadExecutor().execute(new Runnable() {
@Override
public void run() {
final DiffUtil.DiffResult result;
result = PagedStorageDiffHelper.computeDiff(
oldSnapshot.mStorage,
newSnapshot.mStorage,
mConfig.getDiffCallback());
mMainThreadExecutor.execute(new Runnable() {
@Override
public void run() {
if (mMaxScheduledGeneration == runGeneration) {
latchPagedList(pagedList, newSnapshot, result,
oldSnapshot.mLastLoad, commitCallback);
}
}
});
}
});
}
我有点好奇你的DiffUtil.ItemCallback和我的有什么区别吗?还是说做了什么特殊的处理?另外你的paging-runtime版本是多少呢?能不能提供一个小demo学习一下。谢谢!
from mvvm-architecture.
能讲一下你那边用paging实现点赞的方法吗?感觉像是paging的问题
from mvvm-architecture.
Related Issues (20)
- sharedpref读取问题 HOT 1
- 大佬看下QQ邮件哦
- 无网络情况下请求接口闪退 HOT 5
- 网络请求 HOT 1
- 大佬 buildSrc 依赖配置是怎么实现。求赐教 HOT 1
- 首页列表上下滑动时好卡啊 HOT 2
- 登陆退出 HOT 2
- 可以加入开发行列一起丰富这个框架吗 HOT 2
- master分支代码爆红 HOT 2
- 【关于】作者本人对这个MVVM项目的定位是什么? HOT 2
- 登陆 HOT 2
- 登录返回401,Unauthorized HOT 2
- com.google.protobuf plugin找不到的问题 HOT 1
- 关于状态管理的疑问 HOT 4
- ViewModelScope.launch HOT 1
- SSL peer shut down incorrectly HOT 1
- 关于gradle的插件 versionPlugin HOT 3
- 请教一个问题
- 升级viewmodel到2.3.0 升级lifecycle到2.2.0 ,在LoginViewModel中如果构造函数有参数时,就会提示这个错误,不知道怎么改,是代码要修改还是google版本的bug呢
- 大佬我写的列表库和网络请求完美支持MVVM给我个友链如何 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mvvm-architecture.