Skip to content

Commit

Permalink
Fix recognition api state issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Soapwood committed Apr 4, 2024
1 parent 063752e commit 89f5eed
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
5 changes: 4 additions & 1 deletion VXMusic/Recognition/AudD/AudDClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public void SetDefaultApiKey()

public async Task<bool> TestApiConnection()
{
return await _audDHttpClient.TestConnection();
_logger.LogTrace("Testing AudD API Connection");
bool testConnectionResult = await _audDHttpClient.TestConnection();
_logger.LogTrace(testConnectionResult ? "Connected!" : "Connection Failed.");
return testConnectionResult;
}
}
5 changes: 4 additions & 1 deletion VXMusic/Recognition/Shazam/ShazamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public void SetDefaultApiKey()

public async Task<bool> TestApiConnection()
{
return await _shazamHttpClient.TestConnection();
_logger.LogTrace("Testing Shazam API Connection");
bool testConnectionResult = await _shazamHttpClient.TestConnection();
_logger.LogTrace(testConnectionResult ? "Connected!" : "Connection Failed.");
return testConnectionResult;
}

public async Task<IRecognitionApiClientResponse> RunRecognition()
Expand Down
6 changes: 4 additions & 2 deletions VXMusicDesktop/MVVM/View/RecognitionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@

<!-- BYOAPI -->
<CheckBox x:Name="ShazamByoApiCheckBox"
Content="BYOAPI Key"
Content="Enable BYOAPI"
IsChecked="{Binding IsShazamByoApiEnabled}"
IsEnabled="{Binding IsShazamApiEnabled}"
VerticalAlignment="Center" HorizontalAlignment="Center"
Style="{StaticResource CustomCheckBoxStyle}"
Checked="ShazamByoApiCheckButtonChecked" Unchecked="ShazamByoApiCheckButtonUnchecked"/>
Expand Down Expand Up @@ -276,8 +277,9 @@

<!-- BYOAPI -->
<CheckBox x:Name="AudDByoApiCheckBox"
Content="BYOAPI Key"
Content="Enable BYOAPI"
IsChecked="{Binding IsAudDByoApiEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsAudDApiEnabled, Mode=TwoWay}"
VerticalAlignment="Center" HorizontalAlignment="Center"
Style="{StaticResource CustomCheckBoxStyle}"
Checked="AudDByoApiCheckButtonChecked" Unchecked="AudDByoApiCheckButtonUnchecked"/>
Expand Down
20 changes: 15 additions & 5 deletions VXMusicDesktop/MVVM/View/RecognitionView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ private void ShazamByoApiCheckButtonChecked(object sender, RoutedEventArgs e)
recognitionViewModel.SharedViewModel.IsShazamApiConnected = false;
recognitionViewModel.IsShazamByoApiEnabled = true;

ShazamByoApiCheckBox.Content = "Disable BYOAPI";

recognitionViewModel.PerformSaveAndTestShazamByoApi();
//LastFmPasswordBoxHintText.Visibility = String.IsNullOrEmpty(connectionsViewModel.LastFmPassword) ? Visibility.Visible : Visibility.Hidden;
}
Expand All @@ -89,8 +91,11 @@ private void ShazamByoApiCheckButtonUnchecked(object sender, RoutedEventArgs e)
{
recognitionViewModel.SharedViewModel.IsShazamApiConnected = false;
recognitionViewModel.IsShazamByoApiEnabled = false;

recognitionViewModel.SetShazamApiKeyToDefaultAndTest();

ShazamByoApiCheckBox.Content = "Enable BYOAPI";

if(recognitionViewModel.IsShazamApiEnabled)
recognitionViewModel.SetShazamApiKeyToDefaultAndTest();
}
}

Expand Down Expand Up @@ -150,12 +155,14 @@ private void AudDByoApiCheckButtonChecked(object sender, RoutedEventArgs e)
if (this.DataContext is RecognitionViewModel recognitionViewModel)
{
// Disable button if the other API is enabled
if (recognitionViewModel.IsShazamApiEnabled)
return;
//if (recognitionViewModel.IsShazamApiEnabled)
// return;

recognitionViewModel.SharedViewModel.IsAudDApiConnected = false;
recognitionViewModel.IsAudDByoApiEnabled = true;

AudDByoApiCheckBox.Content = "Disable BYOAPI";

recognitionViewModel.PerformSaveAndTestAudDByoApi();
}
}
Expand All @@ -166,8 +173,11 @@ private void AudDByoApiCheckButtonUnchecked(object sender, RoutedEventArgs e)
{
recognitionViewModel.SharedViewModel.IsAudDApiConnected = false;
recognitionViewModel.IsAudDByoApiEnabled = false;

AudDByoApiCheckBox.Content = "Enable BYOAPI";

recognitionViewModel.SetAudDApiKeyToDefaultAndTest();
if(recognitionViewModel.IsAudDApiEnabled)
recognitionViewModel.SetAudDApiKeyToDefaultAndTest();
}
}

