io.realm.Sort Java Examples

The following examples show how to use io.realm.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 vote down vote up
public Observable<List<Member>> getMemberNotAdnim() {
    return Observable.create(new OnSubscribeRealm<List<Member>>() {
        @Override
        public List<Member> get(Realm realm) {
            final RealmResults<Member> realmResults = realm.where(Member.class)
                    .equalTo(Member.TEAM_ID, BizLogic.getTeamId())
                    .equalTo(Member.IS_QUIT, false)
                    .notEqualTo(Member.ROLE, Member.ADMIN)
                    .findAllSorted(Member.ALIAS_PINYIN, Sort.ASCENDING);
            final List<Member> members = new ArrayList<>(realmResults.size());
            for (Member realmResult : realmResults) {
                Member member = new Member();
                copy(member, realmResult);
                members.add(member);
            }
            return members;
        }
    }).subscribeOn(Schedulers.io());
}
 
Example #2
Source File: RealmDataService.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 获取登录列表
 * @return
 */
public Observable<List<LoginHistoryVO>> findLoginHistory() {
    return RealmObservable.object(new Func1<Realm, List<LoginHistoryVO>>() {
        @Override
        public List<LoginHistoryVO> call(Realm realm) {
            List<LoginHistoryVO> list = new ArrayList<LoginHistoryVO>();
            String unitId = O2SDKManager.Companion.instance().prefs().getString(O2.INSTANCE.getPRE_BIND_UNIT_ID_KEY(), "");
            RealmResults<LoginHistoryRealmObject> results = realm.where(LoginHistoryRealmObject.class)
                    .equalTo("unitId", unitId).findAll().sort("lastLoginTime", Sort.DESCENDING);
            if (results != null && !results.isEmpty()) {
                Iterator<LoginHistoryRealmObject> iterator = results.iterator();
                while (iterator.hasNext()) {
                    LoginHistoryRealmObject o = iterator.next();
                    list.add(new LoginHistoryVO(o.getId(), o.getLoginName(),o.getLoginPhone(), o.getLastLoginTime(), o.getUnitId()));
                }
            }
            return list;
        }
    });
}
 
Example #3
Source File: TransactionsRealmCache.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
public Single<Transaction[]> fetchTransaction(Wallet wallet, int maxTransactions, List<Integer> networkFilters) {
       return Single.fromCallable(() -> {
           try (Realm instance = realmManager.getRealmInstance(wallet))
           {
               RealmResults<RealmTransaction> txs = instance.where(RealmTransaction.class)
                       .sort("timeStamp", Sort.DESCENDING)
                       .findAll();
               Log.d(TAG, "Found " + txs.size() + " TX Results");
               return convertCount(txs, maxTransactions, networkFilters);
           }
           catch (Exception e)
           {
               return new Transaction[0];
           }
       });
}
 
Example #4
Source File: WidgetListFactory.java    From WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public RemoteViews getViewAt(int i) {
    RemoteViews remoteViews = new RemoteViews(
            context.getPackageName(), R.layout.item_list_app_widget);
    Realm realm=Realm.getInstance(new RealmConfiguration.Builder()
            .deleteRealmIfMigrationNeeded()
            .name(RealmHelper.DATABASE_NAME)
            .build());
    List<ReadLaterArticleData> list = realm.copyFromRealm(
            realm.where(ReadLaterArticleData.class)
                    .equalTo("userId", userId)
                    .sort("timestamp", Sort.DESCENDING)
                    .findAll());
    ReadLaterArticleData data = list.get(i);
    remoteViews.setTextViewText(R.id.text_view_author,data.getAuthor());
    remoteViews.setTextViewText(R.id.text_view_title, StringUtil.replaceInvalidChar(data.getTitle()));
    Intent intent = new Intent();
    intent.putExtra(DetailActivity.ID, data.getId());
    intent.putExtra(DetailActivity.TITLE, data.getTitle());
    intent.putExtra(DetailActivity.URL, data.getLink());
    intent.putExtra(DetailActivity.FROM_FAVORITE_FRAGMENT, false);
    intent.putExtra(DetailActivity.FROM_BANNER, false);
    remoteViews.setOnClickFillInIntent(R.id.item_main, intent);
    return remoteViews;
}
 
