package com.njnu.kai.practice.image;

import com.njnu.kai.support.BaseTestListFragment;
import com.njnu.kai.support.TestFunction;

import java.io.File;

import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

/**
 * @author hongkai.qian
 * @version 1.0.0
 * @since 17/4/12
 */
public class ImageCompressFragment extends BaseTestListFragment {

    @TestFunction("压缩图片")
    public void onTest01() {
        File file = new File("/sdcard/dcim/camera/IMG_20170412_195631.jpg");
        Luban.get(getContext())
                .load(file)                     //传人要压缩的图片
                .putGear(Luban.THIRD_GEAR)      //设定压缩档次，默认三挡
                .setCompressListener(new OnCompressListener() { //设置回调

                    @Override
                    public void onStart() {
                        appendResult("onStart");
                    }

                    @Override
                    public void onSuccess(File file) {
                        appendResult(file.getAbsolutePath());
                    }

                    @Override
                    public void onError(Throwable e) {
                        appendResult(e.getMessage());
                    }
                }).launch();
    }
}

@@ -142,24 +142,183 @@
 a.io.File;%0A%0A
+import rx.Observable;%0Aimport rx.android.schedulers.AndroidSchedulers;%0Aimport rx.functions.Action1;%0Aimport rx.functions.Func1;%0Aimport rx.schedulers.Schedulers;%0A
 import top.z
@@ -335,16 +335,16 @@
 .Luban;%0A
-
 import t
@@ -537,16 +537,29 @@
 on(%22%E5%8E%8B%E7%BC%A9%E5%9B%BE%E7%89%87
+ Use listener
 %22)%0A    p
@@ -1361,16 +1361,16 @@
       %7D%0A
-
         
@@ -1395,11 +1395,1173 @@
 );%0A    %7D
+%0A%0A    @TestFunction(%22%E5%8E%8B%E7%BC%A9%E5%9B%BE%E7%89%87 use rxJava%22)%0A    public void onTest02() %7B%0A        File file = new File(%22/sdcard/dcim/camera/IMG_20170412_195631.jpg%22);%0A        Luban.get(getContext())%0A                .load(file)%0A                .putGear(Luban.THIRD_GEAR)%0A                .asObservable()%0A                .subscribeOn(Schedulers.io())%0A                .observeOn(AndroidSchedulers.mainThread())%0A                .doOnError(new Action1%3CThrowable%3E() %7B%0A                    @Override%0A                    public void call(Throwable throwable) %7B%0A                        appendResult(throwable.getMessage());%0A                    %7D%0A                %7D)%0A                .onErrorResumeNext(new Func1%3CThrowable, Observable%3C? extends File%3E%3E() %7B%0A                    @Override%0A                    public Observable%3C? extends File%3E call(Throwable throwable) %7B%0A                        return Observable.empty();%0A                    %7D%0A                %7D)%0A                .subscribe(new Action1%3CFile%3E() %7B%0A                    @Override%0A                    public void call(File file) %7B%0A                        appendResult(file.getAbsolutePath());%0A                    %7D%0A                %7D);%0A    %7D
 %0A%7D%0A

test compress image use rxJava