|
@@ -7,7 +7,6 @@ import android.content.Intent
|
|
|
import android.net.Uri
|
|
|
import android.os.Bundle
|
|
|
import android.os.Environment
|
|
|
-import android.view.MenuItem
|
|
|
import android.view.View
|
|
|
import android.widget.Button
|
|
|
import android.widget.TextView
|
|
@@ -32,6 +31,7 @@ import com.doverfuelingsolutions.issp.utils.sp.SPKeys
|
|
|
import com.doverfuelingsolutions.issp.utils.sp.SPUtil
|
|
|
import com.doverfuelingsolutions.issp.view.fragment.FragmentPreference
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
+import com.moos.library.CircleProgressView
|
|
|
import kotlinx.coroutines.launch
|
|
|
import java.io.File
|
|
|
|
|
@@ -145,9 +145,9 @@ class PreferenceActivity : AppCompatActivity(),
|
|
|
val currentVersion = AppUtil.getVersionName()
|
|
|
DFSLog.i("current version is $currentVersion")
|
|
|
|
|
|
- viewModel.isLookingUpdate.value = true
|
|
|
+ viewModel.isSubmitting.value = true
|
|
|
val result = SystemApi.remoteVersion()
|
|
|
- viewModel.isLookingUpdate.value = false
|
|
|
+ viewModel.isSubmitting.value = false
|
|
|
|
|
|
if (!result.success || result.data == null) {
|
|
|
DFSLog.e("latest version check failed: ${result.message}")
|
|
@@ -173,9 +173,10 @@ class PreferenceActivity : AppCompatActivity(),
|
|
|
findViewById<TextView>(R.id.versionTitle).text = StringUtil.get(R.string.new_version, remoteVersion.version)
|
|
|
findViewById<TextView>(R.id.versionInfo).text = StringUtil.get(R.string.new_version, remoteVersion.info)
|
|
|
}
|
|
|
- val loadingTip = dialogView.findViewById<TextView>(R.id.loadingTip).apply {
|
|
|
- text = StringUtil.get(R.string.in_download)
|
|
|
- }
|
|
|
+ val progressView = dialogView.findViewById<CircleProgressView>(R.id.progressView)
|
|
|
+// val loadingTip = dialogView.findViewById<TextView>(R.id.loadingTip).apply {
|
|
|
+// text = StringUtil.get(R.string.in_download)
|
|
|
+// }
|
|
|
val dialog = MaterialAlertDialogBuilder(this@PreferenceActivity)
|
|
|
.setTitle(R.string.find_new_version)
|
|
|
.setView(dialogView)
|
|
@@ -191,19 +192,19 @@ class PreferenceActivity : AppCompatActivity(),
|
|
|
val downloadAction = DownloadAction(
|
|
|
this@PreferenceActivity,
|
|
|
Uri.parse("${WayneApiConfig.HOST_ASSETS}/isspt/${remoteVersion.name}"),
|
|
|
- localName
|
|
|
- )
|
|
|
+ localName)
|
|
|
downloadAction.start { status, size, total ->
|
|
|
lifecycleScope.launch {
|
|
|
when (status) {
|
|
|
// 下载中
|
|
|
DownloadManager.STATUS_RUNNING -> {
|
|
|
- val percentage = (size.toDouble() * 10000 / total).toInt().toDouble() / 100
|
|
|
- loadingTip.text = StringUtil.get(R.string.download_progress, percentage)
|
|
|
+// val percentage = (size.toDouble() * 10000 / total).toInt().toDouble() / 100
|
|
|
+// loadingTip.text = StringUtil.get(R.string.download_progress, percentage)
|
|
|
+ progressView.progress = size.toFloat() * 100 / total
|
|
|
}
|
|
|
// 下载结束
|
|
|
DownloadManager.STATUS_SUCCESSFUL -> {
|
|
|
- loadingTip.text = StringUtil.get(R.string.download_done)
|
|
|
+// loadingTip.text = StringUtil.get(R.string.download_done)
|
|
|
actionButton.visibility = View.VISIBLE
|
|
|
|
|
|
// 安装应用
|
|
@@ -237,7 +238,7 @@ class PreferenceActivity : AppCompatActivity(),
|
|
|
}
|
|
|
// 下载失败
|
|
|
DownloadManager.STATUS_FAILED -> {
|
|
|
- loadingTip.text = StringUtil.get(R.string.download_fail)
|
|
|
+// loadingTip.text = StringUtil.get(R.string.download_fail)
|
|
|
actionButton.visibility = View.VISIBLE
|
|
|
}
|
|
|
}
|
|
@@ -247,6 +248,6 @@ class PreferenceActivity : AppCompatActivity(),
|
|
|
}
|
|
|
|
|
|
class PreferenceViewModel : ViewModel() {
|
|
|
- val isLookingUpdate = MutableLiveData(false)
|
|
|
+ val isSubmitting = MutableLiveData(false)
|
|
|
}
|
|
|
}
|