Skip to content

Commit

Permalink
DataGrid Finalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Hen676 committed Oct 2, 2022
1 parent f8229b4 commit 6ae1f04
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 303 deletions.
4 changes: 1 addition & 3 deletions FadedVanguardLogUploader/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ namespace FadedVanguardLogUploader
public partial class App : Application
{
public static AppSettings Settings = new();
public static FluentTheme Fluent = new(new Uri("avares://ControlCatalog/Styles"));

private static FluentTheme Fluent = new(new Uri("avares://ControlCatalog/Styles"));
public override void Initialize()
{
if (Settings.ApiToggle)
GW2ApiHttps.Init();

Fluent.Mode = Settings.ModeToggle ? FluentThemeMode.Dark : FluentThemeMode.Light;

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(Settings.Lang);

Styles.Insert(0, Fluent);
Expand Down
45 changes: 45 additions & 0 deletions FadedVanguardLogUploader/Resources/Lang/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions FadedVanguardLogUploader/Resources/Lang/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@
<data name="LNG_Menu_Settings" xml:space="preserve">
<value>_Settings</value>
</data>
<data name="LNG_Menu_Settings_ClearFilter" xml:space="preserve">
<value>Clear Encounter Filter</value>
</data>
<data name="LNG_Menu_Settings_DarkMode" xml:space="preserve">
<value>Dark Mode</value>
</data>
Expand All @@ -376,4 +379,16 @@
<data name="LNG_Menu_Settings_PageAmount" xml:space="preserve">
<value>Page Amount</value>
</data>
<data name="LNG_Restart_Language_Body" xml:space="preserve">
<value>Language code: {0}</value>
</data>
<data name="LNG_Restart_Language_Title" xml:space="preserve">
<value>Restart required for language change to take effect</value>
</data>
<data name="LNG_Restart_Theme_Body" xml:space="preserve">
<value>Dark Theme: {0}</value>
</data>
<data name="LNG_Restart_Theme_Title" xml:space="preserve">
<value>Restart required for theme change to take effect</value>
</data>
</root>
3 changes: 1 addition & 2 deletions FadedVanguardLogUploader/Utils/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ internal class Filter
{
public DateTimeOffset timeOffsetMin = DateTimeOffset.MinValue;
public DateTimeOffset timeOffsetMax = DateTimeOffset.MaxValue;
public List<Encounter> encounter = new();
// TODO Implement Spec filtering
//public Specialization specialization = Specialization.Empty;

public bool Predicate(ListItem i)
{
return (encounter.Count == 0 || encounter.Contains(i.Encounter))
return (App.Settings.FilterEncounter.Count == 0 || App.Settings.FilterEncounter.Contains(i.Encounter))
&& i.CreationDate >= timeOffsetMin
&& i.CreationDate <= timeOffsetMax;
}
Expand Down
20 changes: 2 additions & 18 deletions FadedVanguardLogUploader/ViewModels/ListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public int ProgressBarMax
public ListViewModel()
{
UploadCommand = ReactiveCommand.Create(UploadAsync);
FilterSettings.encounter = App.Settings.FilterEncounter;
}

public void Load()
Expand All @@ -62,28 +61,13 @@ public void Load()
Filter();
}

public void FilterAddOrRemoveEncounter(Encounter encounter)
{
if (!FilterSettings.encounter.Contains(encounter))
FilterSettings.encounter.Add(encounter);
else
FilterSettings.encounter.Remove(encounter);

App.Settings.FilterEncounter = FilterSettings.encounter;
}
public void ClearFilter()
{
FilterSettings.encounter.Clear();
App.Settings.FilterEncounter.Clear();
}

private async void UploadAsync()
{
var popup = new PopupViewModel();
var uploadlist = StoredItems.Where(x => x.IsSelected).ToList();
if (uploadlist.Count > 50 || uploadlist.Count == 0)
{
popup.Message = "Error: Inavlid amount of files to upload " + uploadlist.Count + "/50";
popup.Title = "Error: Inavlid amount of files to upload " + uploadlist.Count + "/50";
await ShowDialog.Handle(popup);
return;
}
Expand Down Expand Up @@ -132,7 +116,7 @@ private async void UploadAsync()
await Application.Current.Clipboard.SetTextAsync(result);

ProgressBarValue = ProgressBarMax;
popup.Message = result;
popup.Title = result;
await ShowDialog.Handle(popup);
ProgressBarValue = 0;
}
Expand Down
62 changes: 38 additions & 24 deletions FadedVanguardLogUploader/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Avalonia.Controls;
using Avalonia.Themes.Fluent;
using FadedVanguardLogUploader.Enums;
using FadedVanguardLogUploader.IO;
using ReactiveUI;
using System;
using System.Globalization;
using System.Collections.ObjectModel;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading;
Expand Down Expand Up @@ -72,6 +71,7 @@ public SortingType SortType
this.RaiseAndSetIfChanged(ref sort, value);
}
}
public ObservableCollection<Encounter> FilterList { get; } = new(App.Settings.FilterEncounter);
public Interaction<PopupViewModel, bool> ShowDialog { get; } = new Interaction<PopupViewModel, bool>();
public ReactiveCommand<Unit, Unit> AboutCommand { get; }
public ReactiveCommand<Unit, Unit> SaveCommand { get; }
Expand All @@ -80,8 +80,8 @@ public SortingType SortType
public ReactiveCommand<string, Unit> LanguageCommand { get; }

