package com.tejia.lijin.app.ui.dialog;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.graphics.Color;
|
import android.graphics.Typeface;
|
import android.text.Spannable;
|
import android.text.SpannableString;
|
import android.text.style.ForegroundColorSpan;
|
import android.text.style.RelativeSizeSpan;
|
import android.text.style.StyleSpan;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.entity.recommendinfo.ConvertLinkInfo;
|
import com.tejia.lijin.app.entity.user.VIPUpgradedNotify;
|
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
|
import com.tejia.lijin.app.util.downutil.StringUtils;
|
|
/**
|
* 转链
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class VipUpgradedDialog extends Dialog {
|
|
public VipUpgradedDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public VipUpgradedDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
public static class Builder {
|
private ConvertLinkInfo convertLinkInfo;
|
private Context context;
|
private OnClickListener closeClickListener;
|
private OnClickListener positiveClickListener;
|
private VIPUpgradedNotify notifyData;
|
|
public Builder(Context context) {
|
this.context = context;
|
}
|
|
|
public VipUpgradedDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
final VipUpgradedDialog dialog = new VipUpgradedDialog(context, R.style.Dialog1);
|
View layout = inflater.inflate(R.layout.dialog_vip_upgraded, null);
|
|
//设置值
|
TextView tv_upgraded_desc = layout.findViewById(R.id.tv_upgraded_desc);
|
tv_upgraded_desc.setText(String.format("成功由%s\n升级为%s", notifyData.getFromLevelName(), notifyData.getToLevelName()));
|
|
TextView tv_day = layout.findViewById(R.id.tv_day);
|
ImageView iv_level = layout.findViewById(R.id.iv_now_level);
|
TextView tv_detail = layout.findViewById(R.id.tv_detail);
|
|
//String text=
|
|
int year = notifyData.getDay() / 365;
|
int day = notifyData.getDay() % 365;
|
int start1 = -1;
|
int end1 = -1;
|
int start2 = -1;
|
int end2 = -1;
|
String st = "共耗时";
|
|
if (year > 0) {
|
start1 = st.length();
|
st += year + "年";
|
end1 = st.length() - 1;
|
}
|
if (day > 0) {
|
start2 = st.length();
|
st += day + "天";
|
end2 = st.length() - 1;
|
}
|
|
Spannable style = new SpannableString(st);
|
ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.parseColor("#FFE270"));
|
RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.333f);
|
if (start1 >= 0) {
|
style.setSpan(redSpan, start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
style.setSpan(sizeSpan, start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
style.setSpan(new StyleSpan(Typeface.BOLD), start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
}
|
|
if (start2 >= 0) {
|
redSpan = new ForegroundColorSpan(Color.parseColor("#FFE270"));
|
sizeSpan = new RelativeSizeSpan(1.333f);
|
style.setSpan(redSpan, start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
style.setSpan(sizeSpan, start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
style.setSpan(new StyleSpan(Typeface.BOLD), start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
}
|
|
tv_day.setText(style);
|
|
int resourceId = 0;
|
switch (notifyData.getToLevel()) {
|
case "vipPre1":
|
resourceId = R.drawable.vippre1_highlight;
|
break;
|
case "vipPre2":
|
resourceId = R.drawable.vippre2_highlight;
|
break;
|
case "vip":
|
resourceId = R.drawable.vip_highlight;
|
break;
|
case "tearcher":
|
resourceId = R.drawable.tearcher_highlight;
|
}
|
|
iv_level.setImageResource(resourceId);
|
|
tv_detail.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (!StringUtils.isNullOrEmpty(notifyData.getDetailLink())) {
|
context.startActivity(new Intent(context, ShareBrowserActivity.class).putExtra("url", notifyData.getDetailLink()));
|
}
|
if (dialog.isShowing())
|
dialog.dismiss();
|
if (positiveClickListener != null)
|
positiveClickListener.onClick(dialog, 1);
|
}
|
});
|
layout.findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (dialog.isShowing())
|
dialog.dismiss();
|
if (closeClickListener != null)
|
closeClickListener.onClick(dialog, 1);
|
}
|
});
|
|
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
|
|
android.view.WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
|
params.width = android.view.WindowManager.LayoutParams.MATCH_PARENT;
|
params.height = android.view.WindowManager.LayoutParams.MATCH_PARENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.setCanceledOnTouchOutside(false);
|
return dialog;
|
}
|
|
public Builder setCloseClickListener(OnClickListener closeClickListener) {
|
this.closeClickListener = closeClickListener;
|
return this;
|
}
|
|
public Builder setPositiveClickListener(OnClickListener positiveClickListener) {
|
this.positiveClickListener = positiveClickListener;
|
return this;
|
}
|
|
public Builder setData(VIPUpgradedNotify notifyData) {
|
this.notifyData = notifyData;
|
return this;
|
}
|
}
|
}
|