package com.yeshi.ec.rebate.myapplication.ui.dialog;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.view.Gravity;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
|
import com.bumptech.glide.Glide;
|
import com.wpc.library.util.SystemCommon;
|
import com.wpc.library.util.common.DimenUtils;
|
import com.wpc.library.util.common.StringUtils;
|
import com.yeshi.ec.rebate.myapplication.R;
|
import com.yeshi.ec.rebate.myapplication.util.GlideCircleTransform;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class ShowHighLevelInviteDialog extends Dialog {
|
|
public ShowHighLevelInviteDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public ShowHighLevelInviteDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
|
public static class Builder {
|
private Context context;
|
String title;
|
String portrait;
|
String nickName;
|
String inviteTime;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Context context) {
|
this.context = context;
|
}
|
|
public Builder setPortrait(String portrait) {
|
this.portrait = portrait;
|
return this;
|
}
|
|
public Builder setTitle(String title) {
|
this.title = title;
|
return this;
|
}
|
|
public Builder setNickName(String nickName) {
|
this.nickName = nickName;
|
return this;
|
}
|
|
public Builder setInviteTime(String inviteTime) {
|
this.inviteTime = inviteTime;
|
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 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 ShowHighLevelInviteDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final ShowHighLevelInviteDialog dialog = new ShowHighLevelInviteDialog(context, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.item_highlevel_invite, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
TextView tv_title = layout.findViewById(R.id.tv_title);
|
TextView tv_highlevel_player_hint = layout.findViewById(R.id.tv_highlevel_player_hint);
|
ImageView iv_portrait = layout.findViewById(R.id.iv_portrait);
|
TextView tv_nickname = layout.findViewById(R.id.tv_nickname);
|
TextView tv_invite_time = layout.findViewById(R.id.tv_invite_time);
|
TextView tv_confirm = layout.findViewById(R.id.tv_confirm);
|
if (!StringUtils.isEmpty(title)) {
|
tv_title.setText(title);
|
}
|
if (!StringUtils.isEmpty(nickName)) {
|
tv_nickname.setText(nickName);
|
} else {
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.WRAP_CONTENT);
|
params.bottomMargin = DimenUtils.dip2px(context, 48);
|
params.topMargin = DimenUtils.dip2px(context, 48);
|
params.gravity = Gravity.CENTER;
|
tv_highlevel_player_hint.setLayoutParams(params);
|
tv_highlevel_player_hint.setGravity(Gravity.CENTER);
|
tv_highlevel_player_hint.setText("感谢你直接下载使用本APP,\n并无邀请人");
|
}
|
tv_nickname.setVisibility(StringUtils.isEmpty(nickName) ? View.GONE : View.VISIBLE);
|
tv_invite_time.setVisibility(StringUtils.isEmpty(nickName) ? View.GONE : View.VISIBLE);
|
iv_portrait.setVisibility(StringUtils.isEmpty(nickName) ? View.GONE : View.VISIBLE);
|
|
if (!StringUtils.isEmpty(inviteTime))
|
tv_invite_time.setText(inviteTime);
|
if (!StringUtils.isEmpty(portrait))
|
Glide.with(context).load(portrait).transform(new GlideCircleTransform(context)).into(iv_portrait);
|
// set the confirm button
|
if (positiveButtonClickListener != null) {
|
tv_confirm.setText(positiveButtonText);
|
tv_confirm.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
}
|
});
|
}
|
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);
|
return dialog;
|
}
|
}
|
}
|