修改识别模式

This commit is contained in:
2026-05-19 15:22:44 +08:00
parent 45828c7e9b
commit 066334932f
11 changed files with 535 additions and 165 deletions

View File

@@ -4,7 +4,7 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-05-18T03:55:13.002969200Z"> <DropdownSelection timestamp="2026-05-18T09:18:19.023586Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=80bece4" /> <DeviceId pluginId="PhysicalDevice" identifier="serial=80bece4" />

View File

@@ -1,29 +1,30 @@
package com.example.defenseapplication.bean package com.example.defenseapplication.bean
data class DeviceBean( data class DeviceBean(
val alertAudio: String, val alertAudio: String? = null,//告警播放
val audioContet: Any, val audioContet: String? = null,//告警内容
val container: Any, val container: String? = null,//容器数量
val countNum: Any, val countNum: String? = null,
val deviceEm: String, val deviceEm: String? = null,//设备型号
val deviceFamilyId: String, val deviceFamilyId: String? = null,
val deviceImg: Any, val deviceImg: String? = null,
val deviceName: String, val deviceName: String? = null,//设备名称
val deviceNo: String, val deviceNo: String? = null,//设备编号
val deviceSn: String, val deviceSn: String? = null,//设备序列号
val endTime: Any, val endTime: String? = null,//自动布放结束时间
val expirationTime: String, val expirationTime: String? = null,
val fwVer: String, val fwVer: String? = null,//固件版本
val id: String, val id: String? = null,
val light: String, val light: String? = null,//强光开启
val patternPerception: Any, val patternPerception: String? = null,//识别模式
val startTime: Any, val startTime: String? = null,//自动布放开始时间
val status: String, val status: String? = null,//状态 1-在线 0-离线 2-故障 3-到期
val strikeInterval: Any, val strikeInterval: String? = null,//打击间隔
val strikePosition: Any, val strikePosition: String? = null,//打击位置
val strikeRange: Any, val strikeRange: String? = null,//打击距离
val userId: String, val userId: String? = null,
val wifiName: String, val wifiName: String? = null,//WiFi名称
val wifiPassword: String, val wifiPassword: String? = null,//WiFi密码
val workMode: String val workMode: String? = null,//工作模式 0-自动 1-半自动
val optionPassword: String? = null, //操作密码
) )

View File

