Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The UISettings.ColorValueChanged is not called on Windows 10 #106

Open
github-actions bot opened this issue Mar 9, 2024 · 0 comments
Open

The UISettings.ColorValueChanged is not called on Windows 10 #106

github-actions bot opened this issue Mar 9, 2024 · 0 comments
Labels

Comments

@github-actions
Copy link

github-actions bot commented Mar 9, 2024

https://github\.com/CommunityToolkit/WindowsCommunityToolkit/issues/4412\#issuecomment\-1823919825

{

new LineSeries<double>

{

Values = _values,

Fill = null

}

};

//TODO: The UISettings.ColorValueChanged is not called on Windows 10

        _itemService.OnItemsChanged += ItemService_OnItemsChanged;
        _itemService.OnItemsInitialized += ItemService_OnItemsChanged;

        UpdateVisual(_itemService.GetItems());

        var accentColor = (Color)Application.Current.Resources["SystemAccentColor"];
        var skColor = new SKColor(accentColor.R, accentColor.G, accentColor.B);

        ObservableCollection<ISeries> series =
        [
            new LineSeries<decimal>
            {
                Values = _values,
                Fill = null,
                Stroke = new SolidColorPaint(skColor) { StrokeThickness = 6 },
                GeometryStroke = new SolidColorPaint(skColor) { StrokeThickness = 0 },
                GeometryFill = new SolidColorPaint(skColor) { StrokeThickness = 0 }
            }
        ];

        Series = series;

        DateTime currentDate = DateTime.Now;
        var months = new string[6];

        for (int i = 0; i < 6; i++)
        {
            months[5 - i] = currentDate.AddMonths(-i).ToString("MMM", CultureInfo.CurrentCulture);
        }

        XAxes = [
            new Axis
            {
                ShowSeparatorLines = false,
                Labels = months,
                LabelsPaint = new SolidColorPaint(SKColors.White),
                TextSize = 14
            }];

        YAxes = [
            new Axis
            {
                ShowSeparatorLines = false,
                Labeler = value => value.ToString("C", CurrencyCache.CurrencyCultures[_settingsService.DefaultCurrency]),
                LabelsPaint = new SolidColorPaint(SKColors.LightGray),
                TextSize = 14
            }];
    }

    private void UISettings_ColorValuesChanged(UISettings sender, object args)
    {
        //TODO: The UISettings.ColorValueChanged is not called on Windows 10
        //https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4412#issuecomment-1823919825

        var accentColor = (Color)Application.Current.Resources["SystemAccentColor"];
        var skColor = new SKColor(accentColor.R, accentColor.G, accentColor.B);

        ((LineSeries<decimal>)Series[0]).Stroke = new SolidColorPaint(skColor) { StrokeThickness = 6 };
        ((LineSeries<decimal>)Series[0]).GeometryStroke = new SolidColorPaint(skColor) { StrokeThickness = 0 };
        ((LineSeries<decimal>)Series[0]).GeometryFill = new SolidColorPaint(skColor) { StrokeThickness = 0 };

        ((Axis)XAxes[0]).LabelsPaint = new SolidColorPaint(SKColors.Pink);
        ((Axis)YAxes[0]).LabelsPaint = new SolidColorPaint(SKColors.LightBlue);
    }

    private void ItemService_OnItemsChanged(object? sender, IEnumerable<ItemViewModel> e)
    {
        UpdateVisual(e);
    }

    private async void UpdateVisual(IEnumerable<ItemViewModel> items)
    {
        SetSum(items);

        _values.Clear();
        for (int i = 0; i < 6; i++) 
        {
            var date = DateTime.Now.AddMonths(-i);
            var days = DateTime.DaysInMonth(date.Year, date.Month);

            var tasks = items.Select(async item => 
            item.IsArchived ? 0 : await _currencyCache.ConvertToDefaultCurrency
            (
                item.Item?.Billing.BasePrice * item.GetPaymentsInPeriod(days, (DateTime.Now - date).Days) ?? 0,
                item?.Item?.Billing?.CurrencyId ?? "EUR",
                _settingsService.DefaultCurrency)
            );

            var values = await Task.WhenAll(tasks);

            _values.Insert(0, values.Sum());
        }
    }

    private async void SetSum(IEnumerable<ItemViewModel> e)
@github-actions github-actions bot added the todo label Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants