Skip to content

Commit

Permalink
Adding sleep timer (#431)
Browse files Browse the repository at this point in the history
* Initial commit

* Initial commit of sleep timer flyout UI

* Added animations

* Added percent left

* Added animations

* Created dedicated service class for sleep timer

* Pausing sleep timer if focus timer starts

* Added more time options

* Added localizations

* Code cleanup
  • Loading branch information
dpaulino authored Feb 27, 2024
1 parent 2784125 commit 815586a
Show file tree
Hide file tree
Showing 63 changed files with 885 additions and 82 deletions.
7 changes: 7 additions & 0 deletions src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@
<Compile Include="Controls\Shimmer.xaml.cs">
<DependentUpon>Shimmer.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\SleepTimerButton.xaml.cs">
<DependentUpon>SleepTimerButton.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\SoundGridControl.xaml.cs">
<DependentUpon>SoundGridControl.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -584,6 +587,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\SleepTimerButton.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\SoundGridControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
1 change: 1 addition & 0 deletions src/AmbientSounds.Uwp/App.Configuration.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@ private static IServiceProvider ConfigureServices(IAppSettings? appsettings = nu
[Singleton(typeof(StreakHistoryCache), typeof(IStreakHistoryCache))]
[Singleton(typeof(StreakHistoryRepository), typeof(IStreakHistoryRepository))]
[Singleton(typeof(MicrosoftStoreUpdater), typeof(IAppStoreUpdater))]
[Singleton(typeof(SleepTimerService), typeof(ISleepTimerService))]
private static partial void ConfigureServices(IServiceCollection services);
}
2 changes: 2 additions & 0 deletions src/AmbientSounds.Uwp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@
<x:String x:Key="GlyphPlusBold">&#xF8AA;</x:String>
<x:String x:Key="GlyphUnlock">&#xE785;</x:String>
<x:String x:Key="GlyphShiftUp">&#xE752;</x:String>
<x:String x:Key="GlyphMoonSolid">&#xF1DB;</x:String>
<x:String x:Key="GlyphMoon">&#xE708;</x:String>

<x:Double x:Key="NarrowWindowBreakpoint">540</x:Double>
</ResourceDictionary>
Expand Down
162 changes: 162 additions & 0 deletions src/AmbientSounds.Uwp/Controls/SleepTimerButton.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<UserControl
x:Class="AmbientSounds.Controls.SleepTimerButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:animations="using:Microsoft.Toolkit.Uwp.UI.Animations"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ex="using:JeniusApps.Common.UI.Uwp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:strings="using:AmbientSounds.Strings"
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:ui="using:Microsoft.Toolkit.Uwp.UI"
xmlns:vm="using:AmbientSounds.ViewModels"
xmlns:winui="using:Microsoft.UI.Xaml.Controls"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<Grid>
<Button
AutomationProperties.Name="{x:Bind strings:Resources.SleepTimerText}"
Style="{StaticResource SmallSubtleIconButton}"
ToolTipService.ToolTip="{x:Bind strings:Resources.SleepTimerText}">
<Grid>
<FontIcon
FontFamily="{StaticResource FluentUIGlyphs}"
FontSize="{StaticResource SmallIconSize}"
Glyph="{StaticResource GlyphMoon}"
Visibility="{x:Bind ex:UIExtensions.InvertBoolToVis(ViewModel.CountdownVisible), Mode=OneWay}" />

<Grid ui:VisualExtensions.NormalizedCenterPoint="0.5" Visibility="{x:Bind ViewModel.CountdownVisible, Mode=OneWay}">
<animations:Implicit.ShowAnimations>
<animations:OpacityAnimation
From="0"
To="1"
Duration="0:0:3" />
<animations:ScaleAnimation
From="0.5"
To="1"
Duration="0:0:3" />
</animations:Implicit.ShowAnimations>

<winui:ProgressRing
Width="20"
Height="20"
Foreground="{ThemeResource AccentFillColorDisabledBrush}"
IsIndeterminate="False"
Maximum="100"
Value="100" />
<winui:ProgressRing
Width="20"
Height="20"
Foreground="{ThemeResource AccentFillColorDefaultBrush}"
IsIndeterminate="False"
Maximum="100"
Value="{x:Bind ViewModel.PercentLeft, Mode=OneWay}" />
<FontIcon
FontFamily="{StaticResource FluentUIGlyphs}"
FontSize="8"
Foreground="{ThemeResource AccentFillColorDefaultBrush}"
Glyph="{StaticResource GlyphMoonSolid}" />
</Grid>
</Grid>

<Button.Flyout>
<Flyout Placement="Bottom">
<Flyout.FlyoutPresenterStyle>
<Style BasedOn="{StaticResource DefaultFlyoutPresenterStyle}" TargetType="FlyoutPresenter">
<Setter Property="Padding" Value="12" />
</Style>
</Flyout.FlyoutPresenterStyle>

<Grid Width="200">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>

<TextBlock
FontSize="12"
Foreground="{ThemeResource AccentFillColorDefaultBrush}"
Text="{x:Bind strings:Resources.SleepTimerText}" />

<Rectangle
Grid.Row="1"
Margin="0,4,0,0"
HorizontalAlignment="Stretch"
Style="{StaticResource ModuleDividerRectStyle}" />

<TextBlock
Grid.Row="2"
Margin="0,4,0,0"
HorizontalAlignment="Left"
ui:VisualExtensions.NormalizedCenterPoint="0.5"
FontSize="16"
Text="{x:Bind ViewModel.TimeLeft, Mode=OneWay}"
Typography.NumeralAlignment="Tabular"
Visibility="{x:Bind ViewModel.CountdownVisible, Mode=OneWay}">
<animations:Implicit.ShowAnimations>
<animations:OpacityAnimation
From="0"
To="1"
Duration="0:0:0.3" />
<animations:ScaleAnimation
From="0.5"
To="1"
Duration="0:0:0.3" />
<animations:TranslationAnimation
From="0,24,0"
To="0"
Duration="0:0:0.3" />
</animations:Implicit.ShowAnimations>
</TextBlock>

<ItemsControl
Grid.Row="3"
Margin="0,6,0,0"
ItemsSource="{x:Bind ViewModel.Options}">
<animations:Implicit.Animations>
<animations:OffsetAnimation Duration="0:0:0.3" />
</animations:Implicit.Animations>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel HorizontalSpacing="{StaticResource SoundCardSpacingDouble}" VerticalSpacing="{StaticResource SoundCardSpacingDouble}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:SleepTimerOptionsViewModel">
<ToggleButton
AutomationProperties.Name="{x:Bind Label}"
Command="{x:Bind StartCommand}"
Content="{x:Bind Label}"
FontSize="10"
IsChecked="{x:Bind IsActive, Mode=OneWay}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

<TextBlock
Grid.Row="4"
Margin="0,12,0,0"
FontSize="10"
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind strings:Resources.SleepTimerDescription}"
TextWrapping="WrapWholeWords"
Visibility="{x:Bind ViewModel.CountdownVisible, Mode=OneWay}">
<animations:Implicit.ShowAnimations>
<animations:OpacityAnimation
From="0"
To="1"
Duration="0:0:0.6" />
</animations:Implicit.ShowAnimations>
</TextBlock>
</Grid>
</Flyout>
</Button.Flyout>
</Button>
</Grid>
</UserControl>
20 changes: 20 additions & 0 deletions src/AmbientSounds.Uwp/Controls/SleepTimerButton.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using AmbientSounds.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Windows.UI.Xaml.Controls;

