forked from timschneeb/GalaxyBudsClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Buds2 feature parity with non-samsung phone
- Loading branch information
Showing
21 changed files
with
316 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 11,7 @@ public enum Pages | |
Dummy2, | ||
Home, | ||
FindMyGear, | ||
GearFitTest, | ||
Touch, | ||
TouchGesture, | ||
TouchCustomAction, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.