package com.tejia.lijin.app.ui.recommend.singleshare;
|
|
import android.Manifest;
|
import android.annotation.SuppressLint;
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.graphics.Bitmap;
|
import android.graphics.Typeface;
|
import android.graphics.drawable.Drawable;
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.os.Message;
|
import androidx.annotation.NonNull;
|
import androidx.annotation.Nullable;
|
import android.text.Spannable;
|
import android.text.SpannableString;
|
import android.text.Spanned;
|
import android.text.style.RelativeSizeSpan;
|
import android.text.style.StyleSpan;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.BaseAdapter;
|
import android.widget.CheckBox;
|
import android.widget.CompoundButton;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.app.hubert.guide.util.ScreenUtils;
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.target.SimpleTarget;
|
import com.bumptech.glide.request.transition.Transition;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
import com.wpc.library.RetainViewFragment;
|
import com.wpc.library.util.common.DimenUtils;
|
import com.wpc.library.util.common.StringUtils;
|
import com.wpc.library.widget.MyGridView;
|
import com.wpc.library.widget.ResizableImageView;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.callBack.GeneralSingelCallback;
|
import com.tejia.lijin.app.callBack.PermissionInterface;
|
import com.tejia.lijin.app.entity.share.ShareImageEntity;
|
import com.tejia.lijin.app.entity.share.SingleGoodsShareInfo;
|
import com.tejia.lijin.app.ui.dialog.ShareGoodsImgNativeDialog;
|
import com.tejia.lijin.app.ui.recommend.ActivityContentCompile;
|
import com.tejia.lijin.app.util.GlideRoundTransform;
|
import com.tejia.lijin.app.util.ImageUtil;
|
import com.tejia.lijin.app.util.PermissionHelper;
|
import com.tejia.lijin.app.util.Toast_Dialog;
|
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
|
import com.tejia.lijin.app.util.share.ShareCacheUtil;
|
import com.tejia.lijin.app.util.umengCustomEvent.GoodsCustomEvent;
|
import com.tejia.lijin.app.util.zxing.ZxingUtils;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
|
/**
|
* 多图分享
|
*/
|
public class MultiImageShareFragment extends RetainViewFragment implements View.OnClickListener, PermissionInterface, GeneralSingelCallback {
|
|
private TextView tv_multiple_goods_title,
|
tv_multiple_after_coupon_price,
|
tv_multiple_normal_price,
|
tv_multiple_sale_num, tv_multiple_coupon_price,
|
tv_tlj_multiple, tv_multiple_free_shipping, cb_copytxt, tv_share_content, tv_remind_content, tv_share_img;
|
private ImageView iv_multiple_qr_code,
|
iv_multiple_first_close, iv_multiple_qr_code_center_img;
|
private CheckBox cb_copy;
|
private ResizableImageView iv_multiple_first_img, iv_multiple_img_coupon_ad;
|
|
private FrameLayout fl_multiple_qr,
|
fl_multiple_img_coupon_ad, fl_multiple_free_shipping;
|
|
private LinearLayout
|
ll_multiple_share_img, ll_multiple_coupon, ll_ambush;
|
private MyGridView gv_multiple_imgs;
|
RelativeLayout ll_ambushlayout;
|
private SingleGoodsShareInfo shareInfo;//分享信息
|
|
private DisplayImageOptions options;
|
private TextView tv_share_content_restore;//还原文字模板
|
private TextView tv_share_content_compile;//编辑文字模板
|
private Toast_Dialog toast_dialog;
|
private TextView tv_template_copy;//复制文字模版
|
|
|
@Override
|
public int getContentResource() {
|
return R.layout.fragment_share_goods_multi_img;
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
Bundle bundle = this.getArguments();
|
shareInfo = (SingleGoodsShareInfo) bundle.getSerializable("shareInfo");
|
initView(contentView);
|
initListener(contentView);
|
mPermissionsChecker = new PermissionHelper(getActivity(), this);
|
}
|
|
private void initView(View contentView) {
|
tv_share_img = contentView.findViewById(R.id.tv_share_img);
|
tv_share_content = contentView.findViewById(R.id.tv_share_content);
|
tv_remind_content = contentView.findViewById(R.id.tv_remind_content);
|
tv_tlj_multiple = contentView.findViewById(R.id.tv_tlj_multiple);
|
iv_multiple_first_img = contentView.findViewById(R.id.iv_multiple_first_img);
|
iv_multiple_first_close = contentView.findViewById(R.id.iv_multiple_first_close);
|
cb_copy = contentView.findViewById(R.id.cb_copy);
|
ll_multiple_share_img = contentView.findViewById(R.id.ll_multiple_share_img);
|
gv_multiple_imgs = contentView.findViewById(R.id.gv_multiple_imgs);
|
fl_multiple_qr = contentView.findViewById(R.id.fl_multiple_qr);
|
iv_multiple_qr_code = contentView.findViewById(R.id.iv_multiple_qr_code);
|
iv_multiple_qr_code_center_img = contentView.findViewById(R.id.iv_multiple_qr_code_center_img);
|
tv_multiple_goods_title = contentView.findViewById(R.id.tv_multiple_goods_title);
|
tv_multiple_after_coupon_price = contentView.findViewById(R.id.tv_multiple_after_coupon_price);
|
tv_multiple_normal_price = contentView.findViewById(R.id.tv_multiple_normal_price);
|
tv_multiple_sale_num = contentView.findViewById(R.id.tv_multiple_sale_num);
|
ll_multiple_coupon = contentView.findViewById(R.id.ll_multiple_coupon);
|
ll_ambush = contentView.findViewById(R.id.ll_ambush);
|
ll_ambushlayout = contentView.findViewById(R.id.ll_ambushlayout);
|
tv_multiple_coupon_price = contentView.findViewById(R.id.tv_multiple_coupon_price);
|
fl_multiple_img_coupon_ad = contentView.findViewById(R.id.fl_multiple_img_coupon_ad);
|
iv_multiple_img_coupon_ad = contentView.findViewById(R.id.iv_multiple_img_coupon_ad);
|
tv_share_content_restore = contentView.findViewById(R.id.tv_share_content_restore);
|
tv_share_content_compile = contentView.findViewById(R.id.tv_share_content_compile);
|
fl_multiple_free_shipping = contentView.findViewById(R.id.fl_multiple_free_shipping);
|
tv_multiple_free_shipping = contentView.findViewById(R.id.tv_multiple_free_shipping);
|
tv_template_copy = contentView.findViewById(R.id.tv_template_copy);
|
cb_copytxt = contentView.findViewById(R.id.cb_copytxt);
|
|
this.options = new DisplayImageOptions.Builder()
|
.showImageForEmptyUri(R.drawable.ic_goods_default)
|
.showImageOnFail(R.drawable.ic_goods_default)
|
.showImageOnLoading(R.drawable.ic_goods_default)
|
.resetViewBeforeLoading(false).cacheInMemory(true)
|
.cacheOnDisk(true).imageScaleType(ImageScaleType.EXACTLY)
|
.considerExifParams(true)
|
.build();
|
tv_tlj_multiple.setVisibility(StringUtils.isEmpty(shareInfo.getTljId()) ? View.GONE : View.VISIBLE);
|
tv_tlj_multiple.setText(StringUtils.isEmpty(shareInfo.getTljId()) ? "" : shareInfo.getSpreadMoney());
|
|
ImageUtil.showImageFace1(getContext(), shareInfo.getGoodsInfo().getTitle(), shareInfo.getGoodsInfo().getShopType(), tv_multiple_goods_title);
|
String price;
|
int startP;
|
|
|
if (shareInfo.getGoodsInfo().isHasCoupon()) {//有优惠券
|
price = "券后价 ¥ " + shareInfo.getGoodsInfo().getCouponPrice();
|
startP = 5;
|
tv_multiple_coupon_price.setText("¥ " + shareInfo.getGoodsInfo().getCouponInfo().getAmount());
|
contentView.findViewById(R.id.v_space).setVisibility(View.VISIBLE);
|
ll_multiple_coupon.setVisibility(View.VISIBLE);
|
tv_multiple_normal_price.setVisibility(View.VISIBLE);
|
fl_multiple_img_coupon_ad.setVisibility(View.VISIBLE);
|
fl_multiple_qr.setBackgroundResource(R.drawable.ic_qr_code_frame_old);
|
} else {
|
price = "¥ " + shareInfo.getGoodsInfo().getZkPrice();
|
startP = 1;
|
contentView.findViewById(R.id.v_space).setVisibility(View.GONE);
|
ll_multiple_coupon.setVisibility(View.GONE);
|
tv_multiple_normal_price.setVisibility(View.GONE);
|
fl_multiple_img_coupon_ad.setVisibility(View.GONE);
|
fl_multiple_qr.setBackgroundResource(R.drawable.ic_qr_code_frame_no_coupon_old);
|
}
|
Spannable span = new SpannableString(price);
|
span.setSpan(new RelativeSizeSpan(1.3f), startP, price.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
span.setSpan(new StyleSpan(Typeface.BOLD), startP, price.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
tv_multiple_after_coupon_price.setText(span);
|
setQRCode(shareInfo.getClickUrl());//设置二维码
|
if (shareInfo.getGoodsInfo().getShopType() == 21) {
|
fl_multiple_free_shipping.setVisibility(View.VISIBLE);
|
tv_multiple_free_shipping.setText("自营");
|
} else {
|
if (shareInfo.getGoodsInfo().isBaoyou()) {
|
fl_multiple_free_shipping.setVisibility(View.VISIBLE);
|
tv_multiple_free_shipping.setText("包邮");
|
} else {
|
fl_multiple_free_shipping.setVisibility(View.GONE);
|
}
|
}
|
|
|
tv_multiple_normal_price.setText(shareInfo.getGoodsInfo().getPriceName() + " ¥" + shareInfo.getGoodsInfo().getZkPrice());
|
|
String saleType = shareInfo.getGoodsInfo().getSalesType() == 1 ? "月销 " : "总销量 ";
|
tv_multiple_sale_num.setText(saleType + shareInfo.getGoodsInfo().getSalesCount());
|
Glide.with(this).load(shareInfo.getNotifyPicture()).into(iv_multiple_img_coupon_ad);
|
|
final RequestOptions options = new RequestOptions().placeholder(R.drawable.ic_goods_default);
|
|
Glide.with(this).load(shareInfo.getGoodsInfo().getImgList().get(0)).apply(options).into(iv_multiple_first_img);
|
multipleImg();
|
iv_multiple_first_close.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (shareInfo.getGoodsInfo().getImgList().size() > 1) {
|
shareInfo.getGoodsInfo().getImgList().remove(0);
|
imgList.clear();
|
multipleImg();
|
Glide.with(getContext()).load(shareInfo.getGoodsInfo().getImgList().get(0)).apply(options).into(iv_multiple_first_img);
|
} else {
|
Toast.makeText(getContext(), "至少保留一张图片", Toast.LENGTH_SHORT).show();
|
}
|
}
|
});
|
tv_share_content.setText(shareInfo.getDescText());
|
tv_remind_content.setText(shareInfo.getNotifyDesc());
|
|
toast_dialog = new Toast_Dialog(getContext());
|
setcommentTexts();//设置淘口令//评论区文案
|
final SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
|
if (sp.getBoolean("sharecheck", true)) {
|
cb_copy.setChecked(true);
|
} else {
|
cb_copy.setChecked(false);
|
}
|
|
cb_copy.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
SharedPreferences.Editor editor = sp.edit();
|
if (b) {
|
editor.putBoolean("sharecheck", true);
|
} else {
|
editor.putBoolean("sharecheck", false);
|
}
|
editor.apply();
|
}
|
});
|
|
final RequestOptions requestOptions = new RequestOptions().transform(new GlideRoundTransform(
|
getContext(), 4));
|
String portrait = getContext().getSharedPreferences("user", Context.MODE_PRIVATE).getString("portrait", "");
|
Glide.with(getContext()).load(portrait).apply(requestOptions).into(iv_multiple_qr_code_center_img);
|
}
|
|
|
private void initListener(View contentView) {
|
tv_share_img.setOnClickListener(this);
|
tv_share_content_compile.setOnClickListener(this);
|
tv_share_content_restore.setOnClickListener(this);
|
tv_template_copy.setOnClickListener(this);
|
cb_copytxt.setOnClickListener(this);
|
}
|
|
/***********动态添加 评论区文案**/
|
private void setcommentTexts() {
|
List<String> commentTextsArr = shareInfo.getCommentTexts();
|
|
if (commentTextsArr == null || commentTextsArr.size() == 0) {
|
ll_ambushlayout.setVisibility(View.GONE);
|
return;
|
}
|
|
ll_ambush.removeAllViews();
|
for (int i = 0; i < commentTextsArr.size(); i++) {
|
View item = LayoutInflater.from(getContext()).inflate(R.layout.item_commenttexts, null);
|
TextView tv_ambush1 = item.findViewById(R.id.tv_ambush1);
|
final TextView tv_ambush = item.findViewById(R.id.tv_ambush);
|
TextView tv_ambush_copy = item.findViewById(R.id.tv_ambush_copy);
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
int left = ScreenUtils.dp2px(getContext(), 10);
|
int top = ScreenUtils.dp2px(getContext(), 13);
|
params.setMargins(left, top, left, top);
|
item.setLayoutParams(params);
|
tv_ambush.setText(commentTextsArr.get(i).toString());
|
tv_ambush1.setText((i + 1) + "");
|
tv_ambush_copy.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
GoodsCustomEvent.goodsDetailShareCopyToken(getContext());
|
|
ClipboardUtil.copy(getContext(), tv_ambush.getText().toString());
|
Toast.makeText(getContext(), "文本复制成功", Toast.LENGTH_SHORT).show();
|
}
|
});
|
ll_ambush.addView(item);
|
}
|
}
|
|
/*****************设置二维码******/
|
private void setQRCode(String clickUrl) {
|
//二维码
|
Bitmap QRCode = ZxingUtils.createBitmap(clickUrl, DimenUtils.dip2px(getContext(), 85));
|
Bitmap QRCodeMul = ZxingUtils.createBitmap(clickUrl, DimenUtils.dip2px(getContext(), 85));
|
iv_multiple_qr_code.setImageBitmap(QRCodeMul);
|
// iv_multiple_qr_code.setScaleType(ImageView.ScaleType.FIT_XY);
|
}
|
|
/**
|
* 多图小图设置
|
*/
|
MultipleImgAdapter imgAdapter;
|
List<String> imgList;
|
|
private void multipleImg() {
|
if (imgList == null) {
|
imgList = new ArrayList<>();
|
for (int i = 0; i < shareInfo.getGoodsInfo().getImgList().size(); i++) {
|
if (i > 0 && i < 5) {
|
imgList.add(shareInfo.getGoodsInfo().getImgList().get(i));
|
}
|
}
|
} else {
|
for (int i = 0; i < shareInfo.getGoodsInfo().getImgList().size(); i++) {
|
if (i > imgList.size() && i < 5) {
|
imgList.add(shareInfo.getGoodsInfo().getImgList().get(i));
|
}
|
}
|
}
|
|
if (imgAdapter == null) {
|
imgAdapter = new MultipleImgAdapter(imgList);
|
gv_multiple_imgs.setAdapter(imgAdapter);
|
} else {
|
imgAdapter.notifyDataSetChanged();
|
// imgAdapter.isSharing(false);
|
}
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
|
}
|
|
private PermissionHelper mPermissionsChecker; // 权限检测器
|
|
/**
|
* 权限请求码
|
*
|
* @return
|
*/
|
@Override
|
public int getPermissionsRequestCode() {
|
return 1001;
|
}
|
|
/**
|
* 请求权限
|
*
|
* @return
|
*/
|
@Override
|
public String[] getPermissions() {
|
return new String[]{Manifest.permission.CAMERA};
|
}
|
|
/**
|
* 权限请求成功
|
*/
|
@Override
|
public void requestPermissionsSuccess() {
|
}
|
|
/**
|
* 权限请求失败
|
*/
|
@Override
|
public void requestPermissionsFail() {
|
// Toast.makeText(this, "你以拒绝权限", Toast.LENGTH_SHORT).show();
|
}
|
|
/**
|
* 请求权限结果
|
*
|
* @param requestCode
|
* @param permissions
|
* @param grantResults
|
*/
|
@Override
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
if (mPermissionsChecker.requestPermissionsResult(requestCode, permissions, grantResults)) {
|
//权限请求结果,并已经处理了该回调
|
return;
|
}
|
}
|
|
int isCheck = 0;
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.tv_template_copy://复制模版文字
|
ClipboardUtil.copy(getContext(), tv_share_content.getText().toString());
|
Toast.makeText(getContext(), "文本复制成功",
|
Toast.LENGTH_SHORT).show();
|
break;
|
case R.id.tv_share_img://分享图片
|
if (mPermissionsChecker.lacksPermissions(getPermissions())) { //检测权限
|
isCheck = 2;
|
mPermissionsChecker.showNormalDialog();
|
} else {
|
if (mPermissionsChecker.lacksPermissions(getPermissions())) { //检测权限
|
mPermissionsChecker.showNormalDialog();
|
} else {
|
copyShareText();
|
|
//隐藏关闭
|
iv_multiple_first_close.setVisibility(View.GONE);
|
imgAdapter.isSharing(true);
|
// if (info.getImgList().size() == 1) {
|
Bitmap shareBp = getViewBp(ll_multiple_share_img);
|
showShareImg(shareBp);
|
iv_multiple_first_close.setVisibility(View.VISIBLE);
|
imgAdapter.isSharing(false);
|
}
|
}
|
break;
|
|
case R.id.tv_share_content_compile://编辑文字模板
|
Intent intent2 = new Intent(getContext(), ActivityContentCompile.class);
|
intent2.putExtra("goodsId", shareInfo.getGoodsInfo().getGoodsId());
|
intent2.putExtra("hasCoupon", shareInfo.getGoodsInfo().isHasCoupon());
|
intent2.putExtra("tljId", shareInfo.getTljId());
|
intent2.putExtra("goodsType", shareInfo.getGoodsInfo().getGoodsType());
|
startActivity(intent2);
|
break;
|
case R.id.tv_share_content_restore://还原文字模板
|
resetShareTextTemplate();
|
break;
|
case R.id.cb_copytxt:
|
if (cb_copy.isChecked())
|
cb_copy.setChecked(false);
|
else
|
cb_copy.setChecked(true);
|
break;
|
|
default:
|
break;
|
|
}
|
}
|
|
|
//复制分享文本
|
private void copyShareText() {
|
ClipboardUtil.copy(getContext(), tv_share_content.getText().toString());
|
Toast.makeText(getContext(), "文本复制成功",
|
Toast.LENGTH_SHORT).show();
|
}
|
|
/*
|
还原分享模板
|
*/
|
private void resetShareTextTemplate() {
|
SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
|
ShoppingApi.resetShareTextTemplate(getContext(), UserUtil.getUid(ShoppingApplication.application), shareInfo.getGoodsInfo().isHasCoupon() + "",
|
shareInfo.getGoodsInfo().getGoodsId(), shareInfo.getTljId(), shareInfo.getGoodsInfo().getGoodsType(), new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
tv_share_content.setText(jsonObject.optJSONObject("data").optString("content"));
|
Toast.makeText(getContext(), "文字模板还原成功", Toast.LENGTH_LONG).show();
|
} else {
|
Toast.makeText(getContext(), jsonObject.optString("msg"), Toast.LENGTH_LONG).show();
|
}
|
}
|
});
|
}
|
|
/**
|
* 截图
|
*
|
* @param v
|
* @return
|
*/
|
public Bitmap getViewBp(View v) {
|
if (null == v) {
|
return null;
|
}
|
v.setDrawingCacheEnabled(true);
|
v.buildDrawingCache();
|
v.measure(View.MeasureSpec.makeMeasureSpec(v.getWidth(),
|
View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(
|
v.getHeight(), View.MeasureSpec.EXACTLY));
|
v.layout((int) v.getX(), (int) v.getY(),
|
(int) v.getX() + v.getMeasuredWidth(),
|
(int) v.getY() + v.getMeasuredHeight());
|
Bitmap b = Bitmap.createBitmap(v.getDrawingCache(), 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
|
v.setDrawingCacheEnabled(false);
|
v.destroyDrawingCache();
|
return b;
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
}
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
}
|
|
|
ShareGoodsImgNativeDialog.Builder mSharebuilder;
|
Dialog multiShareDialog = null;
|
|
private void showShareImg(Bitmap shareBp) {
|
String type = "many";//多图
|
|
if (multiShareDialog == null) {
|
mSharebuilder = new ShareGoodsImgNativeDialog.Builder(getActivity());
|
setShareImages(shareBp);
|
if (ShareCacheUtil.isSingleGoodsShareAllImage(getContext()))
|
mSharebuilder.setSelectAll(true);
|
mSharebuilder.setGeneralSingelCallback(this);
|
multiShareDialog = mSharebuilder.setShareType(type).setShareId(shareInfo.getShareId())
|
.setFootMark(cb_copy.isChecked())//带不带角标
|
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialogInterface, int i) {
|
dialogInterface.dismiss();
|
}
|
})
|
.create();
|
multiShareDialog.show();
|
} else {
|
setShareImages(shareBp);
|
if (!multiShareDialog.isShowing())
|
multiShareDialog.show();
|
}
|
}
|
|
|
/**
|
* 获取分享图
|
*
|
* @return
|
*/
|
private Bitmap getShareImage() {
|
imgAdapter.isSharing(true);
|
iv_multiple_first_close.setVisibility(View.GONE);
|
Bitmap shareBp2 = getViewBp(ll_multiple_share_img);
|
imgAdapter.isSharing(false);
|
iv_multiple_first_close.setVisibility(View.VISIBLE);
|
return shareBp2;
|
}
|
|
/**
|
* 设置分享的图片
|
*/
|
private void setShareImages(Bitmap shareImage) {
|
if (shareImage == null)
|
shareImage = getShareImage();
|
mSharebuilder.setBitmap(shareImage);
|
ArrayList<ShareImageEntity> shangImageList = new ArrayList<>();
|
shangImageList.add(new ShareImageEntity(shareImage, null));
|
List<String> imgList = shareInfo.getGoodsInfo().getImgList();
|
if (imgList.size() > 0)
|
for (String imgUrl : imgList) {
|
shangImageList.add(new ShareImageEntity(null, imgUrl));
|
}
|
mSharebuilder.setShareImageList(shangImageList);
|
}
|
|
private int showCount = 0;
|
|
public class MultipleImgAdapter extends BaseAdapter {
|
|
private List<String> mList;
|
private boolean isSharing = false;
|
|
public MultipleImgAdapter(List<String> list) {
|
this.mList = list;
|
}
|
|
@Override
|
public int getCount() {
|
return mList.size();
|
}
|
|
@Override
|
public Object getItem(int position) {
|
return mList.get(position);
|
}
|
|
|
@Override
|
public long getItemId(int position) {
|
return position;
|
}
|
|
@Override
|
public View getView(final int position, View view, ViewGroup parent) {
|
final MultipleImgAdapter.Holder holder;
|
if (view == null) {
|
holder = new MultipleImgAdapter.Holder();
|
view = LayoutInflater.from(getContext()).inflate(R.layout.item_share_multiple_img, null);
|
holder.iv_img = view.findViewById(R.id.iv_img);
|
holder.iv_img_close = view.findViewById(R.id.iv_img_close);
|
view.setTag(holder);
|
} else {
|
holder = (MultipleImgAdapter.Holder) view.getTag();
|
}
|
holder.iv_img_close.setVisibility(View.GONE);
|
|
// ImageLoader.getInstance().displayImage(mList.get(position), holder.iv_img, options);
|
RequestOptions options=new RequestOptions().placeholder(R.drawable.ic_goods_default);
|
|
Glide.with(getContext()).load(mList.get(position)).apply(options).into(new SimpleTarget<Drawable>(){
|
@Override
|
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
holder.iv_img.setImageDrawable(resource);
|
if (isSharing) {
|
holder.iv_img_close.setVisibility(View.GONE);
|
showCount++;
|
if (showCount == mList.size()) {
|
handler.sendEmptyMessage(0);
|
holder.iv_img_close.postDelayed(new Runnable() {
|
@Override
|
public void run() {
|
iv_multiple_first_close.setVisibility(View.VISIBLE);
|
isSharing(false);
|
//
|
}
|
}, 300);
|
}
|
} else {
|
holder.iv_img_close.setVisibility(View.VISIBLE);
|
}
|
}
|
});
|
|
holder.iv_img_close.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
mList.remove(position);
|
shareInfo.getGoodsInfo().getImgList().remove(position + 1);
|
multipleImg();
|
// notifyDataSetChanged();
|
}
|
});
|
return view;
|
}
|
|
Handler handler = new Handler() {
|
@Override
|
public void handleMessage(Message msg) {
|
super.handleMessage(msg);
|
Bitmap mulBp = getViewBp(ll_multiple_share_img);
|
showShareImg(mulBp);
|
}
|
};
|
|
class Holder {
|
ImageView iv_img;
|
ImageView iv_img_close;
|
}
|
|
public void isSharing(boolean isSharing) {
|
this.isSharing = isSharing;
|
notifyDataSetChanged();
|
}
|
}
|
|
/**
|
* 替换二维码 传送给dialog
|
*/
|
@SuppressLint("HandlerLeak")
|
private Handler qrCodeUpdatehandler = new Handler() {
|
@Override
|
public void handleMessage(Message msg) {
|
super.handleMessage(msg);
|
if (shareInfo.getWxErCode() == null || shareInfo.getWxErCode().length() == 0) {
|
return;
|
}
|
if (msg.what == 1 || msg.what == 0)
|
setQRCode(shareInfo.getWxErCode());
|
else
|
setQRCode(shareInfo.getClickUrl());//设置二维码
|
setShareImages(null);
|
//继续分享
|
mSharebuilder.shareImgs(msg.what);
|
}
|
};
|
|
/*****************分享点击了微信 替换二维码********/
|
@Override
|
public void onSuccess(Object var1, int imgSize) {
|
//保存分享习惯
|
if (shareInfo.getGoodsInfo() != null && shareInfo.getGoodsInfo().getImgList() != null) {
|
if (imgSize == shareInfo.getGoodsInfo().getImgList().size())
|
ShareCacheUtil.saveSingleGoodsShareImage(getContext(), true);
|
else
|
ShareCacheUtil.saveSingleGoodsShareImage(getContext(), false);
|
}
|
qrCodeUpdatehandler.sendEmptyMessage((int) var1);
|
}
|
|
}
|