package com.github.ayltai.newspaper.app.view;

import java.util.concurrent.TimeUnit;

import android.support.annotation.NonNull;

import com.github.ayltai.newspaper.Constants;
import com.github.ayltai.newspaper.app.data.model.FeaturedItem;
import com.github.ayltai.newspaper.app.widget.FeaturedView;
import com.github.ayltai.newspaper.util.RxUtils;

import io.reactivex.Observable;

public class FeaturedPresenter extends ItemPresenter<FeaturedView> {
    @Override
    public void onViewAttached(@NonNull final FeaturedView view, final boolean isFirstTimeAttachment) {
        this.manageDisposable(Observable.interval(Constants.FEATURED_IMAGE_ROTATION, TimeUnit.SECONDS)
            .compose(RxUtils.applyObservableBackgroundToMainSchedulers())
            .subscribe(time -> {
                if (this.getModel() instanceof FeaturedItem) {
                    ((FeaturedItem)this.getModel()).next();

                    this.bindModel(this.getModel());
                }
            }));

        super.onViewAttached(view, isFirstTimeAttachment);
    }
}

@@ -38,17 +38,19 @@
 pp.view;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -79,17 +79,19 @@
 imeUnit;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -125,17 +125,45 @@
 NonNull;
-%0A
+%0D%0Aimport android.util.Log;%0D%0A%0D
 %0Aimport 
@@ -200,16 +200,17 @@
 nstants;
+%0D
 %0Aimport 
@@ -265,16 +265,17 @@
 redItem;
+%0D
 %0Aimport 
@@ -330,58 +330,174 @@
 iew;
-%0Aimport com.github.ayltai.newspaper.util.RxUtils;%0A
+%0D%0Aimport com.github.ayltai.newspaper.media.FrescoImageLoader;%0D%0Aimport com.github.ayltai.newspaper.util.RxUtils;%0D%0Aimport com.github.ayltai.newspaper.util.TestUtils;%0D%0A%0D
 %0Aimp
@@ -524,17 +524,19 @@
 ervable;
-%0A
+%0D%0A%0D
 %0Apublic 
@@ -596,16 +596,17 @@
 dView%3E %7B
+%0D
 %0A    @Ov
@@ -611,16 +611,17 @@
 Override
+%0D
 %0A    pub
@@ -716,16 +716,17 @@
 hment) %7B
+%0D
 %0A       
@@ -820,16 +820,17 @@
 SECONDS)
+%0D
 %0A       
@@ -895,16 +895,17 @@
 ulers())
+%0D
 %0A       
@@ -929,16 +929,17 @@
 ime -%3E %7B
+%0D
 %0A       
@@ -993,16 +993,17 @@
 dItem) %7B
+%0D
 %0A       
@@ -1054,17 +1054,19 @@
 .next();
-%0A
+%0D%0A%0D
 %0A       
@@ -1082,76 +1082,793 @@
     
-this.bindModel(this.getModel());%0A                %7D%0A            %7D));%0A
+if (!this.getModel().getImages().isEmpty()) FrescoImageLoader.loadImage(this.getModel().getImages().get(0).getUrl())%0D%0A                        .compose(RxUtils.applyMaybeBackgroundToMainSchedulers())%0D%0A                        .subscribe(%0D%0A                            bitmap -%3E %7B%0D%0A                                view.setImages(this.getModel().getImages());%0D%0A                                view.setTitle(this.getModel().getTitle());%0D%0A                            %7D,%0D%0A                            error -%3E %7B%0D%0A                                if (TestUtils.isLoggable()) Log.e(this.getClass().getSimpleName(), error.getMessage(), error);%0D%0A                            %7D%0D%0A                        );%0D%0A%0D%0A                    this.bindModel(this.getModel());%0D%0A                %7D%0D%0A            %7D));%0D%0A%0D
 %0A   
@@ -1926,13 +1926,16 @@
 nt);
+%0D
 %0A    %7D
+%0D
 %0A%7D
+%0D
 %0A

Synchronize featured news item image and title display