Beispiel #1
0
        public async Task SetChannel(Channel newChannel)
        {
            if (stateChanging)
            {
                return;
            }
            stateChanging = true;
            if (newChannel == null)
            {
                newChannel = new EmptyChannel();
            }
            bool hadGuide = false;

            if (channel != null && notFirstChannel)
            {
                if (!(channel is EmptyChannel))
                {
                    newChannel.IsMuted = channel.IsMuted;
                    newChannel.Volume  = channel.Volume;
                    hadGuide           = channel.Guide != null;
                    if (hadGuide)
                    {
                        if (guidePanel.Visibility == Visibility.Visible)
                        {
                            StopGuide();
                        }
                        channel.Guide.CurrentBroadcastChanged -= guide_BroadcastChanged;
                        if (channel.Guide.Menu != null)
                        {
                            for (int n = 0; n < channel.Guide.Menu.Items.Count; n++)
                            {
                                MenuHelper.Delete((uint)(MenuHelper.GuideIdOffset + n));
                            }
                        }
                    }
                }
                if (channel.Menu != null)
                {
                    for (int n = 0; n < channel.Menu.Items.Count; n++)
                    {
                        MenuHelper.Delete((uint)(MenuHelper.ChannelIdOffset + n));
                    }
                }
                ProperWindow.CloseAll();
                channel.Stop(); channel.Dispose();
            }

            Title = newChannel.Caption;           // Šiem jāsakrīt, jo to izmanto EmptyChannel loga pogas atrašanai.

            if (Settings.Default.ShowClock)
            {
                // channel piešķiršanas secību nosaka UpdateClock nepieciešamā instance.
                if (newChannel.Timezone == null)
                {
                    HideClock();
                    channel = newChannel;
                }
                else
                {
                    channel = newChannel;
                    ShowClock();
                }
            }
            else
            {
                channel = newChannel;
            }

            if (newChannel.Menu != null)
            {
                newChannel.Menu.Items.AddToMenu(MenuHelper.SystemMenuHandle, 1, MenuHelper.ChannelIdOffset);
            }
            // Tā kā raidījumu saraksta ielāde var prasīt laiku, nomaina izskatu pirms tā.
            await Dispatcher.InvokeAsync(() => {
                System.Windows.Controls.Grid.SetColumnSpan(logoBackground, channel.Brand.HasSharedBackground ? 2:1);
                channel.Brand.Focused = this.IsActive;
                DataContext           = channel;     // Parāda kanālu pirms raidījumu saraksta ielādes, lai tas nebremzē pārslēgšanas uztveri.
            });

            if (newChannel.HasGuide && Settings.Default.UseGuide)
            {
                InitGuide();
                if (!hadGuide)
                {
                    ShowGuide();
                }
                await StartGuide(true).ConfigureAwait(false);
            }
            else
            {
                HideGuide();
            }
            await Dispatcher.InvokeAsync(() => {
                ShowMuteStateInTaskBar(channel.IsMuted);
                UpdateMenuButtonMask();                 // Atkarīgs no raidījum saraksta pieejamības un notiek saskarnes pavedienā.
            });

            channel.Play();
            stateChanging = false;
        }