具有不同PagedLists的分页库和会议室,取决于不同的请求 [英] Paging Library and Room with different PagedLists that depends of different requests

查看:94
本文介绍了具有不同PagedLists的分页库和会议室,取决于不同的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用新的Android体系结构组件设置我的所有列表:房间持久性图书馆分页图书馆。但是我面临以下问题。想象一个应用程序有很多相同模型的不同列表。每个列表对服务器都有自己的url请求。某些元素可以在不同的响应中重复。因此,我认为我必须插入和更新对该模型表的每个响应的所有元素。此外,每个请求都有页面。例如, elements / famous / 0 elements / famous / 1 。因此,当收到第1页响应时,包含列表0元素的列表必须添加第1页返回的元素。

I am trying to set up all my lists using new Android Architecture Components: Room Persistance Library and Paging Library. But I am facing the following problem. Imagine an app that has a lots of diferents lists of the same model. Each list has his own url request to server. Some elements can be repeated in diferent responses. So I think that I have to insert and update all elements of each response to a table of that model. Furthermore, each request has pages. For example, elements/famous/0, elements/famous/1. So, when page 1 response is received the list containing the elements of list 0 have to add the elements returned by page 1.

返回LivePagedListProvided的Room请求就像

A Room request that returns a LivePagedListProvided is like this:

@Query("SELECT * FROM elements")
fun getElements(): LivePagedListProvider<Int, Model>

当查询的某些元素更改或添加到数据库的元素影响查询时, LivePagedListProvider 可观察对象提供了更改,因此UI会自动更改。

When some element of the query changes, or an element added to the database affects de query, the LivePagedListProvider observables provide a change, so the UI changes automatically.

问题是:我应该如何保存和检索元素

The question is: how should I save and retrieve elements that can be contained in differents lists depending on diferent requests using Paging Library?

推荐答案

如果仅使用一个表来存储以下内容,则可以将它们包含在不同的列表中,具体取决于不同的请求。您收到的数据(来自不同请求到服务器的数据),因此在每次更新此表后,所有DataSource都将失效,因此我们看到了自动更新的原因。对于不同的请求,您可以使用不同的表,但这不是一个好方法)
我认为您可以在一定条件下编写 select查询,这表示您的请求之间存在差异如果这些请求中的结果模型相同,则返回服务器。

If you use only one table for local storage of your received data (from different requests to the server), so after each updating this table, all your DataSources will be invalidated, so thats why we see autoupdating. For different requests you can use different tables, but this is a not good) I think you can write select query with some conditions, which represent difference between you requests to the server, if the result model same in those requests.

这篇关于具有不同PagedLists的分页库和会议室,取决于不同的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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