Skip to content

Commit 2e524f0

Browse files
committed
Improve error handling and reformat XAML for clarity
- Added `using System.IO;` to `SpotifyWebClient.cs`. - Enhanced `JsonException` handling in `SpotifyWebClient.cs` to write response content to `data.json` if it does not exist. - Reformatted `HistoryWindow.xaml` for better readability: - Adjusted indentation and line breaks. - Changed the order of attributes. - Ensured attributes are on separate lines. - Replaced `PackIconFontAwesome` with `PackIconMaterial` for the refresh button. - Made minor adjustments to `DataGrid` and `ListBox` elements.
1 parent 9ea2cb1 commit 2e524f0

File tree

2 files changed

+84
-32
lines changed

2 files changed

+84
-32
lines changed

Songify Slim/Util/Spotify/SpotifyAPI.Web/SpotifyWebClient.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
45
using System.Net;
56
using System.Net.Http;
67
using System.Net.Http.Headers;
@@ -81,6 +82,9 @@ public Tuple<ResponseInfo, T> DownloadJson<T>(string url, Dictionary<string, str
8182
catch (JsonException error)
8283
{
8384
Logger.LogStr("SPOTIFY API:" + url);
85+
if (!File.Exists("data.json"))
86+
File.Create("data.json").Close();
87+
File.WriteAllText("data.json", response.Item2);
8488
Logger.LogExc(error);
8589
IOManager.WriteOutput($"{GlobalObjects.RootDirectory}/json.txt", response.Item2);
8690
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(string.Format(UnknownErrorJson, error.Message), JsonSettings));
@@ -99,8 +103,8 @@ public async Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url, Dicti
99103
{
100104
Logger.LogStr("SPOTIFY API:" + url);
101105
Logger.LogExc(error);
102-
IOManager.WriteOutput($"{GlobalObjects.RootDirectory}/json.txt", response.Item2);
103-
106+
IOManager.WriteOutput($"{GlobalObjects.RootDirectory}/json.txt", response.Item2);
107+
104108
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(string.Format(UnknownErrorJson, error.Message), JsonSettings));
105109
}
106110
}
Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,106 @@
1-
<controls:MetroWindow x:Class="Songify_Slim.Views.HistoryWindow"
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6-
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
7-
mc:Ignorable="d"
8-
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
9-
xmlns:properties="clr-namespace:Songify_Slim.Properties"
10-
11-
Title="{x:Static properties:Resources.WinTitle_History}" Height="247.9" Width="588" Loaded="MetroWindow_Loaded"
12-
WindowStartupLocation="CenterOwner" Closed="MetroWindow_Closed">
1+
<controls:MetroWindow
2+
x:Class="Songify_Slim.Views.HistoryWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:properties="clr-namespace:Songify_Slim.Properties"
10+
Title="{x:Static properties:Resources.WinTitle_History}"
11+
Width="588"
12+
Height="247.9"
13+
Closed="MetroWindow_Closed"
14+
Loaded="MetroWindow_Loaded"
15+
WindowStartupLocation="CenterOwner"
16+
mc:Ignorable="d">
1317

1418
<controls:MetroWindow.RightWindowCommands>
1519
<controls:WindowCommands>
16-
<ToggleButton x:Name="Tglbtn_Save" Checked="Tglbtn_Save_Checked" Unchecked="Tglbtn_Save_Checked" />
17-
<ToggleButton x:Name="Tglbtn_Upload" Checked="Tglbtn_Upload_Checked" Unchecked="Tglbtn_Upload_Checked" />
18-
<Button x:Name="Btn_CpyHistoryURL" Click="Btn_CpyHistoryURL_Click" ToolTip="Copy the history URL.">
20+
<ToggleButton
21+
x:Name="Tglbtn_Save"
22+
Checked="Tglbtn_Save_Checked"
23+
Unchecked="Tglbtn_Save_Checked" />
24+
<ToggleButton
25+
x:Name="Tglbtn_Upload"
26+
Checked="Tglbtn_Upload_Checked"
27+
Unchecked="Tglbtn_Upload_Checked" />
28+
<Button
29+
x:Name="Btn_CpyHistoryURL"
30+
Click="Btn_CpyHistoryURL_Click"
31+
ToolTip="Copy the history URL.">
1932
<StackPanel Orientation="Horizontal">
20-
<iconPacks:PackIconMaterial Kind="Link" VerticalAlignment="Center" HorizontalAlignment="Center" />
33+
<iconPacks:PackIconMaterial
34+
HorizontalAlignment="Center"
35+
VerticalAlignment="Center"
36+
Kind="Link" />
2137
</StackPanel>
2238
</Button>
2339
<Button x:Name="BtnRefresh" Click="BtnRefresh_Click">
24-
<iconPacks:PackIconFontAwesome Width="15" Height="15" Kind="SyncAltSolid" />
40+
<iconPacks:PackIconMaterial
41+
Width="15"
42+
Height="15"
43+
Kind="Refresh" />
2544
</Button>
2645
</controls:WindowCommands>
2746
</controls:MetroWindow.RightWindowCommands>
2847

