diff --git a/app/src/main/java/com/mirkowu/mvm/MainActivity.kt b/app/src/main/java/com/mirkowu/mvm/MainActivity.kt index 1e14be2..997e4a2 100644 --- a/app/src/main/java/com/mirkowu/mvm/MainActivity.kt +++ b/app/src/main/java/com/mirkowu/mvm/MainActivity.kt @@ -59,20 +59,16 @@ class MainActivity : BaseActivity() { Manifest.permission.READ_PHONE_STATE ) - BuglyManager.setOnUpgradeListener { upgradeInfo, isManual -> - Log.e(DataBindingFragment.TAG, "setUpgradeListener: upgradeInfo=$upgradeInfo") - + BuglyManager.checkUpgrade { hasNewVersion, upgradeInfo -> + Log.e("BuglyManager", "setUpgradeListener: upgradeInfo=$upgradeInfo") if (upgradeInfo != null) { UpgradeDialog.show(supportFragmentManager, upgradeInfo) - } else if (isManual) { - ToastUtils.showShort("当前已是最新版本!") } } - BuglyManager.checkUpgrade(false, false) - var time=System.currentTimeMillis(); + var time = System.currentTimeMillis(); NetworkUtils.isAvailableByPingAsync("baidu.com") { - time=System.currentTimeMillis()-time + time = System.currentTimeMillis() - time if (it) { binding.tvNetworkStatus.setText("检测耗时${time}ms, 网络OK") binding.tvNetworkStatus.setTextColor(Color.GREEN) diff --git a/app/src/main/java/com/mirkowu/mvm/viewbinding/DataBindingFragment.kt b/app/src/main/java/com/mirkowu/mvm/viewbinding/DataBindingFragment.kt index d2c90a4..322fa47 100644 --- a/app/src/main/java/com/mirkowu/mvm/viewbinding/DataBindingFragment.kt +++ b/app/src/main/java/com/mirkowu/mvm/viewbinding/DataBindingFragment.kt @@ -13,8 +13,6 @@ import com.mirkowu.lib_base.util.bindingView import com.mirkowu.lib_bugly.BuglyManager import com.mirkowu.lib_qr.QRScanner import com.mirkowu.lib_qr.ScanConfig -import com.mirkowu.lib_upgrade.IUpgradeInfo -import com.mirkowu.lib_upgrade.UpgradeDialog import com.mirkowu.lib_util.LogUtil import com.mirkowu.lib_util.PermissionsUtil import com.mirkowu.lib_util.ktxutil.click @@ -132,42 +130,63 @@ class DataBindingFragment : BaseFragment() { startActivity(Intent(context, DownloadActivity::class.java)) } binding.btnBuglyUpgrade.click { - BuglyManager.checkUpgrade(true, true) + showLoadingDialog("检查新版本") + BuglyManager.checkUpgrade { hasNewVersion, upgradeInfo -> + Log.e("BuglyManager", "setUpgradeListener: upgradeInfo=$upgradeInfo ") + hideLoadingDialog() + if (upgradeInfo != null) { + com.mirkowu.lib_bugly.UpgradeDialog.show(childFragmentManager, upgradeInfo) + } else { + ToastUtils.showShort("当前已是最新版本!") + } + } } binding.btnUpgrade.click { // BuglyManager.checkUpgrade(true, false) val url = "https://outexp-beta.cdn.qq.com/outbeta/2021/06/18/commirkowumvm_1.0.1_56987f9a-fb39-56d5-9ac4-a4c055633672.apk" - UpgradeDialog.show(childFragmentManager, object : IUpgradeInfo { - override fun getTitle(): String { - return "title" - } - - override fun getContent(): String { - return "getContent" - } - - override fun getApkUrl(): String { - return url; - } +// UpgradeDialog.show(childFragmentManager, object : IUpgradeInfo { +// override fun getTitle(): String { +// return "title" +// } +// +// override fun getContent(): String { +// return "getContent" +// } +// +// override fun getApkUrl(): String { +// return url; +// } +// +// override fun getVersionName(): String { +// return "1.0.1" +// } +// +// override fun getSavePath(): String { +// return "" +// } +// +// override fun getVersionCode(): Int { +// return 1001 +// } +// +// override fun isForceUpgrade(): Int { +// return 0 +// } +// }) - override fun getVersionName(): String { - return "1.0.1" - } + BuglyManager.checkUpgrade { hasNewVersion, upgradeInfo -> + Log.e("BuglyManager", "setUpgradeListener: upgradeInfo=$upgradeInfo ") - override fun getSavePath(): String { - return "" - } - override fun getVersionCode(): Int { - return 1001 + if (upgradeInfo != null) { + com.mirkowu.lib_bugly.UpgradeDialog.show(childFragmentManager, upgradeInfo) + } else { + ToastUtils.showShort("当前已是最新版本!") } + } - override fun isForceUpgrade(): Int { - return 0 - } - }) } binding.btnQr.click { QRScanner.getInstance().setScanConfig( diff --git a/lib_bugly/src/main/java/com/mirkowu/lib_bugly/BuglyManager.java b/lib_bugly/src/main/java/com/mirkowu/lib_bugly/BuglyManager.java index c4e6593..b830423 100644 --- a/lib_bugly/src/main/java/com/mirkowu/lib_bugly/BuglyManager.java +++ b/lib_bugly/src/main/java/com/mirkowu/lib_bugly/BuglyManager.java @@ -40,16 +40,21 @@ public void onUpgrade(int i, UpgradeInfo upgradeInfo, boolean isManual, boolean LogUtil.e(TAG, "onUpgrade: 是否有新版本 =" + (upgradeInfo != null)); if (sOnUpgradeListener != null) { - sOnUpgradeListener.onUpgrade(upgradeInfo, isManual); + sOnUpgradeListener.onUpgrade(upgradeInfo != null, upgradeInfo); } } }); Beta.upgradeStateListener = new UpgradeStateListener() { @Override public void onUpgradeFailed(boolean b) { + LogUtil.e(TAG, "onUpgradeFailed !"); + if (sOnUpgradeListener != null) { + sOnUpgradeListener.onError(); + } if (sUpgradeStateListener != null) { sUpgradeStateListener.onUpgradeFailed(b); } + } @Override @@ -61,9 +66,13 @@ public void onUpgradeSuccess(boolean b) { @Override public void onUpgradeNoVersion(boolean b) { + if (sOnUpgradeListener != null) { + sOnUpgradeListener.onUpgrade(false, null); + } if (sUpgradeStateListener != null) { sUpgradeStateListener.onUpgradeNoVersion(b); } + } @Override @@ -80,8 +89,8 @@ public void onDownloadCompleted(boolean b) { } } }; - Beta.autoCheckUpgrade = true; //是否自动检查更新 - Beta.initDelay = 5000L; //设置启动延时为5s(默认延时3s),APP启动5s后初始化SDK,避免影响APP启动速度; + Beta.autoCheckUpgrade = false; //是否自动检查更新 +// Beta.initDelay = 5000L; //设置启动延时为5s(默认延时3s),APP启动5s后初始化SDK,避免影响APP启动速度; // 设置是否为上报进程 CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context); @@ -94,13 +103,6 @@ public void onDownloadCompleted(boolean b) { Bugly.init(context, appId, isDebug, strategy); } - public interface OnUpgradeListener { - void onUpgrade(/*boolean hasNewVer,*/ UpgradeInfo upgradeInfo, boolean isManual); - } - - public static void setOnUpgradeListener(OnUpgradeListener onUpgradeListener) { - sOnUpgradeListener = onUpgradeListener; - } public static void registerDownloadListener(DownloadListener downloadListener) { Beta.registerDownloadListener(downloadListener); @@ -122,17 +124,29 @@ public static void cancelDownload() { /** * 检测更新 * - * @param isManual 用户手动点击检查,非用户点击操作请传false - * @param isSilence 是否显示弹窗等交互,[true:没有弹窗和toast] [false:有弹窗或toast] + * @param isManual 用户手动点击检查,非用户点击操作请传false + * @param isSilence 是否静默更新,不显示弹窗等交互,[true:没有弹窗和toast] [false:有弹窗或toast] + * @param onUpgradeListener 回调结果 */ - public static void checkUpgrade(boolean isManual, boolean isSilence) { - Beta.checkUpgrade(isManual, isSilence); + public static void checkUpgrade(OnUpgradeListener onUpgradeListener) { + Beta.checkUpgrade(true, true); + sOnUpgradeListener = onUpgradeListener; } - public static void checkUpgrade(boolean isManual) { - checkUpgrade(isManual, true); + public interface OnUpgradeListener { + /** + * @param hasNewVersion 是否有新版本 + * @param upgradeInfo + */ + void onUpgrade(boolean hasNewVersion, UpgradeInfo upgradeInfo/*, boolean isManual*/); + + // void onNoVersion(); + + default void onError() { + } } + /* * true表示app启动自动初始化升级模块; * false不会自动初始化; diff --git a/lib_bugly/src/main/java/com/mirkowu/lib_bugly/UpgradeDialog.java b/lib_bugly/src/main/java/com/mirkowu/lib_bugly/UpgradeDialog.java index bced53f..e25a6aa 100644 --- a/lib_bugly/src/main/java/com/mirkowu/lib_bugly/UpgradeDialog.java +++ b/lib_bugly/src/main/java/com/mirkowu/lib_bugly/UpgradeDialog.java @@ -40,6 +40,7 @@ public class UpgradeDialog extends BaseDialog implements DownloadListener, Upgra private boolean isForceUpgrade; public static void show(FragmentManager manager, UpgradeInfo upgradeInfo) { + if (upgradeInfo == null) return; UpgradeDialog dialog = new UpgradeDialog(); dialog.upgradeInfo = upgradeInfo; dialog.showAllowingStateLoss(manager); @@ -52,7 +53,7 @@ public UpgradeDialog() { } @Override - public int getLayoutResId() { + public int getLayoutResId() { return R.layout.up_dialog_upgrade; } diff --git a/lib_bugly/src/main/res/values-zh/values.xml b/lib_bugly/src/main/res/values-zh/values.xml index ec2cb7e..505dadd 100644 --- a/lib_bugly/src/main/res/values-zh/values.xml +++ b/lib_bugly/src/main/res/values-zh/values.xml @@ -17,7 +17,7 @@ 有新版本 检查新版本失败,请稍后重试 正在检查,请稍候... - 你已经是最新版了 + 当前已是最新版! 下次再说 继续 更新说明