Skip to content

Commit

Permalink
Testing new settings structure with the Lyrics Page
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDotH committed Apr 24, 2023
1 parent fb6a230 commit 4188949
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
5 changes: 5 additions & 0 deletions OpenLyricsClient/Backend/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public SettingManager SettingManager
get => _settingManager;
}

public SettingsHandler SettingsHandler
{
get => this._settingsHandler;
}

public ArtworkHandler ArtworkHandler
{
get => _artworkHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.IO;
using System;
using System.IO;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using DevBase.Api.Serializer;
using DevBase.Generics;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenLyricsClient.Backend.Structure.Enum;
Expand All @@ -21,9 +23,9 @@ public LyricsSection(string filePath)

public async Task WriteToDisk()
{
await using FileStream stream = this._file.OpenWrite();
await using FileStream stream = this._file.Open(FileMode.Create, FileAccess.Write);;
await using StreamWriter writer = new StreamWriter(stream);

await writer.WriteAsync(this._data?.ToString());
}

Expand All @@ -49,7 +51,7 @@ public async Task ReadFromDisk()

public T GetValue<T>(string field)
{
return this._data[field].Value<T>();
return (T)this._data[field].ToObject<T>();
}

public async Task SetValue<T>(string field, T value)
Expand All @@ -62,7 +64,9 @@ public JObject Defaults()
{
Structure structure = new Structure
{
Selection = EnumLyricsDisplayMode.KARAOKE
Selection = EnumLyricsDisplayMode.KARAOKE,
ArtworkBackground = false,
LyricsBlur = false
};

return new JsonDeserializer().Serialize(structure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ namespace OpenLyricsClient.Backend.Settings.Sections.Lyrics;

public class Structure
{
[JsonProperty("Selection")]
[JsonProperty("Selection Mode")]
public EnumLyricsDisplayMode Selection { get; set; }

[JsonProperty("Artwork Background")]
public bool ArtworkBackground { get; set; }

[JsonProperty("Blur Lyrics")]
public bool LyricsBlur { get; set; }
}
2 changes: 1 addition & 1 deletion OpenLyricsClient/Backend/Settings/SettingsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public SettingsHandler(string workingDirectory)
this._sections = new AList<ISettingSection>();

this._sections.Add(new LyricsSection(string.Format("{0}{1}",
workingDirectory, "lyrics-preferences.json")));
workingDirectory, "Lyrics Preferences.json")));

Task.Factory.StartNew(Initialize).GetAwaiter().GetResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.CompilerServices;
using OpenLyricsClient.Backend;
using OpenLyricsClient.Backend.Romanization;
using OpenLyricsClient.Backend.Settings.Sections.Lyrics;
using OpenLyricsClient.Backend.Structure.Enum;
using ReactiveUI;

Expand All @@ -29,50 +30,46 @@ public SettingsLyricsViewModel()

private void SwitchToKaraoke()
{
Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode = EnumLyricsDisplayMode.KARAOKE;
Core.INSTANCE.SettingManager.WriteSettings();
Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?
.SetValue("Selection Mode", EnumLyricsDisplayMode.KARAOKE);
}

private void SwitchToFade()
{
Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode = EnumLyricsDisplayMode.FADE;
Core.INSTANCE.SettingManager.WriteSettings();
Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?
.SetValue("Selection Mode", EnumLyricsDisplayMode.FADE);
}

private void ToggleArtworkBackground()
{
Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground =
!Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground;

Core.INSTANCE.SettingManager.WriteSettings();
Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?
.SetValue("Artwork Background", !UseArtworkBackground);
}

private void ToggleLyricsBlur()
{
Core.INSTANCE.SettingManager.Settings.DisplayPreferences.LyricsBlur =
!Core.INSTANCE.SettingManager.Settings.DisplayPreferences.LyricsBlur;

Core.INSTANCE.SettingManager.WriteSettings();
Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?
.SetValue("Blur Lyrics", !IsBlurred);
}

public bool IsKaraoke
{
get => Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode == EnumLyricsDisplayMode.KARAOKE;
get => Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?.GetValue<EnumLyricsDisplayMode>("Selection Mode") == EnumLyricsDisplayMode.KARAOKE;
}

public bool IsFade
{
get => Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode == EnumLyricsDisplayMode.FADE;
get => Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?.GetValue<EnumLyricsDisplayMode>("Selection Mode") == EnumLyricsDisplayMode.FADE;
}

public bool UseArtworkBackground
{
get => Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground;
get => Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?.GetValue<bool>("Artwork Background") == true;
}

public bool IsBlurred
{
get => Core.INSTANCE.SettingManager.Settings.DisplayPreferences.LyricsBlur;
get => Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?.GetValue<bool>("Blur Lyrics") == true;
}

protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
Expand Down

0 comments on commit 4188949

Please sign in to comment.