public List<Meizi.ResultsBean> loadDataFromDB() { List<Meizi.ResultsBean> list = new ArrayList<>(); RealmResults<MeiziRealmEntity> results = realm.where(MeiziRealmEntity.class).findAllSorted("publishedAt", Sort.DESCENDING); for (MeiziRealmEntity entity : results) { Meizi.ResultsBean temp = new Meizi.ResultsBean(); temp.setUrl(entity.getUrl()); temp.setHeight(entity.getHeight()); temp.setWidth(entity.getWidth()); temp.setPublishedAt(entity.getPublishedAt()); list.add(temp); } if (list.size() >= 30) { return list.subList(0, 29); } else { return list; } }
private MeiziRealmEntity convert2Realm(Meizi.ResultsBean resultsBean) { MeiziRealmEntity realmEntity = new MeiziRealmEntity(); realmEntity.set_id(resultsBean.get_id()); realmEntity.setCreatedAt(resultsBean.getCreatedAt()); realmEntity.setDesc(resultsBean.getDesc()); realmEntity.setPublishedAt(resultsBean.getPublishedAt()); realmEntity.setUrl(resultsBean.getUrl()); realmEntity.setWidth(resultsBean.getWidth()); realmEntity.setHeight(resultsBean.getHeight()); return realmEntity; }