Skip to content

Commit

Permalink
update SettingWindow PreviewText, and change output loglevel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Asteriskx committed Jul 16, 2023
1 parent 6a214e4 commit ea1a3d9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
26 changes: 2 additions & 24 deletions SagiriApp/Behavior/PostingFormatTextBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

using Microsoft.Xaml.Behaviors;

using Sagiri.Services.Spotify.Track;
using Sagiri.Util.Common;
using SagiriApp.Interop;
using SagiriApp.Views;

namespace SagiriApp.Behavior
{
class PostingFormatTextBehavior : Behavior<TextBox>
{
private Logger _Logger { get; set; } = Logger.GetInstance;
public string PostingFormat
{
get => (string)GetValue(PostingFormatProperty);
Expand Down Expand Up @@ -45,16 +41,12 @@ protected override void OnDetaching()

private void _OnTextChanged(object sender, EventArgs e)
{
var activeWindow = Application.Current.Windows
.OfType<Window>()
.SingleOrDefault(x => x.IsActive);

if (activeWindow is SettingWindow sw)
if (Helper.GetActiveWindow is SettingWindow sw)
{
try
{
PostingFormat = sw.PostingFormatText.Text;
sw.PreviewText.Text = _RenderPreview(sw);
sw.PreviewText.Text = Helper.RenderPreview(sw.PostingFormatText.Text);
sw.SettingSave.IsEnabled = true;
}
catch
Expand All @@ -64,19 +56,5 @@ private void _OnTextChanged(object sender, EventArgs e)
}
}
}

private string _RenderPreview(SettingWindow sw)
{
CurrentTrackInfo trackInfo = new()
{
Album = "メルト 10th ANNIVERSARY MIX",
Artist = "ryo (supercell) - やなぎなぎ",
TrackTitle = "メルト 10th ANNIVERSARY MIX",
TrackNumber = "1",
ReleaseDate = "2017/12/24",
};

return Helper.GenerateTrackText(sw.PostingFormatText.Text, trackInfo);
}
}
}
22 changes: 20 additions & 2 deletions SagiriApp/Interop/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System.Text;

using System.Linq;
using System.Text;
using System.Windows;
using Sagiri.Services.Spotify.Track;

namespace SagiriApp.Interop
{
internal static class Helper
{
internal static Window? GetActiveWindow =>
Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);

internal static string GenerateTrackText(string text, CurrentTrackInfo trackInfo)
{
StringBuilder sb = new(text);
Expand All @@ -23,5 +27,19 @@ internal static string GenerateTrackText(string text, CurrentTrackInfo trackInfo
trackInfo.TrackNumber
);
}

internal static string RenderPreview(string text)
{
CurrentTrackInfo trackInfo = new()
{
Album = "メルト 10th ANNIVERSARY MIX",
Artist = "ryo (supercell) - やなぎなぎ",
TrackTitle = "メルト 10th ANNIVERSARY MIX",
TrackNumber = "1",
ReleaseDate = "2017/12/24",
};

return GenerateTrackText(text, trackInfo);
}
}
}
2 changes: 1 addition & 1 deletion SagiriApp/Models/SagiriModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private void _OnSpotifyCurrentlyPlayingChanged(CurrentTrackInfo trackInfo)
$"🎵 {trackInfo.TrackTitle} - " +
$"🎙 {trackInfo.Artist} - " +
$"💿 {trackInfo.Album}",
Logger.LogLevel.Info
Logger.LogLevel.Debug
);

#endregion Logging
Expand Down
3 changes: 2 additions & 1 deletion SagiriApp/Views/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
xmlns:bh="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:SagiriApp.Views" xmlns:viewmodel="clr-namespace:SagiriApp.ViewModel"
xmlns:local="clr-namespace:SagiriApp.Views"
xmlns:viewmodel="clr-namespace:SagiriApp.ViewModel"
d:DataContext="{d:DesignInstance Type=viewmodel:SagiriViewModel}"
mc:Ignorable="d"
ResizeMode="NoResize"
Expand Down
8 changes: 7 additions & 1 deletion SagiriApp/Views/SettingWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

using MahApps.Metro.Controls;
using SagiriApp.Interop;

namespace SagiriApp.Views
{
Expand All @@ -15,8 +15,14 @@ public partial class SettingWindow : MetroWindow
public SettingWindow()
{
InitializeComponent();

this.Closing += (_, e) => { e.Cancel = true; this.Hide(); };

this.Loaded += (_, _) => {
if (Helper.GetActiveWindow is SettingWindow sw)
sw.PreviewText.Text = Helper.RenderPreview(sw.PostingFormatText.Text);
};

// Must be Relation SagiriViewModel.
var mainWindow = (MainWindow)App.Current.MainWindow;
this.DataContext = mainWindow.DataContext;
Expand Down

0 comments on commit ea1a3d9

Please sign in to comment.