Search in sources :

Example 1 with User

use of com.kboyarshinov.realmrxjavaexample.model.User in project realm-rxjava-example by kboyarshinov.

the class MainActivity method requestWithFlatMap.

private void requestWithFlatMap() {
    if (compositeSubscription == null) {
        return;
    }
    Subscription subscription = dataService.findUser("kboyarshinov").flatMap(new Func1<User, Observable<List<Issue>>>() {

        @Override
        public Observable<List<Issue>> call(User user) {
            return dataService.issuesListByUser(user);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Issue>>() {

        @Override
        public void call(List<Issue> issues) {
            Log.d(TAG, "Issues by user received with size " + issues.size());
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            Log.e(TAG, "Request issues by user error", throwable);
        }
    });
    compositeSubscription.add(subscription);
}
Also used : User(com.kboyarshinov.realmrxjavaexample.model.User) Issue(com.kboyarshinov.realmrxjavaexample.model.Issue) ArrayList(java.util.ArrayList) List(java.util.List) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 2 with User

use of com.kboyarshinov.realmrxjavaexample.model.User in project realm-rxjava-example by kboyarshinov.

the class MainActivity method addNewIssue.

private void addNewIssue() {
    if (compositeSubscription == null) {
        return;
    }
    String title = "Feature request: removing issues";
    String body = "Add function to remove issues";
    User user = new User("kboyarshinov");
    List<Label> labels = new ArrayList<>();
    labels.add(new Label("feature", "FF5722"));
    Subscription subscription = dataService.newIssue(title, body, user, labels).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Action1<Issue>() {

        @Override
        public void call(Issue issue) {
            Log.d(TAG, "Issue with title " + issue.getTitle() + " successfully saved");
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            Log.e(TAG, "Add new issue error", throwable);
        }
    });
    compositeSubscription.add(subscription);
}
Also used : User(com.kboyarshinov.realmrxjavaexample.model.User) Issue(com.kboyarshinov.realmrxjavaexample.model.Issue) ArrayList(java.util.ArrayList) Label(com.kboyarshinov.realmrxjavaexample.model.Label) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 3 with User

use of com.kboyarshinov.realmrxjavaexample.model.User in project realm-rxjava-example by kboyarshinov.

the class RealmDataService method issueFromRealm.

private static Issue issueFromRealm(RealmIssue realmIssue) {
    final String title = realmIssue.getTitle();
    final String body = realmIssue.getBody();
    final User user = userFromRealm(realmIssue.getUser());
    final RealmList<RealmLabel> realmLabels = realmIssue.getLabels();
    final List<Label> labels = new ArrayList<>(realmLabels.size());
    for (RealmLabel realmLabel : realmLabels) {
        labels.add(labelFromRealm(realmLabel));
    }
    return new Issue(title, body, user, labels);
}
Also used : RealmLabel(com.kboyarshinov.realmrxjavaexample.model.RealmLabel) RealmUser(com.kboyarshinov.realmrxjavaexample.model.RealmUser) User(com.kboyarshinov.realmrxjavaexample.model.User) Issue(com.kboyarshinov.realmrxjavaexample.model.Issue) RealmIssue(com.kboyarshinov.realmrxjavaexample.model.RealmIssue) ArrayList(java.util.ArrayList) RealmLabel(com.kboyarshinov.realmrxjavaexample.model.RealmLabel) Label(com.kboyarshinov.realmrxjavaexample.model.Label)

Aggregations

Issue (com.kboyarshinov.realmrxjavaexample.model.Issue)3 User (com.kboyarshinov.realmrxjavaexample.model.User)3 ArrayList (java.util.ArrayList)3 Label (com.kboyarshinov.realmrxjavaexample.model.Label)2 Subscription (rx.Subscription)2 CompositeSubscription (rx.subscriptions.CompositeSubscription)2 RealmIssue (com.kboyarshinov.realmrxjavaexample.model.RealmIssue)1 RealmLabel (com.kboyarshinov.realmrxjavaexample.model.RealmLabel)1 RealmUser (com.kboyarshinov.realmrxjavaexample.model.RealmUser)1 List (java.util.List)1 Func1 (rx.functions.Func1)1