Skip to content

Commit

Permalink
Add Buds2 feature parity with non-samsung phone
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Feb 12, 2024
1 parent 25dc4b1 commit 109ba8f
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 12 deletions.
1 change: 1 addition & 0 deletions GalaxyBudsClient/Interface/Pages/AbstractPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@ public enum Pages
Dummy2,
Home,
FindMyGear,
GearFitTest,
Touch,
TouchGesture,
TouchCustomAction,
Expand Down
11 changes: 10 additions & 1 deletion GalaxyBudsClient/Interface/Pages/AdvancedPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 73,17 @@
PointerPressed="BixbyRemap_OnPointerPressed"/>
</Border>
</Grid>
</Border>

<Border x:Name="GearFitTest" Grid.Row="5" Classes="RoundedBorderListItem BottomSpacer10">
<Grid ClipToBounds="True">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Grid.Row="0" CornerRadius="{StaticResource DefaultCornerRadius}" Classes="BorderHoverStyle" PointerPressed="GearFitTest_OnPointerPressed">
<items:IconListItem FontSize="18" Source="{DynamicResource FitTest}" Text="{DynamicResource mainpage_fit_test}"/>
</Border>
</Grid>
</Border>

</Grid>
Expand Down
7 changes: 7 additions & 0 deletions GalaxyBudsClient/Interface/Pages/AdvancedPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 55,8 @@ public override void OnPageShown()
this.FindControl<Separator>("PassthroughS").IsVisible = BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.AmbientPassthrough);
_sidetone.GetVisualParent()!.IsVisible = BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.AmbientSidetone);
_passthrough.GetVisualParent()!.IsVisible = BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.AmbientPassthrough);
this.FindControl<Border>("GearFitTest").IsVisible =
BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.GearFitTest);
}

private void BackButton_OnPointerPressed(object? sender, PointerPressedEventArgs e)
Expand Down Expand Up @@ -107,5 109,10 @@ private void BixbyRemap_OnPointerPressed(object? sender, PointerPressedEventArgs
{
MainWindow.Instance.Pager.SwitchPage(Pages.BixbyRemap);
}

private void GearFitTest_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
MainWindow.Instance.Pager.SwitchPage(Pages.GearFitTest);
}
}
}
64 changes: 64 additions & 0 deletions GalaxyBudsClient/Interface/Pages/GearFitPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 1,64 @@
<pages:AbstractPage xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="clr-namespace:GalaxyBudsClient.Interface.Pages"
xmlns:elements="clr-namespace:GalaxyBudsClient.Interface.Elements"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="36"
x:Class="GalaxyBudsClient.Interface.Pages.GearFitPage"
DockPanel.Dock="Top" Margin="10,0">
<Grid Margin="0,0,0,20" >
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<elements:PageHeader Grid.Row="1" Title="{DynamicResource mainpage_fit_test}" BackPressed="BackButton_OnPointerPressed"/>

<Border Grid.Row="3" Classes="RoundedBorderListItem BottomSpacer10">
<Grid HorizontalAlignment="Stretch" Margin="0,15,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="15"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="10,0" x:Name="EarbudWarningContainer">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="/Resources/warning.png" Height="20" Margin="0,0,5,0" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Label Grid.Column="1" Margin="0,1,0,0" Content="{DynamicResource gft_warning}"
Foreground="{DynamicResource ForegroundTextBrush}" VerticalAlignment="Top" HorizontalAlignment="Center"/>
</Grid>

<Grid Grid.Row="2" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="35" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="2" Name="LeftStatus" HorizontalAlignment="Right" />
<Image Grid.Column="3" Name="LeftIcon" Source="{DynamicResource LeftBudConnected}" Width="75" Height="75" VerticalAlignment="Top"/>
<Image Grid.Column="5" Name="RightIcon" Source="{DynamicResource RightBudConnected}" Width="75" Height="75" VerticalAlignment="Top"/>
<Label Grid.Column="6" Name="RightStatus" HorizontalAlignment="Left" />
</Grid>

