Java Code Examples for io.realm.RealmResults.size()

The following are Jave code examples for showing how to use size() of the io.realm.RealmResults class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: ExampleActivity.java   View Source Code Vote up 6 votes
private String complexQuery() {
    String status = "\n\nPerforming complex Query operation...";

    Realm realm = Realm.getDefaultInstance();
    status += "\nNumber of people in the DB: " + realm.where(Person.class).count();

    // Find all persons where age between 1 and 99 and name begins with "J".
    RealmResults<Person> results = realm.where(Person.class)
            .between("age", 1, 99)       // Notice implicit "and" operation
            .beginsWith("name", "J")
            .findAll();
    status += "\nNumber of people aged between 1 and 99 who's name start with 'J': " + results.size();

    realm.close();
    return status;
}
 
Example 2
Project: TodoRealm   File: TaskDetailPresenter.java   View Source Code Vote up 6 votes
@Override
public void init(long taskId) {
    RealmResults<Task> taskResults = repository.queryTask(taskId);
    if (taskResults.size() > 0) {
        task = taskResults.get(0);
    }
    task.addChangeListener(new RealmChangeListener<RealmModel>() {
        @Override
        public void onChange(RealmModel element) {
            task.getId();
            view.updateViews(task);
        }
    });
    view.initViews();
    view.updateViews(task);
}
 
Example 3
Project: RealmTasks   File: TaskActivity.java   View Source Code Vote up 6 votes
private void updateList(RealmResults<TaskList> results)
{
    // Use `findAllAsync` because change listeners are not called when items are deleted and using `findFirst()`
    // See https://github.com/realm/realm-java/issues/3138
    if (results.size() > 0)
    {
        TaskList element = results.first();
        setTitle(element.getText());
        if (adapter == null)
        {
            adapter = new TaskAdapter(TaskActivity.this, element.getItems());
            touchHelper = new TouchHelper(new Callback(), adapter);
            touchHelper.attachToRecyclerView(recyclerView);
        }
    }
    else
    {
        setTitle(getString(R.string.title_deleted));
    }
}
 
Example 4
Project: underlx   File: Trip.java   View Source Code Vote up 6 votes
public static RealmResults<Trip> getMissingConfirmTrips(Realm realm) {
    RealmResults<StationUse> uses = realm.where(StationUse.class)
            .greaterThan("entryDate", new Date(new Date().getTime() - TimeUnit.DAYS.toMillis(7))).findAll().where()
            .equalTo("type", "NETWORK_ENTRY").or().equalTo("type", "VISIT").findAll();

    // now we have all station uses that **might** be part of editable trips
    // get all trips that contain these uses and which are yet to be confirmed
    RealmQuery<Trip> tripsQuery = realm.where(Trip.class);
    if (uses.size() > 0) {
        // first item detached from the others because otherwise "Missing left-hand side of OR" might happen
        // https://github.com/realm/realm-java/issues/1014#issuecomment-107235374
        tripsQuery = tripsQuery.equalTo("userConfirmed", false).equalTo("path.station.id", uses.get(0).getStation().getId()).equalTo("path.entryDate", uses.get(0).getEntryDate());
        for (int i = 1; i < uses.size(); i++) {
            tripsQuery = tripsQuery.or().equalTo("userConfirmed", false).equalTo("path.station.id", uses.get(i).getStation().getId()).equalTo("path.entryDate", uses.get(i).getEntryDate());
        }
        return tripsQuery.findAll();
    } else {
        // realm is just terrible. not only is it hard to do a proper WHERE ... IN ... query, it's also hard to generate an empty result set.
        // https://github.com/realm/realm-java/issues/1862
        // https://github.com/realm/realm-java/issues/1575
        // https://github.com/realm/realm-java/issues/4011
        return tripsQuery.equalTo("id", "NEVER_BE_TRUE").findAll();
    }
}
 
