Commit f761e5b038a90e95c739c7d3dd87ffe78184abfe
1 parent
92ef3449
图片上传方法修改
Showing
4 changed files
with
186 additions
and
32 deletions
core/imageload/src/main/java/com/cnlive/core/imageload/preview/presenter/ProcessHtmlPresenter.java
| @@ -11,6 +11,7 @@ import android.util.Log; | @@ -11,6 +11,7 @@ import android.util.Log; | ||
| 11 | import com.bumptech.glide.Glide; | 11 | import com.bumptech.glide.Glide; |
| 12 | import com.cnlive.core.imageload.api.ApiServiceStock; | 12 | import com.cnlive.core.imageload.api.ApiServiceStock; |
| 13 | import com.cnlive.core.imageload.preview.DataProcessingActivity; | 13 | import com.cnlive.core.imageload.preview.DataProcessingActivity; |
| 14 | +import com.cnlive.core.imageload.preview.model.FeedBackInfo; | ||
| 14 | import com.cnlive.core.imageload.preview.model.PreviewData; | 15 | import com.cnlive.core.imageload.preview.model.PreviewData; |
| 15 | import com.cnlive.core.imageload.preview.view.ProcessHtmlView; | 16 | import com.cnlive.core.imageload.preview.view.ProcessHtmlView; |
| 16 | import com.cnlive.core.libs.base.application.AppConfig; | 17 | import com.cnlive.core.libs.base.application.AppConfig; |
| @@ -22,6 +23,7 @@ import com.cnlive.core.network.model.BaseResult; | @@ -22,6 +23,7 @@ import com.cnlive.core.network.model.BaseResult; | ||
| 22 | import com.cnlive.core.network.HttpConn; | 23 | import com.cnlive.core.network.HttpConn; |
| 23 | import com.cnlive.core.network.NetCallBack; | 24 | import com.cnlive.core.network.NetCallBack; |
| 24 | import com.cnlive.core.network.request.BaseRequest; | 25 | import com.cnlive.core.network.request.BaseRequest; |
| 26 | +import com.cnlive.core.network.upload.UploadLogic; | ||
| 25 | import com.cnlive.strike.user.auth.UserService; | 27 | import com.cnlive.strike.user.auth.UserService; |
| 26 | 28 | ||
| 27 | import java.io.File; | 29 | import java.io.File; |
| @@ -56,19 +58,29 @@ public class ProcessHtmlPresenter extends BasePresenter<ProcessHtmlView> { | @@ -56,19 +58,29 @@ public class ProcessHtmlPresenter extends BasePresenter<ProcessHtmlView> { | ||
| 56 | if (TextUtils.isEmpty(imagePath) && mContext == null) return; | 58 | if (TextUtils.isEmpty(imagePath) && mContext == null) return; |
| 57 | List<String> list = new ArrayList(); | 59 | List<String> list = new ArrayList(); |
| 58 | list.add(imagePath); | 60 | list.add(imagePath); |
| 59 | -// | ||
| 60 | -// eventQn = new Event<List<FeedBackInfo>>().setFailureCallback((state, message) -> { | ||
| 61 | -// if (getView() != null) getView().showMessage(message); | ||
| 62 | -// }).setSuccessCallback(data -> { | ||
| 63 | -// if (getView() != null && data.size() > 0) { | ||
| 64 | -// if (data.get(0).getImageUrl().contains("http")) { | ||
| 65 | -// collection(mContext, data.get(0).getImageUrl(), mContext.previewData); | ||
| 66 | -// } else { | ||
| 67 | -// if (getView() != null) getView().showMessage("数据异常"); | ||
| 68 | -// } | ||
| 69 | -// } | ||
| 70 | -// }); | ||
| 71 | -// UploadLogic.uploadonePic(mContext, true, list, eventQn); | 61 | + |
| 62 | + UploadLogic.uploadonePic(mContext, true, list, new NetCallBack<List<com.cnlive.core.network.upload.model.FeedBackInfo>>() { | ||
| 63 | + @Override | ||
| 64 | + public void onRequestState(int state) { | ||
| 65 | + | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + public void onSuccess(List<com.cnlive.core.network.upload.model.FeedBackInfo> data) { | ||
| 70 | + if(data.size() > 0){ | ||
| 71 | + if (data.get(0).getImageUrl().contains("http")) { | ||
| 72 | + collection(mContext, data.get(0).getImageUrl(), mContext.previewData); | ||
| 73 | + } else { | ||
| 74 | + ifViewAttached(view -> view.showMessage("数据异常")); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public void onFailure(String errCode, String errMsg) { | ||
| 81 | + ifViewAttached(view -> view.showMessage(errMsg)); | ||
| 82 | + } | ||
| 83 | + }); | ||
| 72 | 84 | ||
| 73 | } | 85 | } |
| 74 | 86 |
core/network/src/main/java/com/cnlive/core/network/upload/UploadLogic.java
| @@ -12,10 +12,17 @@ import com.cnlive.core.network.HttpConn; | @@ -12,10 +12,17 @@ import com.cnlive.core.network.HttpConn; | ||
| 12 | import com.cnlive.core.network.NetCallBack; | 12 | import com.cnlive.core.network.NetCallBack; |
| 13 | import com.cnlive.core.network.model.StorageInfoData; | 13 | import com.cnlive.core.network.model.StorageInfoData; |
| 14 | import com.cnlive.core.network.model.UploadAuthData; | 14 | import com.cnlive.core.network.model.UploadAuthData; |
| 15 | +import com.cnlive.core.network.upload.interfaces.ProgressCallback; | ||
| 16 | +import com.cnlive.core.network.upload.model.FeedBackInfo; | ||
| 15 | 17 | ||
| 16 | import java.io.File; | 18 | import java.io.File; |
| 19 | +import java.util.ArrayList; | ||
| 20 | +import java.util.HashMap; | ||
| 17 | import java.util.List; | 21 | import java.util.List; |
| 22 | +import java.util.Map; | ||
| 23 | +import java.util.Observer; | ||
| 18 | 24 | ||
| 25 | +import io.reactivex.Observable; | ||
| 19 | import io.reactivex.ObservableSource; | 26 | import io.reactivex.ObservableSource; |
| 20 | import io.reactivex.functions.Function; | 27 | import io.reactivex.functions.Function; |
| 21 | 28 | ||
| @@ -190,7 +197,7 @@ public class UploadLogic { | @@ -190,7 +197,7 @@ public class UploadLogic { | ||
| 190 | * 张楠上传地图信息用 | 197 | * 张楠上传地图信息用 |
| 191 | */ | 198 | */ |
| 192 | 199 | ||
| 193 | - public static void uploadAddressPicInfo(Context context, List<String> picPath, NetCallBack<String> callBack) { | 200 | + public static void uploadAddressPicInfo(Context context, List<String> picPath, NetCallBack<List<String>> callBack) { |
| 194 | HttpConn.action( | 201 | HttpConn.action( |
| 195 | UploadProvider.getStorageInfo() | 202 | UploadProvider.getStorageInfo() |
| 196 | .concatMap(new Function<BaseResult<List<StorageInfoData>>, ObservableSource<BaseResult<UploadAuthData>>>() { | 203 | .concatMap(new Function<BaseResult<List<StorageInfoData>>, ObservableSource<BaseResult<UploadAuthData>>>() { |
| @@ -508,18 +515,109 @@ public class UploadLogic { | @@ -508,18 +515,109 @@ public class UploadLogic { | ||
| 508 | // Log.d(TAG, String.format(ERROR_DEF, tag, stateCode, code, message)); | 515 | // Log.d(TAG, String.format(ERROR_DEF, tag, stateCode, code, message)); |
| 509 | // } | 516 | // } |
| 510 | 517 | ||
| 511 | -// /** | ||
| 512 | -// * Im收藏的时候图片单张上传的方法 | ||
| 513 | -// * | ||
| 514 | -// * @param context | ||
| 515 | -// * @param isZip | ||
| 516 | -// * @param picPath | ||
| 517 | -// * @param event | ||
| 518 | -// */ | ||
| 519 | -// public static void uploadonePic(Context context, boolean isZip, List<String> picPath, Event<List<FeedBackInfo>> event) { | ||
| 520 | -// | 518 | + /** |
| 519 | + * Im收藏的时候图片单张上传的方法 | ||
| 520 | + * | ||
| 521 | + * @param context | ||
| 522 | + * @param isZip | ||
| 523 | + * @param picPath | ||
| 524 | + * @param callBack | ||
| 525 | + */ | ||
| 526 | + public static void uploadonePic(Context context, boolean isZip, List<String> picPath, NetCallBack<List<FeedBackInfo>> callBack) { | ||
| 527 | + | ||
| 528 | + HttpConn.action(UploadProvider.getStorageInfo().flatMap(new Function<BaseResult<List<StorageInfoData>>, ObservableSource<BaseResult<UploadAuthData>>>() { | ||
| 529 | + | ||
| 530 | + @Override | ||
| 531 | + public ObservableSource<BaseResult<UploadAuthData>> apply(BaseResult<List<StorageInfoData>> data) throws Exception { | ||
| 532 | + if (data.isSuccess()) { | ||
| 533 | + if (data.getData().size() > 0 || data.getData() != null) { | ||
| 534 | + return UploadProvider.uploadAuth(data.getData().get(0).getStorageName()); | ||
| 535 | + } else { | ||
| 536 | + return HttpConn.error("-1", "storage info null"); | ||
| 537 | + } | ||
| 538 | + } | ||
| 539 | + return HttpConn.error(data); | ||
| 540 | + } | ||
| 541 | + }).flatMap(new Function<BaseResult<UploadAuthData>, ObservableSource<Map<String, Object>>>() { | ||
| 542 | + | ||
| 543 | + @Override | ||
| 544 | + public ObservableSource<Map<String, Object>> apply(BaseResult<UploadAuthData> uploadAuthDataBaseResult) throws Exception { | ||
| 545 | + String token = uploadAuthDataBaseResult.getData().getToken(); | ||
| 546 | + if (isZip) { | ||
| 547 | + UploadProvider.zipFiles(context, picPath, new UploadProvider.ZipFilesCallBack() { | ||
| 548 | + @Override | ||
| 549 | + public void onSuccess(List<String> files) { | ||
| 550 | + UploadProvider.doUploadPic(context, files, token, new NetCallBack<List<String>>() { | ||
| 551 | + @Override | ||
| 552 | + public void onRequestState(int state) { | ||
| 553 | + if (null != callBack) { | ||
| 554 | + callBack.onRequestState(state); | ||
| 555 | + } | ||
| 556 | + } | ||
| 557 | + | ||
| 558 | + @Override | ||
| 559 | + public void onSuccess(List<String> data) { | ||
| 560 | + List<FeedBackInfo> list = new ArrayList<>(); | ||
| 561 | + for (int i = 0; i < ((ArrayList) data).size(); i++) { | ||
| 562 | + FeedBackInfo info = new FeedBackInfo(); | ||
| 563 | + info.setImageUrl(SEVEN + ((ArrayList) data).get(i)); | ||
| 564 | + list.add(info); | ||
| 565 | + } | ||
| 566 | + if (null != callBack) { | ||
| 567 | + callBack.onSuccess(list); | ||
| 568 | + } | ||
| 569 | + } | ||
| 570 | + | ||
| 571 | + @Override | ||
| 572 | + public void onFailure(String errCode, String errMsg) { | ||
| 573 | + if (null != callBack) { | ||
| 574 | + callBack.onFailure(errCode, errMsg); | ||
| 575 | + } | ||
| 576 | + } | ||
| 577 | + }, null); | ||
| 578 | + } | ||
| 579 | + | ||
| 580 | + @Override | ||
| 581 | + public void onFail(String errCode, String errMsg) { | ||
| 582 | + HttpConn.error(errCode, errMsg); | ||
| 583 | + } | ||
| 584 | + }); | ||
| 585 | + } else { | ||
| 586 | + UploadProvider.doUploadPic(context, picPath, token, new NetCallBack<List<String>>() { | ||
| 587 | + @Override | ||
| 588 | + public void onRequestState(int state) { | ||
| 589 | + if (null != callBack) { | ||
| 590 | + callBack.onRequestState(state); | ||
| 591 | + } | ||
| 592 | + } | ||
| 593 | + | ||
| 594 | + @Override | ||
| 595 | + public void onSuccess(List<String> data) { | ||
| 596 | + List<FeedBackInfo> list = new ArrayList<>(); | ||
| 597 | + for (int i = 0; i < ((ArrayList) data).size(); i++) { | ||
| 598 | + FeedBackInfo info = new FeedBackInfo(); | ||
| 599 | + info.setImageUrl(SEVEN + ((ArrayList) data).get(i)); | ||
| 600 | + list.add(info); | ||
| 601 | + } | ||
| 602 | + if (null != callBack) { | ||
| 603 | + callBack.onSuccess(list); | ||
| 604 | + } | ||
| 605 | + } | ||
| 606 | + | ||
| 607 | + @Override | ||
| 608 | + public void onFailure(String errCode, String errMsg) { | ||
| 609 | + if (null != callBack) { | ||
| 610 | + callBack.onFailure(errCode, errMsg); | ||
| 611 | + } | ||
| 612 | + } | ||
| 613 | + }, null); | ||
| 614 | + } | ||
| 615 | + return null; | ||
| 616 | + } | ||
| 617 | + }), null); | ||
| 618 | +// UploadProvider.getStorageInfo() | ||
| 521 | // Logic.create() | 619 | // Logic.create() |
| 522 | -// .action((Object data, DataCallback<BaseInfo<List<StorageInfoData>>> callback) -> | 620 | +// .action((Object data, DataCallback<BaseResult<List<StorageInfoData>>> callback) -> |
| 523 | // UploadProvider.getStorageInfo(context, callback)) | 621 | // UploadProvider.getStorageInfo(context, callback)) |
| 524 | // .action((BaseInfo<List<StorageInfoData>> data, DataCallback<BaseInfo<UploadAuthData>> callback) -> | 622 | // .action((BaseInfo<List<StorageInfoData>> data, DataCallback<BaseInfo<UploadAuthData>> callback) -> |
| 525 | // UploadProvider.uploadAuth(context, data.getData().get(0).getStorageName(), callback) | 623 | // UploadProvider.uploadAuth(context, data.getData().get(0).getStorageName(), callback) |
| @@ -556,8 +654,8 @@ public class UploadLogic { | @@ -556,8 +654,8 @@ public class UploadLogic { | ||
| 556 | // return list; | 654 | // return list; |
| 557 | // }, callback)) | 655 | // }, callback)) |
| 558 | // .start(event); | 656 | // .start(event); |
| 559 | -// | ||
| 560 | -// } | 657 | + |
| 658 | + } | ||
| 561 | 659 | ||
| 562 | 660 | ||
| 563 | } | 661 | } |
core/network/src/main/java/com/cnlive/core/network/upload/UploadProvider.java
| @@ -14,6 +14,7 @@ import com.cnlive.core.network.model.BaseResult; | @@ -14,6 +14,7 @@ import com.cnlive.core.network.model.BaseResult; | ||
| 14 | import com.cnlive.core.network.HttpConn; | 14 | import com.cnlive.core.network.HttpConn; |
| 15 | import com.cnlive.core.network.NetCallBack; | 15 | import com.cnlive.core.network.NetCallBack; |
| 16 | import com.cnlive.core.network.api.ApiBaseServiceOpen; | 16 | import com.cnlive.core.network.api.ApiBaseServiceOpen; |
| 17 | +import com.cnlive.core.network.model.StorageInfoData; | ||
| 17 | import com.cnlive.core.network.request.BaseRequest; | 18 | import com.cnlive.core.network.request.BaseRequest; |
| 18 | import com.cnlive.core.network.model.UploadAuthData; | 19 | import com.cnlive.core.network.model.UploadAuthData; |
| 19 | import com.cnlive.core.network.upload.interfaces.ProgressCallback; | 20 | import com.cnlive.core.network.upload.interfaces.ProgressCallback; |
| @@ -104,7 +105,7 @@ public class UploadProvider { | @@ -104,7 +105,7 @@ public class UploadProvider { | ||
| 104 | * | 105 | * |
| 105 | * @return | 106 | * @return |
| 106 | */ | 107 | */ |
| 107 | - public static Observable<BaseResult<List<com.cnlive.core.network.model.StorageInfoData>>> getStorageInfo() { | 108 | + public static Observable<BaseResult<List<StorageInfoData>>> getStorageInfo() { |
| 108 | Map<String, String> map = new HashMap<>(); | 109 | Map<String, String> map = new HashMap<>(); |
| 109 | map.put("appId", AppConfig.getAppId()); | 110 | map.put("appId", AppConfig.getAppId()); |
| 110 | map.put("storageType", "2"); | 111 | map.put("storageType", "2"); |
| @@ -477,7 +478,7 @@ public class UploadProvider { | @@ -477,7 +478,7 @@ public class UploadProvider { | ||
| 477 | // } | 478 | // } |
| 478 | 479 | ||
| 479 | 480 | ||
| 480 | - public static void doUploadPic(Context context, List<String> file, String uploadToken, NetCallBack<String> callBack, ProgressCallback progressCallback) { | 481 | + public static void doUploadPic(Context context, List<String> file, String uploadToken, NetCallBack<List<String>> callBack, ProgressCallback progressCallback) { |
| 481 | ArrayList<String> netpiclist = new ArrayList<>(); | 482 | ArrayList<String> netpiclist = new ArrayList<>(); |
| 482 | UploadManager uploadManager = new UploadManager(); | 483 | UploadManager uploadManager = new UploadManager(); |
| 483 | //正式环境:769/img/2018/01/29/"时间戳".jpg | 484 | //正式环境:769/img/2018/01/29/"时间戳".jpg |
| @@ -494,14 +495,13 @@ public class UploadProvider { | @@ -494,14 +495,13 @@ public class UploadProvider { | ||
| 494 | ((Activity) context).runOnUiThread(() -> { | 495 | ((Activity) context).runOnUiThread(() -> { |
| 495 | if (info.isOK()) { | 496 | if (info.isOK()) { |
| 496 | try { | 497 | try { |
| 497 | - netpiclist.add((String) info.response.get("key")); | 498 | + netpiclist.add(UploadLogic.SEVEN + (String) info.response.get("key")); |
| 498 | } catch (JSONException e) { | 499 | } catch (JSONException e) { |
| 499 | e.printStackTrace(); | 500 | e.printStackTrace(); |
| 500 | HttpConn.error(info.statusCode + "", info.error); | 501 | HttpConn.error(info.statusCode + "", info.error); |
| 501 | } | 502 | } |
| 502 | if (netpiclist.size() == file.size()) { | 503 | if (netpiclist.size() == file.size()) { |
| 503 | - String addressImageUrl = UploadLogic.SEVEN + netpiclist.get(0); | ||
| 504 | - callBack.onSuccess(addressImageUrl); | 504 | + callBack.onSuccess(netpiclist); |
| 505 | } | 505 | } |
| 506 | } else { | 506 | } else { |
| 507 | HttpConn.error(info.statusCode + "", info.error); | 507 | HttpConn.error(info.statusCode + "", info.error); |
core/network/src/main/java/com/cnlive/core/network/upload/model/FeedBackInfo.java
0 → 100644
| 1 | +package com.cnlive.core.network.upload.model; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Created by Lynn on 2018/9/4. | ||
| 5 | + */ | ||
| 6 | + | ||
| 7 | +public class FeedBackInfo { | ||
| 8 | + private String imageUrl; | ||
| 9 | + private long imageWidth; | ||
| 10 | + private long imageHeight; | ||
| 11 | + | ||
| 12 | + public String getImageUrl() { | ||
| 13 | + return imageUrl; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public void setImageUrl(String imageUrl) { | ||
| 17 | + this.imageUrl = imageUrl; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public long getImageWidth() { | ||
| 21 | + return imageWidth; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public void setImageWidth(long imageWidth) { | ||
| 25 | + this.imageWidth = imageWidth; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public long getImageHeight() { | ||
| 29 | + return imageHeight; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void setImageHeight(long imageHeight) { | ||
| 33 | + this.imageHeight = imageHeight; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public String toString() { | ||
| 38 | + return "FeedBackInfo{" + | ||
| 39 | + "imageUrl='" + imageUrl + '\'' + | ||
| 40 | + ", imageWidth=" + imageWidth + | ||
| 41 | + ", imageHeight=" + imageHeight + | ||
| 42 | + '}'; | ||
| 43 | + } | ||
| 44 | +} |