Commit c25d296a1c6cb15e209a0b985c3305e9539973e9
1 parent
2be20c32
全屏预览图片长按事件测试优化
Showing
5 changed files
with
66 additions
and
30 deletions
app/strike/src/main/java/com/cnlive/strike/imgutil/ImgActivity.java
| @@ -26,8 +26,11 @@ import com.cnlive.core.imageload.preview.model.PreviewData; | @@ -26,8 +26,11 @@ import com.cnlive.core.imageload.preview.model.PreviewData; | ||
| 26 | import com.cnlive.core.imageload.util.DownLoadImageService; | 26 | import com.cnlive.core.imageload.util.DownLoadImageService; |
| 27 | import com.cnlive.cloud.R; | 27 | import com.cnlive.cloud.R; |
| 28 | import com.cnlive.cloud.user.auth.UserService; | 28 | import com.cnlive.cloud.user.auth.UserService; |
| 29 | +import com.cnlive.core.ui.model.PreViewImgData; | ||
| 30 | +import com.cnlive.core.ui.model.PreViewImgInfo; | ||
| 29 | 31 | ||
| 30 | import java.util.ArrayList; | 32 | import java.util.ArrayList; |
| 33 | +import java.util.List; | ||
| 31 | 34 | ||
| 32 | public class ImgActivity extends AppCompatActivity { | 35 | public class ImgActivity extends AppCompatActivity { |
| 33 | 36 | ||
| @@ -89,14 +92,29 @@ public class ImgActivity extends AppCompatActivity { | @@ -89,14 +92,29 @@ public class ImgActivity extends AppCompatActivity { | ||
| 89 | 92 | ||
| 90 | findViewById(R.id.simpla_see).setOnClickListener(view -> startActivity(new Intent(this,SimplePrevActivity.class))); | 93 | findViewById(R.id.simpla_see).setOnClickListener(view -> startActivity(new Intent(this,SimplePrevActivity.class))); |
| 91 | findViewById(R.id.pre_btn).setOnClickListener(view -> { | 94 | findViewById(R.id.pre_btn).setOnClickListener(view -> { |
| 92 | -// ArrayList<String> list = new ArrayList<>(); | ||
| 93 | -// list.add("https://b-ssl.duitang.com/uploads/item/201505/09/20150509221719_kyNrM.jpeg"); | ||
| 94 | -// list.add("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1035013881,3985887911&fm=26&gp=0.gif"); | ||
| 95 | -// list.add("https://b-ssl.duitang.com/uploads/item/201505/11/20150511122951_MAwVZ.jpeg"); | ||
| 96 | -// list.add("https://b-ssl.duitang.com/uploads/item/201704/23/20170423205828_BhNSv.jpeg"); | ||
| 97 | -// ARouter.getInstance().build("/preview/PreViewImageActivity") | ||
| 98 | -// .withStringArrayList("paths", list) | ||
| 99 | -// .navigation(this); | 95 | + PreViewImgData data = new PreViewImgData(); |
| 96 | + data.setType("1"); | ||
| 97 | + PreViewImgInfo cuData = new PreViewImgInfo(); | ||
| 98 | + cuData.setImgUrl("https://b-ssl.duitang.com/uploads/item/201505/09/20150509221719_kyNrM.jpeg"); | ||
| 99 | + data.setCurrPrewInfo(cuData); | ||
| 100 | + | ||
| 101 | + List<PreViewImgInfo> preViewImgInfos = new ArrayList<>(); | ||
| 102 | + preViewImgInfos.add(cuData); | ||
| 103 | + PreViewImgInfo cuData1 = new PreViewImgInfo(); | ||
| 104 | + cuData1.setImgUrl("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1035013881,3985887911&fm=26&gp=0.gif"); | ||
| 105 | + preViewImgInfos.add(cuData1); | ||
| 106 | + PreViewImgInfo cuData2 = new PreViewImgInfo(); | ||
| 107 | + cuData2.setImgUrl("https://b-ssl.duitang.com/uploads/item/201505/11/20150511122951_MAwVZ.jpeg"); | ||
| 108 | + preViewImgInfos.add(cuData2); | ||
| 109 | + | ||
| 110 | + data.setPicInfoList(preViewImgInfos); | ||
| 111 | + data.setFriend(true); | ||
| 112 | + data.setCollection(true); | ||
| 113 | + data.setLife(true); | ||
| 114 | + data.setSave(true); | ||
| 115 | + ARouter.getInstance().build("/preview/PreViewImageActivity") | ||
| 116 | + .withSerializable("data", data) | ||
| 117 | + .navigation(this); | ||
| 100 | }); | 118 | }); |
| 101 | } | 119 | } |
| 102 | 120 |
core/imageload/src/main/java/com/cnlive/core/ui/activity/PreViewImageActivity.java
| @@ -11,7 +11,6 @@ import com.cnlive.core.imageload.databinding.ActivityPreviewImageBinding; | @@ -11,7 +11,6 @@ import com.cnlive.core.imageload.databinding.ActivityPreviewImageBinding; | ||
| 11 | import com.cnlive.core.imageload.preview.PreviewImageViewActivity; | 11 | import com.cnlive.core.imageload.preview.PreviewImageViewActivity; |
| 12 | import com.cnlive.core.imagepreview.ViewerStatus; | 12 | import com.cnlive.core.imagepreview.ViewerStatus; |
| 13 | import com.cnlive.core.imagepreview.listener.OnItemClickListener; | 13 | import com.cnlive.core.imagepreview.listener.OnItemClickListener; |
| 14 | -import com.cnlive.core.imagepreview.listener.OnItemLongPressListener; | ||
| 15 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; | 14 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 16 | import com.cnlive.core.ui.model.PreViewImgData; | 15 | import com.cnlive.core.ui.model.PreViewImgData; |
| 17 | import com.cnlive.core.ui.presenter.PreViewImagePresenter; | 16 | import com.cnlive.core.ui.presenter.PreViewImagePresenter; |
| @@ -39,7 +38,7 @@ public class PreViewImageActivity extends BaseActivity<PreViewImageView, PreView | @@ -39,7 +38,7 @@ public class PreViewImageActivity extends BaseActivity<PreViewImageView, PreView | ||
| 39 | } | 38 | } |
| 40 | 39 | ||
| 41 | @Override | 40 | @Override |
| 42 | - protected int getViewLayoutId() { | 41 | + protected int getBindLayoutId() { |
| 43 | return R.layout.activity_preview_image; | 42 | return R.layout.activity_preview_image; |
| 44 | } | 43 | } |
| 45 | 44 |
core/imageload/src/main/java/com/cnlive/core/ui/model/PreViewImgInfo.java
| 1 | package com.cnlive.core.ui.model; | 1 | package com.cnlive.core.ui.model; |
| 2 | 2 | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 3 | /** | 5 | /** |
| 4 | * created by hanyayun | 6 | * created by hanyayun |
| 5 | * on 2020/2/21 | 7 | * on 2020/2/21 |
| 6 | */ | 8 | */ |
| 7 | -public class PreViewImgInfo { | 9 | +public class PreViewImgInfo implements Serializable { |
| 8 | //原图 | 10 | //原图 |
| 9 | private String imgUrl; | 11 | private String imgUrl; |
| 10 | //预览图 | 12 | //预览图 |
core/imageload/src/main/java/com/cnlive/core/ui/presenter/PreViewImagePresenter.java
| @@ -52,7 +52,6 @@ import io.reactivex.schedulers.Schedulers; | @@ -52,7 +52,6 @@ import io.reactivex.schedulers.Schedulers; | ||
| 52 | */ | 52 | */ |
| 53 | public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | 53 | public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { |
| 54 | 54 | ||
| 55 | - | ||
| 56 | /** | 55 | /** |
| 57 | * 分享好友、生活圈 | 56 | * 分享好友、生活圈 |
| 58 | * | 57 | * |
| @@ -63,7 +62,8 @@ public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | @@ -63,7 +62,8 @@ public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | ||
| 63 | public void shareFriendLife(Context mContext, String type, String imgUrl) { | 62 | public void shareFriendLife(Context mContext, String type, String imgUrl) { |
| 64 | if (TextUtils.isEmpty(imgUrl)) return; | 63 | if (TextUtils.isEmpty(imgUrl)) return; |
| 65 | if (mContext == null) return; | 64 | if (mContext == null) return; |
| 66 | - ifViewAttached(view -> view.showLoading()); | 65 | + if(getView() != null) getView().showLoading(); |
| 66 | +// ifViewAttached(view -> view.showLoading()); | ||
| 67 | Observable.create((ObservableOnSubscribe<String>) emitter -> { | 67 | Observable.create((ObservableOnSubscribe<String>) emitter -> { |
| 68 | if (FileUtils.isFileExists(imgUrl) && FileUtils.getFileByPath(imgUrl).length() > 0) { | 68 | if (FileUtils.isFileExists(imgUrl) && FileUtils.getFileByPath(imgUrl).length() > 0) { |
| 69 | emitter.onNext(imgUrl); | 69 | emitter.onNext(imgUrl); |
| @@ -88,26 +88,35 @@ public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | @@ -88,26 +88,35 @@ public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | ||
| 88 | 88 | ||
| 89 | @Override | 89 | @Override |
| 90 | public void onNext(String content) { | 90 | public void onNext(String content) { |
| 91 | - ifViewAttached(view -> view.hideLoading()); | 91 | + if(getView() != null) getView().hideLoading(); |
| 92 | +// ifViewAttached(view -> view.hideLoading()); | ||
| 92 | if (!TextUtils.isEmpty(content)) { | 93 | if (!TextUtils.isEmpty(content)) { |
| 93 | if (type.equals("friends")) { | 94 | if (type.equals("friends")) { |
| 94 | - ifViewAttached(view -> view.shareFriends(content)); | 95 | + if(getView() != null) getView().shareFriends(content); |
| 96 | +// ifViewAttached(view -> view.shareFriends(content)); | ||
| 95 | } else if (type.equals("life")) { | 97 | } else if (type.equals("life")) { |
| 96 | - ifViewAttached(view -> view.shareLife(content)); | 98 | + if(getView() != null) getView().shareLife(content); |
| 99 | +// ifViewAttached(view -> view.shareLife(content)); | ||
| 97 | } else { | 100 | } else { |
| 98 | - ifViewAttached(view -> view.showMessage("类型异常")); | 101 | + if(getView() != null) getView().showMessage("类型异常"); |
| 102 | +// ifViewAttached(view -> view.showMessage("类型异常")); | ||
| 99 | } | 103 | } |
| 100 | } else { | 104 | } else { |
| 101 | - ifViewAttached(view -> view.showMessage("非法图片地址")); | 105 | + if(getView() != null) getView().showMessage("非法图片地址"); |
| 106 | +// ifViewAttached(view -> view.showMessage("非法图片地址")); | ||
| 102 | } | 107 | } |
| 103 | } | 108 | } |
| 104 | 109 | ||
| 105 | @Override | 110 | @Override |
| 106 | public void onError(Throwable e) { | 111 | public void onError(Throwable e) { |
| 107 | - ifViewAttached(view -> { | ||
| 108 | - view.hideLoading(); | ||
| 109 | - view.showMessage(e.getMessage()); | ||
| 110 | - }); | 112 | +// ifViewAttached(view -> { |
| 113 | + if(getView() != null) { | ||
| 114 | + getView().hideLoading(); | ||
| 115 | + getView().showMessage(e.getMessage()); | ||
| 116 | + } | ||
| 117 | +// view.hideLoading(); | ||
| 118 | +// view.showMessage(e.getMessage()); | ||
| 119 | +// }); | ||
| 111 | } | 120 | } |
| 112 | 121 | ||
| 113 | @Override | 122 | @Override |
| @@ -219,17 +228,21 @@ public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | @@ -219,17 +228,21 @@ public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | ||
| 219 | * @param url | 228 | * @param url |
| 220 | */ | 229 | */ |
| 221 | public void savePicture(Activity context, String url) { | 230 | public void savePicture(Activity context, String url) { |
| 222 | - ifViewAttached(view -> view.hideLoading()); | 231 | + if(getView() != null) getView().hideLoading(); |
| 232 | +// ifViewAttached(view -> view.hideLoading()); | ||
| 223 | if (TextUtils.isEmpty(url)) { | 233 | if (TextUtils.isEmpty(url)) { |
| 224 | - ifViewAttached(view -> view.showMessage("非法图片地址")); | 234 | + if(getView() != null) getView().showMessage("非法图片地址"); |
| 235 | +// ifViewAttached(view -> view.showMessage("非法图片地址")); | ||
| 225 | return; | 236 | return; |
| 226 | } | 237 | } |
| 227 | if (FileUtils.isFileExists(url)) { | 238 | if (FileUtils.isFileExists(url)) { |
| 228 | // 本地图片 做copy操作 | 239 | // 本地图片 做copy操作 |
| 229 | - ifViewAttached(view -> view.saveLocalImg(url)); | 240 | + if(getView() != null) getView().saveLocalImg(url); |
| 241 | +// ifViewAttached(view -> view.saveLocalImg(url)); | ||
| 230 | } else { | 242 | } else { |
| 231 | if (!url.contains("http")) { | 243 | if (!url.contains("http")) { |
| 232 | - ifViewAttached(view -> view.showMessage("非法图片地址")); | 244 | + if(getView() != null) getView().showMessage("非法图片地址"); |
| 245 | +// ifViewAttached(view -> view.showMessage("非法图片地址")); | ||
| 233 | return; | 246 | return; |
| 234 | } | 247 | } |
| 235 | Observable.create(new ObservableOnSubscribe<String>() { | 248 | Observable.create(new ObservableOnSubscribe<String>() { |
| @@ -256,15 +269,18 @@ public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | @@ -256,15 +269,18 @@ public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | ||
| 256 | @Override | 269 | @Override |
| 257 | public void onNext(String s) { | 270 | public void onNext(String s) { |
| 258 | if (!TextUtils.isEmpty(s)) { | 271 | if (!TextUtils.isEmpty(s)) { |
| 259 | - ifViewAttached(view -> view.saveLocalImg(s)); | 272 | + if(getView() != null) getView().saveLocalImg(s); |
| 273 | +// ifViewAttached(view -> view.saveLocalImg(s)); | ||
| 260 | } else { | 274 | } else { |
| 261 | - ifViewAttached(view -> view.showMessage("数据异常")); | 275 | + if(getView() != null) getView().showMessage("数据异常"); |
| 276 | +// ifViewAttached(view -> view.showMessage("数据异常")); | ||
| 262 | } | 277 | } |
| 263 | } | 278 | } |
| 264 | 279 | ||
| 265 | @Override | 280 | @Override |
| 266 | public void onError(Throwable e) { | 281 | public void onError(Throwable e) { |
| 267 | - ifViewAttached(view -> view.showMessage(e.getMessage())); | 282 | + if(getView() != null) getView().showMessage(e.getMessage()); |
| 283 | +// ifViewAttached(view -> view.showMessage(e.getMessage())); | ||
| 268 | } | 284 | } |
| 269 | 285 | ||
| 270 | @Override | 286 | @Override |
core/imageload/src/main/java/com/cnlive/core/ui/view/PreViewImageView.java
| @@ -79,7 +79,8 @@ public class PreViewImageView extends BaseView { | @@ -79,7 +79,8 @@ public class PreViewImageView extends BaseView { | ||
| 79 | PreViewImgInfo curPreInfo = activity.data.getCurrPrewInfo(); | 79 | PreViewImgInfo curPreInfo = activity.data.getCurrPrewInfo(); |
| 80 | for (int i = 0; i < preViewImgList.size(); i++) { | 80 | for (int i = 0; i < preViewImgList.size(); i++) { |
| 81 | activity.picList.add(TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) ? preViewImgList.get(i).getImgUrl() : preViewImgList.get(i).getPreviewImgUrl()); | 81 | activity.picList.add(TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) ? preViewImgList.get(i).getImgUrl() : preViewImgList.get(i).getPreviewImgUrl()); |
| 82 | - if (curPreInfo.getPreviewImgUrl().equals(preViewImgList.get(i).getPreviewImgUrl()) || curPreInfo.getImgUrl().equals(preViewImgList.get(i).getImgUrl())) { | 82 | + if ((!TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) && !TextUtils.isEmpty(curPreInfo.getPreviewImgUrl()) && curPreInfo.getPreviewImgUrl().equals(preViewImgList.get(i).getPreviewImgUrl()) ) |
| 83 | + || (!TextUtils.isEmpty(preViewImgList.get(i).getImgUrl()) && !TextUtils.isEmpty(curPreInfo.getImgUrl()) && curPreInfo.getImgUrl().equals(preViewImgList.get(i).getImgUrl()))) { | ||
| 83 | activity.position = i; | 84 | activity.position = i; |
| 84 | } | 85 | } |
| 85 | } | 86 | } |