Example 5
Project: Neuronizer   File: PreviewRepositoryImpl.java   View Source Code Vote up 6 votes
@Override
public Iterable<Preview> getAll(ItemsPerPreview itemsPerPreview) {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<TodoListDAO> allTodoListDAO = realm.where(TodoListDAO.class).findAllSorted("position", Sort.DESCENDING);
    RealmResults<NoteDAO> allNoteDAO = realm.where(NoteDAO.class).findAllSorted("position", Sort.DESCENDING);

    List<Preview> previews = new ArrayList<>(allTodoListDAO.size() + allNoteDAO.size());

    for (TodoListDAO todoListDAO : allTodoListDAO) {
        previews.add(constructPreview(realm, todoListDAO, itemsPerPreview));
    }
    for (NoteDAO noteDAO : allNoteDAO) {
        previews.add(new NotePreview(RealmConverter.convert(noteDAO)));
    }
    realm.close();
    return previews;
}
 
Example 6
Project: LikeGank   File: ImagePresenter.java   View Source Code Vote up 6 votes
private void saveData(List<Content> data) {
    RealmResults<Content> all = mRealm.where(Content.class).findAll();
    if (all.size() > 0) {
        Content content = all.get(0);
        if (content != null) {
            if (!(content.content).equals(data.get(0).content)) {
                mRealm.executeTransaction(realm -> {
                    realm.delete(Android.class);
                    mList.clear();
                    mList.addAll(data);
                    realm.copyToRealmOrUpdate(data);
                });
            } else {//数据一样不保存,同时不做 Adapter 刷新
                mPage = mPageIndex;
                AppUtils.toast(R.string.tip_no_new_data);
                mView.hideLoading();
            }
        }
    } else {
        mList.addAll(data);
        mRealm.executeTransaction(realm -> realm.copyToRealmOrUpdate(data));//第一次进入应用时
    }
}
 
Example 7
Project: LikeGank   File: AndroidPresenter.java   View Source Code Vote up 6 votes
private void saveData(List<Android> data) {//刷新时才调用到
    RealmResults<Android> all = mRealm.where(Android.class).findAll();
    if (all.size() > 0) {
        Android android = all.get(0);
        if (android != null) {
            if (!(android.content).equals(data.get(0).content)) {
                mRealm.executeTransaction(realm -> {
                    items.clear();
                    time2 = "";
                    realm.delete(Android.class);
                    realm.copyToRealmOrUpdate(data);
                });
            } else {//数据一样不保存,同时不做 Adapter 刷新
                mPage = mPageIndex;
                AppUtils.toast(R.string.tip_no_new_data);
                mView.hideLoading();
            }
        }
    } else {
        mRealm.executeTransaction(realm -> realm.copyToRealmOrUpdate(data));
    }
}
 
Example 8
Project: OpenLibre   File: SensorStatusFragment.java   View Source Code Vote up 5 votes
public void setupUi(View view) {
    Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
    RealmResults<SensorData> sensorDataResults = realmProcessedData.where(SensorData.class).
            findAllSorted(START_DATE, Sort.DESCENDING);

    TextView sensorId = (TextView) view.findViewById(R.id.tv_sensor_id_value);
    TextView sensorStartDate = (TextView) view.findViewById(R.id.tv_sensor_start_date_value);
    TextView sensorEndsIn = (TextView) view.findViewById(R.id.tv_sensor_ends_in_value);

    if (sensorDataResults.size() == 0) {
        sensorId.setText(getResources().getString(R.string.no_sensor_registered));
        sensorStartDate.setText("");
        sensorEndsIn.setText("");
    } else {
        SensorData sensorData = sensorDataResults.first();
        sensorId.setText(sensorData.getTagId());
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
        sensorStartDate.setText(dateFormat.format(new Date(sensorData.getStartDate())));
        long timeLeft = sensorData.getTimeLeft();
        if (timeLeft >= TimeUnit.MINUTES.toMillis(1L)) {
            sensorEndsIn.setText(getDurationBreakdown(getResources(), sensorData.getTimeLeft()));
        } else {
            sensorEndsIn.setText(getResources().getString(R.string.sensor_expired));
        }
    }
    realmProcessedData.close();
}
 
