<commit_before>﻿#region

using System;
using Windows.Media.Playback;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using Audiotica.Core;
using Audiotica.Core.Utilities;
using Audiotica.Data.Collection.Model;

#endregion

namespace Audiotica.PartialView
{
    public sealed partial class NowPlayingSheet : IModalSheetPage
    {
        public NowPlayingSheet()
        {
            InitializeComponent();
            CurrentQueueView.Loaded += CurrentQueueViewOnLoaded;
        }

        private void CurrentQueueViewOnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            CurrentQueueView.SelectedItem = App.Locator.Player.CurrentQueue;
            CurrentQueueView.ScrollIntoView(CurrentQueueView.SelectedItem);
        }

        public Popup Popup { get; private set; }
        private bool _justLoaded;
        public void OnOpened(Popup popup)
        {
            _justLoaded = true;
            Popup = popup;
            App.Locator.AudioPlayerHelper.TrackChanged += AudioPlayerHelperOnTrackChanged;
        }

        private void AudioPlayerHelperOnTrackChanged(object sender, EventArgs eventArgs)
        {
            CurrentQueueView.SelectedItem = App.Locator.Player.CurrentQueue;
            CurrentQueueView.ScrollIntoView(CurrentQueueView.SelectedItem);
        }

        public void OnClosed()
        {
            CurrentQueueView.Loaded -= CurrentQueueViewOnLoaded;
            App.Locator.AudioPlayerHelper.TrackChanged -= AudioPlayerHelperOnTrackChanged;
            Popup = null;
        }

        private void CurrentQueueView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var song = CurrentQueueView.SelectedItem as QueueSong;

            if (song == null) return;

            var currentPlayingId = AppSettingsHelper.Read<long>(PlayerConstants.CurrentTrack);

            if (e.RemovedItems.Count != 0 && song.Id != currentPlayingId)
            {
                App.Locator.AudioPlayerHelper.PlaySong(song);
            }
        }

        private bool _seeking;
        private void Slider_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            _seeking = true;
            BackgroundMediaPlayer.Current.Pause();
        }

        private void Slider_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            _seeking = false;
            BackgroundMediaPlayer.Current.Position = App.Locator.Player.Position;
            BackgroundMediaPlayer.Current.Play();
        }

        private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            if (_justLoaded)
            {
                _justLoaded = false;
                return;
            }

            var diff = e.NewValue - e.OldValue;
            if (!(diff > 5) && !(diff < -5)) return;

            if (_seeking) return;

            BackgroundMediaPlayer.Current.Position = App.Locator.Player.Position;
            BackgroundMediaPlayer.Current.Play();
        }
    }
}<commit_msg>Fix annoying stop when bootup (player)<commit_after>﻿#region

using System;
using Windows.Media.Playback;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using Audiotica.Core;
using Audiotica.Core.Utilities;
using Audiotica.Data.Collection.Model;

#endregion

namespace Audiotica.PartialView
{
    public sealed partial class NowPlayingSheet : IModalSheetPage
    {
        public NowPlayingSheet()
        {
            InitializeComponent();
            CurrentQueueView.Loaded += CurrentQueueViewOnLoaded;
        }

        private void CurrentQueueViewOnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            CurrentQueueView.SelectedItem = App.Locator.Player.CurrentQueue;
            CurrentQueueView.ScrollIntoView(CurrentQueueView.SelectedItem);
        }

        public Popup Popup { get; private set; }
        private bool _justLoaded;
        public void OnOpened(Popup popup)
        {
            _justLoaded = true;
            Popup = popup;
            App.Locator.AudioPlayerHelper.TrackChanged += AudioPlayerHelperOnTrackChanged;
        }

        private void AudioPlayerHelperOnTrackChanged(object sender, EventArgs eventArgs)
        {
            CurrentQueueView.SelectedItem = App.Locator.Player.CurrentQueue;
            CurrentQueueView.ScrollIntoView(CurrentQueueView.SelectedItem);
        }

        public void OnClosed()
        {
            CurrentQueueView.Loaded -= CurrentQueueViewOnLoaded;
            App.Locator.AudioPlayerHelper.TrackChanged -= AudioPlayerHelperOnTrackChanged;
            Popup = null;
        }

        private void CurrentQueueView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var song = CurrentQueueView.SelectedItem as QueueSong;

            if (song == null) return;

            var currentPlayingId = AppSettingsHelper.Read<long>(PlayerConstants.CurrentTrack);

            if (e.RemovedItems.Count != 0 && song.Id != currentPlayingId)
            {
                App.Locator.AudioPlayerHelper.PlaySong(song);
            }
        }

        private bool _seeking;
        private void Slider_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            _seeking = true;
            BackgroundMediaPlayer.Current.Pause();
        }

        private void Slider_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            _seeking = false;
            BackgroundMediaPlayer.Current.Position = App.Locator.Player.Position;
            BackgroundMediaPlayer.Current.Play();
        }

        private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            if (_justLoaded || BackgroundMediaPlayer.Current.Position == App.Locator.Player.Position)
            {
                _justLoaded = false;
                return;
            }

            var diff = e.NewValue - e.OldValue;
            if (!(diff > 5) && !(diff < -5)) return;

            if (_seeking) return;

            BackgroundMediaPlayer.Current.Position = App.Locator.Player.Position;
            BackgroundMediaPlayer.Current.Play();
        }
    }
}
{'fraction_non_alphanumeric': 0.07629216960693284, 'fraction_numerical': 0.0009285051067780873, 'mean_word_length': 2.299132210311383, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1791290', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1615, 'n_words': 317}