@@ -30,6 +30,7 @@ import com.example.defenseapplication.bean.FamilyBean
import com.example.defenseapplication.bean.SwitchFamilyRequest import com.example.defenseapplication.bean.SwitchFamilyRequest
import com.example.defenseapplication.databinding.HomeMenuFragmentBinding import com.example.defenseapplication.databinding.HomeMenuFragmentBinding
import com.example.defenseapplication.utils.DeviceIdEvent import com.example.defenseapplication.utils.DeviceIdEvent
import com.example.defenseapplication.utils.DeviceUpdateEvent
import com.example.defenseapplication.utils.FamilySwitchEvent import com.example.defenseapplication.utils.FamilySwitchEvent
import com.example.defenseapplication.utils.MessageStatusManager import com.example.defenseapplication.utils.MessageStatusManager
import com.example.defenseapplication.utils.RetrofitNetwork import com.example.defenseapplication.utils.RetrofitNetwork
@@ -154,6 +155,12 @@ class HomeMenuFragment : Fragment() {
} }
} }
private val deviceUpdateListener = object : DeviceUpdateEvent.DeviceUpdateListener {
override fun onDeviceUpdated(deviceId: String) {
refreshDeviceList()
}
}
private fun updateFamilyDisplayText(familyName: String) { private fun updateFamilyDisplayText(familyName: String) {
val familyBean = familyBeanList.find { it.parentName == familyName } val familyBean = familyBeanList.find { it.parentName == familyName }
val isAdmin = familyBean?.role == "appadmin" val isAdmin = familyBean?.role == "appadmin"
@@ -212,6 +219,7 @@ class HomeMenuFragment : Fragment() {
MessageStatusManager.addListener(unreadCountChangeListener) MessageStatusManager.addListener(unreadCountChangeListener)
FamilySwitchEvent.addListener(familySwitchListener) FamilySwitchEvent.addListener(familySwitchListener)
DeviceUpdateEvent.addListener(deviceUpdateListener)
updateUnreadCountUI(MessageStatusManager.getUnreadCount()) updateUnreadCountUI(MessageStatusManager.getUnreadCount())
} }
@@ -448,7 +456,7 @@ class HomeMenuFragment : Fragment() {
private fun updateDeviceList() { private fun updateDeviceList() {
val deviceUiList = deviceBeanList.map { val deviceUiList = deviceBeanList.map {
DeviceUi(it.deviceName, it.status, it.id) DeviceUi(it.deviceName ?: "", it.status ?: "", it.id ?: "")
} }
if (deviceUiList.isEmpty()) { if (deviceUiList.isEmpty()) {
@@ -518,6 +526,7 @@ class HomeMenuFragment : Fragment() {
binding.rvDeviceList.adapter = null binding.rvDeviceList.adapter = null
MessageStatusManager.removeListener(unreadCountChangeListener) MessageStatusManager.removeListener(unreadCountChangeListener)
FamilySwitchEvent.removeListener(familySwitchListener) FamilySwitchEvent.removeListener(familySwitchListener)
DeviceUpdateEvent.removeListener(deviceUpdateListener)
_binding = null // 避免内存泄漏 _binding = null // 避免内存泄漏
} }
} }

View File

@@ -1,17 +1,38 @@
package com.example.defenseapplication.liveVideo package com.example.defenseapplication.liveVideo
import TimePickerFragment import TimePickerFragment
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.example.defenseapplication.R
import com.example.defenseapplication.databinding.AutoModeActivityBinding import com.example.defenseapplication.databinding.AutoModeActivityBinding
import com.example.defenseapplication.utils.DeviceIdEvent
import com.example.defenseapplication.utils.DeviceUpdateEvent
import com.example.defenseapplication.utils.RetrofitNetwork
import com.example.defenseapplication.view.AutoModeNoticeDialog import com.example.defenseapplication.view.AutoModeNoticeDialog
import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ImmersionBar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.Calendar import java.util.Calendar
//自动模式 //自动模式
class AutoModeActivity : AppCompatActivity() { class AutoModeActivity : AppCompatActivity() {
private lateinit var binding: AutoModeActivityBinding private lateinit var binding: AutoModeActivityBinding
private lateinit var calendar: Calendar private lateinit var calendar: Calendar
private var selectedMode = "0"
private var selectedYear = 0
private var selectedMonth = 0
private var selectedDay = 0
private var selectedHour = 0
private var selectedMinute = 0
private var selectedStartHour = 21
private var selectedStartMinute = 30
private var selectedEndHour = 8
private var selectedEndMinute = 30
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = AutoModeActivityBinding.inflate(layoutInflater) binding = AutoModeActivityBinding.inflate(layoutInflater)
@@ -22,8 +43,15 @@ class AutoModeActivity : AppCompatActivity() {
.titleBar(binding.topBar) .titleBar(binding.topBar)
.init() .init()
calendar = Calendar.getInstance()
selectedYear = calendar.get(Calendar.YEAR)
selectedMonth = calendar.get(Calendar.MONTH)
selectedDay = calendar.get(Calendar.DAY_OF_MONTH)
initListener() initListener()
loadCurrentSettings()
showAutoModeNoticeDialog() showAutoModeNoticeDialog()
} }
@@ -32,43 +60,195 @@ class AutoModeActivity : AppCompatActivity() {
finish() finish()
} }
binding.rbAutoMode.setOnClickListener { binding.rbAutoMode.setOnCheckedChangeListener { _, isChecked ->
binding.rbSemiAutoMode.isChecked = false if (isChecked) {
selectedMode = "0"
showAutoModeNoticeDialog() showAutoModeNoticeDialog()
binding.time.visibility = android.view.View.VISIBLE
}
} }
binding.rbSemiAutoMode.setOnClickListener { binding.rbSemiAutoMode.setOnCheckedChangeListener { _, isChecked ->
binding.rbAutoMode.isChecked = false if (isChecked) {
selectedMode = "1"
binding.time.visibility = android.view.View.GONE
} }
// 起始时间选择 }
binding.itemStartTime.setOnClickListener { binding.itemStartTime.setOnClickListener {
showTimePicker { hour, minute -> showDateTimePicker { year, month, day, hour, minute ->
val startTimeStr = String.format("%02d:%02d", hour, minute) selectedStartHour = hour
selectedStartMinute = minute
val startTimeStr = String.format("%04d-%02d-%02d %02d:%02d", year, month + 1, day, hour, minute)
binding.tvStartTime.text = startTimeStr binding.tvStartTime.text = startTimeStr
} }
} }
// 结束时间选择
binding.itemEndTime.setOnClickListener { binding.itemEndTime.setOnClickListener {
showTimePicker { hour, minute -> showDateTimePicker { year, month, day, hour, minute ->
val endTimeStr = String.format("%02d:%02d", hour, minute) selectedEndHour = hour
selectedEndMinute = minute
val endTimeStr = String.format("%04d-%02d-%02d %02d:%02d", year, month + 1, day, hour, minute)
binding.tvEndTime.text = endTimeStr binding.tvEndTime.text = endTimeStr
} }
} }
} }
/**
* 显示时间选择器对话框 private fun loadCurrentSettings() {
* @param onTimeSelected 时间选择回调,参数为小时和分钟 val deviceId = DeviceIdEvent.getDeviceId()
*/ if (deviceId.isNullOrEmpty()) {
return
}
CoroutineScope(Dispatchers.IO).launch {
try {
val response = RetrofitNetwork.getNetworkService().getDeviceInfo(deviceId)
withContext(Dispatchers.Main) {
if (response.code == 200 && response.data != null) {
response.data.workMode?.let { mode ->
selectedMode = mode
if (mode == "0") {
binding.rbAutoMode.isChecked = true
binding.rbSemiAutoMode.isChecked = false
binding.time.visibility = android.view.View.VISIBLE
} else {
binding.rbAutoMode.isChecked = false
binding.rbSemiAutoMode.isChecked = true
binding.time.visibility = android.view.View.GONE
}
}
response.data.startTime?.let { startTime ->
binding.tvStartTime.text = if (startTime.length >= 5) {
if (startTime.contains("-")) {
startTime
} else {
String.format("%04d-%02d-%02d %s", selectedYear, selectedMonth + 1, selectedDay, startTime)
}
} else {
String.format("%04d-%02d-%02d %02d:%02d", selectedYear, selectedMonth + 1, selectedDay, 21, 30)
}
parseDateTime(startTime, true)
}
response.data.endTime?.let { endTime ->
binding.tvEndTime.text = if (endTime.length >= 5) {
if (endTime.contains("-")) {
endTime
} else {
String.format("%04d-%02d-%02d %s", selectedYear, selectedMonth + 1, selectedDay, endTime)
}
} else {
String.format("%04d-%02d-%02d %02d:%02d", selectedYear, selectedMonth + 1, selectedDay, 8, 30)
}
parseDateTime(endTime, false)
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
private fun showTimePicker(onTimeSelected: (hour: Int, minute: Int) -> Unit) { private fun showTimePicker(onTimeSelected: (hour: Int, minute: Int) -> Unit) {
val timePickerFragment = TimePickerFragment { hour, minute -> val timePickerFragment = TimePickerFragment { hour, minute ->
onTimeSelected(hour, minute) onTimeSelected(hour, minute)
} }
timePickerFragment.show(supportFragmentManager, "timePicker") timePickerFragment.show(supportFragmentManager, "timePicker")
} }
private fun showDateTimePicker(onDateTimeSelected: (year: Int, month: Int, day: Int, hour: Int, minute: Int) -> Unit) {
}
private fun parseDateTime(dateTimeStr: String, isStartTime: Boolean) {
if (dateTimeStr.contains("-") && dateTimeStr.contains(" ")) {
val dateTimeParts = dateTimeStr.split(" ")
if (dateTimeParts.size == 2) {
val dateParts = dateTimeParts[0].split("-")
val timeParts = dateTimeParts[1].split(":")
if (dateParts.size == 3 && timeParts.size == 2) {
if (isStartTime) {
selectedStartHour = timeParts[0].toIntOrNull() ?: 21
selectedStartMinute = timeParts[1].toIntOrNull() ?: 30
} else {
selectedEndHour = timeParts[0].toIntOrNull() ?: 8
selectedEndMinute = timeParts[1].toIntOrNull() ?: 30
}
return
}
}
}
if (dateTimeStr.contains(":")) {
val timeParts = dateTimeStr.split(":")
if (timeParts.size == 2) {
if (isStartTime) {
selectedStartHour = timeParts[0].toIntOrNull() ?: 21
selectedStartMinute = timeParts[1].toIntOrNull() ?: 30
} else {
selectedEndHour = timeParts[0].toIntOrNull() ?: 8
selectedEndMinute = timeParts[1].toIntOrNull() ?: 30
}
}
}
}
private fun showAutoModeNoticeDialog() { private fun showAutoModeNoticeDialog() {
val dialog = AutoModeNoticeDialog(this) val dialog = AutoModeNoticeDialog(this)
dialog.setOnConfirmListener { dialog.setOnConfirmListener { year, month, day, hour, minute ->
selectedYear = year
selectedMonth = month
selectedDay = day
selectedHour = hour
selectedMinute = minute
saveAutoModeSettings()
} }
dialog.show() dialog.show()
} }
private fun saveAutoModeSettings() {
val deviceId = DeviceIdEvent.getDeviceId()
if (deviceId.isNullOrEmpty()) {
Toast.makeText(this, "设备ID为空", Toast.LENGTH_SHORT).show()
return
}
val startTime = String.format("%04d-%02d-%02d %02d:%02d", selectedYear, selectedMonth + 1, selectedDay, selectedStartHour, selectedStartMinute)
val endTime = String.format("%04d-%02d-%02d %02d:%02d", selectedYear, selectedMonth + 1, selectedDay, selectedEndHour, selectedEndMinute)
val effectiveTime = String.format("%04d-%02d-%02d %02d:%02d", selectedYear, selectedMonth + 1, selectedDay, selectedHour, selectedMinute)
CoroutineScope(Dispatchers.IO).launch {
try {
val deviceBean = com.example.defenseapplication.bean.DeviceBean(
id = deviceId,
workMode = selectedMode,
startTime = startTime,
endTime = endTime
)
val response = RetrofitNetwork.getNetworkService().updateDeviceInfo(deviceBean)
withContext(Dispatchers.Main) {
if (response.code == 200) {
val modeText = if (selectedMode == "0") {
getString(R.string.full_auto_mode)
} else {
getString(R.string.semi_auto_mode)
}
val resultIntent = Intent()
resultIntent.putExtra("auto_mode", modeText)
resultIntent.putExtra("auto_mode_value", selectedMode)
resultIntent.putExtra("effective_time", effectiveTime)
setResult(RESULT_OK, resultIntent)
Toast.makeText(this@AutoModeActivity, "修改成功,生效时间:$effectiveTime", Toast.LENGTH_SHORT).show()
DeviceUpdateEvent.notifyDeviceUpdated(deviceId)
} else {
Toast.makeText(this@AutoModeActivity, response.msg, Toast.LENGTH_SHORT).show()
}
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
Toast.makeText(this@AutoModeActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
}
}
}
}
} }

View File

@@ -56,8 +56,8 @@ class DeviceInfoActivity : AppCompatActivity() {
} }
private fun updateDeviceInfo(device: com.example.defenseapplication.bean.DeviceBean) { private fun updateDeviceInfo(device: com.example.defenseapplication.bean.DeviceBean) {
binding.tvDeviceModelValue.text = device.deviceNo.toString() ?: "未知型号" binding.tvDeviceModelValue.text = device.deviceNo.toString()
binding.tvDeviceNoValue.text = device.startTime.toString() ?: "自动布防开始时间" binding.tvDeviceNoValue.text = device.deviceSn.toString()
binding.tvFwVersionValue.text = device.endTime.toString() ?: "自动布防结束时间" binding.tvFwVersionValue.text = device.fwVer.toString()
} }
} }

View File

@@ -1,19 +1,30 @@
package com.example.defenseapplication.liveVideo package com.example.defenseapplication.liveVideo
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.widget.Toast
import com.example.defenseapplication.R import com.example.defenseapplication.R
import com.example.defenseapplication.base.BaseActivity import com.example.defenseapplication.base.BaseActivity
import com.example.defenseapplication.databinding.SettingsActivityBinding import com.example.defenseapplication.databinding.SettingsActivityBinding
import com.example.defenseapplication.utils.DeviceIdEvent
import com.example.defenseapplication.utils.DeviceUpdateEvent
import com.example.defenseapplication.utils.LanguageUtil import com.example.defenseapplication.utils.LanguageUtil
import com.example.defenseapplication.utils.RetrofitNetwork
import com.example.defenseapplication.view.CustomDialogFragmentText import com.example.defenseapplication.view.CustomDialogFragmentText
import com.example.defenseapplication.view.LanguageDialog import com.example.defenseapplication.view.LanguageDialog
import com.example.defenseapplication.view.RecognitionModeDialog import com.example.defenseapplication.view.RecognitionModeDialog
import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ImmersionBar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
//设置页面 //设置页面
class SettingsActivity : BaseActivity() { class SettingsActivity : BaseActivity() {
private lateinit var binding: SettingsActivityBinding private lateinit var binding: SettingsActivityBinding
private val SP_NAME = "DeviceSettings"
private val KEY_RECOGNITION_MODE = "recognition_mode"
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -35,7 +46,7 @@ class SettingsActivity : BaseActivity() {
binding.itemRecognitionMode.setOnClickListener { binding.itemRecognitionMode.setOnClickListener {
val dialog = RecognitionModeDialog(this) val dialog = RecognitionModeDialog(this)
dialog.setOnConfirmListener { mode -> dialog.setOnConfirmListener { mode ->
binding.tvRecognitionMode.text = mode updateRecognitionMode(mode)
} }
dialog.show() dialog.show()
} }
@@ -45,7 +56,7 @@ class SettingsActivity : BaseActivity() {
.setTitle(getString(R.string.device_name)) .setTitle(getString(R.string.device_name))
.setInputText(binding.tvDeviceName.text.toString()) .setInputText(binding.tvDeviceName.text.toString())
dialog.setOnConfirmListener { name -> dialog.setOnConfirmListener { name ->
binding.tvDeviceName.text = name updateDeviceName(name)
} }
dialog.show(supportFragmentManager, "CustomDialogFragment") dialog.show(supportFragmentManager, "CustomDialogFragment")
} }
@@ -84,6 +95,136 @@ class SettingsActivity : BaseActivity() {
val intent = Intent(this, WiFiManagementActivity::class.java) val intent = Intent(this, WiFiManagementActivity::class.java)
startActivity(intent) startActivity(intent)
} }
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@SettingsActivity, response.msg, Toast.LENGTH_SHORT).show()
}
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
Toast.makeText(this@SettingsActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
}
}
}
}
private fun updateDeviceInfo(device: com.example.defenseapplication.bean.DeviceBean) {
binding.tvDeviceName.text = device.deviceName ?: "未设置"
binding.tvWifiName.text = device.wifiName ?: "未设置"
val serverMode = device.patternPerception
val cacheMode = getCachedRecognitionMode()
binding.tvRecognitionMode.text = when {
!serverMode.isNullOrEmpty() -> {
val displayMode = when (serverMode) {
"0" -> getString(R.string.bluetooth_recognition)
"1" -> getString(R.string.bluetooth_face_recognition)
else -> serverMode
}
saveRecognitionMode(displayMode)
displayMode
}
!cacheMode.isNullOrEmpty() -> cacheMode
else -> getString(R.string.bluetooth_recognition)
}
}
private fun getCachedRecognitionMode(): String? {
val sp = getSharedPreferences("DeviceSettings", Context.MODE_PRIVATE)
return sp.getString("recognition_mode", null)
}
private fun saveRecognitionMode(mode: String) {
val sp = getSharedPreferences("DeviceSettings", Context.MODE_PRIVATE)
sp.edit().putString("recognition_mode", mode).apply()
}
private fun updateDeviceName(name: String) {
val deviceId = DeviceIdEvent.getDeviceId()
if (deviceId.isNullOrEmpty()) {
Toast.makeText(this, "设备ID为空", Toast.LENGTH_SHORT).show()
return
}
CoroutineScope(Dispatchers.IO).launch {
try {
val deviceBean = com.example.defenseapplication.bean.DeviceBean(
id = deviceId,
deviceName = name,
)
val response = RetrofitNetwork.getNetworkService().updateDeviceInfo(deviceBean)
withContext(Dispatchers.Main) {
if (response.code == 200) {
binding.tvDeviceName.text = name
Toast.makeText(this@SettingsActivity, "修改成功", Toast.LENGTH_SHORT).show()
DeviceUpdateEvent.notifyDeviceUpdated(deviceId)
} else {
Toast.makeText(this@SettingsActivity, response.msg, Toast.LENGTH_SHORT).show()
}
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
Toast.makeText(this@SettingsActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
}
}
}
}
private fun updateRecognitionMode(mode: String) {
val deviceId = DeviceIdEvent.getDeviceId()
if (deviceId.isNullOrEmpty()) {
Toast.makeText(this, "设备ID为空", Toast.LENGTH_SHORT).show()
return
}
val patternPerception = when (mode) {
getString(R.string.bluetooth_recognition) -> "0"
getString(R.string.bluetooth_face_recognition) -> "1"
else -> "0"
}
CoroutineScope(Dispatchers.IO).launch {
try {
val deviceBean = com.example.defenseapplication.bean.DeviceBean(
id = deviceId,
patternPerception = patternPerception,
)
val response = RetrofitNetwork.getNetworkService().updateDeviceInfo(deviceBean)
withContext(Dispatchers.Main) {
if (response.code == 200) {
binding.tvRecognitionMode.text = mode
saveRecognitionMode(mode)
Toast.makeText(this@SettingsActivity, "修改成功", Toast.LENGTH_SHORT).show()
DeviceUpdateEvent.notifyDeviceUpdated(deviceId)
} else {
Toast.makeText(this@SettingsActivity, response.msg, Toast.LENGTH_SHORT).show()
}
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
Toast.makeText(this@SettingsActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
}
}
}
} }
} }