Example #5
Source File: MainActivity.java    From 600SeriesAndroidUploader with MIT License 6 votes vote down vote up
private void startDisplayCgm() {
    Log.d(TAG, "startDisplayCgm");

    displayCgmResults = historyRealm.where(PumpHistoryCGM.class)
            .notEqualTo("sgv", 0)
            .sort("eventDate", Sort.ASCENDING)
            .findAllAsync();

    displayCgmResults.addChangeListener(new OrderedRealmCollectionChangeListener<RealmResults<PumpHistoryCGM>>() {
        @Override
        public void onChange(@NonNull RealmResults realmResults, @NonNull OrderedCollectionChangeSet changeSet) {
            Log.d(TAG, "displayCgmResults triggered size=" + displayCgmResults.size());
            refreshDisplayCgm();
            refreshDisplayChart();
        }
    });
}
 
Example #6
Source File: MainActivity.java    From 600SeriesAndroidUploader with MIT License 6 votes vote down vote up
private void startDisplayChart() {
    Log.d(TAG, "startDisplayChart");
    if (historyRealm == null) return;

    // reset if last chart interaction was over 5 mins
    if (System.currentTimeMillis() - chartChangeTimestamp > 5 * 60000L)
        chartTimeOffset = 0;

    final long timestamp = timeLastSGV == 0 ? System.currentTimeMillis() : timeLastSGV - chartTimeOffset;

    displayChartResults = historyRealm.where(PumpHistoryCGM.class)
            .notEqualTo("sgv", 0)
            .greaterThan("eventDate", new Date(timestamp - 24 * 60 * 60000L))
            .lessThanOrEqualTo("eventDate", new Date(timestamp + 5 * 60000L))
            .sort("eventDate", Sort.ASCENDING)
            .findAllAsync();

    displayChartResults.addChangeListener(new OrderedRealmCollectionChangeListener<RealmResults<PumpHistoryCGM>>() {
        @Override
        public void onChange(@NonNull RealmResults<PumpHistoryCGM> realmResults, @NonNull OrderedCollectionChangeSet changeSet) {
            Log.d(TAG, "displayChartResults triggered size=" + displayChartResults.size());
            updateChart(realmResults, timestamp);
        }
    });
}
 
Example #7
Source File: LogFragment.java    From OpenLibre with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_log_list, container, false);

    // Set the adapter
    if (view instanceof RecyclerView) {
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setAdapter(new LogRecyclerViewAdapter(this,
                mRealmProcessedData
                        .where(ReadingData.class)
                        .isNotEmpty(ReadingData.TREND)
                        .findAllSortedAsync(ReadingData.DATE, Sort.DESCENDING)
        ));
        recyclerView.setHasFixedSize(true);
        recyclerView.addItemDecoration(
                new DividerItemDecoration(this.getContext(), DividerItemDecoration.VERTICAL_LIST)
        );
        registerForContextMenu(recyclerView);
    }
    return view;
}
 
Example #8
Source File: TokensRealmSource.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
public Single<Token[]> fetchTokensWithBalance(Wallet wallet) {
    return Single.fromCallable(() -> {
        try (Realm realm = realmManager.getRealmInstance(wallet))
        {
            RealmResults<RealmToken> realmItems = realm.where(RealmToken.class)
                    .sort("addedTime", Sort.ASCENDING)
                    .findAll();

            return convertMulti(realmItems, System.currentTimeMillis(), wallet, realm);
        }
        catch (Exception e)
        {
            return new Token[0]; //ensure fetch completes
        }
    });
}
 
