设备(1)

This commit is contained in:
2026-05-18 17:39:30 +08:00
parent a9fb39cfde
commit 45828c7e9b
23 changed files with 895 additions and 67 deletions

View File

@@ -1,14 +1,17 @@
package com.example.defenseapplication.liveVideo
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.defenseapplication.R
import com.example.defenseapplication.databinding.AlarmLogActivityBinding
import com.example.defenseapplication.databinding.DeviceInfoActivityBinding
import com.example.defenseapplication.utils.DeviceIdEvent
import com.example.defenseapplication.utils.RetrofitNetwork
import com.gyf.immersionbar.ImmersionBar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
//设备信息
class DeviceInfoActivity : AppCompatActivity() {
private lateinit var binding: DeviceInfoActivityBinding
@@ -23,5 +26,38 @@ class DeviceInfoActivity : AppCompatActivity() {
binding.ivBack.setOnClickListener {
finish()
}
fetchDeviceInfo()
}
private fun fetchDeviceInfo() {
val deviceId = DeviceIdEvent.getDeviceId()
if (deviceId.isNullOrEmpty()) {
Toast.makeText(this, "设备ID为空", Toast.LENGTH_SHORT).show()
return
}
CoroutineScope(Dispatchers.IO).launch {
try {
val response = RetrofitNetwork.getNetworkService().getDeviceInfo(deviceId)
withContext(Dispatchers.Main) {
if (response.code == 200 && response.data != null) {
updateDeviceInfo(response.data)
} else {
Toast.makeText(this@DeviceInfoActivity, response.msg, Toast.LENGTH_SHORT).show()
}
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
Toast.makeText(this@DeviceInfoActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
}
}
}
}
private fun updateDeviceInfo(device: com.example.defenseapplication.bean.DeviceBean) {
binding.tvDeviceModelValue.text = device.deviceNo.toString() ?: "未知型号"
binding.tvDeviceNoValue.text = device.startTime.toString() ?: "自动布防开始时间"
binding.tvFwVersionValue.text = device.endTime.toString() ?: "自动布防结束时间"
}
}

View File

@@ -21,11 +21,12 @@ import android.view.animation.ScaleAnimation
import android.widget.Toast
import androidx.activity.OnBackPressedDispatcher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.test.isEnabled
import androidx.core.content.ContextCompat
import com.example.defenseapplication.R
import com.example.defenseapplication.base.BaseActivity
import com.example.defenseapplication.databinding.LiveVideoActivityBinding
import com.example.defenseapplication.utils.ActivityManager
import com.example.defenseapplication.utils.DeviceIdEvent
import com.gyf.immersionbar.ImmersionBar
import com.gyf.immersionbar.ktx.destroyImmersionBar
import java.io.File
@@ -33,7 +34,7 @@ import java.io.IOException
private const val TAG = "LiveVideoActivity"
//智能防御机A1
class LiveVideoActivity : AppCompatActivity(), SurfaceHolder.Callback {
class LiveVideoActivity : BaseActivity(), SurfaceHolder.Callback {
private lateinit var binding: LiveVideoActivityBinding
private var mediaPlayer: MediaPlayer? = null
@@ -72,6 +73,11 @@ class LiveVideoActivity : AppCompatActivity(), SurfaceHolder.Callback {
.titleBar(binding.topBar)
.init()
val deviceName = intent.getStringExtra("device_name")
if (!deviceName.isNullOrEmpty()) {
binding.tvTitle.text = deviceName
}
initSurfaceView()
initListener()
}
@@ -163,6 +169,10 @@ class LiveVideoActivity : AppCompatActivity(), SurfaceHolder.Callback {
private fun initListener() {
binding.btnBack.setOnClickListener {
ActivityManager.finishExceptHome()
val intent = Intent(this, com.example.defenseapplication.home.HomeActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
startActivity(intent)
finish()
}