Skip to content

Commit

Permalink
Merge pull request #4 from ErisLoona/avalonia-migration
Browse files Browse the repository at this point in the history
Avalonia migration
  • Loading branch information
ErisLoona authored Nov 27, 2024
2 parents 34a10c4 + c745293 commit ca04169
Show file tree
Hide file tree
Showing 78 changed files with 4,737 additions and 24,486 deletions.
10 changes: 10 additions & 0 deletions App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Manga_Manager.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
24 changes: 24 additions & 0 deletions App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace Manga_Manager
{
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}

base.OnFrameworkInitializationCompleted();
}
}
}
18 changes: 0 additions & 18 deletions App.config

This file was deleted.

Binary file added Assets/arrowleft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/export.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/reset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions BulkUpdateCheck.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<Window xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d" d:DesignWidth="459" d:DesignHeight="604"
Width="459" Height="604"
x:Class="Manga_Manager.BulkUpdateCheck"
Title="Bulk update check"
Background="DimGray"
RequestedThemeVariant="Light"
FontSize="12"
Foreground="White"
WindowStartupLocation="CenterScreen"
Icon="/Assets/icon.png">

<Window.Styles>
<Style Selector="Button">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Margin" Value="5,3,5,3"/>
<Setter Property="Background" Value="#F8C8DC"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template">
<ControlTemplate>
<ContentPresenter x:Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Padding="{TemplateBinding Padding}"
RecognizesAccessKey="True"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</ControlTemplate>
</Setter>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="12"/>
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background"
Value="#FFE5F0"/>
<Setter Property="TextBlock.Foreground"
Value="Black"/>
</Style>
</Window.Styles>

<Grid RowDefinitions="6*, 4*, 82*, 8*">
<Grid Grid.Row="0" ColumnDefinitions="60*, 40*">
<TextBlock Grid.Column="0" Text="Manga name" TextAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Center" Background="DimGray" Foreground="White" FontSize="16" Margin="3"/>
<TextBlock Grid.Column="1" Text="Status" TextAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Center" Background="DimGray" Foreground="White" FontSize="16" Margin="3"/>
</Grid>
<ProgressBar Grid.Row="1" x:Name="ProgressBar" Minimum="0" Value="0" Background="White" Foreground="#F8C8DC" ShowProgressText="True" Margin="3,0,3,0" ProgressTextFormat="{}{0}/{3} mangas checked"/>
<Grid Grid.Row="2" ColumnDefinitions="60*, 40*">
<ListBox Grid.Column="0" x:Name="MangaNameList" SelectionChanged="MangaNameList_SelectionChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="DimGray" Foreground="White" Padding="3, 3, 0, 3" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>
<ListBox Grid.Column="1" x:Name="ChapterStatusList" SelectionChanged="ChapterStatusList_SelectionChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="DimGray" Foreground="White" Padding="0, 3, 3, 3"/>
</Grid>
<Button Grid.Row="3" x:Name="CancelButton" Click="CancelButton_Clicked" Content="Cancel" FontSize="18"/>
</Grid>

</Window>
143 changes: 143 additions & 0 deletions BulkUpdateCheck.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using static Manga_Manager.Globals;
using MangaDex_Library;
using System.Linq;
using Avalonia.Media;
using MsBox.Avalonia.Enums;
using MsBox.Avalonia;

namespace Manga_Manager;

public partial class BulkUpdateCheck : Window
{
private bool checking = true, cancelled = false, destroyInput1 = false, destroyInput2 = false;
private List<int> mangaIndexes = new List<int>();
private Dictionary<int, int> mangaIndexesNewChapters = new Dictionary<int, int>();
private CancellationTokenSource tokenSource = new CancellationTokenSource();
private CancellationToken cancelCheck;

public BulkUpdateCheck()
{
InitializeComponent();
StartChecking();
}

private async void StartChecking()
{
for (int i = 0; i < mangaList.Count; i++)
if (mangaList[i].CheckInBulk == true)
mangaIndexes.Add(i);
ProgressBar.Maximum = mangaIndexes.Count;
cancelCheck = tokenSource.Token;
IProgress<int> progress = new Progress<int>(v => { ProgressBar.Value++; });
await Task.Run(async () =>
{
foreach (int i in mangaIndexes)
{
if (cancelCheck.IsCancellationRequested)
{
cancelled = true;
return;
}
MDLParameters.MangaID = mangaList[i].ID;
MDLGetData.GetLastChapter();
if (apiError == true)
{
await MessageBoxManager.GetMessageBoxStandard("API error", "An error occurred while trying to contact the MangaDex API.\nPlease double-check the Manga link and try again later.", ButtonEnum.Ok).ShowAsync();
apiError = false;
return;
}
decimal onlineChapter = MDLGetData.GetLastChapter();
mangaList[i].OnlineLastChapter = onlineChapter;
mangaList[i].LastChecked = new DateOnly(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
mangaIndexesNewChapters[i] = Convert.ToInt32(Math.Ceiling(onlineChapter - mangaList[i].FileLastChapter));
progress.Report(0);
}
mangaIndexesNewChapters = mangaIndexesNewChapters.OrderByDescending(pair => pair.Value).ToDictionary();
}, cancelCheck);
checking = false;
CancelButton.Content = "Close";
if (cancelled == true)
return;
foreach (KeyValuePair<int, int> result in mangaIndexesNewChapters)
{
MangaNameList.Items.Add(new TextBlock
{
Foreground = new SolidColorBrush(Colors.White),
FontSize = 12,
Text = mangaList[result.Key].Title
});
if (result.Value == 0)
ChapterStatusList.Items.Add(new TextBlock
{
Foreground = new SolidColorBrush(Colors.White),
FontSize = 12,
Text = "-> Up to date!"
});
else if (result.Value == 1)
ChapterStatusList.Items.Add(new TextBlock
{
Foreground = new SolidColorBrush(Colors.White),
FontSize = 12,
Text = "-> 1 chapter ahead."
});
else if (result.Value < 0)
ChapterStatusList.Items.Add(new TextBlock
{
Foreground = new SolidColorBrush(Colors.White),
FontSize = 12,
Text = "-> Please check book link!"
});
else
ChapterStatusList.Items.Add(new TextBlock
{
Foreground = new SolidColorBrush(Colors.White),
FontSize = 12,
Text = "-> " + Convert.ToString(result.Value) + " chapters ahead."
});
}
}

private void MangaNameList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (destroyInput1 == true)
{
destroyInput1 = false;
return;
}
destroyInput2 = true;
ChapterStatusList.SelectedIndex = MangaNameList.SelectedIndex;
}

private void ChapterStatusList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (destroyInput2 == true)
{
destroyInput2 = false;
return;
}
destroyInput1 = true;
MangaNameList.SelectedIndex = ChapterStatusList.SelectedIndex;
}

