override fun onBackPressed() {
//不让退出了哇
- val checkNetWork = OtaViewModelCreator.getOtaViewModel(null)?.checkNetWork()
- /**val checkNetWork = OtaViewModelCreator.getOtaViewModel(null)?.checkNetWork()
-- val currentActionState = OtaViewModelCreator.getOtaViewModel(null)?.currentActionState
-- val tipsWifiConnect = OtaViewModelCreator.getOtaViewModel(null)?.isTipsWifiConnect
- if (checkNetWork != true ||
- currentActionState?.value == UpdateActionState.LAST_VERSION ||
- currentActionState?.value == UpdateActionState.BATTERY_LEVEL_NOT_ENOUGH
- || tipsWifiConnect?.value == true
- ) {
- if (checkNetWork != true || currentActionState?.value == UpdateActionState.LAST_VERSION || tipsWifiConnect?.value == true) {
-- super.onBackPressed()
- }*/
+ createNewVersionDialog()
+ }
+
+ private fun createNewVersionDialog() {
+ val manager = App.sContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
+ val layoutParams = WindowManager.LayoutParams()
+ layoutParams.gravity = Gravity.CENTER
+ layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
+ val screenWidth = windowManager.defaultDisplay.width
+ layoutParams.width = screenWidth - 40;
+ layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT
+ layoutParams.alpha = 1.0f
+ layoutParams.packageName = App.sContext.getPackageName()
+ layoutParams.buttonBrightness = 1f
+ layoutParams.windowAnimations = android.R.style.Animation_Dialog
+
+ val view: View = View.inflate(App.sContext, R.layout.dialog_tips, null)
+
+ val descText: TextView = view.findViewById(R.id.description)
+ val titleText: TextView = view.findViewById(R.id.notify)
+ titleText.text = view.context.getString(R.string.update_tips_title_text)
+ descText.text = view.context.getString(R.string.update_tips_exit_desc)
+ val yesButton: Button = view.findViewById(R.id.button_ok) as Button
+ val noButton: Button = view.findViewById(R.id.button_cancel) as Button
+ yesButton.setOnClickListener {
+ manager.removeView(view)
+ finish()
}
+ noButton.setOnClickListener { manager.removeView(view) }
+ manager.addView(view, layoutParams)
}
+
override fun onResume() {
super.onResume()
//检查一下网络更新