package com.yeshi.ec.rebate.myapplication.ui.dialog;
|
|
import android.app.Activity;
|
import android.app.Dialog;
|
import android.content.ClipData;
|
import android.content.ClipboardManager;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.graphics.Color;
|
import android.graphics.Paint;
|
import android.graphics.drawable.GradientDrawable;
|
import android.text.InputType;
|
import android.text.Spannable;
|
import android.text.SpannableString;
|
import android.text.Spanned;
|
import android.text.method.ScrollingMovementMethod;
|
import android.text.style.RelativeSizeSpan;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.EditText;
|
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.load.engine.DiskCacheStrategy;
|
import com.wpc.library.util.SystemCommon;
|
import com.yeshi.ec.rebate.myapplication.BasicTextHttpResponseHandler;
|
import com.yeshi.ec.rebate.myapplication.R;
|
import com.yeshi.ec.rebate.myapplication.ShoppingApi;
|
import com.yeshi.ec.rebate.myapplication.entity.TaoBaoGoodsBrief;
|
import com.yeshi.ec.rebate.myapplication.entity.recommendinfo.ConvertLinkInfo;
|
import com.yeshi.ec.rebate.myapplication.entity.recommendinfo.JumpUnit;
|
import com.yeshi.ec.rebate.myapplication.util.GlideRoundTransform;
|
import com.yeshi.ec.rebate.myapplication.util.JumpActivityUtil;
|
import com.yeshi.ec.rebate.myapplication.util.clipboard.ClipboardUtil;
|
import com.yeshi.ec.rebate.myapplication.util.downutil.StringUtils;
|
import com.yeshi.ec.rebate.myapplication.util.user.UserUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
/**
|
* 转链
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class ConvertLinkDialog extends Dialog {
|
|
public ConvertLinkDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public ConvertLinkDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
public static class Builder {
|
private Activity context;
|
private TaoBaoGoodsBrief taoBaoGoodsBrief;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
private int type = 0;//默认为0
|
|
private ConvertLinkInfo convertLinkInfo;
|
|
public Builder(Activity context) {
|
this.context = context;
|
}
|
|
public Builder setMessage(TaoBaoGoodsBrief taoBaoGoodsBrief) {
|
this.taoBaoGoodsBrief = taoBaoGoodsBrief;
|
return this;
|
}
|
|
public Builder setType(int type) {/**判断是否未加入淘宝联盟*/
|
this.type = type;
|
return this;
|
}
|
|
public Builder setConvertLinkInfo(ConvertLinkInfo convertLinkInfo) {/**判断是否未加入淘宝联盟*/
|
this.convertLinkInfo = convertLinkInfo;
|
return this;
|
}
|
|
private void clearClipBoard() {
|
ClipboardUtil.emptyClipboard(context);
|
|
}
|
|
public ConvertLinkDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
final ConvertLinkDialog dialog = new ConvertLinkDialog(context, R.style.Dialog1);
|
View layout = inflater.inflate(R.layout.item_convert_link, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
layout.findViewById(R.id.iv_cancle).setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (dialog != null && dialog.isShowing())
|
dialog.dismiss();
|
clearClipBoard();
|
}
|
});
|
|
TextView tv_go = layout.findViewById(R.id.tv_go);
|
TextView tv_convert = layout.findViewById(R.id.tv_convert);
|
TextView tv_title = layout.findViewById(R.id.tv_title);
|
TextView tv_state_desc = layout.findViewById(R.id.tv_state_desc);
|
final TextView tv_text = layout.findViewById(R.id.tv_text);
|
tv_text.setMovementMethod(ScrollingMovementMethod.getInstance());
|
tv_text.setHighlightColor(context.getResources().getColor(android.R.color.transparent));
|
//设置按钮背景
|
dialog.setContentView(layout);
|
//赋值
|
tv_title.setText(convertLinkInfo.getTitle());
|
tv_text.setText(convertLinkInfo.getText());
|
if (convertLinkInfo.getState() == ConvertLinkInfo.STATE_CONVERT) {
|
tv_go.setVisibility(View.VISIBLE);
|
tv_convert.setVisibility(View.GONE);
|
tv_go.setText("转链");
|
tv_go.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
clearClipBoard();
|
toConvert(tv_text.getText() + "", convertLinkInfo.getConvert(), new IConvertResult() {
|
@Override
|
public void onSuccess() {
|
if (dialog.isShowing())
|
dialog.dismiss();
|
}
|
});
|
}
|
});
|
} else if (convertLinkInfo.getState() == ConvertLinkInfo.STATE_CONVERT_VIEW) {
|
tv_go.setVisibility(View.VISIBLE);
|
tv_convert.setVisibility(View.VISIBLE);
|
tv_convert.setText("转链");
|
tv_go.setText("去看看");
|
tv_convert.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
clearClipBoard();
|
toConvert(tv_text.getText() + "", convertLinkInfo.getConvert(), new IConvertResult() {
|
@Override
|
public void onSuccess() {
|
if (dialog.isShowing())
|
dialog.dismiss();
|
}
|
});
|
}
|
});
|
tv_go.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
clearClipBoard();
|
JumpActivityUtil.jumpPage(context, convertLinkInfo.getView().getJumpDetail(), convertLinkInfo.getView().getParams());
|
if (dialog.isShowing())
|
dialog.dismiss();
|
}
|
});
|
} else if (convertLinkInfo.getState() == ConvertLinkInfo.STATE_GUESS_LIKE) {
|
tv_go.setVisibility(View.VISIBLE);
|
tv_convert.setVisibility(View.GONE);
|
tv_go.setText("猜你喜欢");
|
tv_go.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
clearClipBoard();
|
JumpActivityUtil.jumpPage(context, convertLinkInfo.getGuessLike().getJumpDetail(), convertLinkInfo.getGuessLike().getParams());
|
if (dialog.isShowing())
|
dialog.dismiss();
|
}
|
});
|
}
|
|
tv_state_desc.setText(convertLinkInfo.getStateDesc());
|
|
android.view.WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
|
params.width = (int) ((SystemCommon.getScreenWidth(context) * 19) / 23);
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.setCanceledOnTouchOutside(false);
|
return dialog;
|
}
|
|
ShapeLoadingDialog pd = null;
|
|
private void toConvert(String text, final JumpUnit jump, final IConvertResult result) {
|
if (pd == null) {
|
pd = new ShapeLoadingDialog.Builder(context).build();
|
}
|
if (!pd.isShowing())
|
pd.show();
|
|
Long uid = UserUtil.getUid(context);
|
ShoppingApi.setConvertLinkDoc(context, text, uid, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onStart() {
|
super.onStart();
|
}
|
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
result.onSuccess();
|
JumpActivityUtil.jumpPage(context, jump.getJumpDetail(), jump.getParams());
|
} else {
|
Toast.makeText(context, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
if (pd.isShowing())
|
pd.dismiss();
|
}
|
});
|
}
|
|
interface IConvertResult {
|
public void onSuccess();
|
}
|
}
|
}
|