映射LiveData< PagedList< X>>到LiveData< PagedList< Y>>. [英] Map LiveData<PagedList<X>> to LiveData<PagedList<Y>>

查看:82
本文介绍了映射LiveData< PagedList< X>>到LiveData< PagedList< Y>>.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将域对象映射到UI对象,并使用实时页面列表进行显示.

I need to map domain objects to UI objects and display using a live paged list.

我试图将LiveData<PagedList<X>>映射到LiveData<PagedList<Y>>,并将PositionalDataSource<X>映射到PositionalDataSource<Y>,但是由于包私有和私有限制,如果不将我的代码放在android.arch.paging中,这两者似乎都是不可能的打包并使用反射,或使用分页库的修改版本.

I have tried to map LiveData<PagedList<X>> to LiveData<PagedList<Y>>, and map PositionalDataSource<X> to PositionalDataSource<Y>, but due to package private and private restrictions these both appear to be impossible without placing my code in android.arch.paging package and using reflection, or using a modified version of the paging lib.

有人知道不使用这种不受欢迎的方法来做到这一点的方法吗?

Does anyone know of a way to do this without resorting to such undesirable methods?

(请注意,如果分页库API使用接口而不是抽象基类,这将不是问题-这将允许包装任何分页列表/数据源并添加适当的映射.)

(Note that this would not be an issue if the paging library API used interfaces instead of abstract base classes - that would allow wrapping any paged list/data source and add appropriate mappings.)

推荐答案

DataSource和DataSource.Factory具有mapBy()mapPageBy(),在这种情况下可以为您提供帮助.请小心,因为这两个将限制"Y"结果列表的大小.

DataSource and DataSource.Factory have mapBy() and mapPageBy(), which could help you in this case. Just be careful cause these two will restrict the size of the "Y"-result-list.

如果结果的大小与原始列表的大小不同,则DataSource将引发异常.

If the size of the result differs from the original list's size then DataSource will throw an Exception.

这篇关于映射LiveData&lt; PagedList&lt; X&gt;&gt;到LiveData&lt; PagedList&lt; Y&gt;&gt;.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