Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mood based shuffling. #400

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AmbientSounds.Uwp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
<x:String x:Key="GlyphDownload">&#xEBD3;</x:String>
<x:String x:Key="GlyphDelete">&#xE107;</x:String>
<x:String x:Key="GlyphCustomPremium">&#xEB28;</x:String>
<x:String x:Key="GlyphMoods">&#xE170;</x:String>
<x:String x:Key="GlyphPhoto">&#xE91B;</x:String>
<x:String x:Key="GlyphCompact">&#xEE49;</x:String>
<x:String x:Key="GlyphExpand">&#xE1D9;</x:String>
Expand Down
84 changes: 84 additions & 0 deletions src/AmbientSounds.Uwp/Strings/en-US/Resources.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,84 @@ public static string SearchText
}
}
#endregion

#region MoodCalm
/// <summary>
/// Looks up a localized string similar to: Calm
/// </summary>
public static string MoodCalm
{
get
{
return _resourceLoader.GetString("MoodCalm");
}
}
#endregion

#region MoodCreative
/// <summary>
/// Looks up a localized string similar to: Creative
/// </summary>
public static string MoodCreative
{
get
{
return _resourceLoader.GetString("MoodCreative");
}
}
#endregion

#region MoodEnergetic
/// <summary>
/// Looks up a localized string similar to: Energetic
/// </summary>
public static string MoodEnergetic
{
get
{
return _resourceLoader.GetString("MoodEnergetic");
}
}
#endregion

#region MoodFocused
/// <summary>
/// Looks up a localized string similar to: Focused
/// </summary>
public static string MoodFocused
{
get
{
return _resourceLoader.GetString("MoodFocused");
}
}
#endregion

#region MoodPicker
/// <summary>
/// Looks up a localized string similar to: Play a random sound, depending on your mood.
/// </summary>
public static string MoodPicker
{
get
{
return _resourceLoader.GetString("MoodPicker");
}
}
#endregion

#region MoodStressed
/// <summary>
/// Looks up a localized string similar to: Stressed
/// </summary>
public static string MoodStressed
{
get
{
return _resourceLoader.GetString("MoodStressed");
}
}
#endregion
}

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("DotNetPlus.ReswPlus", "2.1.3")]
Expand Down Expand Up @@ -2713,6 +2791,12 @@ public enum KeyEnum
SearchPageHeader,
SearchEmptyPlaceholderText,
SearchText,
MoodCalm,
MoodCreative,
MoodEnergetic,
MoodFocused,
MoodPicker,
MoodStressed,
}

private static ResourceLoader _resourceLoader;
Expand Down
18 changes: 18 additions & 0 deletions src/AmbientSounds.Uwp/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -895,4 +895,22 @@
<data name="SearchText" xml:space="preserve">
<value>Search</value>
</data>
<data name="MoodCalm" xml:space="preserve">
<value>Calm</value>
</data>
<data name="MoodCreative" xml:space="preserve">
<value>Creative</value>
</data>
<data name="MoodEnergetic" xml:space="preserve">
<value>Energetic</value>
</data>
<data name="MoodFocused" xml:space="preserve">
<value>Focused</value>
</data>
<data name="MoodPicker" xml:space="preserve">
<value>Play a random sound, depending on your mood.</value>
</data>
<data name="MoodStressed" xml:space="preserve">
<value>Stressed</value>
</data>
</root>
15 changes: 15 additions & 0 deletions src/AmbientSounds.Uwp/Views/ShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@
FontSize="14"
Glyph="{StaticResource GlyphShuffle}" />
</Button>
<Button
AutomationProperties.Name="{x:Bind strings:Resources.MoodPicker}"
Style="{StaticResource SubtleIconButton}"
ToolTipService.ToolTip="{x:Bind strings:Resources.MoodPicker}">
<FontIcon FontFamily="{StaticResource FluentUIGlyphs}" Glyph="{StaticResource GlyphMoods}" />
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Command="{x:Bind ViewModel.PlayMoodSoundCommand}" CommandParameter="Calm" Text="{x:Bind strings:Resources.MoodCalm}"/>
<MenuFlyoutItem Command="{x:Bind ViewModel.PlayMoodSoundCommand}" CommandParameter="Creative" Text="{x:Bind strings:Resources.MoodCreative}"/>
<MenuFlyoutItem Command="{x:Bind ViewModel.PlayMoodSoundCommand}" CommandParameter="Energetic" Text="{x:Bind strings:Resources.MoodEnergetic}"/>
<MenuFlyoutItem Command="{x:Bind ViewModel.PlayMoodSoundCommand}" CommandParameter="Focused" Text="{x:Bind strings:Resources.MoodFocused}"/>
<MenuFlyoutItem Command="{x:Bind ViewModel.PlayMoodSoundCommand}" CommandParameter="Stressed" Text="{x:Bind strings:Resources.MoodStressed}"/>
</MenuFlyout>
</Button.Flyout>
</Button>
<Button
AutomationProperties.Name="{x:Bind strings:Resources.ScreensaverMode}"
Click="{x:Bind ViewModel.GoToScreensaver}"
Expand Down
11 changes: 11 additions & 0 deletions src/AmbientSounds/Models/Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public class Sound : IVersionedAsset
/// </summary>
public int FileVersion { get; set; }

