Commit aba0dff9cc61ba0d42aa2ed7f0c456a35ac39dee

Authored by 韩亚云
1 parent fd12b744

图片库代码更新

Showing 31 changed files with 96 additions and 2572 deletions
core/imageload/src/main/java/com/cnlive/core/gridview/GridImgUtil.java
... ... @@ -4,39 +4,33 @@ import android.content.Context;
4 4 import android.graphics.drawable.Drawable;
5 5 import android.widget.ImageView;
6 6  
  7 +import com.bumptech.glide.Glide;
7 8 import com.bumptech.glide.request.RequestListener;
8 9 import com.bumptech.glide.request.target.SimpleTarget;
9   -import com.cnlive.core.imageload.R;
10   -import com.cnlive.core.libs.base.application.GlideApp;
11 10  
12 11 /**
13 12 * created by hanyayun
14 13 * on 2020/2/13
15 14 */
16 15 public class GridImgUtil {
  16 +
17 17 public static void loadImage(Context context, final Object src, final ImageView view) {
18   - GlideApp.with(context)
  18 + Glide.with(context)
19 19 .load(src)
20   -// .placeholder(R.drawable.img_placeholder)
21   -// .error(R.drawable.img_placeholder)
22 20 .into(view);
23 21 }
24 22  
25 23 public static void loadImage(Context context, final Object src, final ImageView view, RequestListener<Drawable> listener) {
26   - GlideApp.with(context)
  24 + Glide.with(context)
27 25 .load(src)
28   -// .placeholder(R.drawable.img_placeholder)
29   -// .error(R.drawable.img_placeholder)
30 26 .listener(listener)
31 27 .into(view);
32 28 }
33 29  
34 30 public static void loadImage(Context context, final Object src, final SimpleTarget<Drawable> target) {
35   - GlideApp.with(context)
  31 + Glide.with(context)
36 32 .load(src)
37 33 .thumbnail(0.1f)
38   -// .placeholder(R.drawable.img_placeholder)
39   -// .error(R.drawable.img_placeholder)
40 34 .into(target);
41 35 }
42 36 }
... ...
core/imageload/src/main/java/com/cnlive/core/imageload/config/SingleConfig.java
... ... @@ -4,7 +4,6 @@ import android.content.Context;
4 4 import android.graphics.Bitmap;
5 5 import android.util.Log;
6 6 import android.view.View;
7   -import android.view.animation.Animation;
8 7  
9 8 import com.bumptech.glide.load.engine.DiskCacheStrategy;
10 9 import com.bumptech.glide.request.transition.ViewPropertyAnimationFactory;
... ... @@ -21,6 +20,7 @@ public class SingleConfig {
21 20 private Context context;
22 21 private boolean ignoreCertificateVerify; //https是否忽略校验
23 22 private String url;
  23 + private Bitmap bitmap;
24 24  
25 25 private float thumbnail; //缩略图缩放倍数
26 26 private String filePath; //文件路径
... ... @@ -77,6 +77,7 @@ public class SingleConfig {
77 77  
78 78 public SingleConfig(ConfigBuilder builder) {
79 79 this.url = builder.url;
  80 + this.bitmap = builder.bitmap;
80 81 this.thumbnail = builder.thumbnail;
81 82 this.filePath = builder.filePath;
82 83 this.file = builder.file;
... ... @@ -171,6 +172,10 @@ public class SingleConfig {
171 172 return url;
172 173 }
173 174  
  175 + public Bitmap getBitmap() {
  176 + return bitmap;
  177 + }
  178 +
174 179 public float getThumbnail() {
175 180 return thumbnail;
176 181 }
... ... @@ -374,6 +379,7 @@ public class SingleConfig {
374 379 * @return
375 380 */
376 381 private String url;
  382 + private Bitmap bitmap;
377 383 private float thumbnail;
378 384 private String filePath;
379 385 private File file;
... ... @@ -387,7 +393,7 @@ public class SingleConfig {
387 393 private boolean asBitmap;//只获取bitmap
388 394 private BitmapListener bitmapListener;
389 395  
390   - // TODO: 2017/4/24 宽高的获取
  396 + // 宽高的获取
391 397 private int width;
392 398 private int height;
393 399  
... ... @@ -414,7 +420,6 @@ public class SingleConfig {
414 420  
415 421 //UI:
416 422 private int placeHolderResId;
417   -
418 423 private int errorResId;
419 424  
420 425 private int shapeMode;//默认矩形,可选直角矩形,圆形/椭圆
... ... @@ -464,6 +469,11 @@ public class SingleConfig {
464 469 return this;
465 470 }
466 471  
  472 + public ConfigBuilder setGif(boolean gif) {
  473 + isGif = gif;
  474 + return this;
  475 + }
  476 +
467 477 /**
468 478 * 设置网络路径
469 479 *
... ... @@ -472,9 +482,11 @@ public class SingleConfig {
472 482 */
473 483 public ConfigBuilder url(String url) {
474 484 this.url = url;
475   - if (url.contains("gif")) {
476   - isGif = true;
477   - }
  485 + return this;
  486 + }
  487 +
  488 + public ConfigBuilder bitmap(Bitmap bitmap){
  489 + this.bitmap = bitmap;
478 490 return this;
479 491 }
480 492  
... ... @@ -497,9 +509,6 @@ public class SingleConfig {
497 509 }
498 510  
499 511 this.filePath = filePath;
500   - if (filePath.contains("gif")) {
501   - isGif = true;
502   - }
503 512 return this;
504 513 }
505 514  
... ... @@ -526,11 +535,6 @@ public class SingleConfig {
526 535 return this;
527 536 }
528 537  
529   - public ConfigBuilder setGif(boolean gif) {
530   - isGif = gif;
531   - return this;
532   - }
533   -
534 538 /**
535 539 * 加载ContentProvider资源
536 540 *
... ... @@ -542,11 +546,6 @@ public class SingleConfig {
542 546 this.contentProvider = contentProvider;
543 547 return this;
544 548 }
545   -
546   - if (contentProvider.contains("gif")) {
547   - isGif = true;
548   - }
549   -
550 549 return this;
551 550 }
552 551  
... ... @@ -557,13 +556,7 @@ public class SingleConfig {
557 556 * @return
558 557 */
559 558 public ConfigBuilder raw(String rawPath) {
560   -
561 559 this.rawPath = rawPath;
562   -
563   - if (rawPath.contains("gif")) {
564   - isGif = true;
565   - }
566   -
567 560 return this;
568 561 }
569 562  
... ... @@ -575,11 +568,6 @@ public class SingleConfig {
575 568 */
576 569 public ConfigBuilder asserts(String assertspath) {
577 570 this.assertspath = assertspath;
578   -
579   - if (assertspath.contains("gif")) {
580   - isGif = true;
581   - }
582   -
583 571 return this;
584 572 }
585 573  
... ... @@ -766,9 +754,5 @@ public class SingleConfig {
766 754 this.isNeedVignette = true;
767 755 return this;
768 756 }
769   -
770   -
771 757 }
772   -
773   -
774 758 }
... ...
core/imageload/src/main/java/com/cnlive/core/imageload/loader/GlideLoader.java
... ... @@ -30,6 +30,7 @@ import com.cnlive.core.imageload.config.ShapeMode;
30 30 import com.cnlive.core.imageload.config.SingleConfig;
31 31 import com.cnlive.core.imageload.util.DownLoadImageService;
32 32 import com.cnlive.core.imageload.util.ImageUtil;
  33 +
33 34 import androidx.annotation.Nullable;
34 35 import jp.wasabeef.glide.transformations.BlurTransformation;
35 36 import jp.wasabeef.glide.transformations.ColorFilterTransformation;
... ... @@ -51,7 +52,7 @@ import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
51 52 * created by hanyayun
52 53 * on 2019/11/19
53 54 */
54   -public class GlideLoader implements ILoader{
  55 +public class GlideLoader implements ILoader {
55 56  
56 57 /**
57 58 * @param context 上下文
... ... @@ -207,7 +208,9 @@ public class GlideLoader implements ILoader{
207 208 if (!TextUtils.isEmpty(config.getUrl())) {
208 209 request = requestManager.load(ImageUtil.appendUrl(config.getUrl()));
209 210 Log.e("TAG","getUrl : "+config.getUrl());
210   - } else if (!TextUtils.isEmpty(config.getFilePath())) {
  211 + }else if(config.getBitmap() != null){
  212 + request = requestManager.load(config.getBitmap());
  213 + } if (!TextUtils.isEmpty(config.getFilePath())) {
211 214 request = requestManager.load(ImageUtil.appendUrl(config.getFilePath()));
212 215 Log.e("TAG","getFilePath : "+config.getFilePath());
213 216 } else if (!TextUtils.isEmpty(config.getContentProvider())) {
... ...
core/imageload/src/main/java/com/cnlive/core/imageload/loader/ILoader.java
... ... @@ -23,7 +23,7 @@ public interface ILoader {
23 23  
24 24 void clearDiskCache();
25 25  
26   - void clearMomoryCache(Context context,View view);
  26 + void clearMomoryCache(Context context, View view);
27 27  
28 28 void clearMomory();
29 29  
... ...
core/imageload/src/main/java/com/cnlive/core/imageload/preview/DataProcessingActivity.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview;
2   -
3   -
4   -import android.app.Activity;
5   -import android.content.Context;
6   -import android.content.Intent;
7   -import android.os.Bundle;
8   -import android.text.TextUtils;
9   -import android.view.View;
10   -import android.view.ViewGroup;
11   -
12   -import androidx.databinding.ViewDataBinding;
13   -
14   -import com.cnlive.core.imageload.R;
15   -import com.cnlive.core.imageload.databinding.ActivityDataProcessingBinding;
16   -import com.cnlive.core.imageload.preview.model.PreviewData;
17   -import com.cnlive.core.imageload.preview.model.ProcessImageInfo;
18   -import com.cnlive.core.imageload.preview.presenter.ProcessHtmlPresenter;
19   -import com.cnlive.core.imageload.preview.view.ProcessHtmlView;
20   -import com.cnlive.core.imageload.preview.widget.DownloadUtil;
21   -import com.cnlive.core.libs.base.frame.activity.BaseActivity;
22   -
23   -import java.util.ArrayList;
24   -
25   -/**
26   - * 作者: 吴奎庆
27   - * <p>
28   - * 时间: 2018/9/19
29   - * <p>
30   - * 简介: 图片预览页面数据处理的页面
31   - */
32   -
33   -public class DataProcessingActivity extends BaseActivity<ProcessHtmlView, ProcessHtmlPresenter> {
34   -
35   -
36   - public ArrayList<ProcessImageInfo> list;
37   - public String imgUrl;
38   - public PreviewData previewData;
39   - private static String type = "HTML5";
40   - public ActivityDataProcessingBinding binding;
41   -
42   - public static void startActivity(Context contxt, ArrayList<ProcessImageInfo> list, String url, PreviewData previewData) {
43   - Intent intent = new Intent(contxt, DataProcessingActivity.class);
44   - intent.putParcelableArrayListExtra("data", list);
45   - intent.putExtra("previewData", previewData);
46   - intent.putExtra("imgUrl", url);
47   - Activity activity = (Activity) contxt;
48   - activity.startActivity(intent);
49   - activity.overridePendingTransition(R.anim.preview_activity_in, R.anim.preview_activity_out);
50   - }
51   -
52   - @Override
53   - protected int getBindLayoutId() {
54   - return R.layout.activity_data_processing;
55   - }
56   -
57   - @Override
58   - protected void initBindingLayoutData(ViewDataBinding baseBinding) {
59   - super.initBindingLayoutData(baseBinding);
60   - binding = (ActivityDataProcessingBinding) baseBinding;
61   -
62   - }
63   -
64   - @Override
65   - protected void initView() {
66   - getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN |
67   - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
68   - getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
69   -
70   -
71   - if (getIntent() != null && "com.cnlive.strike.moudle.preview.ui.DataProcessingActivity".equals(getIntent().getAction())) {
72   - String html5Type = getIntent().getStringExtra("prviewType");
73   - imgUrl = getIntent().getStringExtra("imgUrl");
74   - if (!TextUtils.isEmpty(type) && type.equals(html5Type)) {
75   - if (getMvpView()!=null)getMvpView().initHtm5Type();
76   - }
77   - }else {
78   - list = getIntent().getParcelableArrayListExtra("data");
79   - imgUrl = getIntent().getStringExtra("imgUrl");
80   - previewData = (PreviewData) getIntent().getSerializableExtra("previewData");
81   - }
82   -
83   - if (getMvpView() != null) getMvpView().initView();
84   - }
85   -
86   - @Override
87   - public void finish() {
88   - super.finish();
89   - overridePendingTransition(R.anim.preview_activity_in, R.anim.preview_activity_out);
90   - }
91   -
92   - @Override
93   - protected void onDestroy() {
94   - super.onDestroy();
95   - if (getMvpView() != null) getMvpView().hideLoading();
96   - DownloadUtil.getInstance().cancle();
97   - }
98   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/PreviewImageViewActivity.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview;
2   -
3   -import android.Manifest;
4   -import android.app.Activity;
5   -import android.content.Intent;
6   -import android.graphics.Color;
7   -import android.view.View;
8   -
9   -import com.alibaba.android.arouter.facade.annotation.Route;
10   -import com.cnlive.core.imageload.R;
11   -import com.cnlive.core.imageload.databinding.ActivityPreviewImageViewBinding;
12   -import com.cnlive.core.imageload.preview.adapter.PreviewAdapter;
13   -import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo;
14   -import com.cnlive.core.imageload.preview.model.PreviewData;
15   -import com.cnlive.core.imageload.preview.presenter.PreviewImagePresenter;
16   -import com.cnlive.core.imageload.preview.view.PreviewImageView;
17   -import com.cnlive.core.libs.base.frame.activity.BaseActivity;
18   -import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener;
19   -import com.cnlive.core.libs.base.util.StatusBarUtil;
20   -
21   -import java.util.ArrayList;
22   -import java.util.List;
23   -
24   -import androidx.core.app.ActivityCompat;
25   -import androidx.core.app.ActivityOptionsCompat;
26   -import androidx.databinding.ViewDataBinding;
27   -import androidx.fragment.app.Fragment;
28   -
29   -/**
30   - * 创建:wukuiqing
31   - * <p>
32   - * 时间:2018/3/26
33   - * <p>
34   - * 描述:
35   - */
36   -@Route(path = "/preview/PreviewImageViewActivity")
37   -public class PreviewImageViewActivity extends BaseActivity<PreviewImageView, PreviewImagePresenter> {
38   -
39   - ImagePreviewShowInfo previewInfo;
40   - public PreviewData data;
41   - public ArrayList<ImagePreviewShowInfo> picList = new ArrayList<>();
42   - public String TYPE_OLENY_IMG = "onlyShowImg";
43   - public String TYPE_OLENY_OTHERIMG = "otherImg";
44   - public String TYPE_HTML_IMG = "htmlImg";
45   - public String showPic;
46   - public List<Fragment> fragmentList;
47   - public PreviewAdapter fragmentAdapter;
48   - public int currentItem = 0;
49   - public ActivityPreviewImageViewBinding binding;
50   -
51   -
52   - /**
53   - * 视频预览
54   - *
55   - * @param context
56   - */
57   - public static void startPreviewPictrue(Activity context, View transitionView, PreviewData data) {
58   - Intent intent = new Intent(context, PreviewImageViewActivity.class);
59   - intent.putExtra("data", data);
60   - ActivityOptionsCompat options = ActivityOptionsCompat
61   - .makeSceneTransitionAnimation(context, transitionView, "transition");
62   - ActivityCompat.startActivity(context, intent, options.toBundle());
63   - }
64   -
65   - @Override
66   - protected void initView() {
67   - getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
68   - StatusBarUtil.setTransparentForWindow(this);
69   - StatusBarUtil.addTranslucentView(this,0);
70   - if (getPresenter()!=null)getPresenter().processData(PreviewImageViewActivity.this,getIntent());
71   - }
72   -
73   - @Override
74   - protected int getBindLayoutId() {
75   - return R.layout.activity_preview_image_view;
76   - }
77   -
78   -
79   - @Override
80   - protected void initBindingLayoutData(ViewDataBinding baseBinding) {
81   - super.initBindingLayoutData(baseBinding);
82   - binding = (ActivityPreviewImageViewBinding) baseBinding;
83   -
84   - }
85   -
86   - @Override
87   - public void onBackPressed() {
88   - if(!isFinishing()) {
89   - finish();
90   - overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
91   - }
92   - }
93   -
94   -
95   - //弹出处理图片的工具页面
96   - public void showProcessDialog(ImagePreviewShowInfo info){
97   - previewInfo=info;
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());
103   - }
104   - }
105   -
106   - @Override
107   - public void onFail() {
108   -
109   - }
110   - });
111   - }
112   -
113   - @Override
114   - protected void onDestroy() {
115   - super.onDestroy();
116   - if(getPresenter() != null){
117   - getPresenter().cancel();
118   - }
119   - }
120   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/PreviewImgFragment.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview;
2   -
3   -import android.os.Bundle;
4   -import android.view.View;
5   -
6   -import com.bumptech.glide.Glide;
7   -import com.cnlive.core.imageload.R;
8   -import com.cnlive.core.imageload.databinding.FragmentPreviewImgBinding;
9   -import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo;
10   -import com.cnlive.core.imageload.preview.presenter.PreviewImgPresenter;
11   -import com.cnlive.core.imageload.preview.view.PreviewImgView;
12   -import com.cnlive.core.libs.base.frame.fragment.BaseFragment;
13   -
14   -import androidx.annotation.Nullable;
15   -import androidx.databinding.ViewDataBinding;
16   -
17   -
18   -/**
19   - * 作者: 吴奎庆
20   - * <p>
21   - * 时间: 2018/12/4
22   - * <p>
23   - * 简介:
24   - */
25   -public class PreviewImgFragment extends BaseFragment<PreviewImgView, PreviewImgPresenter> {
26   -
27   - public ImagePreviewShowInfo previewData;
28   - public FragmentPreviewImgBinding binding;
29   -
30   - public static PreviewImgFragment newInstance(ImagePreviewShowInfo info) {
31   - Bundle args = new Bundle();
32   - args.putSerializable("data", info);
33   - PreviewImgFragment fragment = new PreviewImgFragment();
34   - fragment.setArguments(args);
35   - return fragment;
36   - }
37   -
38   - @Override
39   - protected int getBindLayoutId() {
40   - return R.layout.fragment_preview_img;
41   - }
42   -
43   - @Override
44   - protected void initBindingLayoutData(ViewDataBinding baseBinding) {
45   - super.initBindingLayoutData(baseBinding);
46   - binding = (FragmentPreviewImgBinding) baseBinding;
47   -
48   - }
49   -
50   -
51   - @Override
52   - protected void initParams(Bundle params) {
53   - previewData = (ImagePreviewShowInfo) params.getSerializable("data");
54   -
55   - }
56   -
57   - @Override
58   - protected void initView() {
59   - if (getMvpView() != null) getMvpView().initView(previewData);
60   - }
61   -
62   - @Override
63   - public void onDestroy() {
64   - super.onDestroy();
65   - Glide.with(this).onDestroy();
66   - if (getMvpView() != null) getMvpView().timerCancel();
67   - }
68   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/adapter/PrevieBindingAdapter.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.adapter;
2   -
3   -import android.content.Context;
4   -import android.view.LayoutInflater;
5   -import android.view.View;
6   -import android.view.ViewGroup;
7   -
8   -import androidx.databinding.DataBindingUtil;
9   -import androidx.databinding.ViewDataBinding;
10   -import androidx.recyclerview.widget.RecyclerView;
11   -
12   -/**
13   - * Created by gujun on 2017/5/23.
14   - */
15   -
16   -public class PrevieBindingAdapter<T> extends PreviewBaseRecyclerAdapter<T> {
17   - private int layoutId;
18   - protected int itemBRId;
19   -
20   - protected OnAdapterViewClickListener<T> l;
21   - protected OnAdapterViewLoadMoreListener loadMoreListener;
22   -
23   - public PrevieBindingAdapter(Context context) {
24   - super(context);
25   - }
26   -
27   - public PrevieBindingAdapter(Context context, int layoutId, int itemBRId) {
28   - super(context);
29   - this.layoutId = layoutId;
30   - this.itemBRId = itemBRId;
31   - }
32   -
33   - public void setOnViewClickListener(OnAdapterViewClickListener listener) {
34   - l = listener;
35   - }
36   -
37   - public void setOnLoadMoreListener(OnAdapterViewLoadMoreListener listener) {
38   - loadMoreListener = listener;
39   - }
40   -
41   - @Override
42   - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
43   - ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), layoutId, parent, false);
44   - PreviewBindingViewHolder viewHolder = new PreviewBindingViewHolder(binding.getRoot());
45   - viewHolder.setBinding(binding);
46   - return viewHolder;
47   - }
48   -
49   - @Override
50   - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
51   - PreviewBindingViewHolder videoListViewHolder = (PreviewBindingViewHolder) holder;
52   - videoListViewHolder.getBinding().setVariable(itemBRId, getItem(position));
53   - if (l != null)
54   -// videoListViewHolder.getBinding().setVariable(BR.viewClickListener, l);
55   - videoListViewHolder.getBinding().executePendingBindings();
56   - if (loadMoreListener != null && position == getList().size() - 1) {
57   - loadMoreListener.onLoadMore();
58   - }
59   - }
60   -
61   - public interface OnAdapterViewClickListener<T> {
62   - void onViewClick(View v, T program);
63   - }
64   -
65   - public interface OnAdapterViewLoadMoreListener {
66   - void onLoadMore();
67   - }
68   -
69   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/adapter/PreviewAdapter.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.adapter;
2   -
3   -
4   -import java.util.List;
5   -
6   -import androidx.fragment.app.Fragment;
7   -import androidx.fragment.app.FragmentManager;
8   -import androidx.fragment.app.FragmentStatePagerAdapter;
9   -
10   -/**
11   - * 作者: 吴奎庆
12   - * <p>
13   - * 时间: 2018/6/14
14   - * <p>
15   - * 简介:
16   - */
17   -
18   -public class PreviewAdapter extends FragmentStatePagerAdapter {
19   - List<Fragment> fragmentList;
20   - public PreviewAdapter(FragmentManager fm , List<Fragment> fragmentList) {
21   - super(fm);
22   - this.fragmentList=fragmentList;
23   - }
24   -
25   - @Override
26   - public Fragment getItem(int position) {
27   - return fragmentList.get(position);
28   - }
29   -
30   - @Override
31   - public int getCount() {
32   - return fragmentList!=null?fragmentList.size():0;
33   - }
34   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/adapter/PreviewBaseRecyclerAdapter.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.adapter;
2   -
3   -import android.content.Context;
4   -
5   -import java.util.ArrayList;
6   -import java.util.Collections;
7   -import java.util.List;
8   -
9   -import androidx.recyclerview.widget.RecyclerView;
10   -
11   -/**
12   - * 作者: 吴奎庆
13   - * <p>
14   - * 时间: 2018/12/20
15   - * <p>
16   - * 简介:
17   - */
18   -
19   -public abstract class PreviewBaseRecyclerAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
20   - protected List<T> mItems;
21   - protected Context mContext;
22   -
23   - public PreviewBaseRecyclerAdapter(Context context) {
24   - this.mContext = context;
25   - this.mItems = new ArrayList();
26   - }
27   -
28   - public List<T> getList() {
29   - return this.mItems;
30   - }
31   -
32   - public void addItem(T item) {
33   - this.addItem(this.mItems.size(), item);
34   - }
35   -
36   - public void addItem(int index, T item) {
37   - if (item != null) {
38   - this.mItems.add(index, item);
39   -
40   - try {
41   - this.notifyItemInserted(index);
42   - } catch (Exception var4) {
43   -
44   - }
45   -
46   - }
47   - }
48   -
49   - public void addItems(List<T> items) {
50   - if (items != null) {
51   - int position = this.mItems.size() - 1;
52   - this.mItems.addAll(items);
53   - this.notifyDataSetChanged();
54   - }
55   - }
56   -
57   - public void addItems(int indext, List<T> items) {
58   - if (items != null) {
59   - this.mItems.addAll(indext, items);
60   - this.notifyItemRangeInserted(indext, items.size());
61   - }
62   - }
63   -
64   - public boolean containsAll(List<T> items) {
65   - return this.mItems.containsAll(items);
66   - }
67   -
68   - public void updateItem(T tasks, int position) {
69   - if (tasks != null) {
70   - this.mItems.set(position, tasks);
71   -
72   - try {
73   - this.notifyItemChanged(position);
74   - } catch (Exception var4) {
75   -
76   - }
77   -
78   - }
79   - }
80   -
81   - public void updateItems(List<T> items) {
82   - if (items != null) {
83   - this.mItems.clear();
84   - this.mItems.addAll(items);
85   - this.notifyDataSetChanged();
86   - }
87   - }
88   -
89   - public int indexOf(T item) {
90   - return item != null && this.mItems != null && this.mItems.size() > 0 ? this.mItems.indexOf(item) : -1;
91   - }
92   -
93   - public void removeItem(int index) {
94   - this.mItems.remove(index);
95   - this.notifyItemRemoved(index);
96   - }
97   -
98   - public void removeAllItems() {
99   - this.mItems.clear();
100   - this.notifyDataSetChanged();
101   - }
102   -
103   - public void moveItem(T item, int fromPosition, int toPosition) {
104   - if (fromPosition > toPosition) {
105   - Collections.rotate(this.mItems.subList(toPosition, fromPosition + 1), 1);
106   - } else {
107   - Collections.rotate(this.mItems.subList(fromPosition, toPosition + 1), -1);
108   - }
109   -
110   - this.notifyItemMoved(fromPosition, toPosition);
111   - this.mItems.set(toPosition, item);
112   - this.notifyItemChanged(toPosition);
113   - }
114   -
115   - public void getView(int position, RecyclerView.ViewHolder viewHolder, int type, T item) {
116   - }
117   -
118   - public T getItem(int location) {
119   - return this.mItems.get(location);
120   - }
121   -
122   - public int getItemCount() {
123   - return this.mItems == null ? 0 : this.mItems.size();
124   - }
125   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/adapter/PreviewBindingViewHolder.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.adapter;
2   -
3   -/**
4   - * 作者: 吴奎庆
5   - * <p>
6   - * 时间: 2018/12/20
7   - * <p>
8   - * 简介:
9   - */
10   -
11   -import android.view.View;
12   -
13   -import androidx.databinding.ViewDataBinding;
14   -import androidx.recyclerview.widget.RecyclerView;
15   -
16   -public class PreviewBindingViewHolder extends RecyclerView.ViewHolder {
17   - private ViewDataBinding binding;
18   -
19   - public PreviewBindingViewHolder(View itemView) {
20   - super(itemView);
21   - }
22   -
23   - public void setBinding(ViewDataBinding binding) {
24   - this.binding = binding;
25   - }
26   -
27   - public ViewDataBinding getBinding() {
28   - return this.binding;
29   - }
30   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/adapter/ProcessHtmlAdapter.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.adapter;
2   -
3   -import android.content.Context;
4   -
5   -import com.cnlive.core.imageload.R;
6   -import com.cnlive.core.imageload.BR;
7   -import com.cnlive.core.imageload.databinding.ItemProcessHtmlBinding;
8   -import com.cnlive.core.imageload.preview.model.ProcessImageInfo;
9   -
10   -import androidx.recyclerview.widget.RecyclerView;
11   -
12   -/**
13   - * 作者: 吴奎庆
14   - * <p>
15   - * 时间: 2018/9/19
16   - * <p>
17   - * 简介:
18   - */
19   -
20   -public class ProcessHtmlAdapter extends PrevieBindingAdapter<ProcessImageInfo> {
21   - Context mContext;
22   - OnItemClickListener listener;
23   -
24   - public void setItemClickListener(OnItemClickListener listener) {
25   - this.listener = listener;
26   - }
27   -
28   - public ProcessHtmlAdapter(Context context) {
29   - super(context, R.layout.item_process_html, BR.data);
30   - mContext = context;
31   - }
32   -
33   - @Override
34   - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
35   - super.onBindViewHolder(holder, position);
36   - PreviewBindingViewHolder itemHolder = (PreviewBindingViewHolder) holder;
37   - ItemProcessHtmlBinding binding = (ItemProcessHtmlBinding) itemHolder.getBinding();
38   - binding.tvItem.setText(getItem(position).funName);
39   - binding.root.setOnClickListener(v -> {
40   - listener.OnItemClick(getItem(position));
41   - });
42   - }
43   -
44   - public interface OnItemClickListener {
45   - void OnItemClick(ProcessImageInfo item);
46   - }
47   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/model/FeedBackInfo.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.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   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/model/ImagePreviewShowInfo.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.model;
2   -
3   -import java.io.Serializable;
4   -
5   -/**
6   - * created by hanyayun
7   - * on 2019/11/26
8   - */
9   -public class ImagePreviewShowInfo implements Serializable {
10   - private String imgPath;
11   - private String previewPath;
12   -
13   - public String getImgPath() {
14   - return imgPath;
15   - }
16   -
17   - public void setImgPath(String imgPath) {
18   - this.imgPath = imgPath;
19   - }
20   -
21   - public String getPreviewPath() {
22   - return previewPath;
23   - }
24   -
25   - public void setPreviewPath(String previewPath) {
26   - this.previewPath = previewPath;
27   - }
28   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/model/PreviewData.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.model;
2   -
3   -import java.io.Serializable;
4   -import java.util.ArrayList;
5   -
6   -/**
7   - * Created by xiansong on 2018/4/4.
8   - */
9   -
10   -public class PreviewData implements Serializable {
11   -
12   - //moment/sub
13   - private String collectionType;
14   - private String sid;
15   - // 0:文本, 1:图片, 2:视频, 3:h5
16   - private String type;
17   - private String itemId;
18   - private boolean isCollection;
19   - private String userId;
20   - //预览的图片 以及视频的预览图
21   - private String showImg;
22   - private String videoVid;
23   - private String videoPath;
24   - //是否是本地视频
25   - private boolean isLocal;
26   - //本地视频的地址
27   - private String videoLocalPath;
28   - //是否展示 保存 收藏的弹框
29   - private boolean isHideDialog;
30   - //保存文件
31   - private boolean isSave;
32   - //本地视频必须传此参数
33   - private int locwid;
34   - private int lochei;
35   - //是否展示好友(默认转发)
36   - private boolean isFriend = true;
37   - //是否展示转发生活圈(默认展示)
38   - private boolean isLife = false;
39   -
40   - //是否展示扫描二维码
41   - private boolean isScan = true;
42   - private boolean isHide;
43   -
44   - private ArrayList<ImagePreviewShowInfo> picList;
45   -
46   - public String getCollectionType() {
47   - return collectionType;
48   - }
49   -
50   - public void setCollectionType(String collectionType) {
51   - this.collectionType = collectionType;
52   - }
53   -
54   - public boolean isScan() {
55   - return isScan;
56   - }
57   -
58   - public void setScan(boolean scan) {
59   - isScan = scan;
60   - }
61   -
62   - public boolean isFriend() {
63   - return isFriend;
64   - }
65   -
66   - public void setFriend(boolean friend) {
67   - isFriend = friend;
68   - }
69   -
70   - public boolean isLife() {
71   - return isLife;
72   - }
73   -
74   - public void setLife(boolean life) {
75   - isLife = life;
76   - }
77   -
78   - public int getLocwid() {
79   - return locwid;
80   - }
81   -
82   - public void setLocwid(int locwid) {
83   - this.locwid = locwid;
84   - }
85   -
86   - public int getLochei() {
87   - return lochei;
88   - }
89   -
90   - public void setLochei(int lochei) {
91   - this.lochei = lochei;
92   - }
93   -
94   -
95   - public boolean isSave() {
96   - return isSave;
97   - }
98   -
99   - public void setSave(boolean save) {
100   - isSave = save;
101   - }
102   -
103   - public String getVideoLocalPath() {
104   - return videoLocalPath;
105   - }
106   -
107   - public void setVideoLocalPath(String videoLocalPath) {
108   - this.videoLocalPath = videoLocalPath;
109   - }
110   -
111   - public boolean isHideDialog() {
112   - return isHideDialog;
113   - }
114   -
115   - public void setHideDialog(boolean hideDialog) {
116   - isHideDialog = hideDialog;
117   - }
118   -
119   -
120   - public boolean isHide() {
121   - return isHide;
122   - }
123   -
124   - public void setHide(boolean hide) {
125   - isHide = hide;
126   - }
127   -
128   - public boolean isCollection() {
129   - return isCollection;
130   - }
131   -
132   - public void setCollection(boolean collection) {
133   - isCollection = collection;
134   - }
135   -
136   - public String getShowImg() {
137   - return showImg;
138   - }
139   -
140   - public void setShowImg(String showImg) {
141   - this.showImg = showImg;
142   - }
143   -
144   - public String getVideoVid() {
145   - return videoVid;
146   - }
147   -
148   - public void setVideoVid(String videoVid) {
149   - this.videoVid = videoVid;
150   - }
151   -
152   - public boolean isLocal() {
153   - return isLocal;
154   - }
155   -
156   - public void setLocal(boolean local) {
157   - isLocal = local;
158   - }
159   -
160   - public ArrayList<ImagePreviewShowInfo> getPicList() {
161   - return picList;
162   - }
163   -
164   - public void setPicList(ArrayList<ImagePreviewShowInfo> picList) {
165   - this.picList = picList;
166   - }
167   -
168   - public String getVideoPath() {
169   - return videoPath;
170   - }
171   -
172   - public void setVideoPath(String videoPath) {
173   - this.videoPath = videoPath;
174   - }
175   -
176   - public String getSid() {
177   - return sid;
178   - }
179   -
180   - public void setSid(String sid) {
181   - this.sid = sid;
182   - }
183   -
184   - public String getType() {
185   - return type;
186   - }
187   -
188   - public void setType(String type) {
189   - this.type = type;
190   - }
191   -
192   - public String getItemId() {
193   - return itemId;
194   - }
195   -
196   - public void setItemId(String itemId) {
197   - this.itemId = itemId;
198   - }
199   -
200   - public String getUserId() {
201   - return userId;
202   - }
203   -
204   - public void setUserId(String userId) {
205   - this.userId = userId;
206   - }
207   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/model/ProcessImageInfo.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.model;
2   -
3   -import android.os.Parcel;
4   -import android.os.Parcelable;
5   -
6   -import androidx.databinding.BaseObservable;
7   -
8   -/**
9   - * 作者: 吴奎庆
10   - * <p>
11   - * 时间: 2018/9/1
12   - * <p>
13   - * 简介:
14   - */
15   -
16   -public class ProcessImageInfo extends BaseObservable implements Parcelable {
17   - public String funName;
18   - public String type;
19   - public String qrContent;
20   -
21   - public ProcessImageInfo(String funName, String type, String qrContent) {
22   - this.funName = funName;
23   - this.type = type;
24   - this.qrContent = qrContent;
25   - }
26   -
27   - protected ProcessImageInfo(Parcel in) {
28   - funName = in.readString();
29   - type = in.readString();
30   - qrContent = in.readString();
31   - }
32   -
33   - public static final Creator<ProcessImageInfo> CREATOR = new Creator<ProcessImageInfo>() {
34   - @Override
35   - public ProcessImageInfo createFromParcel(Parcel in) {
36   - return new ProcessImageInfo(in);
37   - }
38   -
39   - @Override
40   - public ProcessImageInfo[] newArray(int size) {
41   - return new ProcessImageInfo[size];
42   - }
43   - };
44   -
45   - public String getFunName() {
46   - return funName;
47   - }
48   -
49   - public void setFunName(String funName) {
50   - this.funName = funName;
51   - }
52   -
53   - public String getType() {
54   - return type;
55   - }
56   -
57   - public void setType(String type) {
58   - this.type = type;
59   - }
60   -
61   - public String getQrContent() {
62   - return qrContent;
63   - }
64   -
65   - public void setQrContent(String qrContent) {
66   - this.qrContent = qrContent;
67   - }
68   -
69   - @Override
70   - public int describeContents() {
71   - return 0;
72   - }
73   -
74   - @Override
75   - public void writeToParcel(Parcel dest, int flags) {
76   - dest.writeString(funName);
77   - dest.writeString(type);
78   - dest.writeString(qrContent);
79   - }
80   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/presenter/PreviewImagePresenter.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.presenter;
2   -
3   -import android.content.Context;
4   -import android.content.Intent;
5   -import android.text.TextUtils;
6   -
7   -import com.bumptech.glide.Glide;
8   -import com.cnlive.core.imageload.preview.PreviewImageViewActivity;
9   -import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo;
10   -import com.cnlive.core.imageload.preview.model.PreviewData;
11   -import com.cnlive.core.imageload.preview.view.PreviewImageView;
12   -import com.cnlive.core.libs.base.frame.presenter.BasePresenter;
13   -import com.cnlive.core.libs.base.util.FileUtils;
14   -import com.google.gson.Gson;
15   -
16   -import java.io.File;
17   -import java.util.ArrayList;
18   -
19   -import cn.bertsir.zbar.utils.QRUtils;
20   -import io.reactivex.Observable;
21   -import io.reactivex.ObservableOnSubscribe;
22   -import io.reactivex.android.schedulers.AndroidSchedulers;
23   -import io.reactivex.disposables.Disposable;
24   -import io.reactivex.schedulers.Schedulers;
25   -
26   -/**
27   - * created by hanyayun
28   - * on 2019/11/26
29   - */
30   -public class PreviewImagePresenter extends BasePresenter<PreviewImageView> {
31   - //收藏 Event
32   - private Disposable disposable;
33   -
34   - /**
35   - * 识别是否是二维码
36   - *
37   - * @return
38   - */
39   - public void isQr(Context context, String path, int position) {
40   - if (disposable != null) disposable.dispose();
41   - if (context == null || TextUtils.isEmpty(path)) return;
42   - disposable = Observable
43   - .create((ObservableOnSubscribe<String>) emitter -> {
44   - File scanFile = null;
45   - if (FileUtils.isFileExists(path) && FileUtils.getFileByPath(path).length() > 0) {
46   - scanFile = FileUtils.getFileByPath(path);
47   - } else {
48   - if (path.contains("http")) {
49   - File file = Glide.with(context).asFile().load(path).submit().get();
50   - if (file != null && file.exists() && file.length() > 0) {
51   - scanFile = file;
52   - } else {
53   - emitter.onError(new Throwable("图片地址异常"));
54   - }
55   - } else {
56   - emitter.onError(new Throwable("图片地址异常"));
57   - }
58   - }
59   - if (scanFile != null && FileUtils.isFileExists(scanFile) && scanFile.length() > 0) {
60   - String content = null;
61   - content = QRUtils.getInstance().decodeQRcode(scanFile.getAbsolutePath());
62   - if (TextUtils.isEmpty(scanFile.getAbsolutePath())) {
63   - content = QRUtils.getInstance().decodeQRcodeByZxing(scanFile.getAbsolutePath());
64   - }
65   - if (content != null && content.length() > 0) {
66   - emitter.onNext(content);
67   - } else {
68   - emitter.onNext("");
69   - }
70   - } else {
71   - emitter.onError(new Throwable("图片地址异常"));
72   - }
73   - })
74   - .subscribeOn(Schedulers.io()) //指定被观察者中的方法在io线程中进行处理
75   - .observeOn(AndroidSchedulers.mainThread()) //指定观察者接收数据在主线程中
76   - .subscribe(content -> {
77   - if (content != null && content.length() > 0) {
78   - ifViewAttached(view -> view.showQrDialog(content, path));
79   - } else {
80   - ifViewAttached(view -> view.showQrDialog("", path));
81   - }
82   - },
83   - throwable -> ifViewAttached(view -> view.showMessage("图像解析失败.")));
84   - }
85   -
86   -
87   - public void cancel() {
88   - if (disposable != null) disposable.dispose();
89   - }
90   -
91   - /**
92   - * 处理外部进来的数据
93   - *
94   - * @param mActivity
95   - * @param intent
96   - */
97   - public void processData(PreviewImageViewActivity mActivity, Intent intent) {
98   - if (intent == null) {
99   - ifViewAttached(view -> view.showError());
100   - return;
101   - }
102   - PreviewData data = (PreviewData) intent.getSerializableExtra("data");
103   - String type = intent.getStringExtra("type");
104   - if (mActivity.TYPE_OLENY_IMG.equals(type)) {
105   - //展示单张图片的逻辑(不能长按操作)
106   - ifViewAttached(view -> view.showOnlyImg(intent));
107   - } else if (data != null) {
108   - mActivity.showPic = data.getShowImg();
109   - mActivity.picList = data.getPicList();
110   - mActivity.data= (PreviewData) intent.getSerializableExtra("data");
111   - ifViewAttached(view -> view.initData(mActivity.showPic, mActivity.picList));
112   - } else if (mActivity.TYPE_OLENY_OTHERIMG.equals(type)) {
113   - //处理其他页面跳转进来的逻辑
114   - ArrayList<String> preImgList = new ArrayList();
115   - String showPic = intent.getStringExtra("previewUrl");
116   - String collectionType = intent.getStringExtra("collectionType");
117   - if (TextUtils.isEmpty(collectionType))collectionType="moment";
118   - //展示的图片
119   - preImgList = intent.getStringArrayListExtra("preImgList");
120   - mActivity.data=new PreviewData();
121   - boolean isHide = intent.getBooleanExtra("isHide", false);
122   - ArrayList<ImagePreviewShowInfo> itemList = new ArrayList<>();
123   - boolean isFriend = intent.getBooleanExtra("isFriend", false);
124   - boolean isLife = intent.getBooleanExtra("isLife", false);
125   - boolean isCollection = intent.getBooleanExtra("isCollection", false);
126   - mActivity.data = new PreviewData();
127   - ArrayList list = new ArrayList<>();
128   - for (String pic : preImgList) {
129   - try {
130   - Gson gson = new Gson();
131   - ImagePreviewShowInfo info = gson.fromJson(pic, ImagePreviewShowInfo.class);
132   - itemList.add(info);
133   - }catch (Exception e){
134   - ifViewAttached(view -> view.showError());
135   - }
136   -
137   - }
138   - mActivity.data.setPicList(list);
139   - mActivity.data.setHide(isHide);
140   - mActivity.data.setLife(isLife);
141   - mActivity.data.setFriend(isFriend);
142   - mActivity.data.setCollectionType(collectionType);
143   - mActivity.data.setCollection(isCollection);
144   - mActivity.data.setShowImg(showPic);
145   - mActivity.data.setPicList(itemList);
146   - mActivity.showPic = showPic;
147   - mActivity.picList = itemList;
148   - ifViewAttached(view -> view.initData(mActivity.showPic, mActivity.picList));
149   -
150   - }else if (mActivity.TYPE_HTML_IMG.equals(type)){
151   - //处理其他页面跳转进来的逻辑
152   - ArrayList<String> preImgList = new ArrayList();
153   - String showPic = intent.getStringExtra("previewUrl");
154   - String collectionType = intent.getStringExtra("collectionType");
155   - if (TextUtils.isEmpty(collectionType))collectionType="moment";
156   - //展示的图片
157   - preImgList = intent.getStringArrayListExtra("preImgList");
158   - mActivity.data=new PreviewData();
159   - boolean isHide = intent.getBooleanExtra("isHide", false);
160   - ArrayList<ImagePreviewShowInfo> itemList = new ArrayList<>();
161   - boolean isFriend = intent.getBooleanExtra("isFriend", false);
162   - boolean isLife = intent.getBooleanExtra("isLife", false);
163   - boolean isCollection = intent.getBooleanExtra("isCollection", false);
164   - mActivity.data = new PreviewData();
165   - ArrayList list = new ArrayList<>();
166   - for (String pic : preImgList) {
167   - try {
168   - Gson gson = new Gson();
169   - ImagePreviewShowInfo info = gson.fromJson(pic, ImagePreviewShowInfo.class);
170   - itemList.add(info);
171   - }catch (Exception e){
172   - ifViewAttached(view -> view.showError());
173   - }
174   -
175   - }
176   - mActivity.data.setPicList(list);
177   - mActivity.data.setHide(isHide);
178   - mActivity.data.setLife(isLife);
179   - mActivity.data.setFriend(isFriend);
180   - mActivity.data.setCollectionType(collectionType);
181   - mActivity.data.setCollection(isCollection);
182   - mActivity.data.setShowImg(showPic);
183   - mActivity.data.setPicList(itemList);
184   - mActivity.showPic = showPic;
185   - mActivity.picList = itemList;
186   - ifViewAttached(view -> view.initHtml(mActivity.showPic, mActivity.picList));
187   - }else {
188   - ifViewAttached(view -> view.showError());
189   - return;
190   - }
191   - }
192   -}
193   -
core/imageload/src/main/java/com/cnlive/core/imageload/preview/presenter/PreviewImgPresenter.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.presenter;
2   -
3   -
4   -import android.content.Context;
5   -
6   -import com.bumptech.glide.Glide;
7   -import com.bumptech.glide.load.DataSource;
8   -import com.bumptech.glide.load.engine.GlideException;
9   -import com.bumptech.glide.request.FutureTarget;
10   -import com.bumptech.glide.request.RequestListener;
11   -import com.bumptech.glide.request.target.Target;
12   -import com.cnlive.core.imageload.preview.PreviewImgFragment;
13   -import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo;
14   -import com.cnlive.core.imageload.preview.view.PreviewImgView;
15   -import com.cnlive.core.libs.base.frame.presenter.BasePresenter;
16   -import com.cnlive.core.libs.base.util.FileUtils;
17   -import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
18   -
19   -import java.io.File;
20   -
21   -import androidx.annotation.Nullable;
22   -
23   -import io.reactivex.Observable;
24   -import io.reactivex.ObservableEmitter;
25   -import io.reactivex.ObservableOnSubscribe;
26   -import io.reactivex.Observer;
27   -import io.reactivex.android.schedulers.AndroidSchedulers;
28   -import io.reactivex.disposables.Disposable;
29   -import io.reactivex.schedulers.Schedulers;
30   -
31   -/**
32   - * 作者: 吴奎庆
33   - * <p>
34   - * 时间: 2018/12/4
35   - * <p>
36   - * 简介:
37   - */
38   -public class PreviewImgPresenter extends BasePresenter<PreviewImgView> {
39   -
40   - public void showImg(Context context, ImagePreviewShowInfo previewData) {
41   -
42   - if(FileUtils.isFileExists(new File(previewData.getImgPath()))){
43   - ifViewAttached(view -> view.showResourceReady());
44   - ifViewAttached(view -> view.showImg(new File(previewData.getImgPath())));
45   - }else {
46   - Observable.create(new ObservableOnSubscribe<File>() {
47   - @Override
48   - public void subscribe(ObservableEmitter<File> emitter) {
49   - FutureTarget<File> file = Glide.with(context).asFile().load(previewData.getImgPath()).listener(new RequestListener<File>() {
50   - @Override
51   - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {
52   -// ifViewAttached(view -> view.showLoadFail());
53   - return false;
54   - }
55   -
56   - @Override
57   - public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
58   -// ifViewAttached(view -> view.showResourceReady());
59   - return false;
60   - }
61   - }).submit();
62   - try {
63   - File imgfile = file.get();
64   - if (FileUtils.isFileExists(imgfile)) {
65   - emitter.onNext(imgfile);
66   - } else {
67   - emitter.onError(new Throwable("加载失败"));
68   - }
69   - } catch (Exception e) {
70   - emitter.onError(new Throwable("加载失败"));
71   - }
72   -
73   - }
74   - }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<File>() {
75   -
76   -
77   - @Override
78   - public void onSubscribe(Disposable d) {
79   -
80   - }
81   -
82   - @Override
83   - public void onNext(File filse) {
84   -
85   - ifViewAttached(view -> view.showResourceReady());
86   - ifViewAttached(view -> view.showImg(filse));
87   - }
88   -
89   - @Override
90   - public void onError(Throwable e) {
91   - ifViewAttached(view -> view.showLoadFail());
92   - if (e != null) {
93   - ifViewAttached(view -> view.showMessage(e.getMessage()));
94   - }
95   -
96   - }
97   -
98   - @Override
99   - public void onComplete() {
100   -
101   - }
102   - });
103   - }
104   -
105   - }
106   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/presenter/ProcessHtmlPresenter.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.presenter;
2   -
3   -import android.app.Activity;
4   -import android.content.Context;
5   -import android.content.Intent;
6   -import android.net.Uri;
7   -import android.os.Environment;
8   -import android.text.TextUtils;
9   -import android.util.Log;
10   -
11   -import com.bumptech.glide.Glide;
12   -import com.cnlive.core.imageload.api.ApiServiceStock;
13   -import com.cnlive.core.imageload.preview.DataProcessingActivity;
14   -import com.cnlive.core.imageload.preview.model.PreviewData;
15   -import com.cnlive.core.imageload.preview.view.ProcessHtmlView;
16   -import com.cnlive.core.libs.base.application.AppConfig;
17   -import com.cnlive.core.libs.base.frame.presenter.BasePresenter;
18   -import com.cnlive.core.libs.base.util.FileTypeUtil;
19   -import com.cnlive.core.libs.base.util.FileUtils;
20   -import com.cnlive.core.libs.base.util.MD5Util;
21   -import com.cnlive.core.network.model.BaseResult;
22   -import com.cnlive.core.network.HttpConn;
23   -import com.cnlive.core.network.NetCallBack;
24   -import com.cnlive.core.network.request.BaseRequest;
25   -import com.cnlive.core.network.upload.UploadLogic;
26   -import com.cnlive.cloud.user.auth.UserService;
27   -
28   -import java.io.File;
29   -import java.io.FileInputStream;
30   -import java.io.FileOutputStream;
31   -import java.io.InputStream;
32   -import java.util.ArrayList;
33   -import java.util.HashMap;
34   -import java.util.List;
35   -import java.util.Map;
36   -
37   -import cn.bertsir.zbar.utils.QRUtils;
38   -import io.reactivex.Observable;
39   -import io.reactivex.ObservableEmitter;
40   -import io.reactivex.ObservableOnSubscribe;
41   -import io.reactivex.Observer;
42   -import io.reactivex.android.schedulers.AndroidSchedulers;
43   -import io.reactivex.disposables.Disposable;
44   -import io.reactivex.schedulers.Schedulers;
45   -
46   -/**
47   - * 作者: 吴奎庆
48   - * <p>
49   - * 时间: 2018/9/19
50   - * <p>
51   - * 简介:
52   - */
53   -
54   -public class ProcessHtmlPresenter extends BasePresenter<ProcessHtmlView> {
55   -
56   - public void processLocalImag(DataProcessingActivity mContext, String imagePath) {
57   - if (TextUtils.isEmpty(imagePath) && mContext == null) return;
58   - List<String> list = new ArrayList();
59   - list.add(imagePath);
60   -
61   - UploadLogic.uploadonePic(mContext, true, list, new NetCallBack<List<com.cnlive.core.network.upload.model.FeedBackInfo>>() {
62   - @Override
63   - public void onRequestState(int state) {
64   -
65   - }
66   -
67   - @Override
68   - public void onSuccess(List<com.cnlive.core.network.upload.model.FeedBackInfo> data) {
69   - if(data.size() > 0){
70   - if (data.get(0).getImageUrl().contains("http")) {
71   - collection(mContext, data.get(0).getImageUrl(), mContext.previewData);
72   - } else {
73   - ifViewAttached(view -> view.showMessage("数据异常"));
74   - }
75   - }
76   - }
77   -
78   - @Override
79   - public void onFailure(String errCode, String errMsg, Exception e) {
80   - ifViewAttached(view -> view.showMessage(errMsg));
81   - }
82   - });
83   -
84   - }
85   -
86   - /**
87   - * 收藏图片
88   - *
89   - * @param context
90   - * @param imagePath
91   - */
92   - public void collectionPic(DataProcessingActivity context, String imagePath) {
93   - if (context == null && TextUtils.isEmpty(imagePath)) return;
94   - if (FileUtils.isFileExists(imagePath)) {
95   - ifViewAttached(view -> processLocalImag(context, imagePath));
96   - } else {
97   - if (context.previewData != null) collection(context, imagePath, context.previewData);
98   - }
99   -
100   - }
101   -
102   - private void collection(DataProcessingActivity context, String imagePath, PreviewData previewData) {
103   - if (previewData == null) return;
104   - String userID = UserService.getUid(context);
105   - Map<String, String> requestMap = new HashMap<>();
106   - requestMap.put("appId", AppConfig.getAppId());
107   - requestMap.put("sid", userID);
108   - requestMap.put("type", previewData.getType());
109   - if ("2".equals(previewData.getType())) {
110   - requestMap.put("videoImg", previewData.getShowImg());
111   - requestMap.put("videoId", previewData.getVideoVid());
112   - }
113   - if ("3".equals(previewData.getType())) {
114   - //收藏网址暂未实现
115   - requestMap.put("shareUrl", previewData.getShowImg());
116   - }
117   - if (TextUtils.isEmpty(previewData.getItemId())) {
118   - int index = imagePath.lastIndexOf("/");
119   - if (index != -1) {
120   - String collectionId = imagePath.substring(index + 1);
121   - requestMap.put("collectionId", collectionId);
122   - } else {
123   - requestMap.put("collectionId", imagePath);
124   - }
125   - }
126   - requestMap.put("img", imagePath);
127   - if (TextUtils.isEmpty(previewData.getCollectionType())) {
128   - requestMap.put("collectionType", "moment");
129   - } else {
130   - requestMap.put("collectionType", previewData.getCollectionType());
131   - }
132   -
133   - if (context != null && context.previewData != null && context.previewData.getUserId() != null) {
134   - requestMap.put("userId", context.previewData.getUserId());
135   - }
136   -
137   - HttpConn.action(BaseRequest.init()
138   - .service(ApiServiceStock.class)
139   - .collection(requestMap), new NetCallBack<BaseResult>() {
140   - @Override
141   - public void onRequestState(int state) {
142   -
143   - }
144   -
145   - @Override
146   - public void onSuccess(BaseResult data) {
147   - ifViewAttached(view -> view.sucessful("收藏成功"));
148   - }
149   -
150   - @Override
151   - public void onFailure(String errCode, String errMsg, Exception e) {
152   - ifViewAttached(view -> view.showMessage(errMsg));
153   - }
154   - });
155   - }
156   -
157   - /**
158   - * 保存图片
159   - *
160   - * @param url
161   - */
162   - public void savePicture(Context context, String url) {
163   - ifViewAttached(view -> view.hideLoading());
164   - if (TextUtils.isEmpty(url)) {
165   - ifViewAttached(view -> view.showMessage("非法图片地址"));
166   - return;
167   - }
168   - if (FileUtils.isFileExists(url)) {
169   -// 本地图片 做copy操作
170   - ifViewAttached(view -> view.saveLocalImg(url));
171   - } else {
172   - if (!url.contains("http")) {
173   - ifViewAttached(view -> view.showMessage("非法图片地址"));
174   - return;
175   - }
176   - Observable.create(new ObservableOnSubscribe<String>() {
177   - @Override
178   - public void subscribe(ObservableEmitter<String> emitter) throws Exception {
179   - if (url.contains("http")) {
180   - File file = Glide.with(context).asFile().load(url).submit().get();
181   - if (file != null && file.exists() && file.length() > 0) {
182   - String path = file.getAbsolutePath();
183   - emitter.onNext(path);
184   - } else {
185   - emitter.onError(new Throwable("非法图片地址"));
186   - }
187   - } else {
188   - emitter.onError(new Throwable("非法图片地址"));
189   - }
190   - }
191   - }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {
192   - @Override
193   - public void onSubscribe(Disposable d) {
194   -
195   - }
196   -
197   - @Override
198   - public void onNext(String s) {
199   - if (!TextUtils.isEmpty(s)) {
200   - ifViewAttached(view -> view.saveLocalImg(s));
201   - } else {
202   - ifViewAttached(view -> view.showMessage("数据异常"));
203   - }
204   - }
205   -
206   - @Override
207   - public void onError(Throwable e) {
208   - ifViewAttached(view -> view.showMessage(e.getMessage()));
209   - }
210   -
211   - @Override
212   - public void onComplete() {
213   -
214   - }
215   - });
216   - }
217   -
218   - }
219   -
220   - public void getForwardingImgPath(Context mContext, String type, String imgUrl) {
221   - if (TextUtils.isEmpty(imgUrl)) return;
222   - if (mContext == null) return;
223   - Observable.create((ObservableOnSubscribe<String>) emitter -> {
224   - if (FileUtils.isFileExists(imgUrl) && FileUtils.getFileByPath(imgUrl).length() > 0) {
225   - emitter.onNext(imgUrl);
226   - } else {
227   - if (imgUrl.contains("http")) {
228   - File file = Glide.with(mContext).asFile().load(imgUrl).submit().get();
229   - if (file != null && file.exists() && file.length() > 0) {
230   - String path = file.getAbsolutePath();
231   - emitter.onNext(path);
232   - } else {
233   - emitter.onError(new Throwable("非法图片地址"));
234   - }
235   - } else {
236   - emitter.onError(new Throwable("非法图片地址"));
237   - }
238   -
239   - }
240   -
241   - }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {
242   - @Override
243   - public void onSubscribe(Disposable d) {
244   -
245   - }
246   -
247   - @Override
248   - public void onNext(String content) {
249   - ifViewAttached(view -> view.hideLoading());
250   - if (!TextUtils.isEmpty(content)) {
251   - if (type.equals("friends")) {
252   - ifViewAttached(view -> view.forwardFriends(content));
253   - } else if (type.equals("life")) {
254   - ifViewAttached(view -> view.forwardLife(content));
255   - } else {
256   - ifViewAttached(view -> view.showMessage("类型异常"));
257   - }
258   - } else {
259   - ifViewAttached(view -> view.showMessage("非法图片地址"));
260   - }
261   - }
262   -
263   - @Override
264   - public void onError(Throwable e) {
265   - ifViewAttached(view -> {
266   - view.hideLoading();
267   - view.showMessage(e.getMessage());
268   - });
269   - }
270   -
271   - @Override
272   - public void onComplete() {
273   -
274   - }
275   - });
276   -
277   - }
278   -
279   -
280   - public void saveVideo(Activity activity, String imgUrl) {
281   - if (TextUtils.isEmpty(imgUrl)) {
282   - ifViewAttached(view -> view.showMessage("数据异常"));
283   - return;
284   - }
285   - if (imgUrl.contains("http")) {
286   - ifViewAttached(view -> view.saveNetVideo(imgUrl));
287   - } else {
288   - saveVideo(activity, FileUtils.getFileByPath(imgUrl));
289   - }
290   - }
291   -
292   - /**
293   - * 复制文件 MD5 保存文件(保证文件唯一)
294   - *
295   - * @param context
296   - * @param file
297   - */
298   - public void saveVideo(Activity context, File file) {
299   - try {
300   - String filePath = "Strike" + File.separator + "video";
301   - String md5 = MD5Util.getMD5(file);
302   - InputStream inStream = new FileInputStream(file); //读入原文件
303   - File appDir = new File(Environment.getExternalStorageDirectory(), filePath);
304   - if (!appDir.exists()) appDir.mkdir();
305   -
306   - String type = FileTypeUtil.getFileType(file.getAbsolutePath());
307   - String extension;//初始文件扩展名
308   - if (TextUtils.isEmpty(type)) {
309   - extension = ".mp4";
310   - } else {
311   - extension = "." + type;
312   - }
313   -
314   - File newFile = new File(appDir, md5 + extension);
315   - FileOutputStream outputStream = new FileOutputStream(newFile);
316   -
317   - int byteread = 0;
318   - byte[] buffer2 = new byte[1444];
319   - while ((byteread = inStream.read(buffer2)) != -1)
320   - outputStream.write(buffer2, 0, byteread);
321   - inStream.close();
322   - outputStream.close();
323   -
324   - context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(newFile.getAbsolutePath())));
325   - ifViewAttached(view -> view.showSucessfulMessage("保存成功"));
326   - context.finish();
327   - } catch (Exception e) {
328   - Log.e("文件保存异常:", "Exception ", e);
329   - }
330   - }
331   -
332   - public void identifyTheQRCode(Context mActivity, String path) {
333   -
334   - if (TextUtils.isEmpty(path) && mActivity != null) return;
335   - Observable.create(new ObservableOnSubscribe<String>() {
336   - @Override
337   - public void subscribe(ObservableEmitter<String> emitter) throws Exception {
338   - File scanFile = null;
339   - if (FileUtils.isFileExists(path) && FileUtils.getFileByPath(path).length() > 0) {
340   - scanFile = FileUtils.getFileByPath(path);
341   - } else {
342   - if (path.contains("http")) {
343   - File file = Glide.with(mActivity).asFile().load(path).submit().get();
344   - if (file != null && file.exists() && file.length() > 0) {
345   - scanFile = file;
346   - } else {
347   - emitter.onError(new Throwable("非法图片地址"));
348   - }
349   - } else {
350   - emitter.onError(new Throwable("非法图片地址"));
351   - }
352   - }
353   - if (scanFile != null && FileUtils.isFileExists(scanFile) && scanFile.length() > 0) {
354   - String content = null;
355   - content = QRUtils.getInstance().decodeQRcode(scanFile.getAbsolutePath());
356   - if (TextUtils.isEmpty(scanFile.getAbsolutePath())) {
357   - content = QRUtils.getInstance().decodeQRcodeByZxing(scanFile.getAbsolutePath());
358   - }
359   - if (content != null && content.length() > 0) {
360   - emitter.onNext(content);
361   - } else {
362   - emitter.onNext("");
363   - }
364   - } else {
365   - emitter.onError(new Throwable("非法图片地址"));
366   - }
367   -
368   - }
369   - }).subscribeOn(Schedulers.io()) //指定被观察者中的方法在io线程中进行处理
370   - .observeOn(AndroidSchedulers.mainThread())
371   - //指定观察者接收数据在主线程中
372   - .subscribe(new Observer<String>() {
373   - @Override
374   - public void onSubscribe(Disposable d) {
375   - }
376   -
377   - @Override
378   - public void onNext(String qrContent) {
379   -// if (getView()!=null)getView().hideLoading();
380   - if (qrContent != null && qrContent.length() > 0) {
381   - ifViewAttached(view -> view.processQrContent(qrContent));
382   - } else {
383   - ifViewAttached(view -> view.showMessage("未识别二维码"));
384   - }
385   - }
386   -
387   - @Override
388   - public void onError(Throwable e) {
389   - ifViewAttached(view -> view.hideLoading());
390   - ifViewAttached(view -> view.showMessage(e.getMessage()));
391   - }
392   -
393   - @Override
394   - public void onComplete() {
395   -
396   - }
397   - });
398   -
399   - }
400   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/view/PreviewImageView.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.view;
2   -
3   -import android.content.Intent;
4   -import android.text.TextUtils;
5   -import android.view.View;
6   -
7   -import com.cnlive.core.imageload.preview.DataProcessingActivity;
8   -import com.cnlive.core.imageload.preview.PreviewImageViewActivity;
9   -import com.cnlive.core.imageload.preview.PreviewImgFragment;
10   -import com.cnlive.core.imageload.preview.adapter.PreviewAdapter;
11   -import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo;
12   -import com.cnlive.core.imageload.preview.model.PreviewData;
13   -import com.cnlive.core.imageload.preview.model.ProcessImageInfo;
14   -import com.cnlive.core.libs.base.frame.view.BaseView;
15   -import com.cnlive.core.libs.base.util.AlertUtil;
16   -import com.cnlive.cloud.user.auth.UserService;
17   -import com.google.gson.Gson;
18   -
19   -import java.util.ArrayList;
20   -
21   -import androidx.core.view.ViewCompat;
22   -import androidx.viewpager.widget.ViewPager;
23   -
24   -/**
25   - * created by hanyayun
26   - * on 2019/11/26
27   - */
28   -public class PreviewImageView extends BaseView implements ViewPager.OnPageChangeListener {
29   - PreviewImageViewActivity mActivity;
30   -
31   - public PreviewImageView(PreviewImageViewActivity activity) {
32   - this.mActivity = activity;
33   - }
34   -
35   - public void showQrDialog(String qrContent, String path) {
36   - if (mActivity.data == null || mActivity.picList.size() == 0 || mActivity.data == null)
37   - return;
38   - if (mActivity.data.isHide()) return;
39   - ArrayList<ProcessImageInfo> itemList = new ArrayList<>();
40   - if (mActivity.data.isFriend())
41   - itemList.add(new ProcessImageInfo("转发好友", "friends", qrContent));
42   - if (mActivity.data.isLife())
43   - itemList.add(new ProcessImageInfo("转发生活圈", "life", qrContent));
44   - if (mActivity.data.isCollection())
45   - itemList.add(new ProcessImageInfo("收藏", "collection", qrContent));
46   - itemList.add(new ProcessImageInfo("保存图片", "save", qrContent));
47   - PreviewData previewData = new PreviewData();
48   - previewData.setCollectionType(mActivity.data.getCollectionType());
49   - previewData.setType("1");
50   - previewData.setShowImg(mActivity.data.getShowImg());
51   - previewData.setUserId(UserService.getUid(mActivity));
52   - previewData.setScan(mActivity.data.isScan());
53   - DataProcessingActivity.startActivity(mActivity, itemList, path, previewData);
54   - }
55   -
56   -
57   - public void showMessage(String message) {
58   - if (mActivity == null) return;
59   - AlertUtil.showDeftToast(mActivity, message);
60   - }
61   -
62   - public void showOnlyImg(Intent intent) {
63   - String type = intent.getStringExtra("type");
64   - String collectionType = intent.getStringExtra("collectionType");
65   - if (TextUtils.isEmpty(type)) {
66   - showError();
67   - }
68   - if (mActivity.TYPE_OLENY_IMG.equals(type)) {
69   - String previewUrl = intent.getStringExtra("previewUrl");
70   - String imgUrl = intent.getStringExtra("imgUrl");
71   - mActivity.data = new PreviewData();
72   - mActivity.data.setShowImg(imgUrl);
73   - mActivity.data.setCollectionType(collectionType);
74   - ArrayList list = new ArrayList<>();
75   - ImagePreviewShowInfo info = new ImagePreviewShowInfo();
76   - info.setPreviewPath(previewUrl);
77   - info.setImgPath(imgUrl);
78   - list.add(info);
79   - mActivity.data.setPicList(list);
80   - mActivity.data.setLife(false);
81   - mActivity.data.setFriend(false);
82   - mActivity.data.setScan(false);
83   - mActivity.data.setCollection(false);
84   - mActivity.showPic = mActivity.data.getShowImg();
85   - mActivity.picList = mActivity.data.getPicList();
86   - initData(mActivity.showPic, mActivity.picList);
87   - } else {
88   - showError();
89   - }
90   -
91   - }
92   -
93   - public void initData(String showPic, ArrayList<ImagePreviewShowInfo> picList) {
94   - if (mActivity == null) return;
95   - if (mActivity.fragmentList == null) {
96   - mActivity.fragmentList = new ArrayList<>();
97   - } else {
98   - mActivity.fragmentList.clear();
99   - }
100   -
101   - for (ImagePreviewShowInfo info : picList) {
102   - if (showPic.equals(info.getImgPath())) {
103   - mActivity.currentItem = picList.indexOf(info);
104   - }
105   - mActivity.fragmentList.add(PreviewImgFragment.newInstance(info));
106   - }
107   -
108   - mActivity.fragmentAdapter = new PreviewAdapter(mActivity.getSupportFragmentManager(), mActivity.fragmentList);
109   - mActivity.binding.vpPhotos.setAdapter(mActivity.fragmentAdapter);
110   - mActivity.binding.vpPhotos.setCurrentItem(mActivity.currentItem);
111   - if (mActivity.picList.size() == 1 || mActivity.picList.size() == 0) {
112   - mActivity.binding.rlIndicator.setVisibility(View.GONE);
113   - } else {
114   - mActivity.binding.rlIndicator.setVisibility(View.VISIBLE);
115   - setIndicator(mActivity.currentItem, mActivity.picList.size());
116   - }
117   - mActivity.binding.vpPhotos.addOnPageChangeListener(this);
118   - ViewCompat.setTransitionName(mActivity.binding.vpPhotos, "transition");
119   - }
120   -
121   - public void setIndicator(int position, int all) {
122   - if (mActivity==null)return;
123   - mActivity.binding.tvCurrent.setText(position + 1 + "");
124   - mActivity.binding.tvAll.setText(all + "");
125   - }
126   -
127   - public void initHtml(String showPic, ArrayList<ImagePreviewShowInfo> picList) {
128   - if (mActivity == null) return;
129   - if (mActivity.fragmentList == null) {
130   - mActivity.fragmentList = new ArrayList<>();
131   - } else {
132   - mActivity.fragmentList.clear();
133   - }
134   - Gson gson = new Gson();
135   - ImagePreviewShowInfo imagePreviewShowInfo = gson.fromJson(showPic, ImagePreviewShowInfo.class);
136   - for (ImagePreviewShowInfo info : picList) {
137   -
138   - if (imagePreviewShowInfo != null
139   - && imagePreviewShowInfo.getImgPath().equals(info.getImgPath())) {
140   - mActivity.currentItem = picList.indexOf(info);
141   - }
142   - mActivity.fragmentList.add(PreviewImgFragment.newInstance(info));
143   - }
144   -
145   - mActivity.fragmentAdapter = new PreviewAdapter(mActivity.getSupportFragmentManager(), mActivity.fragmentList);
146   - mActivity.binding.vpPhotos.setAdapter(mActivity.fragmentAdapter);
147   - mActivity.binding.vpPhotos.setCurrentItem(mActivity.currentItem);
148   - mActivity.binding.vpPhotos.addOnPageChangeListener(this);
149   - if (mActivity.picList.size() == 1 || mActivity.picList.size() == 0) {
150   - mActivity.binding.rlIndicator.setVisibility(View.GONE);
151   - } else {
152   - mActivity.binding.rlIndicator.setVisibility(View.VISIBLE);
153   - setIndicator(mActivity.currentItem, mActivity.picList.size());
154   - }
155   - ViewCompat.setTransitionName(mActivity.binding.vpPhotos, "transition");
156   - }
157   -
158   - public void showError() {
159   - mActivity.binding.rlIndicator.setVisibility(View.GONE);
160   - mActivity.binding.vpPhotos.setVisibility(View.GONE);
161   - mActivity.binding.ivError.setVisibility(View.VISIBLE);
162   - }
163   -
164   - @Override
165   - public void onPageScrolled(int i, float v, int i1) {
166   -
167   - }
168   -
169   - @Override
170   - public void onPageSelected(int i) {
171   - setIndicator(i, mActivity.picList.size());
172   - }
173   -
174   - @Override
175   - public void onPageScrollStateChanged(int i) {
176   -
177   - }
178   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/view/PreviewImgView.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.view;
2   -
3   -import android.text.TextUtils;
4   -import android.view.View;
5   -
6   -import com.bumptech.glide.Glide;
7   -import com.bumptech.glide.load.engine.DiskCacheStrategy;
8   -import com.bumptech.glide.request.RequestOptions;
9   -import com.cnlive.core.imageload.R;
10   -import com.cnlive.core.imageload.preview.PreviewImageViewActivity;
11   -import com.cnlive.core.imageload.preview.PreviewImgFragment;
12   -import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo;
13   -import com.cnlive.core.libs.base.frame.view.BaseView;
14   -import com.cnlive.core.libs.base.util.AlertUtil;
15   -import com.cnlive.core.libs.base.util.FileTypeUtil;
16   -import com.cnlive.largeimage.factory.FileBitmapDecoderFactory;
17   -
18   -import java.io.File;
19   -import java.util.Timer;
20   -import java.util.TimerTask;
21   -
22   -/**
23   - * 作者: 吴奎庆
24   - * <p>
25   - * 时间: 2018/12/4
26   - * <p>
27   - * 简介:
28   - */
29   -public class PreviewImgView extends BaseView {
30   - PreviewImgFragment mFragment;
31   - private Timer timer;
32   -
33   - public PreviewImgView(PreviewImgFragment mFragment) {
34   - this.mFragment = mFragment;
35   - }
36   -
37   - public void initView(ImagePreviewShowInfo previewData) {
38   - RequestOptions options = new RequestOptions();
39   - options.diskCacheStrategy(DiskCacheStrategy.ALL);
40   - options.skipMemoryCache(true);
41   - String previewPath = previewData.getPreviewPath();
42   - if (!TextUtils.isEmpty(previewPath))
43   - Glide.with(mFragment).asDrawable().load(previewPath).apply(options).into(mFragment.binding.preview);
44   -// mFragment.binding.lvLoading.setViewColor(mFragment.getActivity().getResources().getColor(R.color.transparent90_white));
45   -// mFragment.binding.lvLoading.startAnim();
46   - mFragment.getPresenter().showImg(mFragment.getActivity(), previewData);
47   - mFragment.binding.gifview.setOnLongClickListener(new View.OnLongClickListener() {
48   - @Override
49   - public boolean onLongClick(View v) {
50   - PreviewImageViewActivity activity = (PreviewImageViewActivity) mFragment.getActivity();
51   - if (activity != null)
52   - activity.showProcessDialog(previewData);
53   -
54   - return false;
55   - }
56   - });
57   -
58   - mFragment.binding.imageView.setOnLongClickListener(new View.OnLongClickListener() {
59   - @Override
60   - public boolean onLongClick(View v) {
61   - PreviewImageViewActivity activity = (PreviewImageViewActivity) mFragment.getActivity();
62   - if (activity != null)
63   - activity.showProcessDialog(previewData);
64   -
65   - return false;
66   - }
67   - });
68   -
69   - mFragment.binding.imageView.setOnClickListener(v -> {
70   - PreviewImageViewActivity activity = (PreviewImageViewActivity) mFragment.getActivity();
71   - if (activity != null)
72   - activity.onBackPressed();
73   -
74   - });
75   -
76   - mFragment.binding.gifview.setOnClickListener(v -> {
77   - PreviewImageViewActivity activity = (PreviewImageViewActivity) mFragment.getActivity();
78   - if (activity != null)
79   - activity.onBackPressed();
80   -
81   - });
82   -
83   - }
84   -
85   - public void showLoadFail() {
86   -// mFragment.binding.lvLoading.stopAnim();
87   - mFragment.binding.lvLoading.setVisibility(View.GONE);
88   - mFragment.binding.preview.setVisibility(View.VISIBLE);
89   - Glide.with(mFragment).asDrawable().load(R.drawable.preview_zwtp).into(mFragment.binding.preview);
90   - mFragment.binding.preview.setOnClickListener(v -> {
91   - PreviewImageViewActivity activity = (PreviewImageViewActivity) mFragment.getActivity();
92   - if (activity != null)
93   - activity.onBackPressed();
94   - });
95   - mFragment.binding.imageView.setVisibility(View.GONE);
96   - }
97   -
98   - public void showResourceReady() {
99   -// mFragment.binding.lvLoading.stopAnim();
100   - mFragment.binding.lvLoading.setVisibility(View.GONE);
101   - }
102   -
103   - public void showMessage(String message) {
104   - if (mFragment == null) return;
105   - AlertUtil.showDeftToast(mFragment.getActivity(), message);
106   - }
107   -
108   - public void showImg(File filse) {
109   - if ("gif".equals(FileTypeUtil.getFileType(filse.getPath()))) {
110   - mFragment.binding.gifview.setVisibility(View.VISIBLE);
111   - RequestOptions options = new RequestOptions();
112   - options.diskCacheStrategy(DiskCacheStrategy.ALL);
113   - Glide.with(mFragment).asGif().load(filse).apply(options).into(mFragment.binding.gifview);
114   - } else {
115   - mFragment.binding.imageView.setVisibility(View.VISIBLE);
116   - mFragment.binding.imageView.setImage(new FileBitmapDecoderFactory(filse));
117   -
118   - }
119   - hidView(mFragment.binding.preview);
120   - }
121   -
122   - private void hidView(View view) {
123   -
124   - TimerTask task = new TimerTask() {
125   - @Override
126   - public void run() {
127   - mFragment.getActivity().runOnUiThread(new Runnable() {
128   - @Override
129   - public void run() {
130   - view.setVisibility(View.GONE);
131   - }
132   - });
133   -
134   - }
135   - };
136   - timer = new Timer();
137   - timer.schedule(task, 50);//3秒后执行TimeTask的run方法
138   - }
139   -
140   - public void timerCancel() {
141   - if (timer != null) timer.cancel();
142   - }
143   -
144   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/view/ProcessHtmlView.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.view;
2   -
3   -import android.annotation.SuppressLint;
4   -import android.content.ContentResolver;
5   -import android.content.ContentValues;
6   -import android.content.Context;
7   -import android.content.Intent;
8   -import android.net.Uri;
9   -import android.os.Environment;
10   -import android.provider.MediaStore;
11   -import android.text.TextUtils;
12   -import android.util.Log;
13   -import android.view.View;
14   -
15   -import com.bumptech.glide.Glide;
16   -import com.bumptech.glide.request.FutureTarget;
17   -import com.bumptech.glide.request.target.Target;
18   -import com.cnlive.core.imageload.preview.DataProcessingActivity;
19   -import com.cnlive.core.imageload.preview.adapter.ProcessHtmlAdapter;
20   -import com.cnlive.core.imageload.preview.model.PreviewData;
21   -import com.cnlive.core.imageload.preview.model.ProcessImageInfo;
22   -import com.cnlive.core.imageload.preview.router.PreviewRouters;
23   -import com.cnlive.core.imageload.preview.widget.CustomTipDialog;
24   -import com.cnlive.core.imageload.preview.widget.DownloadUtil;
25   -import com.cnlive.core.libs.base.frame.view.BaseView;
26   -import com.cnlive.core.libs.base.util.AlertUtil;
27   -import com.cnlive.core.libs.base.util.FileTypeUtil;
28   -import com.cnlive.core.libs.base.util.FileUtils;
29   -import com.cnlive.core.libs.base.util.MD5Util;
30   -import com.cnlive.core.libs.base.util.NetworkUtil;
31   -import com.cnlive.cloud.moudle.qr.uitl.IdentifyTheQRCodeCallback;
32   -import com.cnlive.cloud.moudle.qr.uitl.QrContentUtil;
33   -import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
34   -import com.cnlive.media.picker.entity.Media;
35   -
36   -import java.io.File;
37   -import java.io.FileInputStream;
38   -import java.io.FileOutputStream;
39   -import java.io.InputStream;
40   -import java.util.ArrayList;
41   -
42   -import androidx.annotation.Nullable;
43   -import androidx.recyclerview.widget.LinearLayoutManager;
44   -import cn.bertsir.zbar.utils.QRUtils;
45   -import io.reactivex.Observable;
46   -import io.reactivex.ObservableEmitter;
47   -import io.reactivex.ObservableOnSubscribe;
48   -import io.reactivex.Observer;
49   -import io.reactivex.android.schedulers.AndroidSchedulers;
50   -import io.reactivex.disposables.Disposable;
51   -import io.reactivex.schedulers.Schedulers;
52   -
53   -
54   -/**
55   - * 作者: 吴奎庆
56   - * <p>
57   - * 时间: 2018/9/19
58   - * <p>
59   - * 简介:
60   - */
61   -
62   -public class ProcessHtmlView extends BaseView {
63   - DataProcessingActivity mContext;
64   - private CustomTipDialog loadingDiaog;
65   - private ProcessHtmlAdapter adapter;
66   -
67   - public ProcessHtmlView(DataProcessingActivity processHtmlActivity) {
68   - mContext = processHtmlActivity;
69   - }
70   -
71   - ProcessHtmlAdapter.OnItemClickListener listener = new ProcessHtmlAdapter.OnItemClickListener() {
72   - @Override
73   - public void OnItemClick(ProcessImageInfo data) {
74   - if (mContext == null || mContext.imgUrl == null || mContext.getPresenter() == null)
75   - return;
76   - showLoading();
77   - switch (data.type) {
78   - case "save":
79   - mContext.getPresenter().savePicture(mContext, mContext.imgUrl);
80   - break;
81   - case "collection":
82   - mContext.getPresenter().collectionPic(mContext, mContext.imgUrl);
83   - break;
84   - case "scan":
85   - mContext.getPresenter().identifyTheQRCode(mContext, mContext.imgUrl);
86   - break;
87   - case "friends":
88   - mContext.getPresenter().getForwardingImgPath(mContext, "friends", mContext.imgUrl);
89   - break;
90   - case "life":
91   - mContext.getPresenter().getForwardingImgPath(mContext, "life", mContext.imgUrl);
92   - break;
93   - case "videoSave":
94   - mContext.getPresenter().saveVideo(mContext, mContext.previewData.getVideoPath());
95   - break;
96   - }
97   - }
98   - };
99   -
100   - DownloadUtil.OnDownloadListener downloadListener = new DownloadUtil.OnDownloadListener() {
101   - @Override
102   - public void onDownloadSuccess(String path) {
103   - jumpMain(path);
104   - }
105   -
106   - @Override
107   - public void onDownloading(int progress) {
108   -
109   - }
110   -
111   - @Override
112   - public void onDownloadFailed(String message) {
113   - showMessage(message);
114   - hideLoading();
115   -
116   - }
117   - };
118   -
119   -
120   - public void jumpMain(String path) {
121   - Observable.create(new ObservableOnSubscribe<String>() {
122   - @Override
123   - public void subscribe(ObservableEmitter<String> emitter) throws Exception {
124   - if (!TextUtils.isEmpty(path)) {
125   - emitter.onNext(path);
126   - } else {
127   - emitter.onError(new Throwable("文件地址为空"));
128   - }
129   - }
130   -
131   - }).subscribeOn(Schedulers.io()) //指定被观察者中的方法在io线程中进行处理
132   - .observeOn(AndroidSchedulers.mainThread()) //指定观察者接收数据在主线程中
133   - .subscribe(new Observer<String>() {
134   - @Override
135   - public void onSubscribe(Disposable d) {
136   - }
137   -
138   - @Override
139   - public void onNext(String s) {
140   - hideLoading();
141   - showSucessfulMessage("下载完成");
142   - if (mContext != null) {
143   - try {
144   - File file = FileUtils.getFileByPath(s);
145   - if (file != null && file.exists()) {
146   - ContentResolver localContentResolver = mContext.getContentResolver();
147   - if (localContentResolver != null) {
148   - ContentValues localContentValues = getVideoContentValues(file);
149   - if (localContentValues != null)
150   - localContentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, localContentValues);
151   - }
152   - mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(s)));
153   - }
154   - } catch (Exception e) {
155   - e.printStackTrace();
156   - }
157   -
158   - }
159   - }
160   -
161   - @Override
162   - public void onError(Throwable e) {
163   - showMessage(e.getMessage());
164   - }
165   -
166   - @Override
167   - public void onComplete() {
168   -
169   - }
170   - });
171   - }
172   -
173   - public ContentValues getVideoContentValues(File paramFile) {
174   - long paramLong = System.currentTimeMillis();
175   - if (paramFile == null || !paramFile.exists()) return null;
176   - ContentValues localContentValues = new ContentValues();
177   - localContentValues.put("title", paramFile.getName());
178   - localContentValues.put("_display_name", paramFile.getName());
179   - localContentValues.put("mime_type", "video/3gp");
180   - localContentValues.put("datetaken", Long.valueOf(paramLong));
181   - localContentValues.put("date_modified", Long.valueOf(paramLong));
182   - localContentValues.put("date_added", Long.valueOf(paramLong));
183   - localContentValues.put("_data", paramFile.getAbsolutePath());
184   - localContentValues.put("_size", Long.valueOf(paramFile.length()));
185   - return localContentValues;
186   - }
187   -
188   - public void initView() {
189   - adapter = new ProcessHtmlAdapter(mContext);
190   - mContext.binding.rv.setLayoutManager(new LinearLayoutManager(mContext));
191   - mContext.binding.rv.setAdapter(adapter);
192   - adapter.addItems(mContext.list);
193   - mContext.binding.tvCancel.setOnClickListener(v -> {
194   - if (mContext != null) mContext.finish();
195   - });
196   - mContext.binding.root.setOnClickListener(v -> {
197   - if (mContext != null) mContext.finish();
198   - });
199   - adapter.setItemClickListener(listener);
200   - if (mContext.previewData != null && mContext.previewData.isScan())
201   - processImage(mContext.imgUrl);
202   -
203   - }
204   -
205   - public void showMessage(String message) {
206   - if (mContext == null) return;
207   - AlertUtil.showDeftToast(mContext, message);
208   - hideLoading();
209   - }
210   -
211   - public void showSucessfulMessage(String message) {
212   - if (mContext == null) return;
213   - AlertUtil.showSuccessToast(mContext, message);
214   - }
215   -
216   - public void forwardFriends(String content) {
217   - if (mContext == null) return;
218   - PreviewRouters.startSelectFriend(mContext, content, 0x2002, 0x1002);
219   - if (mContext == null) mContext.finish();
220   - }
221   -
222   - public void forwardLife(String content) {
223   - File file = new File(content); //pic 1 video 3
224   - if (!FileUtils.isFileExists(content)) return;
225   - ArrayList<Media> medialist = new ArrayList<>();
226   - Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), 0, "");
227   - medialist.add(media);
228   - PreviewRouters.startReleaseManagementAcityity(mContext, file.getPath(), file.getName(), 1, 1, file.length(), 0, "");
229   - if (mContext == null) mContext.finish();
230   - }
231   -
232   - public void sucessful(String message) {
233   - showSucessfulMessage(message);
234   - hideLoading();
235   -
236   - }
237   -
238   - /**
239   - * 复制本地图片到指定文件夹下
240   - *
241   - * @param imagePath
242   - */
243   - public void saveLocalImg(String imagePath) {
244   - saveImageToGallery(mContext, new File(imagePath));
245   - }
246   -
247   - public void saveImageToGallery(Context context, File file) {
248   - try {
249   - String md5 = MD5Util.getMD5(file);
250   - InputStream inStream = new FileInputStream(file); //读入原文件
251   - File appDir = new File(Environment.getExternalStorageDirectory(), "strike");
252   - if (!appDir.exists()) appDir.mkdir();
253   -
254   - String type = FileTypeUtil.getFileType(file.getAbsolutePath(), true);
255   - String extension;//初始文件扩展名
256   - if (TextUtils.isEmpty(type)) {
257   - extension = ".jpg";
258   - } else {
259   - extension = "." + type;
260   - }
261   -
262   - File newFile = new File(appDir, md5 + extension);
263   - FileOutputStream outputStream = new FileOutputStream(newFile);
264   -
265   - int byteread = 0;
266   - byte[] buffer2 = new byte[1444];
267   - while ((byteread = inStream.read(buffer2)) != -1)
268   - outputStream.write(buffer2, 0, byteread);
269   - inStream.close();
270   - outputStream.close();
271   - if (newFile != null) {
272   - MediaStore.Images.Media.insertImage(context.getContentResolver(),
273   - file.getAbsolutePath(), newFile.getName(), null);
274   -
275   - }
276   - context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(newFile.getAbsolutePath())));
277   - showSucessfulMessage("保存成功");
278   - } catch (Exception e) {
279   - if (e != null && e.getMessage() != null)
280   - Log.e("保存图片异常", e.getMessage());
281   - }
282   - }
283   -
284   -
285   - @SuppressLint("WrongConstant")
286   - public void showLoading() {
287   - if (mContext == null) return;
288   - if (loadingDiaog == null) {
289   - loadingDiaog = new CustomTipDialog.Builder(mContext)
290   - .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
291   - .setTipWord("请稍后")
292   - .create();
293   - }
294   - loadingDiaog.show();
295   - mContext.binding.root.setVisibility(View.GONE);
296   - }
297   -
298   - public void hideLoading() {
299   - if (loadingDiaog != null) loadingDiaog.dismiss();
300   - if (mContext != null) mContext.finish();
301   - }
302   -
303   - public void saveNetVideo(String imgUrl) {
304   - showLoading();
305   - String saveDir = "Strike" + File.separator + "video";
306   - DownloadUtil.getInstance().download(imgUrl, saveDir, downloadListener);
307   - }
308   -
309   - /**
310   - * 这是处理 html5页面 图片预览的逻辑
311   - */
312   - public void initHtm5Type() {
313   - if (mContext.list == null) mContext.list = new ArrayList<>();
314   - mContext.list.add(new ProcessImageInfo("转发好友", "friends", ""));
315   - mContext.list.add(new ProcessImageInfo("转发生活圈", "life", ""));
316   - mContext.list.add(new ProcessImageInfo("收藏", "collection", ""));
317   - mContext.list.add(new ProcessImageInfo("保存图片", "save", ""));
318   - if (mContext.previewData == null) mContext.previewData = new PreviewData();
319   - mContext.previewData.setType("1");
320   - mContext.previewData.setShowImg(mContext.imgUrl);
321   - mContext.previewData.setCollectionType("html");
322   - }
323   -
324   - public void processImage(String imgUrl) {
325   - if (TextUtils.isEmpty(imgUrl)) {
326   - showMessage("图片获取失败");
327   - return;
328   - }
329   - if (!NetworkUtil.isConnectInternet(mContext)) {
330   - showMessage("网络异常");
331   - return;
332   - }
333   - Observable.create(new ObservableOnSubscribe<String>() {
334   - @Override
335   - public void subscribe(ObservableEmitter<String> emitter) throws Exception {
336   - File scanFile = getFile(emitter, imgUrl, mContext);
337   - if (scanFile != null && FileUtils.isFileExists(scanFile) && scanFile.length() > 0) {
338   -
339   - String content = null;
340   - content = QRUtils.getInstance().decodeQRcode(scanFile.getAbsolutePath());
341   - if (TextUtils.isEmpty(scanFile.getAbsolutePath())) {
342   - content = QRUtils.getInstance().decodeQRcodeByZxing(scanFile.getAbsolutePath());
343   - }
344   - if (content != null && content.length() > 0) {
345   - emitter.onNext(content);
346   - } else emitter.onNext("");
347   - } else {
348   - emitter.onError(new Throwable("图片解析异常"));
349   - }
350   -
351   - }
352   -
353   - }).subscribeOn(Schedulers.io()) //指定被观察者中的方法在io线程中进行处理
354   - .observeOn(AndroidSchedulers.mainThread()) //指定观察者接收数据在主线程中
355   - .subscribe(new Observer<String>() {
356   - @Override
357   - public void onSubscribe(Disposable d) {
358   - }
359   -
360   - @Override
361   - public void onNext(String s) {
362   - showProcessDialog(s);
363   - }
364   -
365   - @Override
366   - public void onError(Throwable e) {
367   - showMessage(e.getMessage());
368   - }
369   -
370   - @Override
371   - public void onComplete() {
372   -
373   - }
374   - });
375   - }
376   -
377   - @Nullable
378   - private File getFile(ObservableEmitter<String> emitter, String imgUrl, Context mContext) throws InterruptedException, java.util.concurrent.ExecutionException {
379   - File scanFile = null;
380   - if (FileUtils.isFileExists(imgUrl) && FileUtils.getFileByPath(imgUrl).length() > 0) {
381   - scanFile = FileUtils.getFileByPath(imgUrl);
382   - } else {
383   - if (imgUrl.contains("http")) {
384   -// File file = Glide.with(mContext).asFile().load(imgUrl).submit().get();
385   -
386   - FutureTarget<File> future = Glide.with(mContext)
387   - .load(imgUrl)
388   - .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
389   - File file = future.get();
390   - if (file != null && file.exists() && file.length() > 0) {
391   - scanFile = file;
392   - } else {
393   - emitter.onError(new Throwable("图片解析异常"));
394   - }
395   - } else {
396   - emitter.onError(new Throwable("图片解析异常"));
397   - }
398   - }
399   - return scanFile;
400   - }
401   -
402   -
403   - private void showProcessDialog(String content) {
404   - if (content.length() > 0 && adapter != null) {
405   - adapter.addItem(new ProcessImageInfo("识别二维码", "scan", content));
406   - }
407   - }
408   -
409   - public void processQrContent(String qrContent) {
410   - if (mContext == null) return;
411   - QrContentUtil.getInstance().getQrContent(mContext, qrContent, new IdentifyTheQRCodeCallback() {
412   - @Override
413   - public void qRCodeCallback(boolean isIdentify, String message) {
414   - hideLoading();
415   - if (!isIdentify) {
416   - showMessage(message);
417   - }
418   - if (mContext != null) mContext.finish();
419   - }
420   - });
421   - }
422   -}
core/imageload/src/main/java/com/cnlive/core/imageload/preview/widget/MutipleTouchViewPager.java deleted 100644 → 0
1   -package com.cnlive.core.imageload.preview.widget;
2   -
3   -import android.content.Context;
4   -import android.util.AttributeSet;
5   -import android.view.MotionEvent;
6   -
7   -import androidx.annotation.NonNull;
8   -import androidx.annotation.Nullable;
9   -import androidx.viewpager.widget.ViewPager;
10   -
11   -/**
12   - * created by hanyayun
13   - * on 2019/11/26
14   - * 解决 pointerIndex out of range的异常
15   - */
16   -public class MutipleTouchViewPager extends ViewPager {
17   -
18   - private boolean mIsDisallowIntercept = false;
19   -
20   - public MutipleTouchViewPager(@NonNull Context context) {
21   - super(context);
22   - }
23   -
24   - public MutipleTouchViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
25   - super(context, attrs);
26   - }
27   -
28   - @Override
29   - public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
30   - mIsDisallowIntercept = disallowIntercept;
31   - super.requestDisallowInterceptTouchEvent(disallowIntercept);
32   - }
33   -
34   - @Override
35   - public boolean dispatchTouchEvent(MotionEvent ev) {
36   - if (ev.getPointerCount() > 1 && mIsDisallowIntercept) {
37   - requestDisallowInterceptTouchEvent(false);
38   - boolean handled = super.dispatchTouchEvent(ev);
39   - requestDisallowInterceptTouchEvent(true);
40   - return handled;
41   - } else {
42   - return super.dispatchTouchEvent(ev);
43   - }
44   - }
45   -}
core/imageload/src/main/java/com/cnlive/core/imagepreview/ImagePreView.java
... ... @@ -129,9 +129,9 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL
129 129 viewPager = new ImageViewPager(getContext());
130 130 viewPager.setOffscreenPageLimit(1);
131 131 viewPager.addOnPageChangeListener(this);
132   - addView(viewPager, new FrameLayout.LayoutParams(
133   - FrameLayout.LayoutParams.MATCH_PARENT,
134   - FrameLayout.LayoutParams.MATCH_PARENT));
  132 + addView(viewPager, new LayoutParams(
  133 + LayoutParams.MATCH_PARENT,
  134 + LayoutParams.MATCH_PARENT));
