From cfb2bf8cda36cadcc49ecb57dee33fddbc9f447b Mon Sep 17 00:00:00 2001 From: Jebzou <22751386+Jebzou@users.noreply.github.com> Date: Sun, 24 Nov 2024 10:53:10 +0100 Subject: [PATCH] Added tracker --- ElectronicObserver/App.xaml.cs | 6 ++++ ...Kind.cs => SenkaLeaderboardRefreshKind.cs} | 3 +- .../Control/Paging/PagingControlViewModel.cs | 19 +++++++---- .../SenkaLeaderboardManager.cs | 30 +++++++++++------ .../SenkaLeaderboardView.xaml | 32 +++++++++++++++++++ .../SenkaLeaderboardViewModel.cs | 8 ++++- 6 files changed, 78 insertions(+), 20 deletions(-) rename ElectronicObserver/Data/{SenkaCutoffKind.cs => SenkaLeaderboardRefreshKind.cs} (60%) diff --git a/ElectronicObserver/App.xaml.cs b/ElectronicObserver/App.xaml.cs index 94f9418e7..2f08b4b69 100644 --- a/ElectronicObserver/App.xaml.cs +++ b/ElectronicObserver/App.xaml.cs @@ -477,6 +477,12 @@ private static Tracker JotTracker() .Property(w => w.ViewModel.DataGridViewModel.ColumnProperties) .Property(w => w.ViewModel.DataGridViewModel.SortDescriptions); + tracker + .Configure() + .Property(w => w.CurrentCutoffData.DataGridViewModel.ColumnProperties) + .Property(w => w.CurrentCutoffData.DataGridViewModel.SortDescriptions) + .Property(w => w.CurrentCutoffData.PagingViewModel.ItemsPerPage); + return tracker; } } diff --git a/ElectronicObserver/Data/SenkaCutoffKind.cs b/ElectronicObserver/Data/SenkaLeaderboardRefreshKind.cs similarity index 60% rename from ElectronicObserver/Data/SenkaCutoffKind.cs rename to ElectronicObserver/Data/SenkaLeaderboardRefreshKind.cs index ff053232c..63603c75e 100644 --- a/ElectronicObserver/Data/SenkaCutoffKind.cs +++ b/ElectronicObserver/Data/SenkaLeaderboardRefreshKind.cs @@ -1,8 +1,7 @@ namespace ElectronicObserver.Data; -public enum SenkaCutoffKind +public enum SenkaLeaderboardRefreshKind { NewDay, MidDay, - NewMonth, } diff --git a/ElectronicObserver/Window/Control/Paging/PagingControlViewModel.cs b/ElectronicObserver/Window/Control/Paging/PagingControlViewModel.cs index 0cac697eb..bf61ef546 100644 --- a/ElectronicObserver/Window/Control/Paging/PagingControlViewModel.cs +++ b/ElectronicObserver/Window/Control/Paging/PagingControlViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -12,7 +13,7 @@ public partial class PagingControlViewModel : ObservableObject public List Items { get; set; } = new(); - public List DisplayedItems { get; private set; } = new(); + public ObservableCollection DisplayedItems { get; private set; } = new(); public int ItemsPerPage { get; set; } = 10; @@ -55,15 +56,19 @@ private void UpdateCollection() { CurrentPage = Math.Clamp(CurrentPage, 1, LastPage); - DisplayedItems = Items switch + DisplayedItems.Clear(); + + if (Items.Count > 0) { - { Count: > 0 } => Items + IEnumerable items = Items .Skip(ItemsPerPage * (CurrentPage - 1)) - .Take(ItemsPerPage) - .ToList(), + .Take(ItemsPerPage); - _ => new(), - }; + foreach (object item in items) + { + DisplayedItems.Add(item); + } + } OnPropertyChanged(nameof(LastPage)); } diff --git a/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardManager.cs b/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardManager.cs index 25363eb9b..d81f11093 100644 --- a/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardManager.cs +++ b/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardManager.cs @@ -9,6 +9,7 @@ using ElectronicObserver.Services; using ElectronicObserver.Utility; using ElectronicObserver.Utility.Mathematics; +using Jot; namespace ElectronicObserver.Window.Wpf.SenkaLeaderboard; @@ -17,35 +18,39 @@ public partial class SenkaLeaderboardManager : ObservableObject public SenkaLeaderboardViewModel CurrentCutoffData { get; } = new(); private TimeChangeService TimeChangeService { get; } + private Tracker Tracker { get; } [ObservableProperty] - private partial SenkaCutoffKind CurrentSenkaCutoffKind { get; set; } + private partial SenkaLeaderboardRefreshKind CurrentSenkaLeaderboardRefreshKind { get; set; } - public SenkaLeaderboardManager(TimeChangeService timeChangeService) + public SenkaLeaderboardManager(TimeChangeService timeChangeService, Tracker tracker) { APIObserver.Instance.ApiReqRanking_Mxltvkpyuklh.ResponseReceived += HandleData; TimeChangeService = timeChangeService; - TimeChangeService.HourChanged += () => CurrentSenkaCutoffKind = GetSankaLeaderboardCutoffKind(); + TimeChangeService.HourChanged += () => CurrentSenkaLeaderboardRefreshKind = GetSankaLeaderboardRefreshKind(); - CurrentSenkaCutoffKind = GetSankaLeaderboardCutoffKind(); + Tracker = tracker; - PropertyChanged += OnSenkaLeaderboardCutoffChanged; + CurrentSenkaLeaderboardRefreshKind = GetSankaLeaderboardRefreshKind(); + + PropertyChanged += OnSenkaLeaderboardRefreshKindChanged; CurrentCutoffData.Update(); + StartJotTracking(); } - private void OnSenkaLeaderboardCutoffChanged(object? sender, PropertyChangedEventArgs e) + private void OnSenkaLeaderboardRefreshKindChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName is not nameof(CurrentSenkaCutoffKind)) return; + if (e.PropertyName is not nameof(CurrentSenkaLeaderboardRefreshKind)) return; CurrentCutoffData.Reset(); } - private SenkaCutoffKind GetSankaLeaderboardCutoffKind() => DateTimeHelper.GetJapanStandardTimeNow() switch + private SenkaLeaderboardRefreshKind GetSankaLeaderboardRefreshKind() => DateTimeHelper.GetJapanStandardTimeNow() switch { - { Hour: >= 15 or < 3 } => SenkaCutoffKind.MidDay, - _ => SenkaCutoffKind.NewDay, + { Hour: >= 15 or < 3 } => SenkaLeaderboardRefreshKind.MidDay, + _ => SenkaLeaderboardRefreshKind.NewDay, }; private void HandleData(string apiname, dynamic data) @@ -72,4 +77,9 @@ private void HandleData(string apiname, dynamic data) CurrentCutoffData.Update(); } } + + private void StartJotTracking() + { + Tracker.Track(this); + } } diff --git a/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardView.xaml b/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardView.xaml index d1d3e5fb9..54df33f3e 100644 --- a/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardView.xaml +++ b/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardView.xaml @@ -2,10 +2,12 @@ x:Class="ElectronicObserver.Window.Wpf.SenkaLeaderboard.SenkaLeaderboardView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:b="http://schemas.microsoft.com/xaml/behaviors" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ElectronicObserver.Window.Wpf.SenkaLeaderboard" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:paging="clr-namespace:ElectronicObserver.Window.Control.Paging" + xmlns:persistentColumns="clr-namespace:ElectronicObserver.Behaviors.PersistentColumns" d:DataContext="{d:DesignInstance Type=local:SenkaLeaderboardViewModel}" d:DesignHeight="250" d:DesignWidth="130" @@ -34,10 +36,40 @@ + + + + + + + + + + diff --git a/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardViewModel.cs b/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardViewModel.cs index f8d527f3e..b6ca54bf4 100644 --- a/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardViewModel.cs +++ b/ElectronicObserver/Window/Wpf/SenkaLeaderboard/SenkaLeaderboardViewModel.cs @@ -5,12 +5,15 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.Input; +using ElectronicObserver.Common.Datagrid; using ElectronicObserver.Data.Bonodere; using ElectronicObserver.KancolleApi.Types.ApiReqRanking.Models; using ElectronicObserver.Resource; using ElectronicObserver.Utility; using ElectronicObserver.ViewModels; using ElectronicObserver.Window.Control.Paging; +using ElectronicObserver.Window.Tools.EquipmentUpgradePlanner; +using Jot; namespace ElectronicObserver.Window.Wpf.SenkaLeaderboard; @@ -25,6 +28,8 @@ public partial class SenkaLeaderboardViewModel : AnchorableViewModel public PagingControlViewModel PagingViewModel { get; } + public DataGridViewModel DataGridViewModel { get; } + [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(SubmitDataCommand))] public partial int LoadedEntriesCount { get; set; } @@ -32,7 +37,7 @@ public partial class SenkaLeaderboardViewModel : AnchorableViewModel public BonodereSubmissionService BonodereSubmissionService { get; } public SenkaLeaderboardTranslationViewModel Translation { get; } - + public bool IsBonodereReady => !string.IsNullOrEmpty(Configuration.Config.DataSubmission.BonodereToken); public SenkaLeaderboardViewModel() : base(SenkaLeaderboardResources.Title, "SenkaLeaderboard", IconContent.FormResourceChart) @@ -47,6 +52,7 @@ public SenkaLeaderboardViewModel() : base(SenkaLeaderboardResources.Title, "Senk BonodereSubmissionService = Ioc.Default.GetRequiredService(); PagingViewModel = new(); + DataGridViewModel = new(new()); Update(); Configuration.Instance.ConfigurationChanged += () => OnPropertyChanged(nameof(IsBonodereReady));