public SoundMood Mood { get; set; }

/// <inheritdoc/>
public override string ToString()
{
Expand All @@ -152,3 +154,12 @@ public enum PublishState
Unpublished,
Rejected
}

public enum SoundMood
{
Calm,
Creative,
Energetic,
Focused,
Stressed
}
7 changes: 7 additions & 0 deletions src/AmbientSounds/Services/IMixMediaPlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,12 @@ public interface IMixMediaPlayerService
/// <param name="guide">The guide to play.</param>
Task PlayGuideAsync(Guide guide);
Task AddRandomAsync();

/// <summary>
/// Plays a random sound depending on the mood.
/// </summary>
/// <param name="sender">the MenuFlyoutItem of the selected mood.</param>
/// <returns></returns>
Task PlayMoodAsync(string tag);
}
}
7 changes: 7 additions & 0 deletions src/AmbientSounds/Services/ISoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,11 @@ public interface ISoundService
/// <param name="oldIndex">The sound's old position.</param>
/// <param name="newIndex">The sound's new position.</param>
Task UpdatePositionsAsync(string soundId, int oldIndex, int newIndex);

/// <summary>
/// Gets a list of sounds that correspond to the specific mood.
/// </summary>
/// <param name="tag">Mood name</param>
/// <returns></returns>
Task<List<Sound>> GetSoundsForMoodAsync(string tag);
}
24 changes: 24 additions & 0 deletions src/AmbientSounds/Services/MixMediaPlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using JeniusApps.Common.Tools;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -166,6 +167,29 @@ public async Task PlayRandomAsync()
}
}

public async Task PlayMoodAsync(string tag)
{
RemoveAll();
List<Sound> sounds = await _soundDataProvider.GetSoundsForMoodAsync(tag);
if (sounds.Count > 0)
{
if (sounds.Count > 3)
{
Random rng = new Random();
sounds = sounds.OrderBy(x => rng.Next()).ToList();
List<Sound> randomSounds = sounds.Take(3).ToList();
foreach (var sound in randomSounds)
{ await ToggleSoundAsync(sound); }
}
else
{ foreach (Sound sound in sounds) { await ToggleSoundAsync(sound); } }
}
else
{ }
// TODO: dialog that shows if there are no sounds in the filtered list.
Debug.WriteLine(sounds.Count + " sounds found with " + tag + " tag.");
}

public async Task AddRandomAsync()
{
if (GetSoundIds().Length >= _maxActive)
Expand Down
43 changes: 43 additions & 0 deletions src/AmbientSounds/Services/SoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,47 @@ public async Task UpdateSoundAsync(Sound updatedSound)
await _soundCache.AddLocalInstalledSoundAsync(updatedSound);
}
}

/// <inheritdoc/>
public async Task<List<Sound>> GetSoundsForMoodAsync(string moodTag)
{
var sounds = await GetLocalSoundsAsync();
List<Sound> filteredSounds = new List<Sound>();
SoundMood? mood = null;

if (moodTag != null)
{
switch (moodTag)
{
case "Stressed":
mood = SoundMood.Stressed;
break;
case "Energetic":
mood = SoundMood.Energetic;
break;
case "Focused":
mood = SoundMood.Focused;
break;
case "Creative":
mood = SoundMood.Creative;
break;
case "Calm":
mood = SoundMood.Calm;
break;
default:
break;
}
}

foreach (var sound in sounds)
{
if (sound.Mood == mood)
{
filteredSounds.Add(sound);
}
}

return filteredSounds;
}

}
6 changes: 6 additions & 0 deletions src/AmbientSounds/ViewModels/ShellPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ private async Task OpenShareAsync()
}
}

[RelayCommand]
private async Task PlayMoodSoundAsync(string mood)
{
await _mixMediaPlayerService.PlayMoodAsync(mood);
}

[RelayCommand]
private async Task OpenPremiumAsync()
{
Expand Down