package com.tejia.lijin.app.ui.dialog;
|
|
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.TextView;
|
|
import com.wpc.library.util.SystemCommon;
|
import com.wpc.library.util.common.StringUtils;
|
import com.tejia.lijin.app.R;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class ShareStatisticsDialog extends Dialog {
|
|
public ShareStatisticsDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public ShareStatisticsDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
|
public static class Builder {
|
private Context context;
|
String todayScan;
|
String totalScan;
|
String estimateOrder;
|
String estimateReward;
|
private String positiveButtonText;
|
private OnClickListener positiveButtonClickListener;
|
|
public Builder(Context context) {
|
this.context = context;
|
}
|
|
public Builder setTodayScan(String todayScan) {
|
this.todayScan = todayScan;
|
return this;
|
}
|
|
public Builder setTotalScan(String totalScan) {
|
this.totalScan = totalScan;
|
return this;
|
}
|
|
public Builder setEstimateOrder(String estimateOrder) {
|
this.estimateOrder = estimateOrder;
|
return this;
|
}
|
|
public Builder setEstimateReward(String estimateReward) {
|
this.estimateReward = estimateReward;
|
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 ShareStatisticsDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final ShareStatisticsDialog dialog = new ShareStatisticsDialog(context, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.item_share_statistics, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
TextView tv_today_scan = layout.findViewById(R.id.tv_today_scan);
|
TextView tv_total_scan = layout.findViewById(R.id.tv_total_scan);
|
TextView tv_estimate_order_num = layout.findViewById(R.id.tv_estimate_order_num);
|
TextView tv_estimate_reward = layout.findViewById(R.id.tv_estimate_reward);
|
TextView tv_confirm = layout.findViewById(R.id.tv_confirm);
|
if (!StringUtils.isEmpty(todayScan))
|
tv_today_scan.setText(todayScan + "次");
|
if (!StringUtils.isEmpty(totalScan))
|
tv_total_scan.setText(totalScan + "次");
|
if (!StringUtils.isEmpty(estimateOrder))
|
tv_estimate_order_num.setText(estimateOrder + "笔");
|
if (!StringUtils.isEmpty(estimateReward))
|
tv_estimate_reward.setText(estimateReward);
|
// 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;
|
}
|
}
|
}
|