zengjiebin лет назад: 7
Родитель
Сommit
b028e37bf6

+ 1 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/DialogConfig.java

@@ -183,6 +183,7 @@ public class DialogConfig {
     }
     public static final int THEME_DEFAULT = 0;
     public static final int THEME_PURPLE = 1;
+    public static final int THEME_UPGRADE = 2;
     private int theme = THEME_DEFAULT;
     @IntDef({THEME_DEFAULT, THEME_PURPLE})
     @Retention(RetentionPolicy.SOURCE)

+ 14 - 20
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -451,12 +451,12 @@ public class SysAppUtil {
                 e.printStackTrace();
             }
         }
-        checkUpdateNewVersion(activity, ignoreMd5, action1);
-//        if(TestUtil.isSheep()) {
-//            checkUpdateNewVersion(activity, ignoreMd5, action1);
-//        } else if(!TestUtil.isDev()) {
-//            TestUtil.checkUpdateFromJenkins(activity, ignoreMd5, action1);
-//        }
+//        checkUpdateNewVersion(activity, ignoreMd5, action1);
+        if(TestUtil.isSheep()) {
+            checkUpdateNewVersion(activity, ignoreMd5, action1);
+        } else if(!TestUtil.isDev()) {
+            TestUtil.checkUpdateFromJenkins(activity, ignoreMd5, action1);
+        }
     }
     //通过接口检查更新
     public static void checkUpdateNewVersion(final Activity activity, final String ignoreMd5, final Action1<Integer> action1) {
@@ -597,22 +597,16 @@ public class SysAppUtil {
             if(version.isForceUpdate() && TestUtil.isSheep()){//强更
                 dialogConfig.setCancelable(false);
             } else {
-                dialogConfig.setBtnRightText("下次更新").setBtnRightOnClickListener(new View.OnClickListener() {
-                    @Override
-                    public void onClick(View view) {
-                        SpUtils.saveIgnoreMd5(TestUtil.isSheep() ? version.getVersion_number()+"" : version.getMd5_address());
-                        if(view instanceof TextView)
-                            UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
-                    }
+                dialogConfig.setBtnRightText("下次更新").setBtnRightOnClickListener(view -> {
+                    SpUtils.saveIgnoreMd5(TestUtil.isSheep() ? version.getVersion_number()+"" : version.getMd5_address());
+                    if(view instanceof TextView)
+                        UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
                 });
             }
-            dialog = ViewUtil.showMsgDialog(activity, dialogConfig);
-            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
-                @Override
-                public void onDismiss(DialogInterface dialogInterface) {
-                    if (action1 != null)
-                        action1.call(0);
-                }
+            dialog = ViewUtil.showUpgradeDialog(activity, dialogConfig);
+            dialog.setOnDismissListener(dialogInterface -> {
+                if (action1 != null)
+                    action1.call(0);
             });
         }
     }

+ 117 - 0
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -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) {

+ 7 - 0
app/src/main/res/drawable/button_full_upgrade_click.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <corners android:radius="30dp" />
+
+    <solid android:color="#33FF834C" />
+</shape>

+ 7 - 0
app/src/main/res/drawable/button_full_upgrade_normal.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <corners android:radius="30dp" />
+
+    <solid android:color="#FF834C" />
+</shape>

+ 9 - 0
app/src/main/res/drawable/selector_button_full_upgrade.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android" >
+  <item android:state_enabled="false" android:drawable="@drawable/button_full_normal_gray" />
+  <item android:state_focused="true" android:drawable="@drawable/button_full_upgrade_click" />
+  <item android:state_checked="true" android:drawable="@drawable/button_full_upgrade_click"/>
+  <item android:state_selected="true" android:drawable="@drawable/button_full_upgrade_click"/>
+  <item android:state_pressed="true" android:drawable="@drawable/button_full_upgrade_click"/>
+  <item android:drawable="@drawable/button_full_upgrade_normal"/>
+</selector>

+ 53 - 0
app/src/main/res/layout/dialog_parent_update.xml

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:layout_margin="@dimen/dp_10">
+
+        <ImageView
+            android:id="@+id/dialog_bg_iv"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:adjustViewBounds="true"
+            android:fitsSystemWindows="true"
+            android:src="@mipmap/bg_upgrade_app" />
+
+        <TextView
+            android:id="@+id/dialog_title"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_alignTop="@id/dialog_bg_iv"
+            android:layout_marginStart="40dp"
+            android:layout_marginTop="50dp"
+            android:gravity="center"
+            android:text="发现新版本"
+            android:textColor="@android:color/white"
+            android:textSize="26sp" />
+
+        <TextView
+            android:id="@+id/dialog_msg"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"
+            android:gravity="center_vertical"
+            android:lineSpacingExtra="4dp"
+            android:paddingStart="40dp"
+            android:paddingTop="20dp"
+            android:paddingEnd="40dp"
+            android:text="内容"
+            android:textColor="@color/black_text_deep"
+            android:textSize="14sp" />
+
+        <include
+            layout="@layout/x_msg_dialog_btn"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_alignBottom="@id/dialog_bg_iv"
+            android:layout_margin="16dp" />
+    </RelativeLayout>
+</FrameLayout>

BIN
app/src/main/res/mipmap-xxhdpi/bg_upgrade_app.png