135 135  
136 136 setVisibility(View.INVISIBLE);
137 137  
... ... @@ -533,7 +533,7 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL
533 533 // }
534 534 // });
535 535 // 单击事件
536   - drawee.getImageView().setOnClickListener(new View.OnClickListener() {
  536 + drawee.getImageView().setOnClickListener(new OnClickListener() {
537 537 @Override
538 538 public void onClick(View v) {
539 539 if (!hasAnimRunning && mItemClickListener != null) {
... ... @@ -547,7 +547,7 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL
547 547 }
548 548 });
549 549 // 长按事件
550   - drawee.getImageView().setOnLongClickListener(new View.OnLongClickListener() {
  550 + drawee.getImageView().setOnLongClickListener(new OnLongClickListener() {
551 551 @Override
552 552 public boolean onLongClick(View v) {
553 553 if (!hasAnimRunning && mItemLongPressListener != null) {
... ...
core/imageload/src/main/java/com/cnlive/core/imagepreview/PhotoLoader.java
... ... @@ -5,8 +5,6 @@ import android.widget.ImageView;
5 5  
6 6 import com.bumptech.glide.request.target.CustomViewTarget;
7 7 import com.bumptech.glide.request.transition.Transition;
8   -import com.cnlive.core.imageload.config.ScaleMode;
9   -import com.cnlive.core.imageload.loader.ImageLoader;
10 8 import com.cnlive.core.libs.base.application.GlideApp;
11 9  
12 10 import androidx.annotation.NonNull;
... ...
core/imageload/src/main/java/com/cnlive/core/imageload/preview/router/PreviewRouters.java renamed to core/imageload/src/main/java/com/cnlive/core/imagepreview/router/PreviewRouters.java
1   -package com.cnlive.core.imageload.preview.router;
  1 +package com.cnlive.core.imagepreview.router;
2 2  
3 3 import android.content.Context;
4 4  
5 5 import com.alibaba.android.arouter.launcher.ARouter;
6 6  
7   -/**
8   - * 作者: 吴奎庆
9   - * <p>
10   - * 时间: 2018/12/20
11   - * <p>
12   - * 简介: 路由打开页面
13   - */
14 7 public class PreviewRouters {
15 8 //打开转发好友页面
16 9 public static void startSelectFriend(Context context,String content, int shareType, int inType) {
... ...
core/imageload/src/main/java/com/cnlive/core/imageload/preview/widget/CustomTipDialog.java renamed to core/imageload/src/main/java/com/cnlive/core/imagepreview/uti/CustomTipDialog.java
1   -package com.cnlive.core.imageload.preview.widget;
  1 +package com.cnlive.core.imagepreview.uti;
2 2  
3 3 import android.app.Dialog;
4 4 import android.content.Context;
... ...
core/imageload/src/main/java/com/cnlive/core/imageload/preview/widget/DownloadUtil.java renamed to core/imageload/src/main/java/com/cnlive/core/imagepreview/uti/DownloadUtil.java
1   -package com.cnlive.core.imageload.preview.widget;
  1 +package com.cnlive.core.imagepreview.uti;
2 2  
  3 +import android.content.Context;
3 4 import android.os.Environment;
4 5 import android.os.Handler;
5 6 import android.os.Message;
6 7  
7 8  
8   -import com.cnlive.core.libs.base.util.FileUtils;
9   -
10 9 import java.io.File;
11 10 import java.io.FileOutputStream;
12 11 import java.io.IOException;
... ... @@ -18,13 +17,6 @@ import okhttp3.OkHttpClient;
18 17 import okhttp3.Request;
19 18 import okhttp3.Response;
20 19  
21   -/**
22   - * 创建:wukuiqing
23   - * <p>
24   - * 时间:2018/3/19
25   - * <p>
26   - * 描述: 下载视频
27   - */
28 20  
29 21 public class DownloadUtil {
30 22 public static final int DOWNLOAD_FAIL = 0;
... ... @@ -46,7 +38,7 @@ public class DownloadUtil {
46 38 }
47 39  
48 40  
49   - public void download(final String url, final String saveDir, final OnDownloadListener listener) {
  41 + public void download(Context context,final String url, final String saveDir, final OnDownloadListener listener) {
50 42 this.listener = listener;
51 43 Request request = new Request.Builder().url(url).build();
52 44 call = okHttpClient.newCall(request);
... ... @@ -71,7 +63,7 @@ public class DownloadUtil {
71 63 FileOutputStream fos = null;
72 64 //储存下载文件的目录
73 65  
74   - String filePath = Environment.getExternalStorageDirectory() + File.separator + saveDir;
  66 + String filePath = (AndroidQUtil.isAndroidQ()? context.getExternalFilesDir("") : Environment.getExternalStorageDirectory()) + File.separator + saveDir;
75 67 String savePath = isExistDir(filePath);
76 68 try {
77 69 is = response.body().byteStream();
... ...
core/imageload/src/main/java/com/cnlive/core/ui/activity/PreViewImageActivity.java
... ... @@ -8,7 +8,6 @@ import android.widget.ImageView;
8 8 import com.alibaba.android.arouter.facade.annotation.Route;
9 9 import com.cnlive.core.imageload.R;
10 10 import com.cnlive.core.imageload.databinding.ActivityPreviewImageBinding;
11   -import com.cnlive.core.imageload.preview.PreviewImageViewActivity;
12 11 import com.cnlive.core.imagepreview.ViewerStatus;
13 12 import com.cnlive.core.imagepreview.listener.OnItemClickListener;
14 13 import com.cnlive.core.libs.base.frame.activity.BaseActivity;
... ... @@ -16,7 +15,6 @@ import com.cnlive.core.ui.model.PreViewImgData;
16 15 import com.cnlive.core.ui.presenter.PreViewImagePresenter;
17 16 import com.cnlive.core.ui.view.PreViewImageView;
18 17  
19   -
20 18 import java.util.ArrayList;
21 19 import java.util.List;
22 20  
... ... @@ -32,7 +30,7 @@ public class PreViewImageActivity extends BaseActivity&lt;PreViewImageView, PreView
32 30 public List<String> picList = new ArrayList<>();
33 31  
34 32 public static void startPreViewActivity(Activity context, View transitionView, PreViewImgData data) {
35   - Intent intent = new Intent(context, PreviewImageViewActivity.class);
  33 + Intent intent = new Intent(context, PreViewImageActivity.class);
36 34 intent.putExtra("data", data);
37 35 context.startActivity(intent);
38 36 }
... ...
core/imageload/src/main/java/com/cnlive/core/ui/presenter/PreViewImagePresenter.java
... ... @@ -11,9 +11,7 @@ import android.util.Log;
11 11 import com.bumptech.glide.Glide;
12 12 import com.bumptech.glide.request.FutureTarget;
13 13 import com.bumptech.glide.request.target.Target;
14   -import com.cnlive.cloud.user.auth.UserService;
15 14 import com.cnlive.core.imageload.api.ApiServiceStock;
16   -import com.cnlive.core.libs.base.application.AppConfig;
17 15 import com.cnlive.core.libs.base.frame.presenter.BasePresenter;
18 16 import com.cnlive.core.libs.base.util.FileTypeUtil;
19 17 import com.cnlive.core.libs.base.util.FileUtils;
... ... @@ -65,7 +63,6 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
65 63 if (TextUtils.isEmpty(imgUrl)) return;
66 64 if (mContext == null) return;
67 65 if(getView() != null) getView().showLoading();
68   -// ifViewAttached(view -> view.showLoading());
69 66 Observable.create((ObservableOnSubscribe<String>) emitter -> {
70 67 if (FileUtils.isFileExists(imgUrl) && FileUtils.getFileByPath(imgUrl).length() > 0) {
71 68 emitter.onNext(imgUrl);
... ... @@ -91,34 +88,25 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
91 88 @Override
92 89 public void onNext(String content) {
93 90 if(getView() != null) getView().hideLoading();
94   -// ifViewAttached(view -> view.hideLoading());
95 91 if (!TextUtils.isEmpty(content)) {
96 92 if (type.equals("friends")) {
97 93 if(getView() != null) getView().shareFriends(content);
98   -// ifViewAttached(view -> view.shareFriends(content));
99 94 } else if (type.equals("life")) {
100 95 if(getView() != null) getView().shareLife(content);
101   -// ifViewAttached(view -> view.shareLife(content));
102 96 } else {
103 97 if(getView() != null) getView().showMessage("类型异常");
104   -// ifViewAttached(view -> view.showMessage("类型异常"));
105 98 }
106 99 } else {
107 100 if(getView() != null) getView().showMessage("非法图片地址");
108   -// ifViewAttached(view -> view.showMessage("非法图片地址"));
109 101 }
110 102 }
111 103  
112 104 @Override
113 105 public void onError(Throwable e) {
114   -// ifViewAttached(view -> {
115 106 if(getView() != null) {
116 107 getView().hideLoading();
117 108 getView().showMessage(e.getMessage());
118 109 }
119   -// view.hideLoading();
120   -// view.showMessage(e.getMessage());
121   -// });
122 110 }
123 111  
124 112 @Override
... ... @@ -140,14 +128,14 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
140 128 if (FileUtils.isFileExists(imagePath)) {
141 129 List<String> list = new ArrayList();
142 130 list.add(imagePath);
143   - UploadLogic.uploadonePic(context, true, list, new NetCallBack<List<FeedBackInfo>>() {
  131 + UploadLogic.uploadonePic(FLAG,context, true, list, new NetCallBack<List<FeedBackInfo>>() {
144 132 @Override
145 133 public void onRequestState(int state) {
146 134  
147 135 }
148 136  
149 137 @Override
150   - public void onSuccess(List<com.cnlive.core.network.upload.model.FeedBackInfo> data) {
  138 + public void onSuccess(List<FeedBackInfo> data) {
151 139 if (data.size() > 0) {
152 140 if (data.get(0).getImageUrl().contains("http")) {
153 141 collection(context, data.get(0).getImageUrl(), context.data);
... ... @@ -171,7 +159,7 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
171 159 private void collection(PreViewImageActivity context, String imagePath, PreViewImgData previewData) {
172 160 if (previewData == null) return;
173 161 Map<String, String> requestMap = new HashMap<>();
174   - requestMap.put("appId", AppConfig.getAppId());
  162 + requestMap.put("appId", BuildConfig.APP_ID);
175 163 requestMap.put("sid", previewData.getUserId());
176 164 requestMap.put("type", previewData.getType());
177 165 requestMap.put("img", imagePath);
... ... @@ -202,7 +190,7 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
202 190 requestMap.put("collectionType", previewData.getCollectionType());
203 191 }
204 192  
205   - HttpConn.action(BaseRequest.init()
  193 + HttpConn.action(FLAG, BaseRequest.init()
206 194 .service(ApiServiceStock.class)
207 195 .collection(requestMap), new NetCallBack<BaseResult>() {
208 196 @Override
... ... @@ -213,13 +201,11 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
213 201 @Override
214 202 public void onSuccess(BaseResult data) {
215 203 if(getView() != null) getView().showSucessfulMessage("收藏成功");
216   -// ifViewAttached(view -> view.showSucessfulMessage("收藏成功"));
217 204 }
218 205  
219 206 @Override
220 207 public void onFailure(String errCode, String errMsg, Exception e) {
221 208 if(getView() != null) getView().showMessage(errMsg);
222   -// ifViewAttached(view -> view.showMessage(errMsg));
223 209 }
224 210 });
225 211 }
... ... @@ -243,7 +229,7 @@ public class PreViewImagePresenter extends BasePresenter&lt;PreViewImageView&gt; {
243 229 String filePath = "Strike" + File.separator + "video";
244 230 String md5 = MD5Util.getMD5(file);
245 231 InputStream inStream = new FileInputStream(file); //读入原文件
246   - File appDir = new File(Environment.getExternalStorageDirectory(), filePath);
  232 + File appDir = new File((AndroidQUtil.isAndroidQ()? activity.getExternalFilesDir("") : Environment.getExternalStorageDirectory()), filePath);
247 233 if (!appDir.exists()) appDir.mkdir();
248 234  
249 235 String type = FileTypeUtil.getFileType(file.getAbsolutePath());
... ...
core/imageload/src/main/java/com/cnlive/core/ui/view/PreViewImageView.java
... ... @@ -18,17 +18,15 @@ import android.view.ViewGroup;
18 18 import android.view.Window;
19 19 import android.widget.ImageView;
20 20  
21   -import com.cnlive.cloud.moudle.qr.uitl.IdentifyTheQRCodeCallback;
22   -import com.cnlive.cloud.moudle.qr.uitl.QrContentUtil;
23 21 import com.cnlive.core.imageload.R;
24 22 import com.cnlive.core.imageload.callback.ImageDownLoadCallBack;
25 23 import com.cnlive.core.imageload.loader.ImageLoader;
26   -import com.cnlive.core.imageload.preview.router.PreviewRouters;
27   -import com.cnlive.core.imageload.preview.widget.CustomTipDialog;
28   -import com.cnlive.core.imageload.preview.widget.DownloadUtil;
29 24 import com.cnlive.core.imageload.util.DownLoadImageService;
30 25 import com.cnlive.core.imagepreview.listener.OnDragStatusListener;
31 26 import com.cnlive.core.imagepreview.listener.OnItemLongPressListener;
  27 +import com.cnlive.core.imagepreview.router.PreviewRouters;
  28 +import com.cnlive.core.imagepreview.uti.CustomTipDialog;
  29 +import com.cnlive.core.imagepreview.uti.DownloadUtil;
32 30 import com.cnlive.core.libs.base.frame.view.BaseView;
33 31 import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener;
34 32 import com.cnlive.core.libs.base.util.AlertUtil;
... ... @@ -81,25 +79,38 @@ public class PreViewImageView extends BaseView {
81 79  
82 80 public void getData(Intent intent) {
83 81 activity.data = (PreViewImgData) intent.getSerializableExtra("data");
  82 + if(!activity.data.isCollection() && !activity.data.isFriend() && !activity.data.isLife() && !activity.data.isSave()){
  83 + activity.data.setShowDialog(false);
  84 + }else {
  85 + activity.data.setShowDialog(true);
  86 + }
84 87 activity.type = activity.data.getType();
85 88 if (TextUtils.isEmpty(activity.type)) {
86 89 showError();
87 90 }
88 91 if (activity.type.equals("1")) {
89 92 preViewImgList = activity.data.getPicInfoList();
90   - if (preViewImgList.size() == 1) {
  93 + if(preViewImgList == null){
  94 + preViewImgList = new ArrayList<>();
  95 + preViewImgList.add(activity.data.getCurrPrewInfo());
91 96 activity.position = 0;
92   - } else {
93   - PreViewImgInfo curPreInfo = activity.data.getCurrPrewInfo();
94   - for (int i = 0; i < preViewImgList.size(); i++) {
95   - activity.picList.add(TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) ? preViewImgList.get(i).getImgUrl() : preViewImgList.get(i).getPreviewImgUrl());
96   - if ((!TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) && !TextUtils.isEmpty(curPreInfo.getPreviewImgUrl()) && curPreInfo.getPreviewImgUrl().equals(preViewImgList.get(i).getPreviewImgUrl()))
97   - || (!TextUtils.isEmpty(preViewImgList.get(i).getImgUrl()) && !TextUtils.isEmpty(curPreInfo.getImgUrl()) && curPreInfo.getImgUrl().equals(preViewImgList.get(i).getImgUrl()))) {
98   - activity.position = i;
  97 + activity.picList.add(TextUtils.isEmpty(preViewImgList.get(0).getPreviewImgUrl()) ? preViewImgList.get(0).getImgUrl() : preViewImgList.get(0).getPreviewImgUrl());
  98 + }else {
  99 + if (preViewImgList.size() == 1) {
  100 + activity.position = 0;
  101 + activity.picList.add(TextUtils.isEmpty(preViewImgList.get(0).getPreviewImgUrl()) ? preViewImgList.get(0).getImgUrl() : preViewImgList.get(0).getPreviewImgUrl());
  102 + } else {
  103 + PreViewImgInfo curPreInfo = activity.data.getCurrPrewInfo();
  104 + for (int i = 0; i < preViewImgList.size(); i++) {
  105 + activity.picList.add(TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) ? preViewImgList.get(i).getImgUrl() : preViewImgList.get(i).getPreviewImgUrl());
  106 + if ((!TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) && !TextUtils.isEmpty(curPreInfo.getPreviewImgUrl()) && curPreInfo.getPreviewImgUrl().equals(preViewImgList.get(i).getPreviewImgUrl()))
  107 + || (!TextUtils.isEmpty(preViewImgList.get(i).getImgUrl()) && !TextUtils.isEmpty(curPreInfo.getImgUrl()) && curPreInfo.getImgUrl().equals(preViewImgList.get(i).getImgUrl()))) {
  108 + activity.position = i;
  109 + }
99 110 }
100 111 }
101   - setPreview();
102 112 }
  113 + setPreview();
103 114 } else if (activity.data.getType().equals("2")) {
104 115  
105 116 }
... ... @@ -122,17 +133,19 @@ public class PreViewImageView extends BaseView {
122 133 activity.binding.imagePre.setOnItemLongPressListener(new OnItemLongPressListener() {
123 134 @Override
124 135 public boolean onItemLongPress(int position, ImageView imageView) {
125   - activity.requestPermission(String.valueOf(R.string.dialog_imagepicker_permission_save_pic),new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, new OnPermissionResponseListener() {
126   - @Override
127   - public void onSuccess(String[] permissions) {
128   - activity.getPresenter().isScan(activity,activity.picList.get(position),position);
129   - }
  136 + if(activity.data.isShowDialog()){
  137 + activity.requestPermission(String.valueOf(R.string.dialog_imagepicker_permission_save_pic),new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, new OnPermissionResponseListener() {
  138 + @Override
  139 + public void onSuccess(String[] permissions) {
  140 + activity.getPresenter().isScan(activity,activity.picList.get(position),position);
  141 + }
130 142  
131   - @Override
132   - public void onFail() {
  143 + @Override
  144 + public void onFail() {
133 145  
134   - }
135   - });
  146 + }
  147 + });
  148 + }
136 149 return false;
137 150 }
138 151 });
... ... @@ -217,7 +230,7 @@ public class PreViewImageView extends BaseView {
217 230 File file = new File(content); //pic 1 video 3
218 231 if (!FileUtils.isFileExists(content)) return;
219 232 ArrayList<Media> medialist = new ArrayList<>();
220   - Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), 0, "");
  233 + Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), 0, "",Uri.fromFile(file).toString());
221 234 medialist.add(media);
222 235 PreviewRouters.startReleaseManagementAcityity(activity, file.getPath(), file.getName(), 1, 1, file.length(), 0, "");
223 236 if (activity == null) activity.finish();
... ... @@ -255,7 +268,7 @@ public class PreViewImageView extends BaseView {
255 268 public void saveNetVideo(String imgUrl) {
256 269 showLoading();
257 270 String saveDir = "Strike" + File.separator + "video";
258   - DownloadUtil.getInstance().download(imgUrl, saveDir, new DownloadUtil.OnDownloadListener() {
  271 + DownloadUtil.getInstance().download(activity,imgUrl, saveDir, new DownloadUtil.OnDownloadListener() {
259 272 @Override
260 273 public void onDownloadSuccess(String path) {
261 274 jumpMain(path);
... ... @@ -350,17 +363,18 @@ public class PreViewImageView extends BaseView {
350 363 */
351 364 public void processQrContent(String qrContent) {
352 365 if (activity == null) return;
353   - QrContentUtil.getInstance().getQrContent(activity, qrContent, new IdentifyTheQRCodeCallback() {
354   - @Override
355   - public void qRCodeCallback(boolean isIdentify, String message) {
356   - hideLoading();
357   - if (!isIdentify) {
358   - showMessage(message);
359   - }else {
360   - if (activity != null) activity.finish();
361   - }
362   - }
363   - });
  366 + //TODO 二维码处理
  367 +// QrContentUtil.getInstance().getQrContent(activity, qrContent, new IdentifyTheQRCodeCallback() {
  368 +// @Override
  369 +// public void qRCodeCallback(boolean isIdentify, String message) {
  370 +// hideLoading();
  371 +// if (!isIdentify) {
  372 +// showMessage(message);
  373 +// }else {
  374 +// if (activity != null) activity.finish();
  375 +// }
  376 +// }
  377 +// });
364 378 }
365 379  
366 380 public void showSucessfulMessage(String message) {
... ...