|
@@ -1,17 +1,11 @@
|
|
package com.doverfuelingsolutions.issp.view
|
|
package com.doverfuelingsolutions.issp.view
|
|
|
|
|
|
import android.app.Activity
|
|
import android.app.Activity
|
|
-import android.app.DownloadManager
|
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
-import android.net.Uri
|
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
-import android.os.Environment
|
|
|
|
import android.view.View
|
|
import android.view.View
|
|
-import android.widget.Button
|
|
|
|
-import android.widget.TextView
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
-import androidx.core.content.FileProvider
|
|
|
|
import androidx.databinding.DataBindingUtil
|
|
import androidx.databinding.DataBindingUtil
|
|
import androidx.lifecycle.MutableLiveData
|
|
import androidx.lifecycle.MutableLiveData
|
|
import androidx.lifecycle.ViewModel
|
|
import androidx.lifecycle.ViewModel
|
|
@@ -19,21 +13,16 @@ import androidx.lifecycle.lifecycleScope
|
|
import com.doverfuelingsolutions.issp.R
|
|
import com.doverfuelingsolutions.issp.R
|
|
import com.doverfuelingsolutions.issp.api.FuelInfoApi
|
|
import com.doverfuelingsolutions.issp.api.FuelInfoApi
|
|
import com.doverfuelingsolutions.issp.api.SystemApi
|
|
import com.doverfuelingsolutions.issp.api.SystemApi
|
|
-import com.doverfuelingsolutions.issp.api.WayneApiConfig
|
|
|
|
import com.doverfuelingsolutions.issp.databinding.ActivityPreferenceBinding
|
|
import com.doverfuelingsolutions.issp.databinding.ActivityPreferenceBinding
|
|
-import com.doverfuelingsolutions.issp.utils.WindowUtil
|
|
|
|
import com.doverfuelingsolutions.issp.utils.AppUtil
|
|
import com.doverfuelingsolutions.issp.utils.AppUtil
|
|
import com.doverfuelingsolutions.issp.utils.DFSToastUtil
|
|
import com.doverfuelingsolutions.issp.utils.DFSToastUtil
|
|
import com.doverfuelingsolutions.issp.utils.StringUtil
|
|
import com.doverfuelingsolutions.issp.utils.StringUtil
|
|
-import com.doverfuelingsolutions.issp.utils.download.DownloadAction
|
|
+import com.doverfuelingsolutions.issp.utils.WindowUtil
|
|
import com.doverfuelingsolutions.issp.utils.log.DFSLog
|
|
import com.doverfuelingsolutions.issp.utils.log.DFSLog
|
|
import com.doverfuelingsolutions.issp.utils.sp.SPKeys
|
|
import com.doverfuelingsolutions.issp.utils.sp.SPKeys
|
|
import com.doverfuelingsolutions.issp.utils.sp.SPUtil
|
|
import com.doverfuelingsolutions.issp.utils.sp.SPUtil
|
|
import com.doverfuelingsolutions.issp.view.fragment.FragmentPreference
|
|
import com.doverfuelingsolutions.issp.view.fragment.FragmentPreference
|
|
-import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
-import com.moos.library.CircleProgressView
|
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
-import java.io.File
|
|
|
|
|
|
|
|
class PreferenceActivity : AppCompatActivity(),
|
|
class PreferenceActivity : AppCompatActivity(),
|
|
View.OnClickListener {
|
|
View.OnClickListener {
|
|
@@ -169,81 +158,7 @@ class PreferenceActivity : AppCompatActivity(),
|
|
return@launch
|
|
return@launch
|
|
}
|
|
}
|
|
|
|
|
|
- val dialogView = View.inflate(this@PreferenceActivity, R.layout.layout_version_update, null).apply {
|
|
+ UpdateActivity.start(this@PreferenceActivity, remoteVersion.version, remoteVersion.name, remoteVersion.info)
|
|
- 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 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)
|
|
|
|
- .setCancelable(false)
|
|
|
|
- .show()
|
|
|
|
- dialog.window?.let { WindowUtil.setFullscreen(it) }
|
|
|
|
- val actionButton = dialogView.findViewById<Button>(R.id.close)
|
|
|
|
- actionButton.setOnClickListener { dialog.dismiss() }
|
|
|
|
-
|
|
|
|
- // TODO 下载中途断网,下载失败,下载完成但是未成功安装,成功安装后怎么删除
|
|
|
|
- // 准备下载
|
|
|
|
- val localName = "update/${remoteVersion.name}"
|
|
|
|
- val downloadAction = DownloadAction(
|
|
|
|
- this@PreferenceActivity,
|
|
|
|
- Uri.parse("${WayneApiConfig.HOST_ASSETS}/isspt/${remoteVersion.name}"),
|
|
|
|
- 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)
|
|
|
|
- progressView.progress = size.toFloat() * 100 / total
|
|
|
|
- }
|
|
|
|
- // 下载结束
|
|
|
|
- DownloadManager.STATUS_SUCCESSFUL -> {
|
|
|
|
-// loadingTip.text = StringUtil.get(R.string.download_done)
|
|
|
|
- actionButton.visibility = View.VISIBLE
|
|
|
|
-
|
|
|
|
- // 安装应用
|
|
|
|
- getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)?.let { folder ->
|
|
|
|
- val file = File("${folder.absolutePath}/$localName")
|
|
|
|
- if (!file.isFile) {
|
|
|
|
- DFSToastUtil.fail(R.string.cant_find_local_file)
|
|
|
|
- dialog.dismiss()
|
|
|
|
- return@let
|
|
|
|
- }
|
|
|
|
- // 先删掉其他APK
|
|
|
|
- file.parentFile?.list()?.forEach {
|
|
|
|
- File(it).let { f ->
|
|
|
|
- if (f.absolutePath != file.absolutePath && f.isFile && f.name.endsWith("apk")) {
|
|
|
|
- f.delete()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- val fileUri = FileProvider.getUriForFile(
|
|
|
|
- this@PreferenceActivity,
|
|
|
|
- "$packageName.provider",
|
|
|
|
- file
|
|
|
|
- )
|
|
|
|
- Intent(Intent.ACTION_VIEW).let { intent ->
|
|
|
|
- intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
- intent.setDataAndType(fileUri, "application/vnd.android.package-archive")
|
|
|
|
- this@PreferenceActivity.startActivity(intent)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 下载失败
|
|
|
|
- DownloadManager.STATUS_FAILED -> {
|
|
|
|
-// loadingTip.text = StringUtil.get(R.string.download_fail)
|
|
|
|
- actionButton.visibility = View.VISIBLE
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|