|
@@ -4,7 +4,9 @@ package com.kfzs.duanduan.react.upfile;
|
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Bitmap;
|
|
|
|
|
|
|
|
import com.nanchen.compresshelper.CompressHelper;
|
|
import com.nanchen.compresshelper.CompressHelper;
|
|
|
|
|
+import com.sheep.gamegroup.model.api.ICallBack;
|
|
|
import com.sheep.gamegroup.model.util.ExceptionHandle;
|
|
import com.sheep.gamegroup.model.util.ExceptionHandle;
|
|
|
|
|
+import com.sheep.gamegroup.util.PngUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.zhy.http.okhttp.OkHttpUtils;
|
|
import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
import com.zhy.http.okhttp.callback.Callback;
|
|
import com.zhy.http.okhttp.callback.Callback;
|
|
@@ -15,6 +17,7 @@ import java.util.ArrayList;
|
|
|
import okhttp3.Call;
|
|
import okhttp3.Call;
|
|
|
import okhttp3.Response;
|
|
import okhttp3.Response;
|
|
|
import okhttp3.ResponseBody;
|
|
import okhttp3.ResponseBody;
|
|
|
|
|
+import rx.functions.Action1;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by howie on 2017/5/11.
|
|
* Created by howie on 2017/5/11.
|
|
@@ -56,21 +59,23 @@ public class UpFileUtils {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void upImages(ArrayList<String> photos, final UpFileListener upFileListener) {
|
|
|
|
|
- upImages(photos, upFileListener, 0);
|
|
|
|
|
|
|
+ public static void upImages(ArrayList<String> photos, final UpFileListener upFileListener, ICallBack<String> action1) {
|
|
|
|
|
+ upImages(photos, upFileListener, action1, 0);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public static void upImages(final ArrayList<String> photos, final UpFileListener upFileListener, final int index) {
|
|
|
|
|
- if (index < photos.size()) {
|
|
|
|
|
|
|
+ public static void upImages(final ArrayList<String> photos, final UpFileListener upFileListener, final ICallBack<String> action1, final int index) {
|
|
|
|
|
+ int size = photos.size();
|
|
|
|
|
+ if (index < size) {
|
|
|
File file;
|
|
File file;
|
|
|
if ((file = new File(photos.get(index))).exists()) {
|
|
if ((file = new File(photos.get(index))).exists()) {
|
|
|
File newFile = new CompressHelper.Builder(SheepApp.getInstance())
|
|
File newFile = new CompressHelper.Builder(SheepApp.getInstance())
|
|
|
.setMaxWidth(2000) // 默认最大宽度为720
|
|
.setMaxWidth(2000) // 默认最大宽度为720
|
|
|
.setMaxHeight(2000) // 默认最大高度为960
|
|
.setMaxHeight(2000) // 默认最大高度为960
|
|
|
.setQuality(80) // 默认压缩质量为80
|
|
.setQuality(80) // 默认压缩质量为80
|
|
|
- .setCompressFormat(Bitmap.CompressFormat.JPEG) // 设置默认压缩为jpg格式
|
|
|
|
|
|
|
+ .setCompressFormat(Bitmap.CompressFormat.PNG) // 设置默认压缩为png格式
|
|
|
.build().compressToFile(file);
|
|
.build().compressToFile(file);
|
|
|
// org.xutils.common.util.FileUtil.copy(newFile.getAbsolutePath(), ClassFileHelper.DIR+"/1.png");
|
|
// org.xutils.common.util.FileUtil.copy(newFile.getAbsolutePath(), ClassFileHelper.DIR+"/1.png");
|
|
|
|
|
+ if(action1 != null)
|
|
|
|
|
+ action1.call(newFile.getAbsolutePath(), size, index);
|
|
|
OkHttpUtils.post()
|
|
OkHttpUtils.post()
|
|
|
.addFile("uploadfile", "1.png", newFile)//
|
|
.addFile("uploadfile", "1.png", newFile)//
|
|
|
.url(URL_RN_UP_IMAGE)
|
|
.url(URL_RN_UP_IMAGE)
|
|
@@ -98,11 +103,11 @@ public class UpFileUtils {
|
|
|
@Override
|
|
@Override
|
|
|
public void onResponse(Object response, int id) {
|
|
public void onResponse(Object response, int id) {
|
|
|
upFileListener.Success(response.toString(), index);
|
|
upFileListener.Success(response.toString(), index);
|
|
|
- upImages(photos, upFileListener, index + 1);
|
|
|
|
|
|
|
+ upImages(photos, upFileListener, action1,index + 1);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}else {//文件不存在就不用上传
|
|
}else {//文件不存在就不用上传
|
|
|
- upImages(photos, upFileListener, index + 1);
|
|
|
|
|
|
|
+ upImages(photos, upFileListener, action1,index + 1);
|
|
|
}
|
|
}
|
|
|
} else
|
|
} else
|
|
|
upFileListener.Success("全部上传完成", -1);
|
|
upFileListener.Success("全部上传完成", -1);
|