|
|
@@ -1291,6 +1291,123 @@ public class ViewUtil {
|
|
|
}
|
|
|
return dialog;
|
|
|
}
|
|
|
+ public static AlertDialog showUpgradeDialog(Context mContext, final DialogConfig dialogConfig) {
|
|
|
+ String title = dialogConfig.getTitle();
|
|
|
+ String msg = dialogConfig.getMsg();
|
|
|
+ String btnLeftText = dialogConfig.getBtnLeftText();
|
|
|
+ final View.OnClickListener btnLeftOnClickListener = dialogConfig.getBtnLeftOnClickListener();
|
|
|
+ String btnRightText = dialogConfig.getBtnRightText();
|
|
|
+ final View.OnClickListener btnRightOnClickListener = dialogConfig.getBtnRightOnClickListener();
|
|
|
+ final View.OnClickListener btnCloseOnClickListener = dialogConfig.getBtnCloseOnClickListener();
|
|
|
+ View dialog_parent = View.inflate(SheepApp.getInstance(), R.layout.dialog_parent_update, null);
|
|
|
+ final AlertDialog dialog = new AlertDialog.Builder(mContext, mContext instanceof Activity ? R.style.MyDialogActivityTheme : R.style.AppTheme_Dialog_Alert).setView(dialog_parent).create();
|
|
|
+ TextView dialog_title = dialog_parent.findViewById(R.id.dialog_title);
|
|
|
+ View dialog_close = dialog_parent.findViewById(R.id.dialog_close);
|
|
|
+ if (!TextUtils.isEmpty(title))
|
|
|
+ dialog_title.setText(title);
|
|
|
+
|
|
|
+ final TextView dialog_msg = dialog_parent.findViewById(R.id.dialog_msg);
|
|
|
+ if (dialog_msg != null) {
|
|
|
+ if (TextUtils.isEmpty(msg)) {
|
|
|
+ dialog_msg.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ dialog_msg.setVisibility(View.VISIBLE);
|
|
|
+ if (dialogConfig.getMsgIndent() > 0) {
|
|
|
+ msg = addIndent(msg, dialogConfig.getMsgIndent());
|
|
|
+ }
|
|
|
+ if (msg.startsWith("<p>")) {//<p></p>这种格式的用dialog_msg.setText(Html.fromHtml(msg));方式显示,避免高度变化,影响用户体验
|
|
|
+ dialog_msg.setText(Html.fromHtml(msg));
|
|
|
+ if (msg.split("<p>").length > 1) {
|
|
|
+ ViewGroup.LayoutParams msgLayoutParams = dialog_msg.getLayoutParams();
|
|
|
+ if (msgLayoutParams instanceof LinearLayout.LayoutParams) {
|
|
|
+ ((LinearLayout.LayoutParams) msgLayoutParams).bottomMargin *= -2;
|
|
|
+ } else if (BuildConfig.DEBUG) {
|
|
|
+ G.showToast("这里的bottomMargin显得多了,需要干掉");
|
|
|
+ }
|
|
|
+ dialog_msg.setLayoutParams(msgLayoutParams);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ setColorMapText(dialog_msg, msg, dialogConfig.getColorMsgMap());
|
|
|
+ }
|
|
|
+ int msgGravity = dialogConfig.getMsgGravity();
|
|
|
+ if (msgGravity != Gravity.NO_GRAVITY)
|
|
|
+ dialog_msg.setGravity(msgGravity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ TextView dialog_btn_left = dialog_parent.findViewById(R.id.dialog_btn_left);
|
|
|
+ boolean isLeftBtnShow = btnLeftText != null || btnLeftOnClickListener != null;
|
|
|
+ if (dialog_btn_left != null) {
|
|
|
+ dialog_btn_left.setBackgroundResource(R.drawable.selector_button_full_upgrade);
|
|
|
+ dialog_btn_left.setTextColor(Color.WHITE);
|
|
|
+ dialog_btn_left.setVisibility(isLeftBtnShow ? View.VISIBLE : View.GONE);
|
|
|
+ if (!TextUtils.isEmpty(btnLeftText))
|
|
|
+ dialog_btn_left.setText(btnLeftText);
|
|
|
+ dialog_btn_left.setOnClickListener(v -> {
|
|
|
+ if (btnLeftOnClickListener != null) {
|
|
|
+ btnLeftOnClickListener.onClick(v);
|
|
|
+ }
|
|
|
+ if (!dialogConfig.isBtnLeftNotDissDialog())
|
|
|
+ dialog.dismiss();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ TextView dialog_btn_right = dialog_parent.findViewById(R.id.dialog_btn_right);
|
|
|
+ boolean isRightBtnShow = btnRightText != null || btnRightOnClickListener != null;
|
|
|
+ if (dialog_btn_right != null) {
|
|
|
+ dialog_btn_right.setBackgroundResource(R.drawable.selector_button_full_upgrade);
|
|
|
+ dialog_btn_right.setTextColor(Color.WHITE);
|
|
|
+ dialog_btn_right.setVisibility(isRightBtnShow ? View.VISIBLE : View.GONE);
|
|
|
+ if (!TextUtils.isEmpty(btnRightText))
|
|
|
+ dialog_btn_right.setText(btnRightText);
|
|
|
+ dialog_btn_right.setOnClickListener(v -> {
|
|
|
+ if (btnRightOnClickListener != null) {
|
|
|
+ btnRightOnClickListener.onClick(v);
|
|
|
+ }
|
|
|
+ dialog.dismiss();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ View dialog_btn_center = dialog_parent.findViewById(R.id.dialog_btn_center);
|
|
|
+ if (dialog_btn_center != null) {
|
|
|
+ dialog_btn_center.setVisibility(isLeftBtnShow && isRightBtnShow ? View.VISIBLE : View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dialog_close != null) {
|
|
|
+ if (dialogConfig.isCancelable())//
|
|
|
+ dialog_close.setOnClickListener(v -> {
|
|
|
+ if (btnCloseOnClickListener != null) {
|
|
|
+ btnCloseOnClickListener.onClick(v);
|
|
|
+ }
|
|
|
+ dialog.dismiss();
|
|
|
+ });
|
|
|
+ else
|
|
|
+ dialog_close.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ dialog.setOnDismissListener(dialog1 -> {
|
|
|
+ try {
|
|
|
+ if (dialogConfig.isFinish()) {
|
|
|
+ if (mContext instanceof Activity) {
|
|
|
+ ((Activity) mContext).finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!(mContext instanceof Activity) && dialog.getWindow() != null) {
|
|
|
+ dialog.getWindow().setType(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_TOAST);
|
|
|
+ }
|
|
|
+ if (!dialogConfig.isCancelable())
|
|
|
+ dialog.setCancelable(false);
|
|
|
+ try {
|
|
|
+ dialog.show();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return dialog;
|
|
|
+ }
|
|
|
|
|
|
//显示gif对话框
|
|
|
public static void showUpGifDialog(Activity activity) {
|