Example 9
Project: Neuronizer   File: TodoListRepositoryImpl.java   View Source Code Vote up 5 votes
@Override
public List<TodoList> getAll() {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<TodoListDAO> todoListDAOs = realm.where(TodoListDAO.class).findAll();
    List<TodoList> todoLists = new ArrayList<>(todoListDAOs.size());
    for (TodoListDAO dao : todoListDAOs) {
        todoLists.add(RealmConverter.convert(dao));
    }
    realm.close();
    return todoLists;
}
 
Example 10
Project: simple-stack   File: TaskRepository.java   View Source Code Vote up 5 votes
private List<Task> mapFrom(RealmResults<DbTask> dbTasks) {
    List<Task> tasks = new ArrayList<>(dbTasks.size());
    for(DbTask dbTask : dbTasks) {
        tasks.add(taskMapper.fromRealm(dbTask));
    }
    return tasks;
}
 
Example 11
Project: RealmTasks   File: TaskListActivity.java   View Source Code Vote up 5 votes
private void updateList(RealmResults<TaskListList> results)
{
    if (results.size() > 0 && adapter == null)
    {
        // The default list is being added on all devices, so according to the merge rules the default list might
        // be added multiple times. This is just a temporary fix. Proper ordered sets are being tracked here:
        // https://github.com/realm/realm-core/issues/1206
        realm.beginTransaction();
        Set<String> seen = new HashSet<>();
        Iterator<TaskList> it = results.first().getItems().iterator();
        while (it.hasNext())
        {
            TaskList list = it.next();
            String id = list.getId();
            if (seen.contains(id))
            {
                it.remove();
            }
            seen.add(id);
        }
        realm.commitTransaction();

        // Create Adapter
        adapter = new TaskListAdapter(TaskListActivity.this, results.first().getItems());
        touchHelper = new TouchHelper(new Callback(), adapter);
        touchHelper.attachToRecyclerView(recyclerView);
    }
}
 
Example 12
Project: SOS-The-Healthcare-Companion   File: DatabaseHandler.java   View Source Code Vote up 5 votes
public ArrayList<CholesterolReading> getCholesterolReadings() {
    RealmResults<CholesterolReading> results =
            realm.where(CholesterolReading.class)
                    .findAllSorted("created", Sort.DESCENDING);
    ArrayList<CholesterolReading> readingList = new ArrayList<>();
    for (int i = 0; i < results.size(); i++) {
        readingList.add(results.get(i));
    }
    return readingList;
}
 
Example 13
Project: simple-stack   File: TaskRepository.java   View Source Code Vote up 5 votes
private List<Task> mapFrom(RealmResults<DbTask> dbTasks) {
    List<Task> tasks = new ArrayList<>(dbTasks.size());
    for(DbTask dbTask : dbTasks) {
        tasks.add(taskMapper.fromRealm(dbTask));
    }
    return tasks;
}
 
Example 14
Project: Ghost-Android   File: NetworkService.java   View Source Code Vote up 5 votes
@Subscribe
public void onLoadTagsEvent(LoadTagsEvent event) {
    RealmResults<Tag> tags = mRealm.where(Tag.class).findAllSorted("name");
    List<Tag> tagsCopy = new ArrayList<>(tags.size());
    for (Tag tag : tags) {
        tagsCopy.add(new Tag(tag.getName()));
    }
    getBus().post(new TagsLoadedEvent(tagsCopy));
}
 
Example 15
Project: SOS-The-Healthcare-Companion   File: DatabaseHandler.java   View Source Code Vote up 5 votes
public List<Reminder> getReminders() {
    RealmResults<Reminder> results =
            realm.where(Reminder.class)
                    .findAllSorted("alarmTime", Sort.DESCENDING);
    List<Reminder> reminders = new ArrayList<>(results.size());
    for (int i = 0; i < results.size(); i++) {
        reminders.add(results.get(i));
    }
    return reminders;
}
 