<Grid Grid.Row="3" HorizontalAlignment="Center">
<elements:ScanButton x:Name="ScanButton" />
</Grid>
</Grid>
</Border>
</Grid>
</pages:AbstractPage>
142 changes: 142 additions & 0 deletions GalaxyBudsClient/Interface/Pages/GearFitPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 1,142 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using GalaxyBudsClient.Interface.Elements;
using GalaxyBudsClient.Message;
using GalaxyBudsClient.Message.Decoder;
using GalaxyBudsClient.Model;
using GalaxyBudsClient.Model.Constants;
using GalaxyBudsClient.Platform;
using GalaxyBudsClient.Utils.DynamicLocalization;
using Serilog;

namespace GalaxyBudsClient.Interface.Pages
{
public class GearFitPage : AbstractPage
{
public override Pages PageType => Pages.GearFitTest;

private readonly ScanButton _scanButton;
private readonly Image _iconLeft;
private readonly Image _iconRight;
private readonly Label _statusLeft;
private readonly Label _statusRight;
private readonly Grid _warningContainer;
private bool _lastWarning;

public GearFitPage()
{
AvaloniaXamlLoader.Load(this);

_scanButton = this.FindControl<ScanButton>("ScanButton");
_iconLeft = this.FindControl<Image>("LeftIcon");
_iconRight = this.FindControl<Image>("RightIcon");
_statusLeft = this.FindControl<Label>("LeftStatus");
_statusRight = this.FindControl<Label>("RightStatus");
_warningContainer = this.FindControl<Grid>("EarbudWarningContainer");

SPPMessageHandler.Instance.BaseUpdate = (_, update) => UpdateDashboard(update);
SPPMessageHandler.Instance.FitTestResult = (_, update) => ShowResults(update);
_scanButton.ScanningStatusChanged = ScanButton_OnScanningStatusChanged;
}

private async void ScanButton_OnScanningStatusChanged(object? sender, bool e)
{
if (e)
{
_statusLeft.Content = "";
_statusRight.Content = "";
await BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.CHECK_THE_FIT_OF_EARBUDS, 1);
}
else
{
await BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.CHECK_THE_FIT_OF_EARBUDS, 0);
}
}

public void UpdateDashboard(IBasicStatusUpdate ext)
{
_lastWarning = _warningContainer.IsVisible = ext.WearState != WearStates.Both;
}

public override void OnPageShown()
{
_warningContainer.IsVisible = _lastWarning;
_statusLeft.Content = "";
_statusRight.Content = "";

if (DeviceMessageCache.Instance.DebugGetAllData == null)
{
UpdateIcons(0,0);
}
else
{
UpdateIcons(DeviceMessageCache.Instance.DebugGetAllData.LeftAdcSOC,
DeviceMessageCache.Instance.DebugGetAllData.RightAdcSOC);
}
}

public override void OnPageHidden()
{
_scanButton.IsSearching = false;
BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.CHECK_THE_FIT_OF_EARBUDS, 0);
}

private void ShowResults(FitTestParser result)
{
_scanButton.IsSearching = false;
BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.CHECK_THE_FIT_OF_EARBUDS, 0);
_statusLeft.Content = GetTextFor(result.Left);
_statusRight.Content = GetTextFor(result.Right);
}

private String GetTextFor(FitTestParser.Result result)
{
switch (result)
{
case FitTestParser.Result.Bad:
return Loc.Resolve("gft_bad");
case FitTestParser.Result.Good:
return Loc.Resolve("gft_good");
case FitTestParser.Result.TestFailed:
return Loc.Resolve("gft_fail");
}

return result.ToString();
}

