Exemplo 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();
        }