Skip to content

Commit

Permalink
edit record timer
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Jul 4, 2024
1 parent 3c18dc9 commit d70b9c0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
13 changes: 10 additions & 3 deletions AudioCuesheetEditor/Model/Entity/Validateable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ public abstract class Validateable<T> : IValidateable<T>

public ValidationResult Validate<TProperty>(Expression<Func<T, TProperty>> expression)
{
if (expression.Body is not MemberExpression body)
if (expression.Body is MemberExpression memberExpression)
{
throw new ArgumentException("'expression' should be a member expression");
return Validate(memberExpression.Member.Name);
}
else if (expression.Body is UnaryExpression unaryExpression && unaryExpression.Operand is MemberExpression unaryMemberExpression)
{
return Validate(unaryMemberExpression.Member.Name);
}
else
{
throw new ArgumentException("The provided expression does not reference a valid property.");
}
return Validate(body.Member.Name);
}

public ValidationResult Validate()
Expand Down
59 changes: 44 additions & 15 deletions AudioCuesheetEditor/Pages/RecordControl.razor
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ along with Foobar. If not, see
<ModalBody>
<Field Horizontal>
<FieldLabel ColumnSize="ColumnSize.Is5.OnWidescreen.Is12.OnDesktop">@_localizer["Seconds till record starts"]</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is7.OnWidescreen.Is12.OnDesktop"><NumericEdit TValue="uint" Min="1" /></FieldBody>
<FieldBody ColumnSize="ColumnSize.Is7.OnWidescreen.Is12.OnDesktop">
<NumericEdit TValue="uint" Min="1" @bind-Value="recordCountdownTimer" />
</FieldBody>
</Field>
</ModalBody>
<ModalFooter>
Expand All @@ -100,13 +102,15 @@ along with Foobar. If not, see
</Modal>

@code {
//TODO: Allow the user to edit the default RecordCountdownTimer
//TODO: Allow the user to stop the record countdown
//TODO: Keyboard enter for modal
Timer updateGUITimer = new Timer(300);
Timer? startRecordTimer;
DateTime recordTimerStarted;

RecordOptions? recordOptions;
uint recordCountdownTimer;

ModalDialog? modalDialog;
Modal? modalInputCountdownTime;

Expand All @@ -120,14 +124,19 @@ along with Foobar. If not, see
{
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_sessionStateContainer.CuesheetChanged -= SessionStateContainer_CuesheetChanged;
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionsSaved;
}

protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
base.OnInitialized();
await base.OnInitializedAsync();

recordOptions = await _localStorageOptionsProvider.GetOptions<RecordOptions>();
ReadOutOptions();

_localizationService.LocalizationChanged += LocalizationService_LocalizationChanged;
_sessionStateContainer.CuesheetChanged += SessionStateContainer_CuesheetChanged;
_localStorageOptionsProvider.OptionSaved += LocalStorageOptionsProvider_OptionsSaved;

InitializeUIUpdate();
}
Expand All @@ -138,7 +147,12 @@ along with Foobar. If not, see
updateGUITimer.Elapsed += delegate
{
StateHasChanged();
if (_sessionStateContainer.Cuesheet.IsRecording == false)
Boolean startRecordTimeEnabled = false;
if (startRecordTimer != null)
{
startRecordTimeEnabled = startRecordTimer.Enabled;
}
if ((startRecordTimeEnabled == false) && (_sessionStateContainer.Cuesheet.IsRecording == false))
{
updateGUITimer.Stop();
}
Expand Down Expand Up @@ -213,16 +227,14 @@ along with Foobar. If not, see
async Task StartRecordCountdownTimer()
{
recordTimerStarted = DateTime.Now;
//TODO: Save input of modal to record options
//TODO: Create timer with input of modal
// var recordOptions = await _localStorageOptionsProvider.GetOptions<RecordOptions>();
// startRecordTimer = new Timer(recordOptions.RecordCountdownTimer * 1000);
// startRecordTimer.Elapsed += async delegate
// {
// await StartRecordingClicked();
// startRecordTimer.Stop();
// };
// startRecordTimer?.Start();
startRecordTimer = new Timer(recordCountdownTimer * 1000);
startRecordTimer.Elapsed += async delegate
{
await StartRecordingClicked();
startRecordTimer.Stop();
};
startRecordTimer.Start();
await _localStorageOptionsProvider.SaveOptionsValue<RecordOptions>(x => x.RecordCountdownTimer, recordCountdownTimer);
updateGUITimer.Start();
await HideCountdownModal();
}
Expand All @@ -233,4 +245,21 @@ along with Foobar. If not, see
_sessionStateContainer.Cuesheet.StopRecording(options);
await StopRecordClicked.InvokeAsync();
}

void LocalStorageOptionsProvider_OptionsSaved(object? sender, IOptions options)
{
if (options is RecordOptions recordingOptions)
{
recordOptions = recordingOptions;
ReadOutOptions();
}
}

void ReadOutOptions()
{
if (recordOptions != null)
{
recordCountdownTimer = recordOptions.RecordCountdownTimer;
}
}
}

0 comments on commit d70b9c0

Please sign in to comment.