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

The following are Jave code examples for showing how to use get() 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.
Example 1
Project: TodoRealm   File: ListDetailPresenter.java   Source Code and License Vote up 6 votes
@Override
public void init() {
    RealmResults<TodoList> listResults = todoRepository.queryList(listId);
    list = listResults.get(0);
    view.initViews(list.getTitle());

    bindData();
    list.addChangeListener(new RealmChangeListener<RealmModel>() {
        @Override
        public void onChange(RealmModel element) {
            if (view != null) {
                bindData();
                view.notifyDataChanged(list.getTitle());
            }
        }
    });
}
 
Example 2
Project: TodoRealm   File: TaskDetailPresenter.java   Source Code and License 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: WatchIt   File: NotificationPublisher.java   Source Code and License Vote up 6 votes
private Movie fetchRandomMovieOrTvSeries() {
    Realm realm = Realm.getDefaultInstance();
    //TODO: Add Random TV Series to fetch
    RealmResults<Movie> movieRealmResults = realm.where(Movie.class).equalTo("isNotified", false).findAll();

    Util.debugLog(TAG, "fetchRandomMovieOrTvSeries: Size of movies with isNotified false " + movieRealmResults.size());

    if (movieRealmResults.size() != 0) {

        Random r = new Random();
        int randomNumber = r.nextInt(movieRealmResults.size());

        Movie movie = movieRealmResults.get(randomNumber);

        realm.beginTransaction();
        movieRealmResults.get(randomNumber).setNotified(true);
        realm.commitTransaction();


        return movie;
    } else {
        return null;
    }
}
 
Example 4
Project: LikeGank   File: AndroidPresenter.java   Source Code and License 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 5
Project: LikeGank   File: ImagePresenter.java   Source Code and License 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 6
Project: LikeGank   File: IOSPresenter.java   Source Code and License Vote up 6 votes
private void saveData(List<IOS> data) {//刷新时才调用到
    RealmResults<IOS> all = mRealm.where(IOS.class).findAll();
    if (all.size() > 0) {
        IOS ios = all.get(0);
        if (ios != null) {
            if (!(ios.content).equals(data.get(0).content)) {
                mRealm.executeTransaction(realm -> {
                    items.clear();
                    time2 = "";
                    realm.delete(IOS.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 7
Project: TrackIt-Android   File: Season.java   Source Code and License Vote up 5 votes
private void generateSeasons() {
    try {
        dataLoaded = true;
        seasonList.clear();

        Realm realm = RealmSingleton.getInstance().getRealm();
        RealmResults<RealmEpisode> episodes = realm.where(RealmEpisode.class)
                .equalTo("showID", showID)
                .equalTo("episodeNumber", 1)
                .distinct("seasonNumber")
                .sort("seasonNumber", Sort.DESCENDING);

        for (int i = 0; i < episodes.size(); i++) {
            RealmEpisode temp = episodes.get(i);
            int seasonNumber = temp.getSeasonNumber();
            if (seasonNumber == 0) {
                seasonList.add(new SeasonItem("Specials", temp.getEpisodeID(), seasonNumber));
            } else {
                seasonList.add(new SeasonItem("Season " + seasonNumber, temp.getEpisodeID(), seasonNumber));
            }
        }
        if (episodes.size() != 0) {
            mSeasonFragmentAdapter.notifyDataSetChanged();
        } else {
            tvError.setVisibility(View.VISIBLE);
        }
    } catch (Exception e) {
        Log.e("SeasonFragment", String.valueOf(e));
    }
}
 
Example 8
Project: CurrentActivity   File: CurrentActivity.java   Source Code and License Vote up 5 votes
@NonNull
private String getCurrentActivity(Context context) {
    String packageName = null;
    String activityName = null;
    String applicationName;

    switch (Settings.getString(Settings.Mode.SELECTION, Settings.Mode.NONE)) {
        case Settings.Mode.ROOT:
            String request = SU.getSU().runCommand("dumpsys activity | grep \"mFocusedActivity\"");

            if (!TextUtils.isEmpty(request)) {
                String requests[] = request.split(" ")[3].split("/");

                packageName = requests[0];
                activityName = requests[1].substring(0, 1).equals(".") ? requests[0] + requests[1] : requests[1];
            }
            break;
        case Settings.Mode.ACCESSIBILITY_SERVICE:
            if (AccessibilityServiceUtils.isAccessibilityServiceEnabled(context, CurrentActivityAccessibilityService.class)) {
                packageName = CurrentActivityAccessibilityService.foregroundPackageName();
                activityName = CurrentActivityAccessibilityService.foregroundClassName();
                if (packageName.equals("null") || activityName.equals("null")) return "";
            } else {
                return context.getString(R.string.should_re_enable_accessibility_service);
            }
            break;
    }

    if (packageName != null && activityName != null) {
        applicationName = ApplicationUtil.getApplicationNameByPackageName(context, packageName);
        if (applicationName != null) {
            RealmResults<CurrentActivityData> results = realm.where(CurrentActivityData.class).findAll();
            if (!Objects.equals(packageName, getPackageName())) {
                if (results.isEmpty()) {
                    saveCurrentActivityData(applicationName, packageName, activityName);
                } else {
                    CurrentActivityData lastData = results.get(results.size() - 1);
                    if (!Objects.equals(lastData.getPackageName(), packageName) || !Objects.equals(lastData.getActivityName(), activityName))
                        saveCurrentActivityData(applicationName, packageName, activityName);
                }
            }
            return (applicationName + " ( " + packageName + " )" + "\n" + activityName);
        } else {
            return (packageName + "\n" + activityName);
        }
    } else {
        return context.getString(R.string.failed_to_get);
    }
}
 
Example 9
Project: Ghost-Android   File: AccountManager.java   Source Code and License Vote up 5 votes
public static void deleteBlog(@NonNull String blogUrl) {
    RealmResults<BlogMetadata> matchingBlogs = findAllBlogsMatchingUrl(blogUrl);
    if (matchingBlogs.isEmpty()) {
        throw new IllegalStateException("No blog found matching the URL: " + blogUrl);
    }
    // we don't allow adding more than 1 blog with the same URL, so this should never happen
    if (matchingBlogs.size() > 1) {
        throw new IllegalStateException("More than 1 blog found matching the URL: " + blogUrl);
    }

    // delete blog metadata before data because data without metadata is harmless, but vice-versa is not
    // keep a copy of the metadata around so we can delete the data Realm after this
    final Realm realm = Realm.getDefaultInstance();
    BlogMetadata blogToDelete = matchingBlogs.get(0);
    RealmConfiguration dataRealmToDelete = realm.copyFromRealm(blogToDelete).getDataRealmConfig();
    RealmUtils.executeTransaction(realm, r -> {
        RealmObject.deleteFromRealm(blogToDelete);
    });

    // delete blog data
    Realm.deleteRealm(dataRealmToDelete);

    // if the active blog was deleted, set the active blog to a different one
    if (blogUrl.equals(getActiveBlogUrl())) {
        List<BlogMetadata> allBlogs = getAllBlogs();
        if (!allBlogs.isEmpty()) {
            setActiveBlog(allBlogs.get(0).getBlogUrl());
        } else {
            setActiveBlog("");
        }
    }
}
 
Example 10
Project: SOS-The-Healthcare-Companion   File: DatabaseHandler.java   Source Code and License Vote up 4 votes
public GlucoseReading getLastGlucoseReading() {
    RealmResults<GlucoseReading> results =
            realm.where(GlucoseReading.class)
                    .findAllSorted("created", Sort.DESCENDING);
    return results.get(0);
}