Example #9
Source File: PumpHistoryHandler.java    From 600SeriesAndroidUploader with MIT License 6 votes vote down vote up
private void systemEventEstimateIsActive() {
    // get the last non-estimated cgm reading
    RealmResults<PumpHistoryCGM> results = historyRealm
            .where(PumpHistoryCGM.class)
            .equalTo("estimate", false)
            .sort("eventDate", Sort.DESCENDING)
            .findAll();
    if (results.size() > 0) {
        Date date = new Date(results.first().getEventDate().getTime() + POLL_PERIOD_MS);
        int rtc = results.first().getCgmRTC() + (int) (POLL_PERIOD_MS / 1000L);
        Log.d(TAG, String.format("Estimate: active start date %s", date));
        systemEvent(PumpHistorySystem.STATUS.ESTIMATE_ACTIVE)
                .key(rtc)
                .start(date)
                .process();
    }
}
 
Example #10
Source File: MessageRealm.java    From talk-android with MIT License 6 votes vote down vote up
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 #11
Source File: MessageRealm.java    From talk-android with MIT License 6 votes vote down vote up
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 #12
Source File: RoomRealm.java    From talk-android with MIT License 6 votes vote down vote up
public Observable<List<Room>> getToJoinRooms() {
    return Observable.create(new OnSubscribeRealm<List<Room>>() {
        @Override
        public List<Room> get(Realm realm) {
            List<Room> rooms = new ArrayList<>();
            RealmResults<Room> realmResults = realm.where(Room.class)
                    .equalTo(Room.TEAM_ID, BizLogic.getTeamId())
                    .equalTo(Room.IS_ARCHIVED, false)
                    .equalTo(Room.IS_QUIT, 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);
            }
            return rooms;
        }
    });
}
 
Example #13
Source File: RoomRealm.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * 查询所有归档的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 #14
Source File: RoomRealm.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * 查询所有不是归档的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 #15
Source File: RoomRealm.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * 查询不是退出,不是归档
 *
 * @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 #16
Source File: RoomRealm.java    From talk-android with MIT License 6 votes vote down vote up
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 #17
Source File: MemberRealm.java    From talk-android with MIT License 6 votes vote down vote up
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 #18
Source File: MemberRealm.java    From talk-android with MIT License 6 votes vote down vote up
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 #19
Source File: MemberRealm.java    From talk-android with MIT License 6 votes vote down vote up
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 #20
Source File: RealmRoomMessage.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static RealmResults<RealmRoomMessage> filterMessage(Realm realm, long roomId, ProtoGlobal.RoomMessageType messageType) {
    RealmResults<RealmRoomMessage> results;
    if (messageType == ProtoGlobal.RoomMessageType.TEXT) {
        results = realm.where(RealmRoomMessage.class).
                equalTo(RealmRoomMessageFields.ROOM_ID, roomId).
                equalTo(RealmRoomMessageFields.MESSAGE_TYPE, messageType.toString()).
                equalTo(RealmRoomMessageFields.DELETED, false).
                equalTo(RealmRoomMessageFields.HAS_MESSAGE_LINK, true).
                findAll().sort(RealmRoomMessageFields.UPDATE_TIME, Sort.DESCENDING);
    } else {
        //TODO [Saeed Mozaffari] [2017-10-28 9:59 AM] - Can Write Better Code?
        results = realm.where(RealmRoomMessage.class).
                equalTo(RealmRoomMessageFields.ROOM_ID, roomId).
                in(RealmRoomMessageFields.MESSAGE_TYPE, new String[]{messageType.toString(), messageType.toString() + "_TEXT"}).
                equalTo(RealmRoomMessageFields.DELETED, false).
                findAll().sort(RealmRoomMessageFields.UPDATE_TIME, Sort.DESCENDING);
    }
    return results;
}
 