Expand Down
38 changes: 14 additions & 24 deletions VXMusicDesktop/MVVM/ViewModel/RecognitionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,6 @@ public bool IsShazamByoApiEnabled
OnPropertyChanged(nameof(IsShazamByoApiEnabled));
}
}

// public bool IsShazamApiConnected
// {
// get { return _isShazamApiConnected; }
// set
// {
// _isShazamApiConnected = value;
// OnPropertyChanged(nameof(IsShazamApiConnected));
// }
// }

public bool IsAudDApiEnabled
{
Expand All @@ -176,16 +166,6 @@ public bool IsAudDByoApiEnabled
OnPropertyChanged(nameof(IsAudDByoApiEnabled));
}
}

// public bool IsAudDApiConnected
// {
// get { return _isAudDApiConnected; }
// set
// {
// _isAudDApiConnected = value;
// OnPropertyChanged(nameof(IsAudDApiConnected));
// }
// }

public bool IsRecognitionReady
{
Expand All @@ -207,17 +187,17 @@ private void ProcessRecognitionApiState()
!String.IsNullOrEmpty(App.VXMusicSession.RecognitionSettings.ShazamSettings.ByoApiKey);

IsAudDApiEnabled = false;
IsAudDByoApiEnabled = App.VXMusicSession.RecognitionSettings.AudDSettings.IsByoApiEnabled &&
!String.IsNullOrEmpty(App.VXMusicSession.RecognitionSettings.AudDSettings.ByoApiKey);
IsAudDByoApiEnabled = false; //App.VXMusicSession.RecognitionSettings.AudDSettings.IsByoApiEnabled &&
//!String.IsNullOrEmpty(App.VXMusicSession.RecognitionSettings.AudDSettings.ByoApiKey);
break;
case RecognitionApi.AudD:
IsAudDApiEnabled = true;
IsAudDByoApiEnabled = App.VXMusicSession.RecognitionSettings.AudDSettings.IsByoApiEnabled &&
!String.IsNullOrEmpty(App.VXMusicSession.RecognitionSettings.AudDSettings.ByoApiKey);

IsShazamApiEnabled = false;
IsShazamByoApiEnabled = App.VXMusicSession.RecognitionSettings.ShazamSettings.IsByoApiEnabled &&
!String.IsNullOrEmpty(App.VXMusicSession.RecognitionSettings.ShazamSettings.ByoApiKey);
IsShazamByoApiEnabled = false; //App.VXMusicSession.RecognitionSettings.ShazamSettings.IsByoApiEnabled &&
//!String.IsNullOrEmpty(App.VXMusicSession.RecognitionSettings.ShazamSettings.ByoApiKey);
break;
default:
IsShazamApiEnabled = false;
Expand Down Expand Up @@ -311,13 +291,23 @@ private void PerformShazamButtonClick(object commandParameter)
{
App.VXMusicSession.SetRecognitionClient(RecognitionApi.Shazam);
VXUserSettings.Recognition.SetRecognitionApi(RecognitionApi.Shazam);

SharedViewModel.IsAudDApiConnected = false;
IsAudDApiEnabled = false;
IsAudDByoApiEnabled = false;

ProcessRecognitionApiState();
}

private void PerformAudDButtonClick(object commandParameter)
{
App.VXMusicSession.SetRecognitionClient(RecognitionApi.AudD);
VXUserSettings.Recognition.SetRecognitionApi(RecognitionApi.AudD);

SharedViewModel.IsShazamApiConnected = false;
IsShazamApiEnabled = false;
IsShazamByoApiEnabled = false;

ProcessRecognitionApiState();
}

Expand Down
3 changes: 2 additions & 1 deletion VXMusicDesktop/VXUserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public static void SetShazamByoApiKey(string byoApiKey)
Properties.Settings.Default.ShazamByoApiKey = byoApiKey;
Properties.Settings.Default.Save();

Logger.LogDebug($"User Setting ShazamByoApiKey set to {Properties.Settings.Default.ShazamByoApiKey}");
Logger.LogDebug($"User Setting ShazamByoApiKey set to **************************");
//Logger.LogDebug($"User Setting ShazamByoApiKey set to {Properties.Settings.Default.ShazamByoApiKey}");
}

public static string GetShazamByoApiKey()
Expand Down

0 comments on commit 89f5eed

Please sign in to comment.