package com.tejia.lijin.app.ui.recommend.singleshare;
|
|
import android.Manifest;
|
import android.app.ActionBar;
|
import android.content.Intent;
|
import android.graphics.Bitmap;
|
import android.graphics.Color;
|
import android.media.MediaScannerConnection;
|
import android.net.Uri;
|
import android.os.Bundle;
|
import android.os.Environment;
|
import android.os.Handler;
|
import android.os.Message;
|
import androidx.annotation.NonNull;
|
import androidx.fragment.app.FragmentTransaction;
|
import android.text.method.ScrollingMovementMethod;
|
import android.view.Gravity;
|
import android.view.LayoutInflater;
|
import android.view.MotionEvent;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.CheckBox;
|
import android.widget.CompoundButton;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.bumptech.glide.Glide;
|
import com.google.gson.Gson;
|
import com.wpc.library.RetainViewFragment;
|
import com.wpc.library.util.common.DimenUtils;
|
import com.wpc.library.util.common.FileUtils;
|
import com.wpc.library.util.common.StringUtils;
|
import com.wpc.library.util.security.MD5Utils;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.callBack.PermissionInterface;
|
import com.tejia.lijin.app.entity.common.ImageShowEntity;
|
import com.tejia.lijin.app.entity.share.ShareGoodsCommentChoiceInfo;
|
import com.tejia.lijin.app.entity.share.ShareImageEntity;
|
import com.tejia.lijin.app.entity.share.SingleGoodsShareInfo;
|
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
|
import com.tejia.lijin.app.ui.trends.BigImageActivity;
|
import com.tejia.lijin.app.util.PermissionHelper;
|
import com.tejia.lijin.app.util.ToastUtil;
|
import com.tejia.lijin.app.util.ToolUtil;
|
import com.tejia.lijin.app.util.Tools;
|
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
|
import com.tejia.lijin.app.util.share.ShareCacheUtil;
|
import com.tejia.lijin.app.util.share.ShareImageUtil;
|
import com.ysh.wpc.appupdate.download.DownLoadFile;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.io.File;
|
import java.util.ArrayList;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Set;
|
|
|
/**
|
* 快捷分享
|
*/
|
public class FastShareFragment extends RetainViewFragment implements View.OnClickListener, PermissionInterface {
|
|
//图片选择
|
private TextView tv_goods_img_num, tv_change_img;
|
private CheckBox cb_select_all;
|
private LinearLayout ll_imgs, ll_select_all;
|
|
//推荐语与评论
|
private LinearLayout ll_copy_recommend_text, ll_copy_comment;
|
private TextView tv_recommend_text, tv_comment_text;
|
|
//评论选择按钮
|
private LinearLayout ll_choice;
|
|
private final static int COPY_TYPE_RECOMMEND = 1;
|
private final static int COPY_TYPE_COMMENT = 2;
|
|
//分享
|
private LinearLayout ll_share_wx, ll_share_wxcircle, ll_share_qq, ll_share_download, ll_share_more;
|
|
private LinearLayout ll_recommend;
|
|
private ImageView iv_wx_circle;
|
|
//小黄条
|
private LinearLayout ll_notice;
|
private TextView tv_notice_content;
|
private ImageView iv_close;
|
|
|
@Override
|
public int getContentResource() {
|
return R.layout.fragment_share_goods_fast;
|
}
|
|
|
private SingleGoodsShareInfo shareInfo;
|
|
private void saveCommentChoices() {
|
ShareCacheUtil.saveFastShareCommentChoices(getContext(), currentChoicedSet);
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
shareInfo = (SingleGoodsShareInfo) this.getArguments().getSerializable("shareInfo");
|
initView(contentView);
|
initListener(contentView);
|
initData();
|
mPermissionsChecker = new PermissionHelper(getActivity(), this);
|
}
|
|
private void initView(View contentView) {
|
ll_imgs = contentView.findViewById(R.id.ll_imgs);
|
tv_goods_img_num = contentView.findViewById(R.id.tv_goods_img_num);
|
tv_change_img = contentView.findViewById(R.id.tv_change_img);
|
cb_select_all = contentView.findViewById(R.id.cb_select_all);
|
ll_select_all = contentView.findViewById(R.id.ll_select_all);
|
ll_copy_recommend_text = contentView.findViewById(R.id.ll_copy_recommend_text);
|
ll_copy_comment = contentView.findViewById(R.id.ll_copy_comment);
|
tv_recommend_text = contentView.findViewById(R.id.tv_recommend_text);
|
ll_recommend = contentView.findViewById(R.id.ll_recommend);
|
tv_recommend_text.setMovementMethod(ScrollingMovementMethod.getInstance());
|
tv_comment_text = contentView.findViewById(R.id.tv_comment_text);
|
tv_comment_text.setMovementMethod(ScrollingMovementMethod.getInstance());
|
iv_wx_circle = contentView.findViewById(R.id.iv_wx_circle);
|
|
|
ll_choice = contentView.findViewById(R.id.ll_choice);
|
|
|
ll_share_wx = contentView.findViewById(R.id.ll_share_wx);
|
ll_share_wxcircle = contentView.findViewById(R.id.ll_share_wxcircle);
|
ll_share_qq = contentView.findViewById(R.id.ll_share_qq);
|
ll_share_download = contentView.findViewById(R.id.ll_share_download);
|
|
ll_share_more = contentView.findViewById(R.id.ll_share_more);
|
|
ll_notice = contentView.findViewById(R.id.ll_notice);
|
tv_notice_content = contentView.findViewById(R.id.tv_notice_content);
|
iv_close = contentView.findViewById(R.id.iv_close);
|
|
loadingDialog = new ShapeLoadingDialog.Builder(getContext()).build();
|
}
|
|
float lastCommentY = 0;
|
float lastRecommendY = 0;
|
|
private void initListener(View contentView) {
|
ll_select_all.setOnClickListener(this);
|
tv_change_img.setOnClickListener(this);
|
ll_copy_comment.setOnClickListener(this);
|
ll_copy_recommend_text.setOnClickListener(this);
|
cb_select_all.setOnClickListener(this);
|
|
ll_share_wx.setOnClickListener(this);
|
ll_share_wxcircle.setOnClickListener(this);
|
ll_share_qq.setOnClickListener(this);
|
ll_share_download.setOnClickListener(this);
|
ll_share_more.setOnClickListener(this);
|
|
|
View.OnTouchListener commentTouch = new View.OnTouchListener() {
|
@Override
|
public boolean onTouch(View v, MotionEvent event) {
|
//下滑
|
float cha = event.getY() - lastCommentY;
|
lastCommentY = event.getY();
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
lastCommentY = 0;
|
//通知父控件不要干扰
|
if (canScroll(tv_comment_text, cha))
|
v.getParent().requestDisallowInterceptTouchEvent(true);
|
else
|
v.getParent().requestDisallowInterceptTouchEvent(false);
|
}
|
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
//通知父控件不要干扰
|
if (canScroll(tv_comment_text, cha))
|
v.getParent().requestDisallowInterceptTouchEvent(true);
|
else
|
v.getParent().requestDisallowInterceptTouchEvent(false);
|
}
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
lastCommentY = 0;
|
v.getParent().requestDisallowInterceptTouchEvent(false);
|
}
|
return false;
|
}
|
};
|
|
|
View.OnTouchListener recommendTouch = new View.OnTouchListener() {
|
@Override
|
public boolean onTouch(View v, MotionEvent event) {
|
//下滑
|
float cha = event.getY() - lastRecommendY;
|
lastRecommendY = event.getY();
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
lastRecommendY = 0;
|
//通知父控件不要干扰
|
if (canScroll(tv_recommend_text, cha))
|
v.getParent().requestDisallowInterceptTouchEvent(true);
|
else
|
v.getParent().requestDisallowInterceptTouchEvent(false);
|
}
|
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
//通知父控件不要干扰
|
if (canScroll(tv_recommend_text, cha))
|
v.getParent().requestDisallowInterceptTouchEvent(true);
|
else
|
v.getParent().requestDisallowInterceptTouchEvent(false);
|
}
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
lastRecommendY = 0;
|
v.getParent().requestDisallowInterceptTouchEvent(false);
|
}
|
return false;
|
}
|
};
|
|
tv_comment_text.setOnTouchListener(commentTouch);
|
tv_recommend_text.setOnTouchListener(recommendTouch);
|
}
|
|
private boolean canScroll(TextView tv, float off) {
|
// Log.i("FastShareFragment", "y:" + tv.getScrollY() + " height:" + tv.getMeasuredHeight() + "paddingTop:" + tv.getPaddingTop() + " offset:" + (tv.getLineCount() * tv.getLineHeight()));
|
if (tv.getScrollY() <= 0 && off >= 0)
|
return false;
|
int offset = tv.getLineCount() * tv.getLineHeight();
|
if (tv.getScrollY() + tv.getMeasuredHeight() > offset && off < 0)
|
return false;
|
return true;
|
}
|
|
|
//二维码图片临时存储目录
|
private String tempERCodePicturePath = Environment.getExternalStorageDirectory() + "/share_single_goods_img_temp";
|
|
//初始化图片选择器
|
private void initImgSelector() {
|
ll_imgs.removeAllViews();
|
//初始化单图的图片选择
|
for (int i = 0; i < shareInfo.getGoodsInfo().getImgList().size(); i++) {
|
final int p = i;
|
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_fast_share_select_img, null);
|
final ImageView iv_share_select_img = view.findViewById(R.id.iv_share_img);
|
FrameLayout fl_select_img = view.findViewById(R.id.fl_select_img);
|
final CheckBox cb_select = view.findViewById(R.id.cb_select);
|
TextView tv_ercode = view.findViewById(R.id.tv_ercode);
|
final String imgUrl = shareInfo.getGoodsInfo().getImgList().get(i);
|
|
cb_select.setTag(imgUrl);
|
Glide.with(this).load(imgUrl).placeholder(R.drawable.ic_goods_default).into(iv_share_select_img);
|
iv_share_select_img.setTag(Integer.MAX_VALUE, i);
|
iv_share_select_img.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (Integer.parseInt(iv_share_select_img.getTag(Integer.MAX_VALUE).toString()) == 0) {
|
//生成二维码图
|
//取第一张图片生成二维码
|
singleImageFragment.setSelectedImgUrl(shareInfo.getGoodsInfo().getImgList().get(0));
|
//延时200ms
|
ll_imgs.postDelayed(new Runnable() {
|
@Override
|
public void run() {
|
if (mPermissionsChecker.lacksPermissions(getPermissions())) { //检测权限
|
mPermissionsChecker.showNormalDialog();
|
} else {
|
if (mPermissionsChecker.lacksPermissions(getPermissions())) { //检测权限
|
mPermissionsChecker.showNormalDialog();
|
} else {
|
singleImageFragment.getViewBp(new SingleGoodsInfoFragment.ViewClipListener() {//截图
|
@Override
|
public void onSuccess(Bitmap bitmap) {
|
File parent = new File(tempERCodePicturePath);
|
try {
|
if (parent.exists())
|
parent.delete();
|
parent.mkdirs();
|
File file = new File(tempERCodePicturePath, System.currentTimeMillis() + ".png");
|
FileUtils.saveBitmap(bitmap, parent.getAbsolutePath(), file.getName());
|
List<ImageShowEntity> list = new ArrayList<>();
|
list.add(new ImageShowEntity(file.getAbsolutePath(), null));
|
if (shareInfo.getGoodsInfo().getImgList().size() > 1)
|
for (int i = 1; i < shareInfo.getGoodsInfo().getImgList().size(); i++) {
|
list.add(new ImageShowEntity(null, shareInfo.getGoodsInfo().getImgList().get(i)));
|
}
|
|
Intent intent = new Intent(getContext(), BigImageActivity.class);
|
intent.putExtra("imgList", new Gson().toJson(list));
|
intent.putExtra("position", 0);
|
startActivity(intent);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
@Override
|
public void onFail() {
|
Toast.makeText(getContext(), "二维码分享图生成失败", Toast.LENGTH_SHORT).show();
|
}
|
});
|
|
|
}
|
}
|
|
|
}
|
}, 200);
|
return;
|
} else {
|
List<ImageShowEntity> list = new ArrayList<>();
|
if (shareInfo.getGoodsInfo().getImgList().size() > 1)
|
for (int i = 0; i < shareInfo.getGoodsInfo().getImgList().size(); i++) {
|
list.add(new ImageShowEntity(null, shareInfo.getGoodsInfo().getImgList().get(i)));
|
}
|
|
Intent intent = new Intent(getContext(), BigImageActivity.class);
|
intent.putExtra("imgList", new Gson().toJson(list));
|
intent.putExtra("position", p);
|
startActivity(intent);
|
}
|
}
|
});
|
|
cb_select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked) {
|
ll_imgs.post(new Runnable() {
|
@Override
|
public void run() {
|
int count = getSelectedImgsCount();
|
if (count < 1 && !isChecked) {
|
cb_select.setChecked(true);
|
ToastUtil.showSingleToast(getContext(), "请至少选择一张图片");
|
return;
|
}
|
setSelectedImgsCount();
|
}
|
});
|
|
}
|
});
|
|
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT
|
, ViewGroup.LayoutParams.WRAP_CONTENT);
|
if (i == 0) {
|
cb_select.setChecked(true);
|
// cb_select.setEnabled(false);
|
params.leftMargin = DimenUtils.dip2px(getContext(), 15);
|
tv_ercode.setVisibility(View.VISIBLE);
|
} else if (i == shareInfo.getGoodsInfo().getImgList().size() - 1) {
|
params.leftMargin = DimenUtils.dip2px(getContext(), 10);
|
params.rightMargin = DimenUtils.dip2px(getContext(), 15);
|
} else {
|
params.leftMargin = DimenUtils.dip2px(getContext(), 10);
|
}
|
fl_select_img.setLayoutParams(params);
|
ll_imgs.addView(view);
|
}
|
|
// ll_imgs.post(new Runnable() {
|
// @Override
|
// public void run() {
|
// setSelectedImgsCount();
|
// }
|
// });
|
|
|
}
|
|
|
/*************小黄条*******/
|
private void getAppPageNotification() {
|
ShoppingApi.getAppPageNotification(getContext(), "fastShare" + shareInfo.getGoodsInfo().getGoodsType(), new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
ToolUtil.setAppPageNotification(ll_notice, tv_notice_content, iv_close, jsonObject);
|
}
|
});
|
}
|
|
private String saveFilePath = android.os.Environment.getExternalStorageDirectory()
|
+ "/tejiaapp";
|
|
private Handler shareHandler = new Handler() {
|
|
@Override
|
public void handleMessage(Message msg) {
|
super.handleMessage(msg);
|
ArrayList<Uri> uriList = new ArrayList<>();
|
if (shareTempImgEntity != null)
|
for (ShareImageEntity entity : shareTempImgEntity)
|
uriList.add(Tools.getImageContentUri(getContext(), new File(entity.getFilePath())));
|
switch (msg.what) {
|
case 1://微信
|
ShareImageUtil.shareWXPictureByIntent(getContext(), uriList);
|
break;
|
case 2://朋友圈
|
ShareImageUtil.shareWXCirclePictureByIntent(getContext(), uriList);
|
break;
|
case 3://QQ
|
ShareImageUtil.shareQQPictureByIntent(getContext(), uriList);
|
break;
|
|
case 4://保存到相册
|
for (ShareImageEntity img : shareTempImgEntity) {
|
File f = new File(img.getFilePath());
|
String name = "multi_" + f.getName();
|
String md5 = MD5Utils.getMD532(name.split("\\.")[0]);
|
File file = new File(saveFilePath + "/" + md5 + ".jpg");
|
if (file.exists()) {
|
file.delete();
|
} else {
|
FileUtils.copyFile(new File(img.getFilePath()), file);
|
}
|
//通知相册更新
|
MediaScannerConnection.scanFile(getContext(), new String[]{file.toString()}, null, null);
|
}
|
Toast.makeText(getContext(), "图片保存成功!", Toast.LENGTH_LONG).show();
|
//删除缓存文件夹
|
cleanCacheDir();
|
break;
|
case 5://更多
|
Intent mulIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
|
mulIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
|
mulIntent.setType("image/png");
|
startActivity(Intent.createChooser(mulIntent, "多图文件分享"));
|
break;
|
}
|
}
|
};
|
|
private List<ShareImageEntity> shareTempImgEntity;
|
|
int platform = 0;
|
|
private ShapeLoadingDialog loadingDialog = null;
|
|
String path = Environment.getExternalStorageDirectory()
|
+ "/rebateshare";
|
final File storageDir = new File(path);
|
|
private void startDownLoadImages(List<String> urlList) throws Exception {
|
List<String> filePathList = new ArrayList<>();
|
for (String picture : urlList) {
|
String fileName = storageDir.getPath() + "/" + System.currentTimeMillis() + "_" + (long) (Math.random() * 10000000000L) + ".png";
|
filePathList.add(fileName);
|
}
|
|
if (urlList.size() > 0) {
|
//去下载
|
new DownLoadFile().downloadMultiImages(urlList, filePathList, getContext(), new DownLoadFile.FileDownLoadListener() {
|
@Override
|
public void finish(List<File> fileList) {
|
if (loadingDialog.isShowing())
|
loadingDialog.dismiss();
|
//完成下载
|
if (shareTempImgEntity == null)
|
shareTempImgEntity = new ArrayList<>();
|
if (fileList != null)
|
for (File f : fileList) {
|
shareTempImgEntity.add(new ShareImageEntity(f.getPath()));
|
}
|
shareHandler.sendEmptyMessage(platform);
|
}
|
|
@Override
|
public void process(int count) {
|
|
}
|
});
|
} else {
|
if (loadingDialog.isShowing())
|
loadingDialog.dismiss();
|
shareHandler.sendEmptyMessage(platform);
|
}
|
}
|
|
private void sharePicture(final int platform) {
|
|
|
|
final List<String> urlList = new ArrayList<>();
|
|
int checkCount = 0;
|
for (int i = 0; i < ll_imgs.getChildCount(); i++) {
|
if (((CheckBox) ll_imgs.getChildAt(i).findViewById(R.id.cb_select)).isChecked()) {
|
checkCount++;
|
if (i > 0)
|
urlList.add(shareInfo.getGoodsInfo().getImgList().get(i));
|
}
|
}
|
|
if (checkCount < 1) {
|
ToastUtil.showSingleToast(getContext(), "请至少选择一张图片");
|
return;
|
}
|
|
this.platform = platform;
|
//检测权限
|
if (mPermissionsChecker.lacksPermissions(getPermissions())) { //检测权限
|
mPermissionsChecker.showNormalDialog();
|
return;
|
} else {
|
if (mPermissionsChecker.lacksPermissions(getPermissions())) { //检测权限
|
mPermissionsChecker.showNormalDialog();
|
return;
|
}
|
}
|
|
|
/************************复制文本开始**************************/
|
|
ClipboardUtil.copy(getContext(), tv_recommend_text.getText() + "");
|
Toast.makeText(getContext(), "复制成功", Toast.LENGTH_SHORT).show();
|
|
if (!loadingDialog.isShowing())
|
loadingDialog.show();
|
if (shareTempImgEntity != null)
|
shareTempImgEntity.clear();
|
|
|
final File parent = new File(tempERCodePicturePath);
|
try {
|
ShoppingApi.addShareCount(getContext(), shareInfo.getShareId(), "single", null);
|
if (shareTempImgEntity == null)
|
shareTempImgEntity = new ArrayList<>();
|
if (checkCount != urlList.size()) {
|
singleImageFragment.getViewBp(new SingleGoodsInfoFragment.ViewClipListener() {
|
@Override
|
public void onSuccess(Bitmap bitmap) {
|
if (parent.exists())
|
parent.delete();
|
parent.mkdirs();
|
File file = new File(tempERCodePicturePath, System.currentTimeMillis() + ".png");
|
try {
|
FileUtils.saveBitmap(bitmap, parent.getAbsolutePath(), file.getName());
|
shareTempImgEntity.add(new ShareImageEntity(file.getAbsolutePath()));
|
startDownLoadImages(urlList);
|
} catch (Exception e) {
|
Toast.makeText(getContext(), "图片下载失败", Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
@Override
|
public void onFail() {
|
Toast.makeText(getContext(), "生成分享图失败", Toast.LENGTH_SHORT).show();
|
}
|
});
|
|
} else {
|
startDownLoadImages(urlList);
|
}
|
|
} catch (Exception e) {
|
if (loadingDialog.isShowing())
|
loadingDialog.dismiss();
|
}
|
|
}
|
|
//初始化数据
|
private void initData() {
|
initImgSelector();
|
//初始化截图容器
|
initGoodsImage();
|
//初始化其他值
|
if (StringUtils.isBlank(shareInfo.getRecommendText())) {
|
ll_recommend.setVisibility(View.GONE);
|
} else {
|
ll_recommend.setVisibility(View.VISIBLE);
|
tv_recommend_text.setText(shareInfo.getRecommendText().trim());
|
}
|
tv_comment_text.setText("");
|
setChoices();
|
getAppPageNotification();
|
}
|
|
private Set<Integer> currentChoicedSet = new HashSet<>();
|
|
private void setChoices() {
|
Set<Integer> sets = ShareCacheUtil.getFastCommentChoices(getContext());
|
ll_choice.removeAllViews();
|
for (ShareGoodsCommentChoiceInfo info : shareInfo.getCommentTextChoiceList()) {
|
final LinearLayout ll = new LinearLayout(getContext());
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ActionBar.LayoutParams.WRAP_CONTENT);
|
params.width = ActionBar.LayoutParams.WRAP_CONTENT;
|
params.gravity = Gravity.CENTER_VERTICAL;
|
params.rightMargin = DimenUtils.dip2px(getContext(), 10);
|
ll.setLayoutParams(params);
|
|
final CheckBox cb = new CheckBox(getContext());
|
cb.setButtonDrawable(R.drawable.selector_share_copycontent_ischecked);
|
cb.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
cb.setClickable(false);
|
cb.setTag(info);
|
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
ShareGoodsCommentChoiceInfo info = (ShareGoodsCommentChoiceInfo) cb.getTag();
|
if (isChecked) {//添加文本
|
currentChoicedSet.add(info.getType());
|
if (tv_comment_text.getText() == null || tv_comment_text.getText().length() == 0) {
|
tv_comment_text.setText(info.getContent());
|
} else
|
tv_comment_text.setText(tv_comment_text.getText() + "\r\n" + info.getContent());
|
} else {//移除文本
|
currentChoicedSet.remove(info.getType());
|
String content = tv_comment_text.getText().toString();
|
if (content.indexOf("\r\n" + info.getContent()) > -1) {
|
content = content.replace("\r\n" + info.getContent(), "");
|
}
|
tv_comment_text.setText(content);
|
}
|
}
|
});
|
|
if (sets.contains(info.getType()))
|
info.setSelected(true);
|
|
if (info.isSelected())
|
cb.setChecked(true);
|
else
|
cb.setChecked(false);
|
|
|
ll.addView(cb);
|
|
TextView tv = new TextView(getContext());
|
tv.setText(info.getName());
|
tv.setPadding(DimenUtils.dip2px(getContext(), 5), 0, 0, 0);
|
tv.setTextColor(Color.parseColor("#ff333333"));
|
tv.setTextSize(14);
|
|
ll.addView(tv);
|
if (info.isCanCancel()) {
|
ll.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
CheckBox checkBox = (CheckBox) ll.getChildAt(0);
|
checkBox.setChecked(!checkBox.isChecked());
|
}
|
});
|
}
|
|
ll_choice.addView(ll);
|
}
|
ll_choice.setVisibility(View.GONE);
|
}
|
|
private SingleGoodsInfoFragment singleImageFragment;
|
|
private void initGoodsImage() {
|
singleImageFragment = new SingleGoodsInfoFragment();
|
Bundle bundle = new Bundle();
|
bundle.putSerializable("shareInfo", shareInfo);
|
bundle.putSerializable("inviteCodeShow", ShareCacheUtil.isFastShareImageShowInviteCode(getContext()));
|
singleImageFragment.setArguments(bundle);
|
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
|
ft.replace(R.id.fl_goods_info, singleImageFragment);
|
ft.commit();
|
}
|
|
private void selectAllImg() {
|
for (int j = 0; j < ll_imgs.getChildCount(); j++) {
|
View view1 = ll_imgs.getChildAt(j);
|
((CheckBox) view1.findViewById(R.id.cb_select)).setChecked(true);
|
}
|
setSelectedImgsCount();
|
}
|
|
private void unSelectAllImg() {
|
|
if (ll_imgs.getChildCount() > 0) {
|
View view1 = ll_imgs.getChildAt(0);
|
((CheckBox) view1.findViewById(R.id.cb_select)).setChecked(true);
|
}
|
|
for (int j = 1; j < ll_imgs.getChildCount(); j++) {
|
View view1 = ll_imgs.getChildAt(j);
|
((CheckBox) view1.findViewById(R.id.cb_select)).setChecked(false);
|
}
|
setSelectedImgsCount();
|
}
|
|
|
private int getSelectedImgsCount() {
|
int count = 0;
|
for (int j = 0; j < ll_imgs.getChildCount(); j++) {
|
View view1 = ll_imgs.getChildAt(j);
|
if (((CheckBox) view1.findViewById(R.id.cb_select)).isChecked()) {
|
count++;
|
}
|
}
|
return count;
|
}
|
|
private void setSelectedImgsCount() {
|
int count = getSelectedImgsCount();
|
if (count == ll_imgs.getChildCount()) {
|
cb_select_all.setChecked(true);
|
} else {
|
cb_select_all.setChecked(false);
|
}
|
|
tv_goods_img_num.setText(String.format("商品图片(%s/%s)", count, shareInfo.getGoodsInfo().getImgList().size()));
|
|
if (count == 1) {
|
ll_share_wxcircle.setClickable(true);
|
iv_wx_circle.setImageResource(R.drawable.ic_link_share_wxcircle);
|
} else if (count == 0) {
|
ToastUtil.showSingleToast(getContext(), "请至少选择一张图片");
|
} else {
|
ll_share_wxcircle.setClickable(false);
|
iv_wx_circle.setImageResource(R.drawable.ic_link_share_wxcircle_invalid);
|
}
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
singleImageFragment.setInviteCodeShowState(false);
|
}
|
|
private PermissionHelper mPermissionsChecker; // 权限检测器
|
|
/**
|
* 权限请求码
|
*
|
* @return
|
*/
|
@Override
|
public int getPermissionsRequestCode() {
|
return 1001;
|
}
|
|
/**
|
* 请求权限
|
*
|
* @return
|
*/
|
@Override
|
public String[] getPermissions() {
|
return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
}
|
|
/**
|
* 权限请求成功
|
*/
|
@Override
|
public void requestPermissionsSuccess() {
|
if (platform > 0) {
|
sharePicture(platform);
|
}
|
}
|
|
/**
|
* 权限请求失败
|
*/
|
@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;
|
}
|
}
|
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.cb_select_all:
|
if (cb_select_all.isChecked())
|
selectAllImg();
|
else {
|
unSelectAllImg();
|
}
|
break;
|
case R.id.ll_select_all:
|
cb_select_all.setChecked(!cb_select_all.isChecked());
|
if (cb_select_all.isChecked())
|
selectAllImg();
|
else {
|
unSelectAllImg();
|
}
|
break;
|
|
case R.id.tv_change_img://更换主图
|
Intent intent = new Intent(getContext(), ShareMainPictureChoiceActivity.class);
|
intent.putExtra("shareInfo", shareInfo);
|
startActivityForResult(intent, 200);
|
break;
|
|
case R.id.ll_copy_comment:
|
ClipboardUtil.copy(getContext(), tv_comment_text.getText() + "");
|
Toast.makeText(getContext(), "复制成功", Toast.LENGTH_SHORT).show();
|
break;
|
case R.id.ll_copy_recommend_text:
|
ClipboardUtil.copy(getContext(), tv_recommend_text.getText() + "");
|
Toast.makeText(getContext(), "复制成功", Toast.LENGTH_SHORT).show();
|
break;
|
|
//分享
|
case R.id.ll_share_download:
|
sharePicture(4);
|
break;
|
case R.id.ll_share_more:
|
sharePicture(5);
|
break;
|
case R.id.ll_share_qq:
|
sharePicture(3);
|
break;
|
case R.id.ll_share_wx:
|
sharePicture(1);
|
break;
|
case R.id.ll_share_wxcircle:
|
sharePicture(2);
|
break;
|
|
}
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
}
|
|
@Override
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
super.onActivityResult(requestCode, resultCode, data);
|
if (resultCode == 200 && requestCode == 200) {
|
String selectedUrl = data.getStringExtra("imgUrl");
|
singleImageFragment.setSelectedImgUrl(selectedUrl);
|
//改变当前的图片顺序
|
if (!shareInfo.getGoodsInfo().getImgList().get(0).equalsIgnoreCase(selectedUrl)) {
|
//有改变才赋值
|
List<String> imgList = shareInfo.getGoodsInfo().getImgList();
|
if (imgList.indexOf(selectedUrl) > -1) {
|
imgList.remove(imgList.indexOf(selectedUrl));
|
imgList.add(0, selectedUrl);
|
}
|
shareInfo.getGoodsInfo().setImgList(imgList);
|
//设置图片顺序
|
initImgSelector();
|
}
|
}
|
}
|
|
private void cleanCacheDir() {
|
try {
|
File file = new File(tempERCodePicturePath);
|
FileUtils.deleteFile(file.getAbsolutePath());
|
FileUtils.deleteFile(storageDir.getAbsolutePath());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
saveCommentChoices();
|
cleanCacheDir();
|
}
|
}
|