2948
<Grid>
30-
<DataGrid x:Name="dgvHistorySongs" Margin="148,10,10,19" SelectionMode="Single" CanUserReorderColumns="False"
31-
CanUserResizeColumns="False" CanUserSortColumns="False">
49+
<DataGrid
50+
x:Name="dgvHistorySongs"
51+
Margin="148,10,10,19"
52+
CanUserReorderColumns="False"
53+
CanUserResizeColumns="False"
54+
CanUserSortColumns="False"
55+
SelectionMode="Single">
3256
<DataGrid.ContextMenu>
3357
<ContextMenu>
34-
<MenuItem Header="Delete" Click="DgvItemDelete_Click" />
58+
<MenuItem Click="DgvItemDelete_Click" Header="Delete" />
3559
</ContextMenu>
3660
</DataGrid.ContextMenu>
3761
<DataGrid.Columns>
38-
<DataGridTextColumn Header="{x:Static properties:Resources.s_Time}" IsReadOnly="True" Binding="{Binding Path=Time}" />
39-
<DataGridTextColumn Header="{x:Static properties:Resources.s_Name}" IsReadOnly="True" Binding="{Binding Path=Name}" Width="*" />
62+
<DataGridTextColumn
63+
Binding="{Binding Path=Time}"
64+
Header="{x:Static properties:Resources.s_Time}"
65+
IsReadOnly="True" />
66+
<DataGridTextColumn
67+
Width="*"
68+
Binding="{Binding Path=Name}"
69+
Header="{x:Static properties:Resources.s_Name}"
70+
IsReadOnly="True" />
4071
</DataGrid.Columns>
4172
</DataGrid>
4273

43-
<ListBox x:Name="LbxHistory" HorizontalAlignment="Left" Width="133" Margin="10,10,0,19"
44-
SelectionChanged="LbxHistory_SelectionChanged">
74+
<ListBox
75+
x:Name="LbxHistory"
76+
Width="133"
77+
Margin="10,10,0,19"
78+
HorizontalAlignment="Left"
79+
SelectionChanged="LbxHistory_SelectionChanged">
4580
<ListBox.ContextMenu>
4681
<ContextMenu>
47-
<MenuItem Header="Delete" Click="MenuItemDelete_Click" />
82+
<MenuItem Click="MenuItemDelete_Click" Header="Delete" />
4883
</ContextMenu>
4984
</ListBox.ContextMenu>
5085
</ListBox>
51-
<StatusBar Height="14" VerticalAlignment="Bottom" Padding="0" ScrollViewer.CanContentScroll="True" Margin="0"
52-
UseLayoutRounding="False">
53-
<Label x:Name="Lbl_Status" FontSize="10" Padding="0" VerticalContentAlignment="Bottom"
54-
HorizontalContentAlignment="Stretch" Width="340" HorizontalAlignment="Left" Margin="0,-4"
55-
VerticalAlignment="Top" Foreground="{DynamicResource MahApps.Brushes.IdealForeground}"/>
86+
<StatusBar
87+
Height="14"
88+
Margin="0"
89+
Padding="0"
90+
VerticalAlignment="Bottom"
91+
ScrollViewer.CanContentScroll="True"
92+
UseLayoutRounding="False">
93+
<Label
94+
x:Name="Lbl_Status"
95+
Width="340"
96+
Margin="0,-4"
97+
Padding="0"
98+
HorizontalAlignment="Left"
99+
VerticalAlignment="Top"
100+
HorizontalContentAlignment="Stretch"
101+
VerticalContentAlignment="Bottom"
102+
FontSize="10"
103+
Foreground="{DynamicResource MahApps.Brushes.IdealForeground}" />
56104
</StatusBar>
57105
</Grid>
58106
</controls:MetroWindow>

0 commit comments

Comments
 (0)