View File

@@ -63,7 +63,7 @@ interface ApiService {
suspend fun getMessage(): GetCodeBean<List<MessageGroup>> suspend fun getMessage(): GetCodeBean<List<MessageGroup>>
/** /**
* 获取设备信息 * 修改设备信息
*/ */
@PUT("/app/updateDeviceInfo") @PUT("/app/updateDeviceInfo")
suspend fun updateDeviceInfo(@Body deviceBean: DeviceBean): GetCodeBean<DeviceBean> suspend fun updateDeviceInfo(@Body deviceBean: DeviceBean): GetCodeBean<DeviceBean>

View File

@@ -0,0 +1,23 @@
package com.example.defenseapplication.utils
object DeviceUpdateEvent {
private val listeners = mutableListOf<DeviceUpdateListener>()
interface DeviceUpdateListener {
fun onDeviceUpdated(deviceId: String)
}
fun addListener(listener: DeviceUpdateListener) {
if (!listeners.contains(listener)) {
listeners.add(listener)
}
}
fun removeListener(listener: DeviceUpdateListener) {
listeners.remove(listener)
}
fun notifyDeviceUpdated(deviceId: String) {
listeners.forEach { it.onDeviceUpdated(deviceId) }
}
}

View File

@@ -7,13 +7,19 @@ import android.view.Gravity
import android.view.WindowManager import android.view.WindowManager
import com.example.defenseapplication.R import com.example.defenseapplication.R
import com.example.defenseapplication.databinding.DialogAutoModeNoticeBinding import com.example.defenseapplication.databinding.DialogAutoModeNoticeBinding
import java.util.Calendar
class AutoModeNoticeDialog(context: Context) : Dialog(context) { class AutoModeNoticeDialog(context: Context) : Dialog(context) {
private lateinit var binding: DialogAutoModeNoticeBinding private lateinit var binding: DialogAutoModeNoticeBinding
private var onConfirmListener: (() -> Unit)? = null private var onConfirmListener: ((year: Int, month: Int, day: Int, hour: Int, minute: Int) -> Unit)? = null
private var selectedYear = 0
private var selectedMonth = 0
private var selectedDay = 0
private var selectedHour = 0
private var selectedMinute = 0
fun setOnConfirmListener(listener: () -> Unit) { fun setOnConfirmListener(listener: (year: Int, month: Int, day: Int, hour: Int, minute: Int) -> Unit) {
this.onConfirmListener = listener this.onConfirmListener = listener
} }
@@ -32,9 +38,29 @@ class AutoModeNoticeDialog(context: Context) : Dialog(context) {
it.setBackgroundDrawableResource(R.drawable.round_bg) it.setBackgroundDrawableResource(R.drawable.round_bg)
} }
val calendar = Calendar.getInstance()
selectedYear = calendar.get(Calendar.YEAR)
selectedMonth = calendar.get(Calendar.MONTH)
selectedDay = calendar.get(Calendar.DAY_OF_MONTH)
selectedHour = calendar.get(Calendar.HOUR_OF_DAY)
selectedMinute = calendar.get(Calendar.MINUTE)
updateDateDisplay()
updateTimeDisplay()
binding.btnConfirm.setOnClickListener { binding.btnConfirm.setOnClickListener {
onConfirmListener?.invoke() onConfirmListener?.invoke(selectedYear, selectedMonth, selectedDay, selectedHour, selectedMinute)
dismiss() dismiss()
} }
} }
private fun updateDateDisplay() {
}
private fun updateTimeDisplay() {
}
} }

