package com.tejia.lijin.app.ui.dialog;
|
|
import android.app.Activity;
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
|
import com.wpc.library.util.SystemCommon;
|
import com.wpc.library.util.common.StringUtils;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.entity.GoldExchangeState;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class GoldExchangeStateDialog extends Dialog {
|
|
public GoldExchangeStateDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
|
public GoldExchangeStateDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
public static class Builder {
|
private Activity context;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private String title;
|
private GoldExchangeState info;
|
private int type;
|
private int cancelColor = 0;
|
private int confirm = 0;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Activity context) {
|
this.context = context;
|
}
|
|
public Builder setTitle(String title) {
|
this.title = title;
|
return this;
|
}
|
|
|
public Builder setInfo(GoldExchangeState info) {
|
this.info = info;
|
return this;
|
}
|
|
public Builder setType(int type) {
|
this.type = type;
|
return this;
|
}
|
|
/**
|
* Set the positive button resource and it's listener
|
*
|
* @param positiveButtonText
|
* @return
|
*/
|
public Builder setPositiveButton(int positiveButtonText,
|
OnClickListener listener) {
|
this.positiveButtonText = (String) context
|
.getText(positiveButtonText);
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setPositiveButtonColor(int color) {
|
confirm = color;
|
return this;
|
}
|
|
public Builder setPositiveButton(String positiveButtonText,
|
OnClickListener listener) {
|
this.positiveButtonText = positiveButtonText;
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButton(int negativeButtonText,
|
OnClickListener listener) {
|
this.negativeButtonText = (String) context
|
.getText(negativeButtonText);
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButton(String negativeButtonText,
|
OnClickListener listener) {
|
this.negativeButtonText = negativeButtonText;
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButtonColor(int color) {
|
cancelColor = color;
|
return this;
|
}
|
|
public GoldExchangeStateDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final GoldExchangeStateDialog dialog = new GoldExchangeStateDialog(context, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.dialog_gold_exchange_state, null);
|
TextView tv_title = layout.findViewById(R.id.tv_title);
|
TextView tv_gold_num = layout.findViewById(R.id.tv_gold_num);
|
TextView tv_desc = layout.findViewById(R.id.tv_desc);
|
TextView tv_confirm = layout.findViewById(R.id.tv_confirm);
|
LinearLayout ll_invite_code = layout.findViewById(R.id.ll_invite_code);
|
TextView tv_invite_code = layout.findViewById(R.id.tv_invite_code);
|
TextView tv_spread_redpacket = layout.findViewById(R.id.tv_spread_redpacket);
|
ImageView iv_close = layout.findViewById(R.id.iv_close);
|
tv_desc.setText(info.getTip());
|
tv_title.setText(title);
|
tv_gold_num.setText(info.getGoldCoin());
|
tv_spread_redpacket.setText(info.getName() + "");
|
|
ll_invite_code.setVisibility(type == 2 ? View.VISIBLE : View.GONE);
|
tv_spread_redpacket.setVisibility((type == 3||type == 4) ? View.VISIBLE : View.GONE);
|
if (info.getType().equals("inviteCodePublish")) {
|
tv_invite_code.setText(info.getInviteCode());
|
}
|
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
// set the confirm button
|
if (cancelColor > 0) {
|
tv_confirm.setBackgroundResource(R.drawable.shape_login_select);
|
tv_confirm.setTextColor(context.getResources().getColor(R.color.black));
|
}
|
if (positiveButtonClickListener != null) {
|
if (!StringUtils.isEmpty(positiveButtonText)) {
|
tv_confirm.setText(positiveButtonText);
|
}
|
tv_confirm.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
}
|
});
|
}
|
iv_close.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
dialog.dismiss();
|
}
|
});
|
dialog.setContentView(layout);
|
|
android.view.WindowManager.LayoutParams params = dialog.getWindow()
|
.getAttributes();
|
params.width = (int) ((SystemCommon.getScreenWidth(context) * 3) / 4);
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
|
dialog.setCanceledOnTouchOutside(false);
|
return dialog;
|
}
|
}
|
}
|