package com.joker.fourfun.presenter;

import com.joker.fourfun.base.BaseMvpPresenter;
import com.joker.fourfun.model.PicOne;
import com.joker.fourfun.net.HttpResultFun;
import com.joker.fourfun.net.UserService;
import com.joker.fourfun.presenter.contract.PictureChildContract;
import com.joker.fourfun.utils.RetrofitUtil;
import com.joker.fourfun.utils.RxUtil;
import com.joker.fourfun.utils.SystemUtil;
import com.orhanobut.logger.Logger;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by joker on 2016/12/1.
 */

public class PictureChildPresenter extends BaseMvpPresenter<PictureChildContract.View> implements
        PictureChildContract
        .Presenter {
    private RetrofitUtil mRetrofit;

    @Inject
    public PictureChildPresenter(RetrofitUtil retrofitUtil) {
        mRetrofit = retrofitUtil;
    }

    @Override
    public void getContent(int before) {
        String date = SystemUtil.beforeToday(before);
        UserService service = mRetrofit.create(UserService.class);
        service.picOne(date)
                .map(new HttpResultFun<List<PicOne>>())
                .compose(RxUtil.<List<PicOne>>rxSchedulerTransformer())
                .subscribe(new Subscriber<List<PicOne>>() {
                    @Override
                    public void onSubscribe(Subscription s) {
                        s.request(Long.MAX_VALUE);
                    }

                    @Override
                    public void onNext(List<PicOne> picOnes) {
                        Logger.e(picOnes.get(0).getPicUrl());
                        mView.showContent(picOnes.get(0));
                    }

                    @Override
                    public void onError(Throwable t) {
                        Logger.e(t, "ERROR");
                        mView.showError("似乎有点问题哦");
                    }

                    @Override
                    public void onComplete() {
                    }
                });
    }
}

@@ -438,89 +438,8 @@
 r;%0A%0A
-import org.reactivestreams.Subscriber;%0Aimport org.reactivestreams.Subscription;%0A%0A
 impo
@@ -487,16 +487,57 @@
 nject;%0A%0A
+import io.reactivex.functions.Consumer;%0A%0A
 /**%0A * C
@@ -698,16 +698,24 @@
 ontract%0A
+        
         
@@ -1243,24 +1243,22 @@
 ibe(new 
-Subscrib
+Consum
 er%3CList%3C
@@ -1336,202 +1336,50 @@
 oid 
-onSubscribe(Subscription s) %7B%0A                        s.request(Long.MAX_VALUE);%0A                    %7D%0A%0A                    @Override%0A                    public void onNext(List%3CPicOne%3E picOnes)
+accept(List%3CPicOne%3E list) throws Exception
  %7B%0A 
@@ -1410,23 +1410,20 @@
 ogger.e(
-picOnes
+list
 .get(0).
@@ -1482,15 +1482,12 @@
 ent(
-picOnes
+list
 .get
@@ -1488,24 +1488,25 @@
 st.get(0));%0A
+%0A
             
@@ -1507,32 +1507,78 @@
               %7D%0A
+                %7D, new Consumer%3CThrowable%3E() %7B
 %0A               
@@ -1628,15 +1628,14 @@
 oid 
-onError
+accept
 (Thr
@@ -1642,17 +1642,42 @@
 owable t
-)
+hrowable) throws Exception
  %7B%0A     
@@ -1705,16 +1705,24 @@
 gger.e(t
+hrowable
 , %22ERROR
@@ -1802,108 +1802,8 @@
    %7D
-%0A%0A                    @Override%0A                    public void onComplete() %7B%0A                    %7D
 %0A   

change params