Просмотр исходного кода

修改升级对话框按钮样式

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

+ 74 - 69
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -453,13 +453,13 @@ public class SysAppUtil {
         }
 //        checkUpdateNewVersion(activity, ignoreMd5, action1);
         if(TestUtil.isSheep()) {
-            checkUpdateNewVersion(activity, ignoreMd5, action1);
+            checkUpdateNewVersion(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) {
+    public static void checkUpdateNewVersion(final String ignoreMd5, final Action1<Integer> action1) {
         SheepApp.getInstance().getNetComponent().getApiService().getNewVersion(SheepApp.getInstance().getConnectAddress().getVersionType())
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
@@ -467,7 +467,7 @@ public class SysAppUtil {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
                         Version version = baseMessage.getData(Version.class);
-                        loadVersion(activity, ignoreMd5, action1, version);
+                        loadVersion(ignoreMd5, action1, version);
                     }
 
                     @Override
@@ -481,7 +481,7 @@ public class SysAppUtil {
                 });
     }
 
-    private static void loadVersion(final Activity activity, final String ignoreMd5, final Action1<Integer> action1, final Version version) {
+    private static void loadVersion(final String ignoreMd5, final Action1<Integer> action1, final Version version) {
         if(version == null){
             if(ignoreMd5 == null)
                 G.showToast("当前版本为最新版本,无需更新");
@@ -530,85 +530,90 @@ public class SysAppUtil {
             if(action1 != null)
                 action1.call(0);
         } else {//有新版本
+            showUpgradeByVersion(version, action1);
+        }
+    }
+
+    public static void showUpgradeByVersion(Version version, Action1<Integer> action1) {
+        if(!TextUtils.isEmpty(version.getAddress()))
             ACache.get(SheepApp.getInstance()).put("version_url", version.getAddress());
-            final String fileName = version.getMd5_address()+".apk";
-            final File file = new File(ClassFileHelper.DIR, fileName);
-            DialogConfig dialogConfig = new DialogConfig();
-            dialogConfig.setTitle("小绵羊V"+version.getVersion_name());
-            dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V"+getConnectAdrressPackageInfo().versionName : version.getUpdate_content()).setMsgGravity(Gravity.START)
-                    .setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
-                private void installApk(File file){
-                    if(file != null && file.exists()) {
-                        //升级后继承渠道
-                        String channel = ChannelContent.getInstance().getChannel_name();
-                        try {
-                            if(!TextUtils.isEmpty(channel) && !ZipChannelUtil.isAddQUA(file)){
-                                ZipChannelUtil.writeQUA(file, channel);
-                            }
-                        } catch (IOException e) {
-                            e.printStackTrace();
+        final String fileName = version.getMd5_address()+".apk";
+        final File file = new File(ClassFileHelper.DIR, fileName);
+        DialogConfig dialogConfig = new DialogConfig();
+        dialogConfig.setTitle("小绵羊V"+version.getVersion_name());
+        dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V"+getConnectAdrressPackageInfo().versionName : version.getUpdate_content()).setMsgGravity(Gravity.START)
+                .setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
+            private void installApk(File file){
+                if(file != null && file.exists()) {
+                    //升级后继承渠道
+                    String channel = ChannelContent.getInstance().getChannel_name();
+                    try {
+                        if(!TextUtils.isEmpty(channel) && !ZipChannelUtil.isAddQUA(file)){
+                            ZipChannelUtil.writeQUA(file, channel);
                         }
-                        ApkUtils.installApk(SheepApp.getInstance(), file.getAbsolutePath());
+                    } catch (IOException e) {
+                        e.printStackTrace();
                     }
+                    ApkUtils.installApk(SheepApp.getInstance(), file.getAbsolutePath());
                 }
-                @Override
-                public void onClick(final View view) {
-                    if(view instanceof TextView)
-                        UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
-                    if(file.exists() && Md5Util.checkMD5(version.getMd5_address(), file)){//文件存在并且md5值相同则直接安装
-                        installApk(file);
-                    } else if(TextUtils.isEmpty(version.getAddress())){//地址错误
-                        G.showToast(R.string.error_download_link);
-                    } else {//下载安装
-                        OkHttpUtils.get().url(version.getAddress()).build().execute(new FileCallBack(ClassFileHelper.DIR, fileName) {
-                            @Override
-                            public void inProgress(float progress, long total, int id) {
-                                if(view instanceof TextView) {
-                                    TextView btnLeftTextView = (TextView) view;
-                                    btnLeftTextView.setEnabled(false);
-                                    btnLeftTextView.setText(String.format(Locale.CHINA, "%d%%", Math.round(progress * 100)));
-                                }
+            }
+            @Override
+            public void onClick(final View view) {
+                if(view instanceof TextView)
+                    UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
+                if(file.exists() && Md5Util.checkMD5(version.getMd5_address(), file)){//文件存在并且md5值相同则直接安装
+                    installApk(file);
+                } else if(TextUtils.isEmpty(version.getAddress())){//地址错误
+                    G.showToast(R.string.error_download_link);
+                } else {//下载安装
+                    OkHttpUtils.get().url(version.getAddress()).build().execute(new FileCallBack(ClassFileHelper.DIR, fileName) {
+                        @Override
+                        public void inProgress(float progress, long total, int id) {
+                            if(view instanceof TextView) {
+                                TextView btnLeftTextView = (TextView) view;
+                                btnLeftTextView.setEnabled(false);
+                                btnLeftTextView.setText(String.format(Locale.CHINA, "%d%%", Math.round(progress * 100)));
+                            }
+                        }
+                        @Override
+                        public void onError(Call call, Exception e, int id) {
+                            if(view instanceof TextView) {
+                                TextView btnLeftTextView = (TextView) view;
+                                btnLeftTextView.setEnabled(true);
+                                btnLeftTextView.setText("重新下载");
                             }
-                            @Override
-                            public void onError(Call call, Exception e, int id) {
-                                if(view instanceof TextView) {
+                        }
+
+                        @Override
+                        public void onResponse(File response, int id) {
+                            if(response != null && response.exists()) {
+                                if(view instanceof TextView){
                                     TextView btnLeftTextView = (TextView) view;
                                     btnLeftTextView.setEnabled(true);
-                                    btnLeftTextView.setText("重新下载");
+                                    btnLeftTextView.setText("立即安装");
                                 }
-                            }
-
-                            @Override
-                            public void onResponse(File response, int id) {
-                                if(response != null && response.exists()) {
-                                    if(view instanceof TextView){
-                                        TextView btnLeftTextView = (TextView) view;
-                                        btnLeftTextView.setEnabled(true);
-                                        btnLeftTextView.setText("立即安装");
-                                    }
 
-                                    installApk(response);
-                                }
+                                installApk(response);
                             }
-                        });
-                    }
+                        }
+                    });
                 }
-            });
-            if(version.isForceUpdate() && TestUtil.isSheep()){//强更
-                dialogConfig.setCancelable(false);
-            } else {
-                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.showUpgradeDialog(activity, dialogConfig);
-            dialog.setOnDismissListener(dialogInterface -> {
-                if (action1 != null)
-                    action1.call(0);
+        });
+        if(version.isForceUpdate() && TestUtil.isSheep()){//强更
+            dialogConfig.setCancelable(false);
+        } else {
+            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.showUpgradeDialog(SheepApp.getInstance().getCurrentActivity(), dialogConfig);
+        dialog.setOnDismissListener(dialogInterface -> {
+            if (action1 != null)
+                action1.call(0);
+        });
     }
 
     private static PackageInfo getConnectAdrressPackageInfo() {

+ 11 - 8
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -40,6 +40,7 @@ import com.sheep.gamegroup.model.entity.DiscoveryVideo;
 import com.sheep.gamegroup.model.entity.LoginEntity;
 import com.sheep.gamegroup.model.entity.LoginUser;
 import com.sheep.gamegroup.model.entity.UserEntity;
+import com.sheep.gamegroup.model.entity.Version;
 import com.sheep.gamegroup.model.entity.Video;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.module.plugin.model.Plugin;
@@ -260,7 +261,7 @@ public class TestUtil {
      */
     public static void test(final Activity activity) {
         final String[] items = {"复制token", "添加token", "复制打点数据", "从jenkins下载小绵羊安装包", "测试表情包",
-                "少数民族姓名", "开启皮肤", "不开启皮肤", "我的游戏", "优惠券弹窗", "填写收件地址弹窗",
+                "测试升级对话框","少数民族姓名", "开启皮肤", "不开启皮肤", "我的游戏", "优惠券弹窗", "填写收件地址弹窗",
                 "朗读文字", "游戏搜索", "测试插件","测试bitmap", "剪切视频", "我的关注", "足迹",
                 "测试联通卡", "测试联通卡2", "测试签名1", "测试签名2", "测试孔剑秋faq正式服",
                 "跳转QQ1", "跳转QQ2", "跳转QQ3", "跳转白白QQ", "龙猫竞猜", "龙猫竞猜-scheme",
@@ -280,6 +281,13 @@ public class TestUtil {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
                         switch (items[which]) {
+                            case "测试升级对话框":
+                                Version version = new Version();
+                                version.setMd5_address("123456");
+                                version.setVersion_name(BuildConfig.VERSION_NAME);
+                                version.setUpdate_content("更新内容(测试):\n1.修复bug;\n2.优化界面;\n3.添加宠物模块");
+                                SysAppUtil.showUpgradeByVersion(version, null);
+                                break;
                             case "少数民族姓名":
                                 G.showToast(Boolean.toString(StringUtils.isChineseName("麦麦提·阿尤甫")));
                                 break;
@@ -884,7 +892,7 @@ public class TestUtil {
         OkHttpUtils.get().url("http://10.8.210.20:8080/jenkins/job/android_small_sheep").build().execute(new StringCallback() {
             @Override
             public void onError(Call call, Exception e, int id) {
-                SysAppUtil.checkUpdateNewVersion(activity, ignoreMd5, action1);
+                SysAppUtil.checkUpdateNewVersion(ignoreMd5, action1);
             }
 
             @Override
@@ -894,12 +902,7 @@ public class TestUtil {
                 try {
                     String result = response.substring(start, end);
                     ArrayList<String> arrayList = StringUtils.getAllSatisfyStr(result, "<a.+?href=\\\"(.+?)\\\">");
-                    ListUtil.removeItem(arrayList, new ListUtil.CallBack<String, Boolean>() {
-                        @Override
-                        public Boolean call(String msg) {
-                            return !msg.endsWith(".apk\">");
-                        }
-                    });
+                    ListUtil.removeItem(arrayList, msg -> !msg.endsWith(".apk\">"));
                     int index = 0;
                     switch (BuildConfig.FLAVOR) {
                         case "developSheeptest":

+ 12 - 18
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -1252,30 +1252,24 @@ public class ViewUtil {
 
         if (dialog_close != null) {
             if (dialogConfig.isCancelable())//
-                dialog_close.setOnClickListener(new View.OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        if (btnCloseOnClickListener != null) {
-                            btnCloseOnClickListener.onClick(v);
-                        }
-                        dialog.dismiss();
+                dialog_close.setOnClickListener(v -> {
+                    if (btnCloseOnClickListener != null) {
+                        btnCloseOnClickListener.onClick(v);
                     }
+                    dialog.dismiss();
                 });
             else
                 dialog_close.setVisibility(View.GONE);
         }
-        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
-            @Override
-            public void onDismiss(DialogInterface dialog) {
-                try {
-                    if (dialogConfig.isFinish()) {
-                        if (mContext instanceof Activity) {
-                            ((Activity) mContext).finish();
-                        }
+        dialog.setOnDismissListener(dialog1 -> {
+            try {
+                if (dialogConfig.isFinish()) {
+                    if (mContext instanceof Activity) {
+                        ((Activity) mContext).finish();
                     }
-                } catch (Exception e) {
-                    e.printStackTrace();
                 }
+            } catch (Exception e) {
+                e.printStackTrace();
             }
         });
 
@@ -1355,7 +1349,7 @@ public class ViewUtil {
         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.setBackgroundResource(R.drawable.selector_button_full_main);
             dialog_btn_right.setTextColor(Color.WHITE);
             dialog_btn_right.setVisibility(isRightBtnShow ? View.VISIBLE : View.GONE);
             if (!TextUtils.isEmpty(btnRightText))