Skip to content

Commit ea1a3d9

Browse files
committed
update SettingWindow PreviewText, and change output loglevel.
1 parent 6a214e4 commit ea1a3d9

File tree

5 files changed

+32
-29
lines changed

5 files changed

+32
-29
lines changed

SagiriApp/Behavior/PostingFormatTextBehavior.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
using System;
2-
using System.Linq;
32
using System.Windows;
43
using System.Windows.Controls;
54

65
using Microsoft.Xaml.Behaviors;
76

8-
using Sagiri.Services.Spotify.Track;
9-
using Sagiri.Util.Common;
107
using SagiriApp.Interop;
118
using SagiriApp.Views;
129

1310
namespace SagiriApp.Behavior
1411
{
1512
class PostingFormatTextBehavior : Behavior<TextBox>
1613
{
17-
private Logger _Logger { get; set; } = Logger.GetInstance;
1814
public string PostingFormat
1915
{
2016
get => (string)GetValue(PostingFormatProperty);
@@ -45,16 +41,12 @@ protected override void OnDetaching()
4541

4642
private void _OnTextChanged(object sender, EventArgs e)
4743
{
48-
var activeWindow = Application.Current.Windows
49-
.OfType<Window>()
50-
.SingleOrDefault(x => x.IsActive);
51-
52-
if (activeWindow is SettingWindow sw)
44+
if (Helper.GetActiveWindow is SettingWindow sw)
5345
{
5446
try
5547
{
5648
PostingFormat = sw.PostingFormatText.Text;
57-
sw.PreviewText.Text = _RenderPreview(sw);
49+
sw.PreviewText.Text = Helper.RenderPreview(sw.PostingFormatText.Text);
5850
sw.SettingSave.IsEnabled = true;
5951
}
6052
catch
@@ -64,19 +56,5 @@ private void _OnTextChanged(object sender, EventArgs e)
6456
}
6557
}
6658
}
67-
68-
private string _RenderPreview(SettingWindow sw)
69-
{
70-
CurrentTrackInfo trackInfo = new()
71-
{
72-
Album = "メルト 10th ANNIVERSARY MIX",
73-
Artist = "ryo (supercell) - やなぎなぎ",
74-
TrackTitle = "メルト 10th ANNIVERSARY MIX",
75-
TrackNumber = "1",
76-
ReleaseDate = "2017/12/24",
77-
};
78-
79-
return Helper.GenerateTrackText(sw.PostingFormatText.Text, trackInfo);
80-
}
8159
}
8260
}

SagiriApp/Interop/Helper.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
using System.Text;
2-
1+
using System.Linq;
2+
using System.Text;
3+
using System.Windows;
34
using Sagiri.Services.Spotify.Track;
45

56
namespace SagiriApp.Interop
67
{
78
internal static class Helper
89
{
10+
internal static Window? GetActiveWindow =>
11+
Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
12+
913
internal static string GenerateTrackText(string text, CurrentTrackInfo trackInfo)
1014
{
1115
StringBuilder sb = new(text);
@@ -23,5 +27,19 @@ internal static string GenerateTrackText(string text, CurrentTrackInfo trackInfo
2327
trackInfo.TrackNumber
2428
);
2529
}
30+
31+
internal static string RenderPreview(string text)
32+
{
33+
CurrentTrackInfo trackInfo = new()
34+
{
35+
Album = "メルト 10th ANNIVERSARY MIX",
36+
Artist = "ryo (supercell) - やなぎなぎ",
37+
TrackTitle = "メルト 10th ANNIVERSARY MIX",
38+
TrackNumber = "1",
39+
ReleaseDate = "2017/12/24",
40+
};
41+
42+
return GenerateTrackText(text, trackInfo);
43+
}
2644
}
2745
}

SagiriApp/Models/SagiriModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private void _OnSpotifyCurrentlyPlayingChanged(CurrentTrackInfo trackInfo)
254254
$"🎵 {trackInfo.TrackTitle} - " +
255255
$"🎙 {trackInfo.Artist} - " +
256256
$"💿 {trackInfo.Album}",
257-
Logger.LogLevel.Info
257+
Logger.LogLevel.Debug
258258
);
259259

260260
#endregion Logging

SagiriApp/Views/SettingWindow.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
xmlns:bh="http://schemas.microsoft.com/xaml/behaviors"
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
88
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
9-
xmlns:local="clr-namespace:SagiriApp.Views" xmlns:viewmodel="clr-namespace:SagiriApp.ViewModel"
9+
xmlns:local="clr-namespace:SagiriApp.Views"
10+
xmlns:viewmodel="clr-namespace:SagiriApp.ViewModel"
1011
d:DataContext="{d:DesignInstance Type=viewmodel:SagiriViewModel}"
1112
mc:Ignorable="d"
1213
ResizeMode="NoResize"

SagiriApp/Views/SettingWindow.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
32
using MahApps.Metro.Controls;
3+
using SagiriApp.Interop;
44

55
namespace SagiriApp.Views
66
{
@@ -15,8 +15,14 @@ public partial class SettingWindow : MetroWindow
1515
public SettingWindow()
1616
{
1717
InitializeComponent();
18+
1819
this.Closing += (_, e) => { e.Cancel = true; this.Hide(); };
1920

21+
this.Loaded += (_, _) => {
22+
if (Helper.GetActiveWindow is SettingWindow sw)
23+
sw.PreviewText.Text = Helper.RenderPreview(sw.PostingFormatText.Text);
24+
};
25+
2026
// Must be Relation SagiriViewModel.
2127
var mainWindow = (MainWindow)App.Current.MainWindow;
2228
this.DataContext = mainWindow.DataContext;

0 commit comments

Comments
 (0)