android realm api,Organize Android Realm data in lists

I'm looking into migrating our current app to realm and trying to figure out what's the best way to organize the data into ream. For this question I'll focus on the Photo object of my data model (but there're others).

All my data objects arrive from an API with endpoints such as: getPopular(), getNearbyPhotos(lat, lng), getUserPhotos(userId), getAlbumPhotos(albumId), getCollection(type). On most of those endpoints there're further parameters such as sort=best/chronological.

We're currently use this non-relational DB on the project which allows sorting and retrieving list of objects using only a listName. We use the listName as combination of the endpoit+parameters.

Realm (as a relational DB) uses standard queries, like:

realm.where(User.class)

.contains("name", "Doe")

.findAll();

that works fine when all the data is available locally, but the problem here is that a lot of the data for those queries are kept on the server side and never sent to the client. For example the Photo model does not contain location nor a score for best sorting.

On my current test project, I'm working around that by creating a ListPhoto similar to what our current project uses object as:

public class ListPhoto extends RealmObject {

@PrimaryKey public String id;

public RealmList list;

}

and using the actual API endpoint and parameters as id.So I'm able to find those objects with a simple query

ListPhoto listPhoto = realm

.where(ListPhoto.class)

.equalTo("id", id)

.findFirst();

But with that approach I'm creating an extra layer of abstraction to simply store grouping and ordering metadata, which I'm not happy with and I ask here:

how could I query data on realm based simply on the order and group that it was inserted without using this dirty hack I came up with?

edit:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值