Ejemplo n.º 1
0
        void OnModelChanged()
        {
//			Console.WriteLine ("READER ON MODEL CHANGED");

            var html = "";

            if (Message != null)
            {
                html = Message.BodyHtml;
            }

            _showingMessages = true;
            UpdateOriginalToggleUI();

            TopBtn.Def.ComponentType    = LcarsComponentType.MiscFunction;
            TopBtn.Def.IsCommandable    = true;
            BottomBtn.Def.ComponentType = LcarsComponentType.MiscFunction;
            BottomBtn.Def.IsCommandable = true;

            TopBtn.SetNeedsDisplay();
            BottomBtn.SetNeedsDisplay();

            var eq = (_lastHtml == html && object.ReferenceEquals(Message, _lastMessage));

            if (!eq)
            {
                _lastHtml    = html;
                _lastMessage = Message;

                var subj   = "";
                var byline = "";
                if (Message != null)
                {
                    subj   = Message.Subject;
                    byline = Message.From;
                    var tm = Message.PublishTime.ToLocalTime();
                    byline += " " + tm.ToLongDateString();
                    byline += " " + tm.ToShortTimeString();
                }

                var head = "<div class='byline'>" + Html.Encode(byline) + "</div>";

                Source source = null;
                if (Message != null)
                {
                    source = Repo.Foreground.Resolve(Message.GetSourceReference());
                }

                var showSubj   = source.ShouldShowSubjectWithBody;
                var subjIsBody = false;
                if (Message != null && Message.BodyHtml == "&nbsp;")
                {
                    showSubj   = false;
                    subjIsBody = true;
                }

                if (source != null && showSubj)
                {
                    head = "<h1>" + Html.Encode(subj) + "</h1>" + head;
                }

                var shtml = html;

                if (subjIsBody)
                {
                    shtml = Message.Subject;
                }

                if (ShouldSanitize(shtml))
                {
                    shtml = Sanitize(shtml);
                }

                shtml = head + shtml;
                SetHtml(shtml, "");
            }
            TextBox.Hidden = string.IsNullOrEmpty(html);

            Info.ScreenTitle = Message.GetTextSummary();

            KillMedia();

            var isAudio = Message.MediaUrl.IndexOf(".mp3") > 0;

            if (Message.HasMedia)
            {
                PlayBtn.Def.IsCommandable = true;
                PlayBtn.Def.ComponentType = LcarsComponentType.SystemFunction;
                PlayBtn.Def.Caption       = GetPlayCaption();
                PlayBtn.Def.Command       = delegate {
                    if (isAudio)
                    {
                        if (_audioPlayer == null)
                        {
                            _audioPlayer = AudioPlayerController.Get(Message.MediaUrl);
                            _audioPlayer.Play();
                            _updatePlayTimer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1), delegate {
                                if (_audioPlayer != null)
                                {
                                    PlayBtn.Def.Caption = _audioPlayer.GetStatus(false);
                                    PlayBtn.SetNeedsDisplay();
                                }
                            });
                        }
                        else
                        {
                            if (_audioPlayer.IsPlaying)
                            {
                                _audioPlayer.Pause();
                            }
                            else
                            {
                                _audioPlayer.Play();
                            }
                        }
                    }
                    else
                    {
                        App.Inst.ShowFullScreenVideo(Message.MediaUrl);
                    }
                    PlayBtn.SetNeedsDisplay();
                };
            }
            else
            {
                PlayBtn.Def.IsCommandable = false;
                PlayBtn.Def.ComponentType = LcarsComponentType.Gray;
                PlayBtn.Def.Caption       = "";
            }
            PlayBtn.SetNeedsDisplay();

            App.Inst.RefreshInfo();
        }
Ejemplo n.º 2
0
        public MenuWindow(params MenuWindowItem[] menus)
        {
            InitializeComponent();

            //Menu Generate
            {
                int menuCount = menus.Length;
                Height = menus.Length * ItemHeight;

                if (menus == null || menuCount == 0)
                {
                    throw new Exception("메뉴 항목이 없습니다.");
                }
                else if (menuCount == 1)
                {
                    SingleBtn.SetBtnColor();
                    SingleBtn.SetOnClick(base.Close);
                    SingleBtn.SetOnClick(menus[0].OnClick);
                    TopText.Content = menus[0].text;

                    TopBtn.Visibility          =
                        BotBtn.Visibility      =
                            BotText.Visibility = Visibility.Hidden;
                }
                else
                {
                    for (int i = 0; i < menuCount; ++i)
                    {
                        if (i > 0)
                        {
                            Border separator = new Border();
                            separator.Height            = 1f;
                            separator.Background        = "#FFFFFF5F".ToBrush();
                            separator.VerticalAlignment = VerticalAlignment.Top;
                            separator.Margin            = new Thickness(0f, ItemHeight * i, 0f, 0f);
                            BackPanel.Children.Add(separator);
                        }

                        if (i == 0)
                        {
                            TopBtn.SetBtnColor();
                            TopBtn.SetOnClick(base.Close);
                            TopBtn.SetOnClick(menus[i].OnClick);
                            TopText.Content = menus[i].text;
                        }
                        else if (i == menuCount - 1)
                        {
                            BotBtn.SetBtnColor();
                            BotBtn.SetOnClick(base.Close);
                            BotBtn.SetOnClick(menus[i].OnClick);
                            BotText.Content = menus[i].text;
                        }
                        else
                        {
                            Border btn = new Border();
                            btn.Height     = ItemHeight;
                            btn.Background = "#00000000".ToBrush();
                            BackPanel.Children.Add(btn);

                            btn.SetBtnColor();
                            btn.SetOnClick(base.Close);
                            btn.SetOnClick(menus[i].OnClick);
                        }
                    }
                }
            }

            Opacity = 0f;
            Left    = MouseInput.AbsolutePosition.x - Width * 0.5f;
            Top     = MouseInput.AbsolutePosition.y - Height * 0.5f;

            SetEvent();
        }