View File

@@ -42,6 +42,7 @@
android:background="@color/face" /> android:background="@color/face" />
<LinearLayout <LinearLayout
android:gravity="center_vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/white" android:background="@color/white"
@@ -52,63 +53,43 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/auto_mode_title" android:text="@string/auto_mode_title"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="16dp" /> android:textSize="16dp" />
<LinearLayout <RadioGroup
android:id="@+id/itemAutoMode" android:id="@+id/rgAutoMode"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:background="@drawable/bg_bottom_sheet_rounded"
android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<android.widget.RadioButton <android.widget.RadioButton
android:id="@+id/rbAutoMode" android:id="@+id/rbAutoMode"
android:layout_width="18dp" android:layout_width="0dp"
android:layout_height="18dp"
android:button="@drawable/radio_button_selector"
android:checked="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_weight="1"
android:background="@drawable/bg_bottom_sheet_rounded"
android:button="@drawable/radio_button_selector"
android:checked="true"
android:layout_marginStart="4dp"
android:gravity="center"
android:text="@string/full_auto_mode" android:text="@string/full_auto_mode"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="14sp" /> android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/itemSemiAutoMode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:background="@drawable/bg_bottom_sheet_rounded"
android:gravity="center"
android:orientation="horizontal">
<android.widget.RadioButton <android.widget.RadioButton
android:id="@+id/rbSemiAutoMode" android:id="@+id/rbSemiAutoMode"
android:layout_width="18dp" android:layout_width="0dp"
android:layout_height="18dp"
android:button="@drawable/radio_button_selector" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_weight="1"
android:background="@drawable/bg_bottom_sheet_rounded"
android:button="@drawable/radio_button_selector"
android:gravity="center"
android:text="@string/semi_auto_mode" android:text="@string/semi_auto_mode"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="14sp" /> android:textSize="14sp" />
</LinearLayout>
</RadioGroup>
</LinearLayout> </LinearLayout>
@@ -117,6 +98,11 @@
android:layout_height="10dp" android:layout_height="10dp"
android:background="@color/face" /> android:background="@color/face" />
<LinearLayout
android:id="@+id/time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout <LinearLayout
android:id="@+id/itemStartTime" android:id="@+id/itemStartTime"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -200,5 +186,7 @@
android:src="@drawable/right_back" /> android:src="@drawable/right_back" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@@ -176,6 +176,7 @@
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
android:id="@+id/tvAutoMode"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/mode_standard" android:text="@string/mode_standard"
@@ -346,6 +347,7 @@
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
android:id="@+id/tvWifiName"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/wifi" android:text="@string/wifi"