private void UpdateIcons(double left, double right)
{
bool isLeftOnline = left > 0;
bool isRightOnline = right > 0;

var type = BluetoothImpl.Instance.DeviceSpec.IconResourceKey;
if (isLeftOnline)
{
_iconLeft.Source = (IImage?)Application.Current?.FindResource($"Left{type}Connected");
}
else
{
_iconLeft.Source = (IImage?)Application.Current?.FindResource($"Left{type}Disconnected");
}

if (isRightOnline)
{
_iconRight.Source = (IImage?)Application.Current?.FindResource($"Right{type}Connected");
}
else
{
_iconRight.Source = (IImage?)Application.Current?.FindResource($"Right{type}Disconnected");
}
}

private void BackButton_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
MainWindow.Instance.Pager.SwitchPage(Pages.Advanced);
}

}
}
7 changes: 7 additions & 0 deletions GalaxyBudsClient/Interface/Pages/NoiseProPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 57,13 @@
Description="{DynamicResource nc_anc_level_description}"
Toggled="AncLevelToggle_OnToggled"/>
</Border>
<Separator Grid.Row="1" x:Name="AncOneToggleSeparator" Margin="20,0,20,0" Background="{DynamicResource BorderSeparatorBrush}" />
<Border Grid.Row="2" x:Name="AncOneToggleBorder" CornerRadius="{DynamicResource DefaultCornerRadius}" Classes="BorderHoverStyle">
<items:SwitchDetailListItem x:Name="AncOneToggle"
Text="{DynamicResource nc_anc_one}"
Description="{DynamicResource nc_anc_one_description}"
Toggled="AncOneToggle_OnToggled"/>
</Border>
</Grid>
</Border>
<Border Grid.Row="5" Classes="RoundedBorderListItem BottomSpacer10" x:Name="VoiceDetectBorder" >
Expand Down
18 changes: 16 additions & 2 deletions GalaxyBudsClient/Interface/Pages/NoiseProPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,7 @@ public class NoiseProPage : AbstractPage
private readonly SwitchListItem _ambientSwitch;

private readonly SwitchListItem _ancSwitch;
private readonly SwitchDetailListItem _ancOne;
private readonly SwitchDetailListItem _ancLevel;

private readonly SwitchDetailListItem _voiceDetect;
Expand All @@ -37,6 38,7 @@ public NoiseProPage()
_ambientSwitch = this.FindControl<SwitchListItem>("AmbientToggle");

_ancSwitch = this.FindControl<SwitchListItem>("AncToggle");
_ancOne = this.FindControl<SwitchDetailListItem>("AncOneToggle");
_ancLevel = this.FindControl<SwitchDetailListItem>("AncLevelToggle");

_voiceDetect = this.FindControl<SwitchDetailListItem>("VoiceDetect");
Expand Down Expand Up @@ -94,6 96,10 @@ private void OnEventReceived(EventDispatcher.Event e, object? arg)
_ancLevel.Toggle();
await BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.NOISE_REDUCTION_LEVEL, _ancLevel.IsChecked);
break;
case EventDispatcher.Event.SwitchAncOne:
_ancOne.Toggle();
await BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.SET_ANC_WITH_ONE_EARBUD, _ancOne.IsChecked);
break;
case EventDispatcher.Event.AmbientToggle:
_ambientSwitch.Toggle();
AmbientToggle_OnToggled(this, _ambientSwitch.IsChecked);
Expand All @@ -115,16 121,19 @@ public override void OnPageShown()
_voiceBorder.IsVisible =
BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.DetectConversations);
this.FindControl<Border>("AncLevelToggleBorder").IsVisible =
this.FindControl<Separator>("AncLevelToggleSeparator").IsVisible =
BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.AncNoiseReductionLevels);
this.FindControl<Separator>("AncLevelToggleSeparator").IsVisible =
BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.AncNoiseReductionLevels);
this.FindControl<Border>("AncOneToggleBorder").IsVisible =
this.FindControl<Separator>("AncOneToggleSeparator").IsVisible =
BluetoothImpl.Instance.DeviceSpec.Supports(IDeviceSpec.Feature.AncWithOneEarbud);
}

