コード例 #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);
            var view = inflater.Inflate(Resource.Layout.PageVideoPlayer, container, false);

            //Find all controls that need programmatic access
            _webView       = view.FindViewById <WebView>(Resource.Id.webView1);
            _listView      = view.FindViewById <ListView>(Resource.Id.listComments);
            _textDesc      = view.FindViewById <TextView>(Resource.Id.textDesc);
            _textVotes     = view.FindViewById <TextView>(Resource.Id.textVotes);
            _editComment   = view.FindViewById <EditText>(Resource.Id.editComment);
            _commentButton = view.FindViewById <Button>(Resource.Id.buttonComment);
            _voteButton    = view.FindViewById <ToggleButton>(Resource.Id.buttonVote);

            _webView.Settings.JavaScriptEnabled = true;

            Vm = Navigator.GetAndRemoveParameter <VideoViewModel>(ViewModelLocator.VIDEO_DETAILS);

            //Static data
            _webView.LoadUrl(Vm.FormattedURL);
            _textDesc.Text = Vm.Model.Description;


            //Bind data
            _votesBinding      = this.SetBinding(() => Vm.VotesFormatted, () => TextVotes.Text);
            _voteStatusBinding = this.SetBinding(() => Vm.Model.HasUserVoted, () => VoteButton.Checked,
                                                 BindingMode.OneWay);
            _commentBinding = this.SetBinding(() => EditComment.Text);
            VoteButton.SetCommand("Click", Vm.VoteCommand);
            CommentButton.SetCommand("Click", Vm.SaveCommentCommand, _commentBinding);

            ListView.Adapter = Vm.Model.Comments.GetAdapter(GetView);
            return(view);
        }
コード例 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            //Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            SetContentView(Resource.Layout.PageVideoPlayer);

            _webView       = FindViewById <WebView>(Resource.Id.webView1);
            _listView      = FindViewById <ListView>(Resource.Id.listComments);
            _editComment   = FindViewById <EditText>(Resource.Id.editComment);
            _commentButton = FindViewById <Button>(Resource.Id.buttonComment);

            var view = LayoutInflater.Inflate(Resource.Layout.HeaderVideoPlayer, ListView, false);

            _listView.AddHeaderView(view);
            _textDesc   = view.FindViewById <TextView>(Resource.Id.textDesc);
            _textVotes  = view.FindViewById <TextView>(Resource.Id.textVotes);
            _voteButton = view.FindViewById <ToggleButton>(Resource.Id.buttonVote);
            _webView.Settings.JavaScriptEnabled = true;

            try
            {
                var key = Intent.GetStringExtra(MyNavigationService.ParamKey);
                Vm = Navigator.GetAndRemoveParameter <VideoViewModel>(key);
            }
            catch (Exception e)
            {
                Console.WriteLine("Player opened without a video");
                Finish();
                return;
            }

            //Static data
            _webView.LoadUrl(Vm.FormattedURL);
            _textDesc.Text = Vm.Model.Description;


            //Bind data
            _votesBinding      = this.SetBinding(() => Vm.VotesFormatted, () => TextVotes.Text);
            _voteStatusBinding = this.SetBinding(() => Vm.Model.HasUserVoted, () => VoteButton.Checked,
                                                 BindingMode.OneWay);
            _commentBinding = this.SetBinding(() => EditComment.Text);
            VoteButton.SetCommand("Click", Vm.VoteCommand);
            CommentButton.SetCommand("Click", Vm.SaveCommentCommand, _commentBinding);
            _commentButton.Click += (sender, args) =>
            {
                ((InputMethodManager)GetSystemService(InputMethodService)).HideSoftInputFromWindow(
                    CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways);
                _editComment.Text = "";
            };
            _editComment.Click += delegate { _listView.SetSelection(Vm.Model.Comments.Count - 1); };

            ListView.Adapter = Vm.Model.Comments.GetAdapter(GetView);
        }