예제 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            _viewModel = _navigationService.GetAndRemoveParameter(Intent) as CommentViewModel;
            SetContentView(Resource.Layout.Comments);

            SetSupportActionBar(FindViewById<Toolbar>(Resource.Id.CommentsToolbar));
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            Title = _viewModel.Title;

            _commentsList = FindViewById<ListView>(Resource.Id.CommentsListView);

            _replyButton = FindViewById<TextView>(Resource.Id.CommentReplyButton);
            _replyButton.SetCommand("Click", _viewModel.ReplyCommand);
            _replyButton.Enabled = false;

            _comment = FindViewById<EditText>(Resource.Id.CommentReplyText);
            _comment.Hint = _viewModel.CommentPlaceholder;

            _commentsList.Adapter = new ObservableAdapter<IListItem>()
            {
                    DataSource = _viewModel.CardViewModels,
                    GetTemplateDelegate = GetCell,
            };
            var footer = new View(this);
            footer.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, (int)Math.Ceiling(TypedValue.ApplyDimension(ComplexUnitType.Dip, 50f, Application.Context.Resources.DisplayMetrics)));

            _commentsList.AddFooterView(footer);

            _comment.TextChanged += (sender, e) => _viewModel.Comments = _comment.Text;

            _viewModel.RequestDismissKeyboard = () =>
            {
                    InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
                    imm.HideSoftInputFromWindow(_comment.WindowToken, 0);

            };
            
            _viewModel.RequestCanExecute = (enabled) => _replyButton.Enabled = enabled;
            _viewModel.PropertyChanged += (sender, e) => 
                {
                    switch(e.PropertyName)
                    {
                        case "Comments":
                            if(!_comment.Text.Equals(_viewModel.Comments))
                                _comment.Text = _viewModel.Comments;
                            break;
                    }
                };
        }