Example #21
Source File: RealmRoomMessage.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void fetchNotDeliveredMessages(final OnActivityMainStart callback) {
    // if client get message and before send status lost connection, will be need to this method
    // and this step is very uncommon so don't need to do this action and get performance,if client
    // needed this method will be used in ActivityMain later
    final Realm realm = Realm.getDefaultInstance();
    RealmResults<RealmRoomMessage> sentMessages = realm.where(RealmRoomMessage.class).notEqualTo(RealmRoomMessageFields.USER_ID, G.userId).equalTo(RealmRoomMessageFields.STATUS, ProtoGlobal.RoomMessageStatus.SENT.toString()).findAllAsync().sort(new String[]{RealmRoomMessageFields.ROOM_ID, RealmRoomMessageFields.MESSAGE_ID}, new Sort[]{Sort.DESCENDING, Sort.ASCENDING});
    sentMessages.addChangeListener(new RealmChangeListener<RealmResults<RealmRoomMessage>>() {
        @Override
        public void onChange(RealmResults<RealmRoomMessage> element) {
            for (RealmRoomMessage roomMessage : element) {
                if (roomMessage == null) {
                    return;
                }
                final RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomMessage.getRoomId()).findFirst();
                if (realmRoom == null) {
                    return;
                }

                callback.sendDeliveredStatus(realmRoom, roomMessage);
            }

            element.removeAllChangeListeners();
            realm.close();
        }
    });
}
 
Example #22
Source File: MemberRealm.java    From talk-android with MIT License 6 votes vote down vote up
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 #23
Source File: NotificationRealm.java    From talk-android with MIT License 6 votes vote down vote up
public Observable<List<Notification>> getNotPinnedNotification() {
    return Observable.create(new OnSubscribeRealm<List<Notification>>() {
        @Override
        public List<Notification> get(Realm realm) {
            RealmResults<Notification> realmResults = realm.where(Notification.class)
                    .equalTo(Notification.TEAM_ID, BizLogic.getTeamId())
                    .notEqualTo(Notification.IS_PINNED, true)
                    .findAllSorted(Notification.UPDATED_AT, Sort.DESCENDING);
            List<Notification> notifications = new ArrayList<>(realmResults.size());
            for (Notification realmResult : realmResults) {
                Notification notification = new Notification();
                copy(notification, realmResult);
                copyObject(notification, realmResult);
                notifications.add(notification);
            }
            return notifications;
        }
    });
}
 
Example #24
Source File: NotificationRealm.java    From talk-android with MIT License 6 votes vote down vote up
public Observable<List<Notification>> getPinnedNotification() {
    return Observable.create(new OnSubscribeRealm<List<Notification>>() {
        @Override
        public List<Notification> get(Realm realm) {
            RealmResults<Notification> realmResults = realm.where(Notification.class)
                    .equalTo(Notification.TEAM_ID, BizLogic.getTeamId())
                    .equalTo(Notification.IS_PINNED, true)
                    .findAllSorted(Notification.UPDATED_AT, Sort.DESCENDING);
            List<Notification> notifications = new ArrayList<>(realmResults.size());
            for (Notification realmResult : realmResults) {
                Notification notification = new Notification();
                copy(notification, realmResult);
                copyObject(notification, realmResult);
                notifications.add(notification);
            }
            return notifications;
        }
    }).subscribeOn(Schedulers.io());
}
 
Example #25
Source File: NotificationRealm.java    From talk-android with MIT License 6 votes vote down vote up
public Observable<List<Notification>> getNotifications(final int count) {
    return Observable.create(new OnSubscribeRealm<List<Notification>>() {
        @Override
        public List<Notification> get(Realm realm) {
            RealmResults<Notification> realmResults = realm.where(Notification.class)
                    .equalTo(Notification.TEAM_ID, BizLogic.getTeamId())
                    .findAll();
            realmResults.sort(Notification.UPDATED_AT, Sort.DESCENDING);
            List<Notification> notifications = new ArrayList<>(realmResults.size());
            int currCount = 0;
            for (Notification realmResult : realmResults) {
                currCount++;
                Notification notification = new Notification();
                copy(notification, realmResult);
                notifications.add(notification);
                if (currCount >= count) {
                    break;
                }
            }
            return notifications;
        }
    }).subscribeOn(Schedulers.io());
}
 
