修改识别模式
This commit is contained in:
2
.idea/deploymentTargetSelector.xml
generated
2
.idea/deploymentTargetSelector.xml
generated
@@ -4,7 +4,7 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<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">
|
||||
<handle>
|
||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=80bece4" />
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
package com.example.defenseapplication.bean
|
||||
|
||||
data class DeviceBean(
|
||||
val alertAudio: String,
|
||||
val audioContet: Any,
|
||||
val container: Any,
|
||||
val countNum: Any,
|
||||
val deviceEm: String,
|
||||
val deviceFamilyId: String,
|
||||
val deviceImg: Any,
|
||||
val deviceName: String,
|
||||
val deviceNo: String,
|
||||
val deviceSn: String,
|
||||
val endTime: Any,
|
||||
val expirationTime: String,
|
||||
val fwVer: String,
|
||||
val id: String,
|
||||
val light: String,
|
||||
val patternPerception: Any,
|
||||
val startTime: Any,
|
||||
val status: String,
|
||||
val strikeInterval: Any,
|
||||
val strikePosition: Any,
|
||||
val strikeRange: Any,
|
||||
val userId: String,
|
||||
val wifiName: String,
|
||||
val wifiPassword: String,
|
||||
val workMode: String
|
||||
val alertAudio: String? = null,//告警播放
|
||||
val audioContet: String? = null,//告警内容
|
||||
val container: String? = null,//容器数量
|
||||
val countNum: String? = null,
|
||||
val deviceEm: String? = null,//设备型号
|
||||
val deviceFamilyId: String? = null,
|
||||
val deviceImg: String? = null,
|
||||
val deviceName: String? = null,//设备名称
|
||||
val deviceNo: String? = null,//设备编号
|
||||
val deviceSn: String? = null,//设备序列号
|
||||
val endTime: String? = null,//自动布放结束时间
|
||||
val expirationTime: String? = null,
|
||||
val fwVer: String? = null,//固件版本
|
||||
val id: String? = null,
|
||||
val light: String? = null,//强光开启
|
||||
val patternPerception: String? = null,//识别模式
|
||||
val startTime: String? = null,//自动布放开始时间
|
||||
val status: String? = null,//状态 1-在线 0-离线 2-故障 3-到期
|
||||
val strikeInterval: String? = null,//打击间隔
|
||||
val strikePosition: String? = null,//打击位置
|
||||
val strikeRange: String? = null,//打击距离
|
||||
val userId: String? = null,
|
||||
val wifiName: String? = null,//WiFi名称
|
||||
val wifiPassword: String? = null,//WiFi密码
|
||||
val workMode: String? = null,//工作模式 0-自动 1-半自动
|
||||
val optionPassword: String? = null, //操作密码
|
||||
)
|
||||
@@ -30,6 +30,7 @@ import com.example.defenseapplication.bean.FamilyBean
|
||||
import com.example.defenseapplication.bean.SwitchFamilyRequest
|
||||
import com.example.defenseapplication.databinding.HomeMenuFragmentBinding
|
||||
import com.example.defenseapplication.utils.DeviceIdEvent
|
||||
import com.example.defenseapplication.utils.DeviceUpdateEvent
|
||||
import com.example.defenseapplication.utils.FamilySwitchEvent
|
||||
import com.example.defenseapplication.utils.MessageStatusManager
|
||||
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) {
|
||||
val familyBean = familyBeanList.find { it.parentName == familyName }
|
||||
val isAdmin = familyBean?.role == "appadmin"
|
||||
@@ -212,6 +219,7 @@ class HomeMenuFragment : Fragment() {
|
||||
|
||||
MessageStatusManager.addListener(unreadCountChangeListener)
|
||||
FamilySwitchEvent.addListener(familySwitchListener)
|
||||
DeviceUpdateEvent.addListener(deviceUpdateListener)
|
||||
updateUnreadCountUI(MessageStatusManager.getUnreadCount())
|
||||
}
|
||||
|
||||
@@ -448,7 +456,7 @@ class HomeMenuFragment : Fragment() {
|
||||
|
||||
private fun updateDeviceList() {
|
||||
val deviceUiList = deviceBeanList.map {
|
||||
DeviceUi(it.deviceName, it.status, it.id)
|
||||
DeviceUi(it.deviceName ?: "", it.status ?: "", it.id ?: "")
|
||||
}
|
||||
|
||||
if (deviceUiList.isEmpty()) {
|
||||
@@ -518,6 +526,7 @@ class HomeMenuFragment : Fragment() {
|
||||
binding.rvDeviceList.adapter = null
|
||||
MessageStatusManager.removeListener(unreadCountChangeListener)
|
||||
FamilySwitchEvent.removeListener(familySwitchListener)
|
||||
DeviceUpdateEvent.removeListener(deviceUpdateListener)
|
||||
_binding = null // 避免内存泄漏
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,38 @@
|
||||
package com.example.defenseapplication.liveVideo
|
||||
|
||||
import TimePickerFragment
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.defenseapplication.R
|
||||
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.gyf.immersionbar.ImmersionBar
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.Calendar
|
||||
//自动模式
|
||||
class AutoModeActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: AutoModeActivityBinding
|
||||
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?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = AutoModeActivityBinding.inflate(layoutInflater)
|
||||
@@ -22,8 +43,15 @@ class AutoModeActivity : AppCompatActivity() {
|
||||
.titleBar(binding.topBar)
|
||||
.init()
|
||||
|
||||
calendar = Calendar.getInstance()
|
||||
selectedYear = calendar.get(Calendar.YEAR)
|
||||
selectedMonth = calendar.get(Calendar.MONTH)
|
||||
selectedDay = calendar.get(Calendar.DAY_OF_MONTH)
|
||||
|
||||
initListener()
|
||||
|
||||
loadCurrentSettings()
|
||||
|
||||
showAutoModeNoticeDialog()
|
||||
}
|
||||
|
||||
@@ -32,43 +60,195 @@ class AutoModeActivity : AppCompatActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
binding.rbAutoMode.setOnClickListener {
|
||||
binding.rbSemiAutoMode.isChecked = false
|
||||
showAutoModeNoticeDialog()
|
||||
binding.rbAutoMode.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
selectedMode = "0"
|
||||
showAutoModeNoticeDialog()
|
||||
binding.time.visibility = android.view.View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
binding.rbSemiAutoMode.setOnClickListener {
|
||||
binding.rbAutoMode.isChecked = false
|
||||
binding.rbSemiAutoMode.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
selectedMode = "1"
|
||||
binding.time.visibility = android.view.View.GONE
|
||||
}
|
||||
}
|
||||
// 起始时间选择
|
||||
|
||||
binding.itemStartTime.setOnClickListener {
|
||||
showTimePicker { hour, minute ->
|
||||
val startTimeStr = String.format("%02d:%02d", hour, minute)
|
||||
showDateTimePicker { year, month, day, 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.itemEndTime.setOnClickListener {
|
||||
showTimePicker { hour, minute ->
|
||||
val endTimeStr = String.format("%02d:%02d", hour, minute)
|
||||
showDateTimePicker { year, month, day, 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
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 显示时间选择器对话框
|
||||
* @param onTimeSelected 时间选择回调,参数为小时和分钟
|
||||
*/
|
||||
|
||||
private fun loadCurrentSettings() {
|
||||
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) {
|
||||
val timePickerFragment = TimePickerFragment { hour, minute ->
|
||||
onTimeSelected(hour, minute)
|
||||
}
|
||||
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() {
|
||||
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()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ class DeviceInfoActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
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() ?: "自动布防结束时间"
|
||||
binding.tvDeviceModelValue.text = device.deviceNo.toString()
|
||||
binding.tvDeviceNoValue.text = device.deviceSn.toString()
|
||||
binding.tvFwVersionValue.text = device.fwVer.toString()
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,30 @@
|
||||
package com.example.defenseapplication.liveVideo
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.base.BaseActivity
|
||||
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.RetrofitNetwork
|
||||
import com.example.defenseapplication.view.CustomDialogFragmentText
|
||||
import com.example.defenseapplication.view.LanguageDialog
|
||||
import com.example.defenseapplication.view.RecognitionModeDialog
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
//设置页面
|
||||
class SettingsActivity : BaseActivity() {
|
||||
|
||||
private lateinit var binding: SettingsActivityBinding
|
||||
private val SP_NAME = "DeviceSettings"
|
||||
private val KEY_RECOGNITION_MODE = "recognition_mode"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -35,7 +46,7 @@ class SettingsActivity : BaseActivity() {
|
||||
binding.itemRecognitionMode.setOnClickListener {
|
||||
val dialog = RecognitionModeDialog(this)
|
||||
dialog.setOnConfirmListener { mode ->
|
||||
binding.tvRecognitionMode.text = mode
|
||||
updateRecognitionMode(mode)
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
@@ -45,7 +56,7 @@ class SettingsActivity : BaseActivity() {
|
||||
.setTitle(getString(R.string.device_name))
|
||||
.setInputText(binding.tvDeviceName.text.toString())
|
||||
dialog.setOnConfirmListener { name ->
|
||||
binding.tvDeviceName.text = name
|
||||
updateDeviceName(name)
|
||||
}
|
||||
dialog.show(supportFragmentManager, "CustomDialogFragment")
|
||||
}
|
||||
@@ -84,6 +95,136 @@ class SettingsActivity : BaseActivity() {
|
||||
val intent = Intent(this, WiFiManagementActivity::class.java)
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ interface ApiService {
|
||||
suspend fun getMessage(): GetCodeBean<List<MessageGroup>>
|
||||
|
||||
/**
|
||||
* 获取设备信息
|
||||
* 修改设备信息
|
||||
*/
|
||||
@PUT("/app/updateDeviceInfo")
|
||||
suspend fun updateDeviceInfo(@Body deviceBean: DeviceBean): GetCodeBean<DeviceBean>
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,19 @@ import android.view.Gravity
|
||||
import android.view.WindowManager
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.databinding.DialogAutoModeNoticeBinding
|
||||
import java.util.Calendar
|
||||
|
||||
class AutoModeNoticeDialog(context: Context) : Dialog(context) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -32,9 +38,29 @@ class AutoModeNoticeDialog(context: Context) : Dialog(context) {
|
||||
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 {
|
||||
onConfirmListener?.invoke()
|
||||
onConfirmListener?.invoke(selectedYear, selectedMonth, selectedDay, selectedHour, selectedMinute)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDateDisplay() {
|
||||
|
||||
}
|
||||
|
||||
private fun updateTimeDisplay() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@
|
||||
android:background="@color/face" />
|
||||
|
||||
<LinearLayout
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white"
|
||||
@@ -52,63 +53,43 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="@string/auto_mode_title"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/itemAutoMode"
|
||||
<RadioGroup
|
||||
android:id="@+id/rgAutoMode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<android.widget.RadioButton
|
||||
android:id="@+id/rbAutoMode"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="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:orientation="horizontal">
|
||||
android:text="@string/full_auto_mode"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<android.widget.RadioButton
|
||||
android:id="@+id/rbAutoMode"
|
||||
android:layout_width="18dp"
|
||||
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_marginStart="8dp"
|
||||
android:text="@string/full_auto_mode"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/itemSemiAutoMode"
|
||||
<android.widget.RadioButton
|
||||
android:id="@+id/rbSemiAutoMode"
|
||||
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:button="@drawable/radio_button_selector"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<android.widget.RadioButton
|
||||
android:id="@+id/rbSemiAutoMode"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:button="@drawable/radio_button_selector" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="@string/semi_auto_mode"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
android:text="@string/semi_auto_mode"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -118,87 +99,94 @@
|
||||
android:background="@color/face" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/itemStartTime"
|
||||
android:id="@+id/time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="@color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/auto_defense_start_time"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16dp" />
|
||||
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/itemStartTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="@color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvStartTime"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/auto_defense_start_time"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="21:30"
|
||||
android:textColor="@color/gray"
|
||||
android:textSize="14sp" />
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:src="@drawable/right_back" />
|
||||
<TextView
|
||||
android:id="@+id/tvStartTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="21:30"
|
||||
android:textColor="@color/gray"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:src="@drawable/right_back" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_marginStart="16dp"
|
||||
android:background="@color/face" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/itemEndTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="@color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/auto_defense_end_time"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvEndTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="08:30"
|
||||
android:textColor="@color/gray"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:src="@drawable/right_back" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_marginStart="16dp"
|
||||
android:background="@color/face" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/itemEndTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="@color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/auto_defense_end_time"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvEndTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="08:30"
|
||||
android:textColor="@color/gray"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:src="@drawable/right_back" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -176,6 +176,7 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAutoMode"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/mode_standard"
|
||||
@@ -346,6 +347,7 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvWifiName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/wifi"
|
||||
|
||||
Reference in New Issue
Block a user