@@ -0,0 +1,1752 @@
+package de.metalmatze.krautreporter.services;%0A%0Aimport android.content.Context;%0A%0Aimport java.util.List;%0A%0Aimport de.metalmatze.krautreporter.api.Api;%0Aimport de.metalmatze.krautreporter.models.Author;%0Aimport de.metalmatze.krautreporter.models.Image;%0Aimport io.realm.Realm;%0Aimport rx.Observable;%0Aimport rx.android.schedulers.AndroidSchedulers;%0Aimport rx.schedulers.Schedulers;%0A%0Apublic class AuthorService %7B%0A    private final Api api;%0A    private Realm realm;%0A%0A    public AuthorService(Context context, Api api) %7B%0A        this.api = api;%0A        this.realm = Realm.getInstance(context);%0A    %7D%0A%0A    public Observable%3CList%3CAuthor%3E%3E getAuthors() %7B%0A        List%3CAuthor%3E authors = realm.where(Author.class).findAll();%0A        return Observable.just(authors);%0A    %7D%0A%0A    public Observable%3CList%3CAuthor%3E%3E updateAuthors() %7B%0A        return api.request().authors()%0A                .subscribeOn(Schedulers.io())%0A                .observeOn(AndroidSchedulers.mainThread())%0A                .map(authors -%3E authors.data)%0A                .map(authors -%3E %7B%0A                    realm.beginTransaction();%0A                    List%3CAuthor%3E realmAuthors = realm.copyToRealmOrUpdate(authors);%0A%0A                    int index = 0;%0A                    for (Author author : realmAuthors) %7B%0A                        List%3CImage%3E images = authors.get(index).getSerializedImages().data;%0A                        List%3CImage%3E realmImages = realm.copyToRealmOrUpdate(images);%0A%0A                        for (Image image : realmImages) %7B%0A                            author.getImages().add(image);%0A                        %7D%0A%0A                        index++;%0A                    %7D%0A%0A                    realm.commitTransaction();%0A%0A                    return realmAuthors;%0A                %7D);%0A    %7D%0A%7D%0A

Create AuthorService that coordinates api and realm