Example #26
Source File: MemberRealm.java    From talk-android with MIT License 6 votes vote down vote up
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 #27
Source File: FragmentiGapMap.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
private void downloadMarkerAvatar(Realm realm, long userId) {
    for (RealmAvatar avatar : realm.where(RealmAvatar.class).equalTo(RealmAvatarFields.OWNER_ID, userId).findAll().sort(RealmAvatarFields.ID, Sort.DESCENDING)) {
        if (avatar.getFile() != null) {
            String pathName = avatar.getFile().getLocalFilePath();
            if (pathName == null) {
                pathName = avatar.getFile().getLocalThumbnailPath();
                if (pathName == null) {
                    HelperAvatar.getAvatar(G.userId, HelperAvatar.AvatarType.USER, false, new OnAvatarGet() {
                        @Override
                        public void onAvatarGet(String avatarPath, long roomId) {
                        }

                        @Override
                        public void onShowInitials(String initials, String color) {
                        }
                    });
                }
            }
            break;
        }
    }

}
 
Example #28
Source File: StatusNotification.java    From 600SeriesAndroidUploader with MIT License 5 votes vote down vote up
private String cgm() {

        RealmResults<PumpStatusEvent> results = pumpStatusEventRealmResults.where()
                .greaterThan("eventDate", new Date(currentTime - 15 * 60000L))
                .equalTo("cgmActive", true)
                .sort("eventDate", Sort.DESCENDING)
                .findAll();

        if (results.size() > 0) {

            PumpHistoryParser.CGM_EXCEPTION cgmException;
            if (results.first().isCgmException())
                cgmException = PumpHistoryParser.CGM_EXCEPTION.convert(
                        pumpStatusEventRealmResults.first().getCgmExceptionType());
            else if (results.first().isCgmCalibrating())
                cgmException = PumpHistoryParser.CGM_EXCEPTION.SENSOR_CAL_PENDING;
            else
                cgmException = PumpHistoryParser.CGM_EXCEPTION.NA;

            switch (cgmException) {
                case NA:
                    return String.format(
                            FormatKit.getInstance().getString(R.string.notification__CAL_remainingtime),
                            FormatKit.getInstance().formatMinutesAsHM(results.first().getCalibrationDueMinutes()));
                case SENSOR_INIT:
                    return String.format(
                            FormatKit.getInstance().getString(R.string.notification__WARMUP_remainingtime),
                            FormatKit.getInstance().formatMinutesAsHM(results.first().getCalibrationDueMinutes()));
                default:
                    return String.format(
                            FormatKit.getInstance().getString(R.string.notification__CGM_EXCEPTION),
                            cgmException.string());
            }
        }

        return "";
    }
 
Example #29
Source File: UrchinService.java    From 600SeriesAndroidUploader with MIT License 5 votes vote down vote up
private String estimate() {
    if (dataStore.isSysEnableEstimateSGV()) {
        RealmResults<PumpHistoryCGM> cgmResults = historyRealm
                .where(PumpHistoryCGM.class)
                .sort("eventDate", Sort.DESCENDING)
                .findAll();
        if (cgmResults.size() > 0 && cgmResults.first().isEstimate())
            return FormatKit.getInstance().getString(R.string.urchin_watchface_Estimate);
    }
    return "";
}
 
Example #30
Source File: HistoryPresenter.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void getHistory() {
    if (realm.isClosed()) {
        return;
    }
    view.setRefreshing(true);
    RealmResults<HistoryItemBd> results = realm
            .where(HistoryItemBd.class)
            .findAllSorted("unixTime", Sort.DESCENDING);
    view.showHistory(results);
    view.setRefreshing(false);
}