private void CancelButton_Clicked(object sender, RoutedEventArgs args)
{
if (checking == true)
tokenSource.Cancel();
else
this.Close();
}

protected override void OnClosing(WindowClosingEventArgs e)
{
if (checking == true)
tokenSource.Cancel();

base.OnClosing(e);
}
}
63 changes: 63 additions & 0 deletions Downloader-AddFromLibrary.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Window xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d" d:DesignWidth="342" d:DesignHeight="569"
Width="342" Height="569"
x:Class="Manga_Manager.Downloader_AddFromLibrary"
Title="Add Manga from library"
Background="DimGray"
RequestedThemeVariant="Light"
FontSize="12"
Foreground="White"
WindowStartupLocation="CenterScreen"
Icon="/Assets/icon.png">

<Window.Styles>
<Style Selector="Button">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Margin" Value="5,3,5,3"/>
<Setter Property="Background" Value="#F8C8DC"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template">
<ControlTemplate>
<ContentPresenter x:Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Padding="{TemplateBinding Padding}"
RecognizesAccessKey="True"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</ControlTemplate>
</Setter>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="12"/>
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background"
Value="#FFE5F0"/>
<Setter Property="TextBlock.Foreground"
Value="Black"/>
</Style>
</Window.Styles>

<Grid RowDefinitions="93*, 7*">
<Border Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ScrollViewer>
<StackPanel x:Name="MangaStackPanel" Spacing="4"/>
</ScrollViewer>
</Border>
<Grid Grid.Row="1" ColumnDefinitions="50*, 50*">
<Button Grid.Column="0" Content="Confirm" Click="ConfirmButton_Clicked"/>
<Button Grid.Column="1" Content="Select all" Click="SelectAllButton_Clicked"/>
</Grid>
</Grid>

</Window>
54 changes: 54 additions & 0 deletions Downloader-AddFromLibrary.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using static Manga_Manager.Globals;
using System.Collections.Generic;
using System.IO;

namespace Manga_Manager;

public partial class Downloader_AddFromLibrary : Window
{
Dictionary<string, int> addedMangaIndexes = new Dictionary<string, int>();

public Downloader_AddFromLibrary()
{
InitializeComponent();

for (int i = 0; i < mangaList.Count; i++)
{
if (mangaList[i].ID != string.Empty && Downloader.addedMangas.Contains(mangaList[i].ID) == false && File.Exists(mangaList[i].Path))
{
MangaStackPanel.Children.Add(new CheckBox()
{
Foreground = new SolidColorBrush(Colors.White),
Margin = new Thickness(3, 0, 0, 0),
Content = mangaList[i].Title
});
addedMangaIndexes[mangaList[i].Title] = i;
}
}
}

private void SelectAllButton_Clicked(object sender, RoutedEventArgs args)
{
foreach (Control child in MangaStackPanel.Children)
{
CheckBox checkBox = child as CheckBox;
checkBox.IsChecked = true;
}
}

private void ConfirmButton_Clicked(object sender, RoutedEventArgs args)
{
List<int> selectedIndexes = new List<int>();
foreach (Control child in MangaStackPanel.Children)
{
CheckBox checkBox = child as CheckBox;
if (checkBox.IsChecked == true)
selectedIndexes.Add(addedMangaIndexes[checkBox.Content.ToString()]);
}
Close(selectedIndexes);
}
}
Loading

0 comments on commit ca04169

Please sign in to comment.