调整
This commit is contained in:
@@ -121,6 +121,9 @@ fun CallLogScreen(
|
||||
else -> null
|
||||
}
|
||||
viewModel.loadCallRecords(range, request)
|
||||
},
|
||||
onScanAudio = {
|
||||
viewModel.scanAllAudio()
|
||||
}
|
||||
)
|
||||
},
|
||||
@@ -305,16 +308,22 @@ fun CallLogContent(
|
||||
@Composable
|
||||
fun CallLogTopBar(
|
||||
selectedTimeRange: String,
|
||||
onTimeRangeSelected: (String) -> Unit
|
||||
onTimeRangeSelected: (String) -> Unit,
|
||||
onScanAudio: () -> Unit = {}
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val timeRanges = listOf("全部", "今天", "本周", "本月")
|
||||
|
||||
CenterAlignedTopAppBar(
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text("通话记录", fontWeight = FontWeight.Bold)
|
||||
},
|
||||
actions = {
|
||||
Box {
|
||||
TextButton(onClick = onScanAudio) {
|
||||
Text("扫描录音")
|
||||
}
|
||||
}
|
||||
Box {
|
||||
TextButton(onClick = { expanded = true }) {
|
||||
Text(selectedTimeRange)
|
||||
|
||||
@@ -13,7 +13,8 @@ import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import java.time.LocalDateTime
|
||||
|
||||
class CallLogViewModel(private val callLogRepository: CallLogRepository = CallLogRepository()
|
||||
class CallLogViewModel(
|
||||
private val callLogRepository: CallLogRepository = CallLogRepository()
|
||||
) : ViewModel() {
|
||||
|
||||
private val _callRecords = MutableStateFlow<List<CallRecord>>(emptyList())
|
||||
@@ -28,75 +29,77 @@ import java.time.LocalDateTime
|
||||
private val _selectedTimeRange = MutableStateFlow("全部")
|
||||
val selectedTimeRange: StateFlow<String> = _selectedTimeRange.asStateFlow()
|
||||
|
||||
// 新增:音频播放相关状态
|
||||
private val _currentlyPlayingAudio = MutableStateFlow<String?>(null)
|
||||
val currentlyPlayingAudio: StateFlow<String?> = _currentlyPlayingAudio.asStateFlow()
|
||||
// 新增:音频播放相关状态
|
||||
private val _currentlyPlayingAudio = MutableStateFlow<String?>(null)
|
||||
val currentlyPlayingAudio: StateFlow<String?> = _currentlyPlayingAudio.asStateFlow()
|
||||
|
||||
private val _playbackError = MutableStateFlow<String?>(null)
|
||||
val playbackError: StateFlow<String?> = _playbackError.asStateFlow()
|
||||
/**
|
||||
* 播放音频
|
||||
*/
|
||||
fun playAudio(audioUrl: String) {
|
||||
_playbackError.value = null
|
||||
private val _playbackError = MutableStateFlow<String?>(null)
|
||||
val playbackError: StateFlow<String?> = _playbackError.asStateFlow()
|
||||
|
||||
// 如果正在播放同一个音频,则停止播放
|
||||
if (AudioPlayManager.isPlaying(audioUrl)) {
|
||||
stopAudio()
|
||||
return
|
||||
}
|
||||
/**
|
||||
* 播放音频
|
||||
*/
|
||||
fun playAudio(audioUrl: String) {
|
||||
_playbackError.value = null
|
||||
|
||||
AudioPlayManager.playAudio(
|
||||
audioUrl = audioUrl,
|
||||
onStart = {
|
||||
_currentlyPlayingAudio.value = audioUrl
|
||||
},
|
||||
onCompletion = {
|
||||
_currentlyPlayingAudio.value = null
|
||||
},
|
||||
onError = { error ->
|
||||
_playbackError.value = error
|
||||
_currentlyPlayingAudio.value = null
|
||||
}
|
||||
)
|
||||
}
|
||||
// 如果正在播放同一个音频,则停止播放
|
||||
if (AudioPlayManager.isPlaying(audioUrl)) {
|
||||
stopAudio()
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止音频播放
|
||||
*/
|
||||
fun stopAudio() {
|
||||
AudioPlayManager.stopAudio()
|
||||
_currentlyPlayingAudio.value = null
|
||||
_playbackError.value = null
|
||||
}
|
||||
AudioPlayManager.playAudio(
|
||||
audioUrl = audioUrl,
|
||||
onStart = {
|
||||
_currentlyPlayingAudio.value = audioUrl
|
||||
},
|
||||
onCompletion = {
|
||||
_currentlyPlayingAudio.value = null
|
||||
},
|
||||
onError = { error ->
|
||||
_playbackError.value = error
|
||||
_currentlyPlayingAudio.value = null
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停音频播放
|
||||
*/
|
||||
fun pauseAudio() {
|
||||
AudioPlayManager.pauseAudio()
|
||||
_currentlyPlayingAudio.value = null
|
||||
}
|
||||
/**
|
||||
* 停止音频播放
|
||||
*/
|
||||
fun stopAudio() {
|
||||
AudioPlayManager.stopAudio()
|
||||
_currentlyPlayingAudio.value = null
|
||||
_playbackError.value = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否正在播放指定音频
|
||||
*/
|
||||
fun isAudioPlaying(audioUrl: String): Boolean {
|
||||
return AudioPlayManager.isPlaying(audioUrl)
|
||||
}
|
||||
/**
|
||||
* 暂停音频播放
|
||||
*/
|
||||
fun pauseAudio() {
|
||||
AudioPlayManager.pauseAudio()
|
||||
_currentlyPlayingAudio.value = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除播放错误
|
||||
*/
|
||||
fun clearPlaybackError() {
|
||||
_playbackError.value = null
|
||||
}
|
||||
/**
|
||||
* 检查是否正在播放指定音频
|
||||
*/
|
||||
fun isAudioPlaying(audioUrl: String): Boolean {
|
||||
return AudioPlayManager.isPlaying(audioUrl)
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除播放错误
|
||||
*/
|
||||
fun clearPlaybackError() {
|
||||
_playbackError.value = null
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
// 清理资源
|
||||
AudioPlayManager.stopAudio()
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
// 清理资源
|
||||
AudioPlayManager.stopAudio()
|
||||
}
|
||||
/**
|
||||
* 加载通话记录
|
||||
* @param timeRange 时间范围描述,用于UI显示
|
||||
@@ -137,4 +140,8 @@ import java.time.LocalDateTime
|
||||
fun clearError() {
|
||||
_errorMessage.value = null
|
||||
}
|
||||
|
||||
fun scanAllAudio() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -101,10 +101,10 @@ fun HomeScreen(
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(
|
||||
text = when (webSocketStatus) {
|
||||
WebSocketService.WebSocketStatus.CONNECTED -> "WebSocket 已连接"
|
||||
WebSocketService.WebSocketStatus.CONNECTING -> "WebSocket 连接中"
|
||||
WebSocketService.WebSocketStatus.DISCONNECTED -> "WebSocket 未连接"
|
||||
WebSocketService.WebSocketStatus.ERROR -> "WebSocket 连接错误"
|
||||
WebSocketService.WebSocketStatus.CONNECTED -> "快捷拨号服务 已连接"
|
||||
WebSocketService.WebSocketStatus.CONNECTING -> "快捷拨号服务 连接中"
|
||||
WebSocketService.WebSocketStatus.DISCONNECTED -> "快捷拨号服务 未连接"
|
||||
WebSocketService.WebSocketStatus.ERROR -> "快捷拨号服务 连接错误"
|
||||
},
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
@@ -140,7 +140,7 @@ fun HomeScreen(
|
||||
text = when (webSocketStatus) {
|
||||
WebSocketService.WebSocketStatus.CONNECTED -> "连接正常"
|
||||
WebSocketService.WebSocketStatus.CONNECTING -> "连接中..."
|
||||
else -> "重连 WebSocket"
|
||||
else -> "重连 快捷拨号服务"
|
||||
},
|
||||
fontSize = 14.sp
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user