Skip to content

Commit

Permalink
Update on VoiceBroadcast currentRecordingState creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Loriaux committed Nov 23, 2022
1 parent 341b9bd commit 61073ed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ struct VoiceBroadcastRecorderView: View {
Image(uiImage: Asset.Images.voiceBroadcastTileLive.image)
}

if let remainingTimeLabel = viewModel.viewState.currentRecordingState.remainingTimeLabel {
Label {
Text(remainingTimeLabel)
.foregroundColor(theme.colors.secondaryContent)
.font(theme.fonts.caption1)
} icon: {
Image(uiImage: Asset.Images.voiceBroadcastTimeLeft.image)
}
Label {
Text(viewModel.viewState.currentRecordingState.remainingTimeLabel)
.foregroundColor(theme.colors.secondaryContent)
.font(theme.fonts.caption1)
} icon: {
Image(uiImage: Asset.Images.voiceBroadcastTimeLeft.image)
}
}.frame(maxWidth: .infinity, alignment: .leading)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct VoiceBroadcastRecorderDetails {

struct VoiceBroadcastRecordingState {
var remainingTime: UInt
var remainingTimeLabel: String?
var remainingTimeLabel: String
}

struct VoiceBroadcastRecorderViewState: BindableState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum MockVoiceBroadcastRecorderScreenState: MockScreenState, CaseIterable {

var screenView: ([Any], AnyView) {
let details = VoiceBroadcastRecorderDetails(senderDisplayName: "", avatarData: AvatarInput(mxContentUri: "", matrixItemId: "!fakeroomid:matrix.org", displayName: "The name of the room"))
let recordingState = VoiceBroadcastRecordingState(remainingTime: BuildSettings.voiceBroadcastMaxLength)
let recordingState = VoiceBroadcastRecordingState(remainingTime: BuildSettings.voiceBroadcastMaxLength, remainingTimeLabel: "1h 20m 47s left")
let viewModel = MockVoiceBroadcastRecorderViewModel(initialViewState: VoiceBroadcastRecorderViewState(details: details, recordingState: .started, currentRecordingState: recordingState, bindings: VoiceBroadcastRecorderViewStateBindings()))

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class VoiceBroadcastRecorderViewModel: VoiceBroadcastRecorderViewModelType, Voic
init(details: VoiceBroadcastRecorderDetails,
recorderService: VoiceBroadcastRecorderServiceProtocol) {
self.voiceBroadcastRecorderService = recorderService
let currentRecordingState = VoiceBroadcastRecordingState(remainingTime: BuildSettings.voiceBroadcastMaxLength)
let currentRecordingState = VoiceBroadcastRecorderViewModel.currentRecordingState(from: BuildSettings.voiceBroadcastMaxLength)
super.init(initialViewState: VoiceBroadcastRecorderViewState(details: details,
recordingState: .stopped,
currentRecordingState: currentRecordingState,
Expand Down Expand Up @@ -81,12 +81,16 @@ class VoiceBroadcastRecorderViewModel: VoiceBroadcastRecorderViewModelType, Voic
}

private func updateRemainingTime(_ remainingTime: UInt) {
state.currentRecordingState = VoiceBroadcastRecorderViewModel.currentRecordingState(from: remainingTime)
}

private static func currentRecordingState(from remainingTime: UInt) -> VoiceBroadcastRecordingState {
let time = TimeInterval(Double(remainingTime))
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .abbreviated
state.currentRecordingState.remainingTime = remainingTime
state.currentRecordingState.remainingTimeLabel = VectorL10n.voiceBroadcastTimeLeft(formatter.string(from: time) ?? "0s")

return VoiceBroadcastRecordingState(remainingTime: remainingTime,
remainingTimeLabel: VectorL10n.voiceBroadcastTimeLeft(formatter.string(from: time) ?? "0s"))
}
}

Expand Down

0 comments on commit 61073ed

Please sign in to comment.