<commit_before>﻿using Crystal3.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Crystal3.Navigation;
using Neptunium.Core.Media.History;
using System.Collections.ObjectModel;
using Crystal3.UI.Commands;
using Windows.ApplicationModel.DataTransfer;

namespace Neptunium.ViewModel
{
    public class SongHistoryPageViewModel : ViewModelBase
    {
        protected override void OnNavigatedTo(object sender, CrystalNavigationEventArgs e)
        {
            NepApp.SongManager.History.SongAdded += History_SongAdded;
            UpdateHistory(NepApp.SongManager.History.HistoryOfSongs);

            base.OnNavigatedTo(sender, e);
        }

        private void History_SongAdded(object sender, SongHistorianSongUpdatedEventArgs e)
        {
            App.Dispatcher.RunAsync(() =>
            {
                UpdateHistory(sender as List<SongHistoryItem>);
            });
        }

        protected override void OnNavigatedFrom(object sender, CrystalNavigationEventArgs e)
        {
            History = null;

            base.OnNavigatedFrom(sender, e);
        }


        private void UpdateHistory(List<SongHistoryItem> collection)
        {
            History = collection.GroupBy(x => x.PlayedDate.Date).OrderByDescending(x => x.Key).Select(x => x);
        }

        public IEnumerable<IGrouping<DateTime, SongHistoryItem>> History
        {
            get { return GetPropertyValue<IEnumerable<IGrouping<DateTime, SongHistoryItem>>>(); }
            private set { SetPropertyValue<IEnumerable<IGrouping<DateTime, SongHistoryItem>>>(value: value); }
        }

        public RelayCommand CopyMetadataCommand => new RelayCommand(x =>
        {
            if (x == null) return;
            if (x is SongHistoryItem)<commit_msg>Fixed a code mistake from an earlier commit which would cause an exception on the song history page when a new song is played.<commit_after>﻿using Crystal3.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Crystal3.Navigation;
using Neptunium.Core.Media.History;
using System.Collections.ObjectModel;
using Crystal3.UI.Commands;
using Windows.ApplicationModel.DataTransfer;

namespace Neptunium.ViewModel
{
    public class SongHistoryPageViewModel : ViewModelBase
    {
        protected override void OnNavigatedTo(object sender, CrystalNavigationEventArgs e)
        {
            NepApp.SongManager.History.SongAdded += History_SongAdded;
            UpdateHistory(NepApp.SongManager.History.HistoryOfSongs);

            base.OnNavigatedTo(sender, e);
        }

        private void History_SongAdded(object sender, SongHistorianSongUpdatedEventArgs e)
        {
            App.Dispatcher.RunAsync(() =>
            {
                UpdateHistory(NepApp.SongManager.History.HistoryOfSongs as List<SongHistoryItem>);
            });
        }

        protected override void OnNavigatedFrom(object sender, CrystalNavigationEventArgs e)
        {
            History = null;

            base.OnNavigatedFrom(sender, e);
        }


        private void UpdateHistory(List<SongHistoryItem> collection)
        {
            History = collection.GroupBy(x => x.PlayedDate.Date).OrderByDescending(x => x.Key).Select(x => x);
        }

        public IEnumerable<IGrouping<DateTime, SongHistoryItem>> History
        {
            get { return GetPropertyValue<IEnumerable<IGrouping<DateTime, SongHistoryItem>>>(); }
            private set { SetPropertyValue<IEnumerable<IGrouping<DateTime, SongHistoryItem>>>(value: value); }
        }

        public RelayCommand CopyMetadataCommand => new RelayCommand(x =>
        {
            if (x == null) return;
            if (x is SongHistoryItem)
{'fraction_non_alphanumeric': 0.0861344537815126, 'fraction_numerical': 0.0015756302521008404, 'mean_word_length': 2.82429718875502, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3309023', 'n_tokens_mistral': 1029, 'n_tokens_neox': 971, 'n_words': 214}