namespace AmbientSounds.Controls;

public sealed partial class SleepTimerButton : UserControl
{
public SleepTimerButton()
{
this.InitializeComponent();
this.DataContext = App.Services.GetRequiredService<SleepTimerViewModel>();
}

public SleepTimerViewModel ViewModel => (SleepTimerViewModel)this.DataContext;

public void Initialize() => ViewModel.Initialize();

public void Uninitialize() => ViewModel.Uninitialize();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,14 @@
<source>Restart</source>
<target state="translated">اعاده تشغيل</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">سيتوقف Ambie مؤقتا عند انتهاء المؤقت</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">مؤقت النوم</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,14 @@
<source>Restart</source>
<target state="translated">Рестартирате</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Ambie ще направи пауза, когато таймерът свърши</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">Таймер за заспиване</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,14 @@
<source>Restart</source>
<target state="translated">Restartovat</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Ambie se po skončení časovače pozastaví</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">Časovač vypnutí</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,14 @@
<source>Restart</source>
<target state="translated">Genstarte</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Ambie holder pause, når timeren slutter</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">Sleep-timer</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,14 @@
<source>Restart</source>
<target state="translated">Neustarten</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Ambie pausiert, wenn der Timer endet</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">Sleep-Timer</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,14 @@
<source>Restart</source>
<target state="translated">Επανεκκίνηση</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Το Ambie θα σταματήσει όταν τελειώσει το χρονόμετρο</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">Χρονοδιακόπτης ύπνου</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,14 @@
<source>Restart</source>
<target state="translated">Reanudar</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Ambie se detendrá cuando finalice el temporizador</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">Temporizador</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,14 @@
<source>Restart</source>
<target state="translated">راه اندازی مجدد</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Ambie مکث خواهد کرد زمانی که تایمر به پایان می رسد</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">تایمر خواب</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,14 @@
<source>Restart</source>
<target state="translated">Redémarrer</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Ambie s’arrêtera à la fin de la minuterie</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">Minuterie de mise en veille</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,14 @@
<source>Restart</source>
<target state="translated">להפעיל מחדש</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">אמבי ישהה כשהטיימר יסתיים</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">טיימר שינה</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,14 @@
<source>Restart</source>
<target state="translated">Ponovno pokretanje</target>
</trans-unit>
<trans-unit id="SleepTimerDescription" translate="yes" xml:space="preserve">
<source>Ambie will pause when the timer ends</source>
<target state="translated">Ambie će pauzirati kada tajmer završi</target>
</trans-unit>
<trans-unit id="SleepTimerText" translate="yes" xml:space="preserve">
<source>Sleep Timer</source>
<target state="translated">Mjerač vremena spavanja</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Loading

0 comments on commit 815586a

Please sign in to comment.