Skip to content

Commit

Permalink
上传控制类Demo调整
Browse files Browse the repository at this point in the history
  • Loading branch information
r17171709 committed Dec 14, 2017
1 parent 5f7be0d commit f9815aa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ImageLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.github.r17171709:AndroidCommonLibrary:v1.8.1'
compile 'com.github.r17171709:AndroidCommonLibrary:v1.8.3'
// PhotoDraweeView PhotoView For Fresco
compile 'me.relex:photodraweeview:1.1.3'
// uCrop Image Cropping Library for Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class UploadActivity: BaseActivity() {
}

override fun deletePic() {
upload.cancelTask("aizuna_"+File(path).name.substring(0, File(path).name.indexOf(".")))
upload.cancelTask(File(path).name.substring(0, File(path).name.indexOf(".")))
picPath.remove(path)
grid_pic.removeView(view)
if (picPath.size==9) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public synchronized void addTask(String filePath, String url, String tag) {

HashMap<String, File> fileHashMap=new HashMap<>();
fileHashMap.put("fileData", new File(filePath));
Response resp=okHttpUtils.syncUpload(url, new HashMap<>(), fileHashMap, (l, l1) -> {
String uploadValue=okHttpUtils.syncUpload(url, new HashMap<>(), fileHashMap, (l, l1) -> {
Log.d("UploadImageManager", "UploadImageManager " + l + " " + l1);
// 上传每20%进度刷新一次,上传完成不进行修改以防止与后续成功的回调不一致
if ((l*100/l1 - bean.getProgress() >= 20) && l != l1) {
Expand All @@ -72,14 +72,14 @@ public synchronized void addTask(String filePath, String url, String tag) {
}
}
});
if (resp==null) {
if (uploadValue==null) {
Log.d("UploadImageManager", filePath + "发布失败");
}
else if (resp.isSuccessful()) {
else {
JSONObject jsonObject= null;
try {
// 上传成功
jsonObject = new JSONObject(resp.body().string());
jsonObject = new JSONObject(uploadValue);
String picUrl=jsonObject.getJSONObject("data").getString("picUrl");
Log.d("UploadImageManager", filePath + "发布成功:" + picUrl);

Expand All @@ -95,9 +95,6 @@ else if (resp.isSuccessful()) {
Log.d("UploadImageManager", filePath + "发布失败");
}
}
else {
Log.d("UploadImageManager", filePath + "发布失败");
}

// 上传失败
bean.setProgress(0);
Expand Down Expand Up @@ -143,7 +140,7 @@ else if (beans.get(tag).getStatue() == UploadTaskBean.UploadState.UPLOADFAIL) {
* 取消一个任务
* @param tag
*/
public synchronized void cancelTask(String tag) {
public void cancelTask(String tag) {
if (tasks.containsKey(tag)) {
tasks.remove(tag).cancel(true);
}
Expand Down

0 comments on commit f9815aa

Please sign in to comment.