修改升级dialog得大小和下载界面的返回逻辑
authork.liang <liangkang648253071@126.com>
Sat, 3 Jul 2021 12:43:15 +0000 (20:43 +0800)
committerk.liang <liangkang648253071@126.com>
Sat, 3 Jul 2021 12:43:15 +0000 (20:43 +0800)
app/src/main/java/com/ic/icfotaclient/presenter/OtaViewModel.kt
app/src/main/java/com/ic/icfotaclient/view/SystemUpdateActivity.kt
app/src/main/res/values-en/strings.xml
app/src/main/res/values-zh-rCN/strings.xml
app/src/main/res/values/strings.xml

index fcf28ac..c14e07b 100644 (file)
@@ -227,6 +227,7 @@ class OtaViewModel : ViewModel() {
                 //如果不为null,弹出一个系统级的dialog,也就是在任何地方都可以弹出的
                 currentActionState.postValue(
                     if (result == null) {
+                        createNewVersionDialog( "无描述")
                         //已经是最新版本了
                         UpdateActionState.LAST_VERSION
                     } else {
@@ -380,15 +381,15 @@ class OtaViewModel : ViewModel() {
         val layoutParams = WindowManager.LayoutParams()
         layoutParams.gravity = Gravity.CENTER
         layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
-        layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT
+        val screenWidth = manager.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 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)
index 265e091..cf26a72 100644 (file)
@@ -1,12 +1,18 @@
 package com.ic.icfotaclient.view
 
+import android.content.Context
 import android.content.Intent
 import android.os.Bundle
 import android.text.TextUtils
 import android.util.Log
+import android.view.Gravity
 import android.view.View
+import android.view.WindowManager
+import android.widget.Button
+import android.widget.TextView
 import androidx.appcompat.app.AppCompatActivity
 import androidx.lifecycle.Observer
+import com.ic.icfotaclient.App
 import com.ic.icfotaclient.R
 import com.ic.icfotaclient.presenter.OtaService
 import com.ic.icfotaclient.presenter.OtaViewModel
@@ -18,17 +24,45 @@ class SystemUpdateActivity : AppCompatActivity() {
 
     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
-            || 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()
         //检查一下网络更新
index f30329a..7f7d11d 100644 (file)
@@ -26,7 +26,7 @@
     <string name="tips_wifi_connect">Please connect WI-FI</string>
     <string name="unsupport_pause_download">Server not support download</string>
     <string name="new_version_tips_title">Has new version!</string>
-    <string name="local_new_version_tips_title">Tip!</string>
+    <string name="local_new_version_tips_title">Notice!</string>
     <string name="local_update_desc_text">Has update in local.</string>
     <string name="update_package_not_in_tips_text">No file</string>
     <string name="update_result_success_tips">Update success:</string>
@@ -35,5 +35,6 @@
     <string name="update_failed_tips_text">Update fail!</string>
     <string name="update_date_format_text">yyyy-MM-dd HH:mm:ss</string>
     <string name="no_update_desc">No update describe...</string>
-    <string name="update_tips_title_text">Tip</string>
+    <string name="update_tips_title_text">Notice</string>
+    <string name="update_tips_exit_desc">You need download again after exit continue?</string>
 </resources>
\ No newline at end of file
index c7471b3..ad4467b 100644 (file)
@@ -36,4 +36,5 @@
     <string name="update_date_format_text">yyyy-MM-dd HH:mm:ss</string>
     <string name="no_update_desc">没有更新说明...</string>
     <string name="update_tips_title_text">升级提示</string>
+    <string name="update_tips_exit_desc">退出后需要重新下载,是否继续?</string>
 </resources>
\ No newline at end of file
index f30329a..7f7d11d 100644 (file)
@@ -26,7 +26,7 @@
     <string name="tips_wifi_connect">Please connect WI-FI</string>
     <string name="unsupport_pause_download">Server not support download</string>
     <string name="new_version_tips_title">Has new version!</string>
-    <string name="local_new_version_tips_title">Tip!</string>
+    <string name="local_new_version_tips_title">Notice!</string>
     <string name="local_update_desc_text">Has update in local.</string>
     <string name="update_package_not_in_tips_text">No file</string>
     <string name="update_result_success_tips">Update success:</string>
@@ -35,5 +35,6 @@
     <string name="update_failed_tips_text">Update fail!</string>
     <string name="update_date_format_text">yyyy-MM-dd HH:mm:ss</string>
     <string name="no_update_desc">No update describe...</string>
-    <string name="update_tips_title_text">Tip</string>
+    <string name="update_tips_title_text">Notice</string>
+    <string name="update_tips_exit_desc">You need download again after exit continue?</string>
 </resources>
\ No newline at end of file