Java Code Examples for io.realm.RealmResults#sort()
The following examples show how to use
io.realm.RealmResults#sort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemberRealm.java From talk-android with MIT License | 6 votes |
public List<Member> getMemberWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, false) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
Example 2
Source File: MainActivity.java From JalanJalan with Do What The F*ck You Want To Public License | 6 votes |
private void readDataFromDb() { if (locationModels.size() > 0) locationModels.clear(); RealmResults<LocationModel> result = realm .where(LocationModel.class) .findAll(); // sortiny by id. // show greater first result.sort("id", RealmResults.SORT_ORDER_DESCENDING); for (LocationModel data : result) { Log.d("tag", "datanya " + data.getId()); locationModels.add(data); } // notify adapter adapterRoute.notifyDataSetChanged(); // update view updateView(); }
Example 3
Source File: MessageRealm.java From talk-android with MIT License | 6 votes |
public List<Message> getLocalUnreadMessagesWithCurrentThread(final String foreignId) { List<Message> messages = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Message> realmResults = realm.where(Message.class) .equalTo(Message.TEAM_ID, BizLogic.getTeamId()) .equalTo(Message.FOREIGN_ID, foreignId) .equalTo(Message.IS_READ, false) .findAll(); realmResults.sort(Message.CREATE_AT_TIME, Sort.ASCENDING); for (Message realmResult : realmResults) { Message message = new Message(); copy(message, realmResult); messages.add(message); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return messages; }
Example 4
Source File: MessageRealm.java From talk-android with MIT License | 6 votes |
public List<Message> getUnSendMessageWithCurrentThread(final String foreignId) { final List<Message> messages = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Message> realmResults = realm.where(Message.class) .equalTo(Message.TEAM_ID, BizLogic.getTeamId()) .equalTo(Message.FOREIGN_ID, foreignId) .notEqualTo(Message.STATUS, 0) .findAll(); realmResults.sort(Message.CREATE_AT_TIME, Sort.ASCENDING); for (Message realmResult : realmResults) { final Message message = new Message(); copy(message, realmResult); messages.add(message); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return messages; }
Example 5
Source File: RoomRealm.java From talk-android with MIT License | 6 votes |
/** * 查询所有归档的Room * * @return 查询到的所有数据 */ public List<Room> getRoomOnArchivedWithCurrentThread() { List<Room> rooms = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .equalTo(Room.IS_ARCHIVED, true) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return rooms; }
Example 6
Source File: RoomRealm.java From talk-android with MIT License | 6 votes |
/** * 查询所有不是归档的Room * * @return 查询到的所有数据 */ public List<Room> getRoomOnNotArchivedWithCurrentThread() { List<Room> rooms = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .equalTo(Room.IS_ARCHIVED, false) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return rooms; }
Example 7
Source File: RoomRealm.java From talk-android with MIT License | 6 votes |
/** * 查询不是退出,不是归档 * * @return 查询到的所有数据 */ public List<Room> getRoomOnNotQuitOnNotArchivedWithCurrentThread() { final List<Room> rooms = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .equalTo(Room.IS_QUIT, false) .equalTo(Room.IS_ARCHIVED, false) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return rooms; }
Example 8
Source File: RoomRealm.java From talk-android with MIT License | 6 votes |
public List<Room> getRoomWithCurrentThread() { final List<Room> rooms = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return rooms; }
Example 9
Source File: MemberRealm.java From talk-android with MIT License | 6 votes |
public List<Member> getNotRobotMemberWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_ROBOT, false) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
Example 10
Source File: MemberRealm.java From talk-android with MIT License | 6 votes |
public List<Member> getNotQuitAndNotRobotMemberWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, false) .equalTo(Member.IS_ROBOT, false) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
Example 11
Source File: MemberRealm.java From talk-android with MIT License | 6 votes |
public List<Member> getAllMemberExceptMeWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, false) .notEqualTo(Member.ID, BizLogic.getUserInfo().get_id()) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
Example 12
Source File: MemberRealm.java From talk-android with MIT License | 6 votes |
public List<Member> getQuitMemberWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, true) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
Example 13
Source File: MemberRealm.java From talk-android with MIT License | 5 votes |
public List<Member> getAdminsMemberWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); final RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .beginGroup() .equalTo(Member.ROLE, Member.ADMIN) .or() .equalTo(Member.ROLE, Member.OWNER) .endGroup() .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmMember : realmResults) { Member member = new Member(); copy(member, realmMember); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
Example 14
Source File: RealmUtility.java From Loop with Apache License 2.0 | 5 votes |
public static List<String> getSuggestions(String query) { List<String> suggestions = new ArrayList<>(); Realm realm = Realm.getDefaultInstance(); try { RealmResults<RealmSuggestion> realmResults = realm.where(RealmSuggestion.class) .contains("token", query) .findAll(); realmResults = realmResults.sort("timestamp", Sort.DESCENDING); if (realmResults != null) { int size = (realmResults.size() > 5) ? 5 : realmResults.size(); for (int i = 0; i < size; i++) { RealmSuggestion realmSuggestion = realmResults.get(i); if (realmSuggestion != null) { String token = realmSuggestion.getToken(); if (!TextUtils.isEmpty(token)) { suggestions.add(suggestions.size(), token); } } } } } finally { realm.close(); } return suggestions; }
Example 15
Source File: DatabaseRealm.java From openwebnet-android with MIT License | 5 votes |
public <T extends RealmObject> List<T> findCopyWhere(Class<T> clazz, String field, Integer value, String orderBy) { RealmResults<T> results = query(clazz).equalTo(field, value).findAll(); if (orderBy != null) { results.sort(orderBy, Sort.ASCENDING); } return getRealmInstance().copyFromRealm(results); }
Example 16
Source File: DatabaseRealm.java From openwebnet-android with MIT License | 5 votes |
public <T extends RealmObject> List<T> findCopyWhere(Class<T> clazz, String field, Boolean value, String orderBy) { RealmResults<T> results = query(clazz).equalTo(field, value).findAll(); if (orderBy != null) { results.sort(orderBy, Sort.ASCENDING); } return getRealmInstance().copyFromRealm(results); }
Example 17
Source File: DatabaseRealm.java From openwebnet-android with MIT License | 4 votes |
public <T extends RealmObject> List<T> findSortedAscending(Class<T> clazz, String field) { RealmResults<T> results = query(clazz).findAll(); results.sort(field, Sort.ASCENDING); return results; }
Example 18
Source File: Carb.java From HAPP with GNU General Public License v3.0 | 4 votes |
public static JSONObject getCOB(Profile p, Date t, Realm realm){ Date now = new Date(); RealmResults<Carb> carbsRecent = getCarbsBetween(new Date(now.getTime() - (24 * 60 * 60 * 1000)) , now, realm); //Past 24 hours of carbs carbsRecent = carbsRecent.sort("timestamp", Sort.ASCENDING); //Sort the Treatments from oldest to newest return cob.cobTotal(carbsRecent, p, t, realm); }
Example 19
Source File: Carb.java From HAPP with GNU General Public License v3.0 | 4 votes |
public static JSONObject getCOBBetween(Profile p, Date from, Date to, Realm realm){ RealmResults<Carb> carbs = getCarbsBetween(from , to, realm); //Past 24 hours of carbs carbs = carbs.sort("timestamp", Sort.ASCENDING); //Sort the Treatments from oldest to newest return cob.cobTotal(carbs, p, new Date(), realm); }