Commit aa8ba763ab96ba5f9baa714ce0c146a2ae9e463b

Authored by 韩亚云
1 parent c25d296a

添加长按事件加载动画,添加是否有二维码扫描功能,添加相应权限

app/strike/src/main/java/com/cnlive/strike/imgutil/ImgActivity.java
... ... @@ -143,7 +143,6 @@ public class ImgActivity extends AppCompatActivity {
143 143 data.setSid(UserService.getUid(this));
144 144 data.setType("1");
145 145 data.setUserId(UserService.getUid(this));
146   - data.setCollection(true);
147 146 data.setSave(true);
148 147  
149 148 ArrayList<ImagePreviewShowInfo> list = new ArrayList<>();
... ...
core/base/src/main/res/anim/anim_enter.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<set xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <translate
  4 + android:duration="500"
  5 + android:fromYDelta="100%"
  6 + android:toYDelta="0" />
  7 +</set>
0 8 \ No newline at end of file
... ...
core/base/src/main/res/anim/anim_exit.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<set xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <translate
  4 + android:duration="500"
  5 + android:fromYDelta="0"
  6 + android:toYDelta="100%" />
  7 +</set>
0 8 \ No newline at end of file
... ...
core/imageload/src/main/java/com/cnlive/core/imageload/preview/PreviewImageViewActivity.java
... ... @@ -96,17 +96,17 @@ public class PreviewImageViewActivity extends BaseActivity&lt;PreviewImageView, Pre
96 96 public void showProcessDialog(ImagePreviewShowInfo info){
97 97 previewInfo=info;
98 98 requestPermission(String.valueOf(R.string.dialog_imagepicker_permission_save_pic),new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, new OnPermissionResponseListener() {
99   - @Override
100   - public void onSuccess(String[] permissions) {
101   - if(getMvpView() != null) {
102   - getMvpView().showQrDialog("", info.getImgPath());
  99 + @Override
  100 + public void onSuccess(String[] permissions) {
  101 + if(getMvpView() != null) {
  102 + getMvpView().showQrDialog("", info.getImgPath());
  103 + }
103 104 }
104   - }
105 105  
106   - @Override
107   - public void onFail() {
  106 + @Override
  107 + public void onFail() {
108 108  
109   - }
  109 + }
110 110 });
111 111 }
112 112  
... ...
core/imageload/src/main/java/com/cnlive/core/ui/model/PreViewImgData.java
... ... @@ -35,7 +35,6 @@ public class PreViewImgData implements Serializable {
35 35 private boolean isLife = true;
36 36 private boolean isCollection;
37 37 private boolean isSave;
38   - private boolean isScan;
39 38  
40 39 //收藏
41 40 private String collectionId;
... ... @@ -195,14 +194,6 @@ public class PreViewImgData implements Serializable {
195 194 isSave = save;
196 195 }
197 196  
198   - public boolean isScan() {
199   - return isScan;
200   - }
201   -
202   - public void setScan(boolean scan) {
203   - isScan = scan;
204   - }
205   -
206 197 public String getCollectionId() {
207 198 return collectionId;
208 199 }
... ...
core/imageload/src/main/java/com/cnlive/core/ui/presenter/PreViewImagePresenter.java
... ... @@ -9,15 +9,16 @@ import android.text.TextUtils;
9 9 import android.util.Log;
10 10  
11 11 import com.bumptech.glide.Glide;
  12 +import com.bumptech.glide.request.FutureTarget;
  13 +import com.bumptech.glide.request.target.Target;
12 14 import com.cnlive.cloud.user.auth.UserService;
13 15 import com.cnlive.core.imageload.api.ApiServiceStock;
14   -import com.cnlive.core.imageload.preview.DataProcessingActivity;
15   -import com.cnlive.core.imageload.preview.model.PreviewData;
16 16 import com.cnlive.core.libs.base.application.AppConfig;
17 17 import com.cnlive.core.libs.base.frame.presenter.BasePresenter;
18 18 import com.cnlive.core.libs.base.util.FileTypeUtil;
19 19 import com.cnlive.core.libs.base.util.FileUtils;
20 20 import com.cnlive.core.libs.base.util.MD5Util;
  21 +import com.cnlive.core.libs.base.util.NetworkUtil;
21 22 import com.cnlive.core.network.HttpConn;
22 23 import com.cnlive.core.network.NetCallBack;
23 24 import com.cnlive.core.network.model.BaseResult;
... ... @@ -37,6 +38,7 @@ import java.util.HashMap;
37 38 import java.util.List;
38 39 import java.util.Map;
39 40  
  41 +import androidx.annotation.Nullable;
40 42 import cn.bertsir.zbar.utils.QRUtils;
41 43 import io.reactivex.Observable;
42 44 import io.reactivex.ObservableEmitter;
... ... @@ -339,6 +341,90 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
339 341 }
340 342 }
341 343  
  344 +
  345 + /**
  346 + *是否存在二维码
  347 + * @param activity
  348 + * @param imgUrl
  349 + */
  350 + public void isScan(Activity activity,String imgUrl,int position) {
  351 + if (TextUtils.isEmpty(imgUrl)) {
  352 + return;
  353 + }
  354 + if (!NetworkUtil.isConnectInternet(activity)) {
  355 + return;
  356 + }
  357 + Observable.create(new ObservableOnSubscribe<String>() {
  358 + @Override
  359 + public void subscribe(ObservableEmitter<String> emitter) throws Exception {
  360 + File scanFile = getFile(emitter, imgUrl, activity);
  361 + if (scanFile != null && FileUtils.isFileExists(scanFile) && scanFile.length() > 0) {
  362 + String content = null;
  363 + content = QRUtils.getInstance().decodeQRcode(scanFile.getAbsolutePath());
  364 + if (TextUtils.isEmpty(scanFile.getAbsolutePath())) {
  365 + content = QRUtils.getInstance().decodeQRcodeByZxing(scanFile.getAbsolutePath());
  366 + }
  367 + if (content != null && content.length() > 0) {
  368 + emitter.onNext(content);
  369 + } else emitter.onNext("");
  370 + } else {
  371 + emitter.onError(new Throwable("图片解析异常"));
  372 + }
  373 +
  374 + }
  375 +
  376 + }).subscribeOn(Schedulers.io()) //指定被观察者中的方法在io线程中进行处理
  377 + .observeOn(AndroidSchedulers.mainThread()) //指定观察者接收数据在主线程中
  378 + .subscribe(new Observer<String>() {
  379 + @Override
  380 + public void onSubscribe(Disposable d) {
  381 + }
  382 +
  383 + @Override
  384 + public void onNext(String s) {
  385 + if(!TextUtils.isEmpty(s) && s.length() > 0 && getView() != null){
  386 + getView().showDialog(position,true);
  387 + }else {
  388 + if(getView() != null) getView().showDialog(position,false);
  389 + }
  390 + }
  391 +
  392 + @Override
  393 + public void onError(Throwable e) {
  394 + if(getView() != null)getView().showDialog(position,false);
  395 + }
  396 +
  397 + @Override
  398 + public void onComplete() {
  399 +
  400 + }
  401 + });
  402 + }
  403 +
  404 +
  405 + @Nullable
  406 + private File getFile(ObservableEmitter<String> emitter, String imgUrl, Context mContext) throws InterruptedException, java.util.concurrent.ExecutionException {
  407 + File scanFile = null;
  408 + if (FileUtils.isFileExists(imgUrl) && FileUtils.getFileByPath(imgUrl).length() > 0) {
  409 + scanFile = FileUtils.getFileByPath(imgUrl);
  410 + } else {
  411 + if (imgUrl.contains("http")) {
  412 + FutureTarget<File> future = Glide.with(mContext)
  413 + .load(imgUrl)
  414 + .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
  415 + File file = future.get();
  416 + if (file != null && file.exists() && file.length() > 0) {
  417 + scanFile = file;
  418 + } else {
  419 + emitter.onError(new Throwable("图片解析异常"));
  420 + }
  421 + } else {
  422 + emitter.onError(new Throwable("图片解析异常"));
  423 + }
  424 + }
  425 + return scanFile;
  426 + }
  427 +
342 428 /**
343 429 * 扫描二维码
344 430 *
... ... @@ -394,7 +480,8 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
394 480 public void onNext(String qrContent) {
395 481 // if (getView()!=null)getView().hideLoading();
396 482 if (qrContent != null && qrContent.length() > 0) {
397   - ifViewAttached(view -> view.processQrContent(qrContent));
  483 + if (getView()!=null)getView().processQrContent(qrContent);
  484 +// ifViewAttached(view -> view.processQrContent(qrContent));
398 485 } else {
399 486 ifViewAttached(view -> view.showMessage("未识别二维码"));
400 487 }
... ...
core/imageload/src/main/java/com/cnlive/core/ui/view/PreViewImageView.java
1 1 package com.cnlive.core.ui.view;
2 2  
  3 +import android.Manifest;
3 4 import android.annotation.SuppressLint;
4 5 import android.app.Dialog;
5 6 import android.content.ContentResolver;
... ... @@ -24,6 +25,7 @@ import com.cnlive.core.imageload.preview.widget.CustomTipDialog;
24 25 import com.cnlive.core.imageload.preview.widget.DownloadUtil;
25 26 import com.cnlive.core.imagepreview.listener.OnItemLongPressListener;
26 27 import com.cnlive.core.libs.base.frame.view.BaseView;
  28 +import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener;
27 29 import com.cnlive.core.libs.base.util.AlertUtil;
28 30 import com.cnlive.core.libs.base.util.FileTypeUtil;
29 31 import com.cnlive.core.libs.base.util.FileUtils;
... ... @@ -71,6 +73,10 @@ public class PreViewImageView extends BaseView {
71 73 if (TextUtils.isEmpty(activity.type)) {
72 74 showError();
73 75 }
  76 +
  77 + PreViewImgInfo preViewImgInfo = new PreViewImgInfo();
  78 + preViewImgInfo.setImgUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1583074722432&di=7ba0e34112d2c6e3b870fa7ce18827b1&imgtype=0&src=http%3A%2F%2Fm.dazhuanglawyer.com%2Ftupian%2F20190904%2F201909041739423115.jpg");
  79 + activity.data.getPicInfoList().add(preViewImgInfo);
74 80 if (activity.type.equals("1")) {
75 81 preViewImgList = activity.data.getPicInfoList();
76 82 if (preViewImgList.size() == 1) {
... ... @@ -79,7 +85,7 @@ public class PreViewImageView extends BaseView {
79 85 PreViewImgInfo curPreInfo = activity.data.getCurrPrewInfo();
80 86 for (int i = 0; i < preViewImgList.size(); i++) {
81 87 activity.picList.add(TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) ? preViewImgList.get(i).getImgUrl() : preViewImgList.get(i).getPreviewImgUrl());
82   - if ((!TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) && !TextUtils.isEmpty(curPreInfo.getPreviewImgUrl()) && curPreInfo.getPreviewImgUrl().equals(preViewImgList.get(i).getPreviewImgUrl()) )
  88 + if ((!TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) && !TextUtils.isEmpty(curPreInfo.getPreviewImgUrl()) && curPreInfo.getPreviewImgUrl().equals(preViewImgList.get(i).getPreviewImgUrl()))
83 89 || (!TextUtils.isEmpty(preViewImgList.get(i).getImgUrl()) && !TextUtils.isEmpty(curPreInfo.getImgUrl()) && curPreInfo.getImgUrl().equals(preViewImgList.get(i).getImgUrl()))) {
84 90 activity.position = i;
85 91 }
... ... @@ -91,6 +97,7 @@ public class PreViewImageView extends BaseView {
91 97 }
92 98 }
93 99  
  100 +
94 101 public void setPreview() {
95 102 activity.binding.imagePre.overlayStatusBar(false)
96 103 .imageData(activity.picList)
... ... @@ -100,48 +107,68 @@ public class PreViewImageView extends BaseView {
100 107 activity.binding.imagePre.setOnItemLongPressListener(new OnItemLongPressListener() {
101 108 @Override
102 109 public boolean onItemLongPress(int position, ImageView imageView) {
103   - showDialog(position);
  110 + activity.requestPermission(String.valueOf(R.string.dialog_imagepicker_permission_save_pic),new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, new OnPermissionResponseListener() {
  111 + @Override
  112 + public void onSuccess(String[] permissions) {
  113 + activity.getPresenter().isScan(activity,activity.picList.get(position),position);
  114 +
  115 + }
  116 +
  117 + @Override
  118 + public void onFail() {
  119 +
  120 + }
  121 + });
104 122 return false;
105 123 }
106 124 });
107 125 }
108 126  
109 127 //长按弹框事件
110   - public void showDialog(int position) {
  128 + public void showDialog(int position,boolean isScan) {
111 129 if (dialog == null) {
112 130 dialog = new Dialog(activity, R.style.CustomDialogStyle);
113 131 View view = View.inflate(activity, R.layout.dialog_show, null);
114 132 dialog.setContentView(view);
115 133 Window window = dialog.getWindow();
116 134 window.setGravity(Gravity.BOTTOM);
117   -// window.setWindowAnimations(R.style.main_menu_animStyle);
  135 + window.setWindowAnimations(R.style.dialogStyle);
118 136 window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
119 137 dialog.findViewById(R.id.share_friend).setVisibility(activity.data.isFriend() ? View.VISIBLE : View.GONE);
120 138 dialog.findViewById(R.id.share_cirfriend).setVisibility(activity.data.isLife() ? View.VISIBLE : View.GONE);
121 139 dialog.findViewById(R.id.cellection).setVisibility(activity.data.isCollection() ? View.VISIBLE : View.GONE);
122 140 dialog.findViewById(R.id.save_picture).setVisibility(activity.data.isSave() ? View.VISIBLE : View.GONE);
123   - dialog.findViewById(R.id.can_scan).setVisibility(activity.data.isScan() ? View.VISIBLE : View.GONE);
124 141 dialog.findViewById(R.id.cancle).setOnClickListener(view1 -> dialog.dismiss());
125 142 dialog.show();
126 143 } else {
127 144 dialog.show();
128 145 }
  146 + dialog.findViewById(R.id.can_scan).setVisibility(isScan ? View.VISIBLE : View.GONE);
  147 + dialog.findViewById(R.id.share_friend).setOnClickListener(view -> {
  148 + dialog.dismiss();
  149 + activity.getPresenter().shareFriendLife(activity, "friends", TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl());
129 150  
130   - dialog.findViewById(R.id.share_friend).setOnClickListener(view ->
131   - activity.getPresenter().shareFriendLife(activity, "friends", TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl()));
132   - dialog.findViewById(R.id.share_cirfriend).setOnClickListener(view ->
133   - activity.getPresenter().shareFriendLife(activity, "life", TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl()));
134   - dialog.findViewById(R.id.cellection).setOnClickListener(view ->
135   - activity.getPresenter().collectionPic(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl()));
  151 + });
  152 + dialog.findViewById(R.id.share_cirfriend).setOnClickListener(view -> {
  153 + dialog.dismiss();
  154 + activity.getPresenter().shareFriendLife(activity, "life", TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl());
  155 + });
  156 + dialog.findViewById(R.id.cellection).setOnClickListener(view -> {
  157 + dialog.dismiss();
  158 + activity.getPresenter().collectionPic(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl());
  159 + });
136 160 dialog.findViewById(R.id.save_picture).setOnClickListener(view -> {
  161 + dialog.dismiss();
137 162 if (activity.data.getType().equals("1")) {
138 163 activity.getPresenter().savePicture(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl());
139 164 } else if (activity.data.getType().equals("1")) {
140 165 activity.getPresenter().saveVideo(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl());
141 166 }
142 167 });
143   - dialog.findViewById(R.id.can_scan).setOnClickListener(view ->
144   - activity.getPresenter().doScan(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl()));
  168 + dialog.findViewById(R.id.can_scan).setOnClickListener(view -> {
  169 + dialog.dismiss();
  170 + activity.getPresenter().doScan(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl());
  171 + });
145 172 }
146 173  
147 174  
... ... @@ -356,7 +383,6 @@ public class PreViewImageView extends BaseView {
356 383  
357 384 public void hideLoading() {
358 385 if (loadingDiaog != null) loadingDiaog.dismiss();
359   - if (activity != null) activity.finish();
360 386 }
361 387  
362 388 public void showError() {
... ...
core/imageload/src/main/res/values/style.xml
... ... @@ -51,4 +51,10 @@
51 51 <item name="android:windowIsTranslucent">true</item>
52 52 <item name="android:windowAnimationStyle">@style/ActivityInOutAnimation</item>
53 53 </style>
  54 +
  55 +
  56 + <style name="dialogStyle" parent="android:Animation">
  57 + <item name="android:windowEnterAnimation">@anim/anim_enter</item>
  58 + <item name="android:windowExitAnimation">@anim/anim_exit</item>
  59 + </style>
54 60 </resources>
55 61 \ No newline at end of file
... ...