private void OnExtendedStatusUpdate(object? sender, ExtendedStatusUpdateParser e)
{
_ambientSwitch.IsChecked = e.NoiseControlMode == NoiseControlMode.AmbientSound;
_ancSwitch.IsChecked = e.NoiseControlMode == NoiseControlMode.NoiseReduction;
_ancLevel.IsChecked = e.NoiseReductionLevel == 1;
_ancOne.IsChecked = e.AncWithOneEarbud;
_voiceDetect.IsChecked = e.DetectConversations;

byte seconds;
Expand Down Expand Up @@ -196,6 205,11 @@ private async void AncLevelToggle_OnToggled(object? sender, bool e)
await BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.NOISE_REDUCTION_LEVEL, e);
}

private async void AncOneToggle_OnToggled(object? sender, bool e)
{
await BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.SET_ANC_WITH_ONE_EARBUD, e);
}

private async void VoiceDetect_OnToggled(object? sender, bool e)
{
await BluetoothImpl.Instance.SendRequestAsync(SPPMessage.MessageIds.SET_DETECT_CONVERSATIONS, e);
Expand Down
1 change: 1 addition & 0 deletions GalaxyBudsClient/Interface/Styles/Base.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 23,7 @@
<CroppedBitmap x:Key="TouchBud" Source="/Resources/features/touch_color.png"/>
<CroppedBitmap x:Key="TouchBean" Source="/Resources/features/touch_bean.png"/>
<CroppedBitmap x:Key="TouchPro" Source="/Resources/features/touch_pro.png"/>
<CroppedBitmap x:Key="FitTest" Source="/Resources/features/earbud_fit_test.png"/>

<!-- Value converters -->
<utils:BitmapAssetValueConverter x:Key="BitmapAssetValueConverter"/>
Expand Down
6 changes: 6 additions & 0 deletions GalaxyBudsClient/Interface/Transition/PageContainer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 142,7 @@ public bool SwitchPage(AbstractPage.Pages page)
{
_lastPageCache.OnPageHidden();
}

Children.Remove(_lastPageCache);
_lastPageCache = null;
_lastWasSuspended = false;
Expand All @@ -164,11 165,16 @@ public bool SwitchPage(AbstractPage.Pages page)
{
_currentPage.OnPageShown();
}

// don't await here, we don't want to wait until animation finished
_pageTransition.Start(_lastPageCache, _currentPage, true, source.Token);

Check warning on line 170 in GalaxyBudsClient/Interface/Transition/PageContainer.xaml.cs

View workflow job for this annotation

GitHub Actions / build-arm64

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 170 in GalaxyBudsClient/Interface/Transition/PageContainer.xaml.cs

View workflow job for this annotation

GitHub Actions / build-x64

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
PageSwitched?.Invoke(this, page);
}
}
catch (Exception ex)
{
Log.Error(ex.ToString());
}
finally
{
_pageSemaphore.Release();
Expand Down
2 changes: 1 addition & 1 deletion GalaxyBudsClient/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 102,7 @@ public MainWindow()
new WelcomePage(), UnsupportedFeaturePage, UpdatePage, UpdateProgressPage, new SystemCoredumpPage(),
new HotkeyPage(), new FirmwareSelectionPage(), new FirmwareTransferPage(), new SpatialTestPage(),
new BixbyRemapPage(), new CrowdsourcingSettingsPage(), new BudsAppDetectedPage(), new TouchpadGesturePage(),
new NoiseProAmbientPage());
new NoiseProAmbientPage(), new GearFitPage());

_titleBar = this.FindControl<CustomTitleBar>("TitleBar");

Check warning on line 107 in GalaxyBudsClient/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build-x64

Possible null reference assignment.

Check warning on line 107 in GalaxyBudsClient/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build-x64

Possible null reference assignment.
_titleBar.PointerPressed = (i, e) => BeginMoveDrag(e);

Check warning on line 108 in GalaxyBudsClient/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build-x64

Dereference of a possibly null reference.

Check warning on line 108 in GalaxyBudsClient/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build-x64

Dereference of a possibly null reference.
Expand Down
Loading

0 comments on commit 109ba8f

Please sign in to comment.