<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Threading;

namespace Plugin.MediaManager.Abstractions
{
    public class MediaQueue : IMediaQueue
    {
        public MediaQueue ()
        {
            _queue = new ObservableCollection<IMediaFile>();

            _queue.CollectionChanged += (sender, e) =>
            {
                if (CollectionChanged != null)
                    CollectionChanged(sender, e);
            };

            RegisterCountTriggers();
            RegisterCurrentTriggers();
        }

        private ObservableCollection<IMediaFile> _queue;

        private ObservableCollection<IMediaFile> _unshuffledQueue;

        private int _count;
        public int Count
        {
            get
            {
                return _count;
            }
        }

        private IMediaFile _current;
        public IMediaFile Current
        {
            get
            {
                if (Count > 0 && Index >= 0)
                {
                    return _current = _queue[Index];
                }

                return _current = null;
            }
        }

        private int _index = -1;
        public int Index
        {
            get
            {
                return _index;
            }
            private set
            {
                _index = value;
                OnPropertyChanged(nameof(Index));
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        private bool repeat;
        public bool Repeat
        {
            get
            {
                return repeat;
            }
            private set
            {
                repeat = value;
                OnPropertyChanged(nameof(Repeat));
            }
        }

        public bool Shuffle
        {
            get
            {
                return _unshuffledQueue != null;
            }
        }

        public event NotifyCollectionChangedEventHandler CollectionChanged;
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        public void Add(IMediaFile item)
        {
            _queue.Add(item);

            // If shuffle is enabled, we need to add the item to the backup queue too
            if (Shuffle)
            {
                _unshuffledQueue.Add(item);
            }

            if (Index == -1)
            {
                Index = 0;
            }
        }

        public void AddRange(IEnumerable<IMediaFile> items)
        {
            _queue.AddRange(items);

            // If shuffle is enabled, we need to add the items to the backup queue too
            if (Shuffle)
            {
                _unshuffledQueue.AddRange(items);
            }

            if (Index == -1)
            {
                Index = 0;
            }
        }

        public void Clear()
        {
            Index = -1;
            _queue.Clear();
            _unshuffledQueue = null;
        }

        public bool Contains(IMediaFile item)
        {
            return _queue.Contains(item);
        }

        public void CopyTo(IMediaFile[] array, int arrayIndex)
        {
            _queue.CopyTo(array, arrayIndex);

            if (Index == -1)<commit_msg>Fixed trigger for "Shuffle" property when clearing the MediaQueue<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Threading;

namespace Plugin.MediaManager.Abstractions
{
    public class MediaQueue : IMediaQueue
    {
        public MediaQueue ()
        {
            _queue = new ObservableCollection<IMediaFile>();

            _queue.CollectionChanged += (sender, e) =>
            {
                if (CollectionChanged != null)
                    CollectionChanged(sender, e);
            };

            RegisterCountTriggers();
            RegisterCurrentTriggers();
        }

        private ObservableCollection<IMediaFile> _queue;

        private ObservableCollection<IMediaFile> _unshuffledQueue;

        private int _count;
        public int Count
        {
            get
            {
                return _count;
            }
        }

        private IMediaFile _current;
        public IMediaFile Current
        {
            get
            {
                if (Count > 0 && Index >= 0)
                {
                    return _current = _queue[Index];
                }

                return _current = null;
            }
        }

        private int _index = -1;
        public int Index
        {
            get
            {
                return _index;
            }
            private set
            {
                _index = value;
                OnPropertyChanged(nameof(Index));
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        private bool repeat;
        public bool Repeat
        {
            get
            {
                return repeat;
            }
            private set
            {
                repeat = value;
                OnPropertyChanged(nameof(Repeat));
            }
        }

        public bool Shuffle
        {
            get
            {
                return _unshuffledQueue != null;
            }
        }

        public event NotifyCollectionChangedEventHandler CollectionChanged;
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        public void Add(IMediaFile item)
        {
            _queue.Add(item);

            // If shuffle is enabled, we need to add the item to the backup queue too
            if (Shuffle)
            {
                _unshuffledQueue.Add(item);
            }

            if (Index == -1)
            {
                Index = 0;
            }
        }

        public void AddRange(IEnumerable<IMediaFile> items)
        {
            _queue.AddRange(items);

            // If shuffle is enabled, we need to add the items to the backup queue too
            if (Shuffle)
            {
                _unshuffledQueue.AddRange(items);
            }

            if (Index == -1)
            {
                Index = 0;
            }
        }

        public void Clear()
        {
            Index = -1;
            _queue.Clear();

            if (_unshuffledQueue != null)
            {
                _unshuffledQueue = null;
                OnPropertyChanged(nameof(Shuffle));
            }
        }

        public bool Contains(IMediaFile item)
        {
            return _queue.Contains(item);
        }

        public void CopyTo(IMediaFile[] array, int arrayIndex)
        {
            _queue.CopyTo(array, arrayIndex);

            if (Index == -1)
{'fraction_non_alphanumeric': 0.06838845697720385, 'fraction_numerical': 0.002371853999209382, 'mean_word_length': 1.1350210970464134, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '4890349', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1752, 'n_words': 439}