Example 16
Project: SOS-The-Healthcare-Companion   File: DatabaseHandler.java   View Source Code Vote up 5 votes
public ArrayList<GlucoseReading> getGlucoseReadings(Date from, Date to) {
    RealmResults<GlucoseReading> results =
            realm.where(GlucoseReading.class)
                    .between("created", from, to)
                    .findAllSorted("created", Sort.DESCENDING);
    ArrayList<GlucoseReading> readingList = new ArrayList<>();
    for (int i = 0; i < results.size(); i++) {
        readingList.add(results.get(i));
    }
    return readingList;
}
 
Example 17
Project: SOS-The-Healthcare-Companion   File: DatabaseHandler.java   View Source Code Vote up 5 votes
public ArrayList<KetoneReading> getKetoneReadings() {
    RealmResults<KetoneReading> results =
            realm.where(KetoneReading.class)
                    .findAllSorted("created", Sort.DESCENDING);
    ArrayList<KetoneReading> readingList = new ArrayList<>();
    for (int i = 0; i < results.size(); i++) {
        readingList.add(results.get(i));
    }
    return readingList;
}
 
Example 18
Project: SOS-The-Healthcare-Companion   File: DatabaseHandler.java   View Source Code Vote up 5 votes
public ArrayList<PressureReading> getPressureReadings() {
    RealmResults<PressureReading> results =
            realm.where(PressureReading.class)
                    .findAllSorted("created", Sort.DESCENDING);
    ArrayList<PressureReading> readingList = new ArrayList<>();
    for (int i = 0; i < results.size(); i++) {
        readingList.add(results.get(i));
    }
    return readingList;
}
 
Example 19
Project: TrackIt-Android   File: SeasonFragmentAdapter.java   View Source Code Vote up 4 votes
@Override
public void onBindViewHolder(final SeasonFragmentAdapter.ViewHolder holder, int position) {

    if (position == 0) {
        totalSeasons = itemsData.get(position).getSeasonNumber();
    }
    holder.seasonNumber.setText(itemsData.get(position).getSeasonTitle());

    Realm realm = RealmSingleton.getInstance().getRealm();
    RealmResults<RealmEpisode> episodes = realm.where(RealmEpisode.class)
            .equalTo("showID", showID)
            .equalTo("seasonNumber", itemsData.get(position).getSeasonNumber())
            .findAll();

    int totalEpisodes = episodes.size();
    int watchedEpisodes = episodes.where()
            .equalTo("watched", true)
            .findAll()
            .size();
    int collectedEpisodes = episodes.where()
            .equalTo("collection", true)
            .findAll()
            .size();
    int aired = episodes.where()
            .lessThanOrEqualTo("airDateTime", cal.getTimeInMillis())
            .findAll()
            .size();

    String watched;
    if (totalEpisodes == aired) {
        watched = watchedEpisodes + "/" + aired;
    } else {
        watched = watchedEpisodes + "/" + aired + " (+" + (totalEpisodes - aired) + " unaired)";
    }
    holder.watchedTextview.setText(watched);
    String collection = "(Collected: " + collectedEpisodes + ")";
    holder.collectionTextview.setText(collection);

    double percent = ((double) watchedEpisodes / aired) * 100;
    holder.squareProgressBar.setProgress(percent);

    holder.mView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent myIntent = new Intent(App.getInstance(), EpisodeDetail.class);
            myIntent.putExtra("episode_id", itemsData.get(holder.getAdapterPosition()).getEpisode());
            myIntent.putExtra("show_title", showTitle);
            myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            App.getInstance().startActivity(myIntent);
        }
    });
}
 
Example 20
Project: pracler   File: LocalHistoryManager.java   View Source Code Vote up 4 votes
public int getHistoryCount()
{
    final RealmResults<LocalPlayHistory> results = realm.where(LocalPlayHistory.class).findAll();
    Log.e("realm_test", results.size() + "");
    return results.size();
}