Skip to content

Commit e55d366

Browse files
committed
feat(Avalonia): add Imgur uploader settings
1 parent 0b8625f commit e55d366

3 files changed

Lines changed: 149 additions & 0 deletions

File tree

‎SnapX.Avalonia/Styling/Resources.axaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<converters:CustomUploaderNameConverter x:Key="CustomUploaderNameConverter" />
2424
<converters:HeaderSecurityBlurConverter x:Key="HeaderSecurityBlurConverter" />
2525
<converters:EnumToBooleanConverter x:Key="EnumToBool" />
26+
<converters:EnumDescriptionConverter x:Key="EnumDescConverter" />
2627
<ui:SymbolIconSource Symbol="Home" x:Key="HomeIcon" />
2728
<ui:SymbolIconSource Symbol="HomeFilled" x:Key="HomeIconFilled" />
2829
<StreamGeometry x:Key="HomeRegular">M21.6062 5.85517C23.0048 4.71494 24.9952 4.71494 26.3938 5.85517L39.5688 16.5966C40.4736 17.3342 41 18.4492 41 19.628V39.1134C41 41.2599 39.2875 43 37.175 43H32.075C29.9625 43 28.25 41.2599 28.25 39.1134V29.7492C28.25 29.0337 27.6792 28.4536 26.975 28.4536H21.025C20.3208 28.4536 19.75 29.0337 19.75 29.7492V39.1134C19.75 41.2599 18.0375 43 15.925 43H10.825C8.71251 43 7 41.2599 7 39.1134V19.628C7 18.4493 7.52645 17.3342 8.43124 16.5966L21.6062 5.85517ZM24.7979 7.87612C24.3317 7.49604 23.6683 7.49604 23.2021 7.87612L10.0271 18.6175C9.72548 18.8634 9.55 19.2351 9.55 19.628V39.1134C9.55 39.8289 10.1208 40.4089 10.825 40.4089H15.925C16.6292 40.4089 17.2 39.8289 17.2 39.1134V29.7492C17.2 27.6027 18.9125 25.8626 21.025 25.8626H26.975C29.0875 25.8626 30.8 27.6027 30.8 29.7492V39.1134C30.8 39.8289 31.3708 40.4089 32.075 40.4089H37.175C37.8792 40.4089 38.45 39.8289 38.45 39.1134V19.628C38.45 19.2351 38.2745 18.8634 37.9729 18.6175L24.7979 7.87612Z</StreamGeometry>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<UserControl
2+
x:Class="SnapX.Avalonia.Views.Settings.Views.ImageUploaders.ImgurUploaderSettingsView"
3+
x:DataType="img:Imgur"
4+
xmlns="https://github.com/avaloniaui"
5+
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
6+
xmlns:img="clr-namespace:SnapX.Core.Upload.Img;assembly=SnapX.Core"
7+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
8+
9+
<StackPanel Spacing="4">
10+
<controls:InfoBar
11+
IsClosable="False"
12+
IsOpen="True"
13+
Margin="0,0,0,8"
14+
Message="Their OAuth2 API is currently broken. We have reached out to Imgur support with no response. User accounts may be limited."
15+
Severity="Warning"
16+
Title="Imgur OAuth2 Unavailable" />
17+
<controls:SettingsExpanderItem Content="Account Type" ToolTip.Tip="Choose between Anonymous or User account uploads">
18+
<controls:SettingsExpanderItem.Footer>
19+
<ComboBox Width="150" x:Name="AccountTypeCombo" />
20+
</controls:SettingsExpanderItem.Footer>
21+
</controls:SettingsExpanderItem>
22+
23+
<controls:SettingsExpanderItem Content="Direct Link" ToolTip.Tip="Return the direct image URL instead of the Imgur page">
24+
<controls:SettingsExpanderItem.Footer>
25+
<ToggleSwitch Theme="{StaticResource CompactToggleSwitchStyle}" x:Name="DirectLinkSwitch" />
26+
</controls:SettingsExpanderItem.Footer>
27+
</controls:SettingsExpanderItem>
28+
29+
<controls:SettingsExpanderItem Content="Use GIFV" ToolTip.Tip="Automatically convert high-quality animations to GIFV">
30+
<controls:SettingsExpanderItem.Footer>
31+
<ToggleSwitch Theme="{StaticResource CompactToggleSwitchStyle}" x:Name="UseGifvSwitch" />
32+
</controls:SettingsExpanderItem.Footer>
33+
</controls:SettingsExpanderItem>
34+
35+
<controls:SettingsExpanderItem Content="Thumbnail Quality" ToolTip.Tip="Select the size of the thumbnail generated by Imgur">
36+
<controls:SettingsExpanderItem.Footer>
37+
<ComboBox Width="150" x:Name="ThumbnailCombo" />
38+
</controls:SettingsExpanderItem.Footer>
39+
</controls:SettingsExpanderItem>
40+
41+
<controls:SettingsExpanderItem Content="Upload to Selected Album" ToolTip.Tip="If enabled, images will be added to the album selected below">
42+
<controls:SettingsExpanderItem.Footer>
43+
<ToggleSwitch Theme="{StaticResource CompactToggleSwitchStyle}" x:Name="UploadSelectedAlbumSwitch" />
44+
</controls:SettingsExpanderItem.Footer>
45+
</controls:SettingsExpanderItem>
46+
47+
<controls:SettingsExpanderItem Content="Selected Album">
48+
<controls:SettingsExpanderItem.Footer>
49+
<StackPanel Orientation="Horizontal" Spacing="8">
50+
<ComboBox Width="250" x:Name="AlbumCombo">
51+
<ComboBox.ItemTemplate>
52+
<DataTemplate x:DataType="img:ImgurAlbumData">
53+
<TextBlock Text="{Binding title, FallbackValue='(Unnamed Album)'}" />
54+
</DataTemplate>
55+
</ComboBox.ItemTemplate>
56+
</ComboBox>
57+
<Button ToolTip.Tip="Refresh Album List" x:Name="RefreshAlbumsButton">
58+
<controls:SymbolIcon Symbol="Refresh" />
59+
</Button>
60+
</StackPanel>
61+
</controls:SettingsExpanderItem.Footer>
62+
</controls:SettingsExpanderItem>
63+
</StackPanel>
64+
</UserControl>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using Avalonia.Controls;
2+
using SnapX.Core.Upload;
3+
using SnapX.Core.Upload.Img;
4+
5+
namespace SnapX.Avalonia.Views.Settings.Views.ImageUploaders;
6+
7+
public partial class ImgurUploaderSettingsView : UserControl
8+
{
9+
public ImgurUploaderSettingsView()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
protected override void OnDataContextChanged(EventArgs e)
15+
{
16+
base.OnDataContextChanged(e);
17+
18+
if (DataContext is not Imgur imgur) return;
19+
var config = SnapX.Core.SnapXL.UploadersConfig;
20+
21+
// --- 1. MANUAL PULL ---
22+
23+
// Account Type
24+
AccountTypeCombo.ItemsSource = Enum.GetValues<AccountType>();
25+
AccountTypeCombo.SelectedItem = config.ImgurAccountType;
26+
27+
// Toggles
28+
DirectLinkSwitch.IsChecked = config.ImgurDirectLink;
29+
UseGifvSwitch.IsChecked = config.ImgurUseGIFV;
30+
UploadSelectedAlbumSwitch.IsChecked = config.ImgurUploadSelectedAlbum;
31+
32+
// Enums
33+
ThumbnailCombo.ItemsSource = Enum.GetValues<ImgurThumbnailType>();
34+
ThumbnailCombo.SelectedItem = config.ImgurThumbnailType;
35+
36+
// Albums (Initial Fill)
37+
ImgurFillAlbumList();
38+
39+
// --- 2. MANUAL PUSH ---
40+
41+
AccountTypeCombo.SelectionChanged += (s, ev) =>
42+
config.ImgurAccountType = (AccountType)(AccountTypeCombo.SelectedItem ?? AccountType.Anonymous);
43+
44+
DirectLinkSwitch.IsCheckedChanged += (s, ev) =>
45+
config.ImgurDirectLink = DirectLinkSwitch.IsChecked ?? false;
46+
47+
UseGifvSwitch.IsCheckedChanged += (s, ev) =>
48+
config.ImgurUseGIFV = UseGifvSwitch.IsChecked ?? false;
49+
50+
UploadSelectedAlbumSwitch.IsCheckedChanged += (s, ev) =>
51+
config.ImgurUploadSelectedAlbum = UploadSelectedAlbumSwitch.IsChecked ?? false;
52+
53+
ThumbnailCombo.SelectionChanged += (s, ev) =>
54+
{
55+
if (ThumbnailCombo.SelectedItem is ImgurThumbnailType type)
56+
config.ImgurThumbnailType = type;
57+
};
58+
59+
RefreshAlbumsButton.Click += (s, ev) => ImgurFillAlbumList();
60+
AlbumCombo.SelectionChanged += (s, ev) =>
61+
{
62+
if (AlbumCombo.SelectedItem is ImgurAlbumData selectedAlbum)
63+
{
64+
config.ImgurSelectedAlbum = selectedAlbum;
65+
}
66+
};
67+
}
68+
69+
private void ImgurFillAlbumList()
70+
{
71+
var config = SnapX.Core.SnapXL.UploadersConfig;
72+
73+
if (config.ImgurAlbumList != null)
74+
{
75+
AlbumCombo.ItemsSource = config.ImgurAlbumList;
76+
77+
if (config.ImgurSelectedAlbum != null)
78+
{
79+
AlbumCombo.SelectedItem = config.ImgurAlbumList
80+
.FirstOrDefault(a => a.id == config.ImgurSelectedAlbum.id);
81+
}
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)