|
@@ -1,14 +1,13 @@
|
|
|
package com.module.backstage.activity.setting
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
+import android.app.XzjhSystemManager
|
|
|
import android.content.Context
|
|
|
-import android.content.Intent
|
|
|
import android.content.res.Resources
|
|
|
import android.graphics.Color
|
|
|
-import android.net.Uri
|
|
|
import android.os.Build
|
|
|
+import android.os.Environment
|
|
|
import android.os.Handler
|
|
|
-import android.os.Looper
|
|
|
import android.util.Log
|
|
|
import android.view.MenuItem
|
|
|
import android.view.View
|
|
@@ -23,7 +22,6 @@ import androidx.core.content.ContextCompat
|
|
|
import androidx.core.view.get
|
|
|
import androidx.lifecycle.LifecycleObserver
|
|
|
import androidx.navigation.findNavController
|
|
|
-import androidx.navigation.fragment.findNavController
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.alibaba.android.arouter.launcher.ARouter
|
|
|
import com.google.gson.Gson
|
|
@@ -32,7 +30,6 @@ import com.hboxs.serialport.plc.DialogClickListener
|
|
|
import com.hboxs.serialport.plc.message.Message
|
|
|
import com.hboxs.serialport.sbc.SBCHeartbeat
|
|
|
import com.hboxs.serialport.sbc.VBoxMessage
|
|
|
-import com.hboxs.serialport.sbc.frame.VboxCommand
|
|
|
import com.hjq.http.EasyHttp
|
|
|
import com.hjq.http.listener.OnDownloadListener
|
|
|
import com.hjq.http.model.HttpMethod
|
|
@@ -81,7 +78,8 @@ import java.io.File
|
|
|
@Route(path = RouteUrl.Home.SettingActivity)
|
|
|
@AndroidEntryPoint
|
|
|
@RegisterEventBus
|
|
|
-class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingViewModel>(),LifecycleObserver,
|
|
|
+class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingViewModel>(),
|
|
|
+ LifecycleObserver,
|
|
|
View.OnClickListener {
|
|
|
private val TAG = "SettingActivity"
|
|
|
private var backPressedTime: Long = 0
|
|
@@ -89,10 +87,10 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
var connectionServerDialog: ConnectionServerDialog? = null
|
|
|
var updateAppDialog: UpdateAppDialog? = null
|
|
|
var apkInfoBean: ApkInfoBean? = null//更新信息
|
|
|
- var windSpeed=0
|
|
|
+ var windSpeed = 0
|
|
|
|
|
|
- private var selectedMenuItemView: View?=null // 存储当前选中的MenuItem
|
|
|
- private var selectedMenuItemTextView: TextView?=null // 存储当前选中的MenuItem
|
|
|
+ private var selectedMenuItemView: View? = null // 存储当前选中的MenuItem
|
|
|
+ private var selectedMenuItemTextView: TextView? = null // 存储当前选中的MenuItem
|
|
|
|
|
|
/**
|
|
|
* 通过 viewModels() + Hilt 获取 ViewModel 实例
|
|
@@ -116,10 +114,20 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
setupCustomMenuItems()
|
|
|
bnvMainNavigationbar.setNavigationItemSelectedListener { menuItem ->
|
|
|
selectedMenuItemView?.setBackgroundColor(Color.TRANSPARENT)
|
|
|
- selectedMenuItemTextView?.setTextColor(ContextCompat.getColor(baseContext, R.color.white))
|
|
|
+ selectedMenuItemTextView?.setTextColor(
|
|
|
+ ContextCompat.getColor(
|
|
|
+ baseContext,
|
|
|
+ R.color.white
|
|
|
+ )
|
|
|
+ )
|
|
|
val customView = menuItem.actionView
|
|
|
if (customView != null) {
|
|
|
- customView.setBackgroundColor(ContextCompat.getColor(baseContext, R.color.system_btn))
|
|
|
+ customView.setBackgroundColor(
|
|
|
+ ContextCompat.getColor(
|
|
|
+ baseContext,
|
|
|
+ R.color.system_btn
|
|
|
+ )
|
|
|
+ )
|
|
|
selectedMenuItemView = customView
|
|
|
val textView = customView.findViewById<TextView>(R.id.menu_title)
|
|
|
textView.setTextColor(ContextCompat.getColor(baseContext, R.color.system_text))
|
|
@@ -139,9 +147,11 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
MMKVName.CONNECT_STATE, ConnectStateEnum.DISCONNECTED.name
|
|
|
)!!
|
|
|
)
|
|
|
- Log.d(TAG, "connectState initView: "+SpUtils.getString(
|
|
|
- MMKVName.CONNECT_STATE, ConnectStateEnum.DISCONNECTED.name
|
|
|
- )!!)
|
|
|
+ Log.d(
|
|
|
+ TAG, "connectState initView: " + SpUtils.getString(
|
|
|
+ MMKVName.CONNECT_STATE, ConnectStateEnum.DISCONNECTED.name
|
|
|
+ )!!
|
|
|
+ )
|
|
|
//退出App
|
|
|
LongClickUtils.setLongClick(
|
|
|
Handler(),
|
|
@@ -153,9 +163,10 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
return true
|
|
|
}
|
|
|
})
|
|
|
- mBinding.tvSoftwareVersion.text = "软件版本号:"+SBCHeartbeat.softwareVersion
|
|
|
- mBinding.tvCrateVersion.text = "机箱版本号:"+SBCHeartbeat.crateVersion
|
|
|
- mBinding.tvAppVersion.text= "App版本号:"+packageManager.getPackageInfo(packageName, 0).versionName
|
|
|
+ mBinding.tvSoftwareVersion.text = "软件版本号:" + SBCHeartbeat.softwareVersion
|
|
|
+ mBinding.tvCrateVersion.text = "机箱版本号:" + SBCHeartbeat.crateVersion
|
|
|
+ mBinding.tvAppVersion.text =
|
|
|
+ "App版本号:" + packageManager.getPackageInfo(packageName, 0).versionName
|
|
|
val deviceId = FileUtil.getDeviceId()
|
|
|
if (deviceId.isNotEmpty()) {
|
|
|
mBinding.tvDevDogtag.text =
|
|
@@ -166,24 +177,27 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
fun event(messageEvent: VBoxMessage) {
|
|
|
- XLogUtil.d(messageEvent.cmd+":settingmessageEvent.data:"+messageEvent.data)
|
|
|
- Log.d(TAG, "settingdataevent0: "+messageEvent.data)
|
|
|
- Log.d(TAG, "settingdataevent1: "+messageEvent.data.length)
|
|
|
- val data =messageEvent.data.substring(2,4)
|
|
|
- when (data){
|
|
|
- "01"->{
|
|
|
+ XLogUtil.d(messageEvent.cmd + ":settingmessageEvent.data:" + messageEvent.data)
|
|
|
+ Log.d(TAG, "settingdataevent0: " + messageEvent.data)
|
|
|
+ Log.d(TAG, "settingdataevent1: " + messageEvent.data.length)
|
|
|
+ val data = messageEvent.data.substring(2, 4)
|
|
|
+ when (data) {
|
|
|
+ "01" -> {
|
|
|
mViewModel.cmdHeartbeat(messageEvent)
|
|
|
}
|
|
|
- "02"->{
|
|
|
+
|
|
|
+ "02" -> {
|
|
|
mViewModel.cmdAllParam(messageEvent)
|
|
|
}
|
|
|
- "03"->{
|
|
|
+
|
|
|
+ "03" -> {
|
|
|
mViewModel.cmdGetDevState(messageEvent)
|
|
|
- if (mViewModel.isM3Success.value == true){
|
|
|
+ if (mViewModel.isM3Success.value == true) {
|
|
|
closeLoading()
|
|
|
}
|
|
|
}
|
|
|
- else->{}
|
|
|
+
|
|
|
+ else -> {}
|
|
|
}
|
|
|
// when (messageEvent.cmd) {
|
|
|
// VboxCommand.CMD_HEARTBEAT ->{
|
|
@@ -343,6 +357,7 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
Heartbeat.managerId = text
|
|
|
connectionServerDialog?.dismiss()
|
|
|
}
|
|
|
+
|
|
|
else -> {}
|
|
|
}
|
|
|
}
|
|
@@ -375,9 +390,11 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
Message.Type.ack -> {
|
|
|
mViewModel.ack(messageEvent)
|
|
|
}
|
|
|
+
|
|
|
Message.Type.response -> {
|
|
|
mViewModel.response(messageEvent)
|
|
|
}
|
|
|
+
|
|
|
Message.Type.connected -> {}
|
|
|
Message.Type.disconnected -> {}
|
|
|
Message.Type.sendError -> {}
|
|
@@ -397,6 +414,7 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
showLoading()
|
|
|
mViewModel.threadSettingParam.startUp()
|
|
|
}
|
|
|
+
|
|
|
else -> {}
|
|
|
}
|
|
|
}
|
|
@@ -411,13 +429,15 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
|
|
|
fun updateApk() {
|
|
|
// 如果是放到外部存储的应用专属目录则不需要适配分区存储特性
|
|
|
- val file = File(getExternalFilesDir("apk" + "/"), "mht.apk")
|
|
|
+// val file = File(getExternalFilesDir("apk" + "/"), "mht.apk")
|
|
|
+ val file = File(Environment.getExternalStorageDirectory().path + "/apk/" + "mht.apk")
|
|
|
+ Log.d(TAG, "onDownloadStart: "+file)
|
|
|
val url = apkInfoBean?.downloadUrl
|
|
|
EasyHttp.download(this).method(HttpMethod.GET)
|
|
|
.file(file)
|
|
|
.url(url).listener(object : OnDownloadListener {
|
|
|
override fun onDownloadStart(file: File) {
|
|
|
- Log.d(TAG, "onDownloadStart: 开始下载")
|
|
|
+ Log.d(TAG, "onDownloadStart: 开始下载"+file)
|
|
|
}
|
|
|
|
|
|
override fun onDownloadProgressChange(file: File, progress: Int) {
|
|
@@ -428,12 +448,19 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
override fun onDownloadSuccess(file: File) {
|
|
|
Log.d(TAG, "onDownloadEnd: 下载成功")
|
|
|
//下载成功安装
|
|
|
- val intent = Intent(Intent.ACTION_VIEW)
|
|
|
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
- intent.setDataAndType(
|
|
|
- Uri.fromFile(file), "application/vnd.android.package-archive"
|
|
|
+// val intent = Intent(Intent.ACTION_VIEW)
|
|
|
+// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
+// intent.setDataAndType(
|
|
|
+// Uri.fromFile(file), "application/vnd.android.package-archive"
|
|
|
+// )
|
|
|
+// startActivity(intent)
|
|
|
+ val mManager: XzjhSystemManager =
|
|
|
+ getSystemService("xzjh_server") as XzjhSystemManager
|
|
|
+ mManager.xzjhSilentInstallApkV2(
|
|
|
+ Environment.getExternalStorageDirectory().path + "/apk/" + "mht.apk",
|
|
|
+ true
|
|
|
)
|
|
|
- startActivity(intent)
|
|
|
+ Log.d(TAG, "onDownloadStart 安装查找目录: "+Environment.getExternalStorageDirectory().path)
|
|
|
updateAppDialog?.dismiss()
|
|
|
}
|
|
|
|
|
@@ -540,17 +567,19 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
val icon = customView.findViewById<ImageView>(R.id.menu_icon)
|
|
|
val titleView = customView.findViewById<TextView>(R.id.menu_title)
|
|
|
icon.setImageResource(iconRes)
|
|
|
- titleView.text =UiUtil.getStringRes(title)
|
|
|
+ titleView.text = UiUtil.getStringRes(title)
|
|
|
|
|
|
// 将自定义布局添加到NavigationView的菜单中
|
|
|
- val menuItem: MenuItem = mBinding.bnvMainNavigationbar.getMenu().add(itemId, itemId, 0, title)
|
|
|
+ val menuItem: MenuItem =
|
|
|
+ mBinding.bnvMainNavigationbar.getMenu().add(itemId, itemId, 0, title)
|
|
|
menuItem.setActionView(customView)
|
|
|
menuItem.title = null // 禁用默认的title显示
|
|
|
}
|
|
|
|
|
|
private fun setDefaultSelectedItem() {
|
|
|
// 找到默认选中的MenuItem
|
|
|
- val menuItem = mBinding.bnvMainNavigationbar.menu.findItem(R.id.backstage_cottoncandyfragment)
|
|
|
+ val menuItem =
|
|
|
+ mBinding.bnvMainNavigationbar.menu.findItem(R.id.backstage_cottoncandyfragment)
|
|
|
menuItem?.let {
|
|
|
// 获取自定义视图
|
|
|
val customView = it.actionView
|
|
@@ -575,13 +604,15 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
|
|
|
private var dialog: ZLoadingDialog? = null
|
|
|
private var loadingJob: Job? = null
|
|
|
+
|
|
|
@SuppressLint("ResourceAsColor")
|
|
|
private fun showLoading() {
|
|
|
if (dialog == null) {
|
|
|
dialog = ZLoadingDialog(this@SettingActivity)
|
|
|
}
|
|
|
dialog!!.setLoadingBuilder(Z_TYPE.DOUBLE_CIRCLE) //设置类型
|
|
|
- .setLoadingColor(R.color.color_red
|
|
|
+ .setLoadingColor(
|
|
|
+ R.color.color_red
|
|
|
) //颜色
|
|
|
.setHintText("Loading...")
|
|
|
.setCancelable(false)
|
|
@@ -609,7 +640,7 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun closeLoading(){
|
|
|
+ private fun closeLoading() {
|
|
|
mViewModel.threadSettingParam.stopUp()
|
|
|
loadingJob?.cancel()
|
|
|
dialog?.dismiss()
|