Inheritance: EarTrumpet.ViewModels.BindableBase
        public void Refresh()
        {
            var defaultDevice = _deviceService.GetAudioDevices().FirstOrDefault(x => x.IsDefault);
            var volume        = _deviceService.GetAudioDeviceVolume(defaultDevice.Id);
            var newDevice     = new DeviceAppItemViewModel(_proxy, defaultDevice, volume);

            if (Device != null && Device.IsSame(newDevice))
            {
                Device.UpdateFromOther(newDevice);
            }
            else
            {
                Device = newDevice;
            }
            RaisePropertyChanged("Device");

            bool hasApps = Apps.Count > 0;

            var sessions = _audioService.GetAudioSessionGroups().Select(x => new AppItemViewModel(_proxy, x));

            List <AppItemViewModel> staleSessionsToRemove = new List <AppItemViewModel>();

            // remove stale apps
            foreach (var app in Apps)
            {
                if (!sessions.Where(x => (x.IsSame(app))).Any())
                {
                    staleSessionsToRemove.Add(app);
                }
            }
            foreach (var app in staleSessionsToRemove)
            {
                Apps.Remove(app);
            }

            // add new apps
            foreach (var session in sessions)
            {
                var findApp = Apps.FirstOrDefault(x => x.IsSame(session));
                if (findApp == null)
                {
                    Apps.AddSorted(session, AppItemViewModelComparer.Instance);
                }
                else
                {
                    // update existing apps
                    findApp.UpdateFromOther(session);
                }
            }

            ListVisibility       = Apps.Count > 0 ? Visibility.Visible : Visibility.Hidden;
            NoAppsPaneVisibility = Apps.Count == 0 ? Visibility.Visible : Visibility.Hidden;

            if (hasApps != (Apps.Count > 0))
            {
                RaisePropertyChanged("ListVisibility");
                RaisePropertyChanged("NoAppsPaneVisibility");
            }
        }
        public void Refresh()
        {
            var devices = _deviceService.GetAudioDevices();
            if (devices.Any())
            {
                var defaultDevice = devices.FirstOrDefault(x => x.IsDefault);
                var volume = _deviceService.GetAudioDeviceVolume(defaultDevice.Id);
                var newDevice = new DeviceAppItemViewModel(_proxy, defaultDevice, volume);
                if (Device != null && Device.IsSame(newDevice))
                {
                    Device.UpdateFromOther(newDevice);
                }
                else
                {
                    Device = newDevice;
                }
                RaisePropertyChanged("Device");
            }

            bool hasApps = Apps.Count > 0;
            var sessions = _audioService.GetAudioSessionGroups().Select(x => new AppItemViewModel(_proxy, x));

            List<AppItemViewModel> staleSessionsToRemove = new List<AppItemViewModel>();

            // remove stale apps
            foreach (var app in Apps)
            {
                if (!sessions.Where(x => (x.IsSame(app))).Any())
                {
                    staleSessionsToRemove.Add(app);
                }
            }
            foreach (var app in staleSessionsToRemove) { Apps.Remove(app); }

            // add new apps
            foreach (var session in sessions)
            {
                var findApp = Apps.FirstOrDefault(x => x.IsSame(session));
                if (findApp == null)
                {
                    Apps.AddSorted(session, AppItemViewModelComparer.Instance);
                }
                else
                {
                    // update existing apps
                    findApp.UpdateFromOther(session);
                }
            }

            ListVisibility = Apps.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
            NoAppsPaneVisibility = Apps.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
            NoItemsContent = Device == null ? Properties.Resources.NoDevicesPanelContent : Properties.Resources.NoAppsPanelContent;
            DeviceVisibility = Device != null ? Visibility.Visible : Visibility.Collapsed;

            RaisePropertyChanged("ListVisibility");
            RaisePropertyChanged("NoAppsPaneVisibility");
            RaisePropertyChanged("NoItemsContent");
            RaisePropertyChanged("DeviceVisibility");
        }
 public void UpdateFromOther(DeviceAppItemViewModel other)
 {
     if (_volume == other.Volume && _isMuted == other.IsMuted)
     {
         return;
     }
     _volume  = other.Volume;
     _isMuted = other.IsMuted;
     RaisePropertyChanged("Volume");
     RaisePropertyChanged("IsMuted");
 }
Example #4
0
        private void DeviceService_MasterVolumeChanged(object sender, EarTrumpetAudioDeviceService.MasterVolumeChangedArgs e)
        {
            var defaultDevice = _deviceService.GetAudioDevices().FirstOrDefault(x => x.IsDefault);

            if (!defaultDevice.Equals(default(EarTrumpetAudioDeviceModel)))
            {
                var updatedDefaultDevice = new DeviceAppItemViewModel(_proxy, defaultDevice, e.Volume);
                Device.UpdateFromOther(updatedDefaultDevice);
                RaisePropertyChanged("Device");
            }
            else
            {
                Refresh();
            }
        }
Example #5
0
 private void DeviceService_MasterVolumeChanged(object sender, EarTrumpetAudioDeviceService.MasterVolumeChangedArgs e)
 {
     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
     {
         var defaultDevice = _deviceService.GetAudioDevices().FirstOrDefault(x => x.IsDefault);
         if (!defaultDevice.Equals(default(EarTrumpetAudioDeviceModel)) && Device != null)
         {
             var updatedDefaultDevice = new DeviceAppItemViewModel(_proxy, defaultDevice, e.Volume);
             Device.UpdateFromOther(updatedDefaultDevice);
             RaisePropertyChanged("Device");
         }
         else
         {
             Refresh();
         }
     }));
 }
 public void UpdateFromOther(DeviceAppItemViewModel other)
 {
     if (_volume == other.Volume) return;
     _volume = other.Volume;
     _isMuted = other.IsMuted;
     RaisePropertyChanged("Volume");
     RaisePropertyChanged("IsMuted");
 }
 public bool IsSame(DeviceAppItemViewModel other)
 {
     return other.Id == Id;
 }
 public bool IsSame(DeviceAppItemViewModel other)
 {
     return(other.Id == Id);
 }