Skip to content

Commit

Permalink
Improve error handling and reformat XAML for clarity
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Inzaniity committed Nov 16, 2024
1 parent 9ea2cb1 commit 2e524f0
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 32 deletions.
8 changes: 6 additions & 2 deletions Songify Slim/Util/Spotify/SpotifyAPI.Web/SpotifyWebClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -81,6 +82,9 @@ public Tuple<ResponseInfo, T> DownloadJson<T>(string url, Dictionary<string, str
catch (JsonException error)
{
Logger.LogStr("SPOTIFY API:" + url);
if (!File.Exists("data.json"))
File.Create("data.json").Close();
File.WriteAllText("data.json", response.Item2);
Logger.LogExc(error);
IOManager.WriteOutput($"{GlobalObjects.RootDirectory}/json.txt", response.Item2);
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(string.Format(UnknownErrorJson, error.Message), JsonSettings));
Expand All @@ -99,8 +103,8 @@ public async Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url, Dicti
{
Logger.LogStr("SPOTIFY API:" + url);
Logger.LogExc(error);
IOManager.WriteOutput($"{GlobalObjects.RootDirectory}/json.txt", response.Item2);
IOManager.WriteOutput($"{GlobalObjects.RootDirectory}/json.txt", response.Item2);

return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(string.Format(UnknownErrorJson, error.Message), JsonSettings));
}
}
Expand Down
108 changes: 78 additions & 30 deletions Songify Slim/Views/HistoryWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,106 @@
<controls:MetroWindow x:Class="Songify_Slim.Views.HistoryWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:properties="clr-namespace:Songify_Slim.Properties"

Title="{x:Static properties:Resources.WinTitle_History}" Height="247.9" Width="588" Loaded="MetroWindow_Loaded"
WindowStartupLocation="CenterOwner" Closed="MetroWindow_Closed">
<controls:MetroWindow
x:Class="Songify_Slim.Views.HistoryWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:Songify_Slim.Properties"
Title="{x:Static properties:Resources.WinTitle_History}"
Width="588"
Height="247.9"
Closed="MetroWindow_Closed"
Loaded="MetroWindow_Loaded"
WindowStartupLocation="CenterOwner"
mc:Ignorable="d">

<controls:MetroWindow.RightWindowCommands>
<controls:WindowCommands>
<ToggleButton x:Name="Tglbtn_Save" Checked="Tglbtn_Save_Checked" Unchecked="Tglbtn_Save_Checked" />
<ToggleButton x:Name="Tglbtn_Upload" Checked="Tglbtn_Upload_Checked" Unchecked="Tglbtn_Upload_Checked" />
<Button x:Name="Btn_CpyHistoryURL" Click="Btn_CpyHistoryURL_Click" ToolTip="Copy the history URL.">
<ToggleButton
x:Name="Tglbtn_Save"
Checked="Tglbtn_Save_Checked"
Unchecked="Tglbtn_Save_Checked" />
<ToggleButton
x:Name="Tglbtn_Upload"
Checked="Tglbtn_Upload_Checked"
Unchecked="Tglbtn_Upload_Checked" />
<Button
x:Name="Btn_CpyHistoryURL"
Click="Btn_CpyHistoryURL_Click"
ToolTip="Copy the history URL.">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Link" VerticalAlignment="Center" HorizontalAlignment="Center" />
<iconPacks:PackIconMaterial
HorizontalAlignment="Center"
VerticalAlignment="Center"
Kind="Link" />
</StackPanel>
</Button>
<Button x:Name="BtnRefresh" Click="BtnRefresh_Click">
<iconPacks:PackIconFontAwesome Width="15" Height="15" Kind="SyncAltSolid" />
<iconPacks:PackIconMaterial
Width="15"
Height="15"
Kind="Refresh" />
</Button>
</controls:WindowCommands>
</controls:MetroWindow.RightWindowCommands>

<Grid>
<DataGrid x:Name="dgvHistorySongs" Margin="148,10,10,19" SelectionMode="Single" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserSortColumns="False">
<DataGrid
x:Name="dgvHistorySongs"
Margin="148,10,10,19"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserSortColumns="False"
SelectionMode="Single">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Delete" Click="DgvItemDelete_Click" />
<MenuItem Click="DgvItemDelete_Click" Header="Delete" />
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Columns>
<DataGridTextColumn Header="{x:Static properties:Resources.s_Time}" IsReadOnly="True" Binding="{Binding Path=Time}" />
<DataGridTextColumn Header="{x:Static properties:Resources.s_Name}" IsReadOnly="True" Binding="{Binding Path=Name}" Width="*" />
<DataGridTextColumn
Binding="{Binding Path=Time}"
Header="{x:Static properties:Resources.s_Time}"
IsReadOnly="True" />
<DataGridTextColumn
Width="*"
Binding="{Binding Path=Name}"
Header="{x:Static properties:Resources.s_Name}"
IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>

<ListBox x:Name="LbxHistory" HorizontalAlignment="Left" Width="133" Margin="10,10,0,19"
SelectionChanged="LbxHistory_SelectionChanged">
<ListBox
x:Name="LbxHistory"
Width="133"
Margin="10,10,0,19"
HorizontalAlignment="Left"
SelectionChanged="LbxHistory_SelectionChanged">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Delete" Click="MenuItemDelete_Click" />
<MenuItem Click="MenuItemDelete_Click" Header="Delete" />
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
<StatusBar Height="14" VerticalAlignment="Bottom" Padding="0" ScrollViewer.CanContentScroll="True" Margin="0"
UseLayoutRounding="False">
<Label x:Name="Lbl_Status" FontSize="10" Padding="0" VerticalContentAlignment="Bottom"
HorizontalContentAlignment="Stretch" Width="340" HorizontalAlignment="Left" Margin="0,-4"
VerticalAlignment="Top" Foreground="{DynamicResource MahApps.Brushes.IdealForeground}"/>
<StatusBar
Height="14"
Margin="0"
Padding="0"
VerticalAlignment="Bottom"
ScrollViewer.CanContentScroll="True"
UseLayoutRounding="False">
<Label
x:Name="Lbl_Status"
Width="340"
Margin="0,-4"
Padding="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Bottom"
FontSize="10"
Foreground="{DynamicResource MahApps.Brushes.IdealForeground}" />
</StatusBar>
</Grid>
</controls:MetroWindow>

0 comments on commit 2e524f0

Please sign in to comment.