public ReactiveCommand<Unit, Unit> AscDesToggleCommand { get; }
public ReactiveCommand<int, Unit> SortCommand { get; }
public ReactiveCommand<int, Unit> FilterCommand { get; }
public ReactiveCommand<SortingType, Unit> SortCommand { get; }
public ReactiveCommand<Encounter, Unit> FilterCommand { get; }
public ReactiveCommand<Unit, Unit> ClearFilterCommand { get; }
public ReactiveCommand<Unit, Unit> UseGw2ApiCommand { get; }
public ReactiveCommand<Unit, Unit> ErrorHiddenCommand { get; }
Expand All @@ -100,12 +100,12 @@ public MainWindowViewModel()
{
AboutCommand = ReactiveCommand.Create(About);
SaveCommand = ReactiveCommand.Create(Save);
ModeCommand = ReactiveCommand.Create(Mode);
LanguageCommand = ReactiveCommand.Create<string>(ChangeLanguage);
ModeCommand = ReactiveCommand.Create(ModeAsync);
LanguageCommand = ReactiveCommand.Create<string>(ChangeLanguageAsync);

AscDesToggleCommand = ReactiveCommand.Create(AscDesToggle);
SortCommand = ReactiveCommand.Create<int>(Sort);
FilterCommand = ReactiveCommand.Create<int>(Filter);
SortCommand = ReactiveCommand.Create<SortingType>(Sort);
FilterCommand = ReactiveCommand.Create<Encounter>(Filter);
ClearFilterCommand = ReactiveCommand.Create(ClearFilter);

UseGw2ApiCommand = ReactiveCommand.Create(UseGw2Api);
Expand All @@ -120,19 +120,23 @@ private void AscDesToggle()
App.Settings.SortingToggle = AscDesToggleHeader = !App.Settings.SortingToggle;
List.Filter();
}
private void Sort(int type)
private void Sort(SortingType type)
{
App.Settings.SortingType = SortType = (SortingType)type;
App.Settings.SortingType = SortType = type;
List.Filter();
}
private void Filter(int encounter)
private void Filter(Encounter encounter)
{
List.FilterAddOrRemoveEncounter((Encounter)encounter);
if (!FilterList.Contains(encounter))
FilterList.Add(encounter);
else
FilterList.Remove(encounter);
App.Settings.FilterEncounter = new(FilterList);
List.Filter();
}
private void ClearFilter()
{
List.ClearFilter();
App.Settings.FilterEncounter.Clear();
List.Filter();
}
private void ErrorHidden()
Expand All @@ -141,13 +145,6 @@ private void ErrorHidden()
List.Filter();
}

// TODO: Force restart for change
private void ChangeLanguage(string code)
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(code);
App.Settings.Lang = code;
}

private void Close(Window window)
{
window.Close();
Expand All @@ -163,11 +160,28 @@ private void UseGw2Api()
GW2ApiHttps.Init();
}

// TODO: Force restart for change
private void Mode()

private async void ModeAsync()
{
App.Settings.ModeToggle = ModeToggle = !ModeToggle;
App.Fluent.Mode = App.Settings.ModeToggle ? FluentThemeMode.Dark : FluentThemeMode.Light;
var popup = new PopupViewModel
{
Title = Resources.Lang.Resources.LNG_Restart_Theme_Title,
Body = string.Format(Resources.Lang.Resources.LNG_Restart_Theme_Body, ModeToggle)
};
await ShowDialog.Handle(popup);
}
private async void ChangeLanguageAsync(string code)
{
if (App.Settings.Lang == code)
return;
App.Settings.Lang = code; ;
var popup = new PopupViewModel
{
Title = Resources.Lang.Resources.LNG_Restart_Language_Title,
Body = string.Format(Resources.Lang.Resources.LNG_Restart_Language_Body, code)
};
await ShowDialog.Handle(popup);
}

private void Save()
Expand All @@ -179,7 +193,7 @@ public async void About()
{
var popup = new PopupViewModel
{
Message = "Faded Vanguard Log Uploader\n\n" +
Title = "Faded Vanguard Log Uploader\n\n" +
"Version: 1.0.0\n" +
"Creator: Hen676\n" +
"Repository: https://github.com/Hen676/FadedDiscordBot.NET"
Expand Down
6 changes: 4 additions & 2 deletions FadedVanguardLogUploader/ViewModels/PopupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ namespace FadedVanguardLogUploader.ViewModels
{
public class PopupViewModel : ViewModelBase
{
public string Message { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public ReactiveCommand<Window, Unit> CloseCommand { get; private set; }
public PopupViewModel()
{
Message = "Error: Popup failed to get message";
Title = "Error: Popup failed to get message";
Body = string.Empty;
CloseCommand = ReactiveCommand.Create<Window>(CloseWindow);
}

Expand Down
Loading

0 comments on commit 6ae1f04

Please sign in to comment.