public async override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            base.OnViewCreated(view, savedInstanceState);
            ViewModel = await EditTimeEntryGroupViewModel.Init(TimeEntryIds.ToList());

            ProjectField.TextField.Click += (sender, e) => OpenProjectListActivity();
            ProjectField.Click           += (sender, e) => OpenProjectListActivity();

            durationBinding    = this.SetBinding(() => ViewModel.Duration, () => DurationTextView.Text);
            startTimeBinding   = this.SetBinding(() => ViewModel.StartDate, () => StartTimeEditText.Text).ConvertSourceToTarget(dateTime => dateTime.ToDeviceTimeString());
            stopTimeBinding    = this.SetBinding(() => ViewModel.StopDate, () => StopTimeEditText.Text).ConvertSourceToTarget(dateTime => dateTime.ToDeviceTimeString());
            projectBinding     = this.SetBinding(() => ViewModel.ProjectName, () => ProjectField.TextField.Text);
            clientBinding      = this.SetBinding(() => ViewModel.ClientName, () => ProjectField.AssistViewTitle);
            descriptionBinding = this.SetBinding(() => ViewModel.Description, () => DescriptionField.TextField.Text, BindingMode.TwoWay);
            isRunningBinding   = this.SetBinding(() => ViewModel.IsRunning).WhenSourceChanges(() => {
                StopTimeEditText.Visibility  = ViewModel.IsRunning ? ViewStates.Gone : ViewStates.Visible;
                stopTimeEditLabel.Visibility = ViewModel.IsRunning ? ViewStates.Gone : ViewStates.Visible;
            });

            var settingsStore = ServiceContainer.Resolve <SettingsStore> ();

            if (settingsStore.ChooseProjectForNew && LogTimeEntriesListFragment.NewTimeEntry)
            {
                OpenProjectListActivity();
            }
            else if (LogTimeEntriesListFragment.NewTimeEntry)
            {
                DescriptionField.RequestFocus();
                ((EditTimeEntryActivity)Activity).ShowSoftKeyboard(DescriptionField.TextField, false);
                LogTimeEntriesListFragment.NewTimeEntry = false;
            }
            else
            {
                DescriptionField.ClearFocus();
            }

            // Set adapter using Mvvm light utils.
            timeEntriesListView.Adapter    = ViewModel.TimeEntryCollection.GetAdapter(GetTimeEntryView);
            timeEntriesListView.ItemClick += (sender, e) => HandleTimeEntryClick(ViewModel.TimeEntryCollection [e.Position]);
        }
Пример #2
0
        public async override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            base.OnViewCreated(view, savedInstanceState);
            ViewModel = await EditTimeEntryViewModel.Init(TimeEntryId);

            // TODO: in theory, this event could be binded but
            // the event "CheckedChange" isn't found when
            // the app is compiled for release. Investigate!
            BillableCheckBox.CheckedChange += (sender, e) => {
                ViewModel.ChangeBillable(BillableCheckBox.Checked);
            };

            DescriptionField.TextField.TextChanged += (sender, e) => {
                ViewModel.ChangeDescription(DescriptionField.TextField.Text);
            };

            DurationTextView.Click += (sender, e) => {
                // TODO: Don't edit duration if Time entry is running?
                if (ViewModel.IsRunning)
                {
                    return;
                }
                ChangeTimeEntryDurationDialogFragment.NewInstance(ViewModel.StopDate, ViewModel.StartDate)
                .SetChangeDurationHandler(this)
                .Show(FragmentManager, "duration_dialog");
            };

            StartTimeEditText.Click += (sender, e) => {
                var title = GetString(Resource.String.ChangeTimeEntryStartTimeDialogTitle);
                ChangeDateTimeDialogFragment.NewInstance(ViewModel.StartDate, title)
                .SetOnChangeTimeHandler(this)
                .Show(FragmentManager, "start_time_dialog");
            };

            StopTimeEditText.Click += (sender, e) => {
                var title = GetString(Resource.String.ChangeTimeEntryStopTimeDialogTitle);
                ChangeDateTimeDialogFragment.NewInstance(ViewModel.StopDate, title)
                .SetOnChangeTimeHandler(this)
                .Show(FragmentManager, "stop_time_dialog");
            };

            ProjectField.TextField.Click += (sender, e) => OpenProjectListActivity();
            ProjectField.Click           += (sender, e) => OpenProjectListActivity();
            TagsField.OnPressTagField    += OnTagsEditTextClick;

            durationBinding  = this.SetBinding(() => ViewModel.Duration, () => DurationTextView.Text);
            startTimeBinding = this.SetBinding(() => ViewModel.StartDate, () => StartTimeEditText.Text)
                               .ConvertSourceToTarget(dateTime => dateTime.ToDeviceTimeString());
            stopTimeBinding = this.SetBinding(() => ViewModel.StopDate, () => StopTimeEditText.Text)
                              .ConvertSourceToTarget(dateTime => dateTime.ToDeviceTimeString());
            projectBinding = this.SetBinding(() => ViewModel.ProjectName, () => ProjectField.TextField.Text);
            clientBinding  = this.SetBinding(() => ViewModel.ClientName, () => ProjectField.AssistViewTitle);
            tagBinding     = this.SetBinding(() => ViewModel.TagList, () => TagsField.TagNames)
                             .ConvertSourceToTarget(tagList => tagList.Select(tag => tag.Name).ToList());
            descriptionBinding = this.SetBinding(() => ViewModel.Description, () => DescriptionField.TextField.Text);
            isPremiumBinding   = this.SetBinding(() => ViewModel.IsPremium, () => BillableCheckBox.Visibility)
                                 .ConvertSourceToTarget(isVisible => isVisible ? ViewStates.Visible : ViewStates.Gone);
            isRunningBinding = this.SetBinding(() => ViewModel.IsRunning).WhenSourceChanges(() => {
                StopTimeEditText.Visibility  = ViewModel.IsRunning ? ViewStates.Gone : ViewStates.Visible;
                stopTimeEditLabel.Visibility = ViewModel.IsRunning ? ViewStates.Gone : ViewStates.Visible;
            });
            isBillableBinding = this.SetBinding(() => ViewModel.IsBillable, () => BillableCheckBox.Checked);
            billableBinding   = this.SetBinding(() => ViewModel.IsBillable)
                                .WhenSourceChanges(() => {
                var label             = ViewModel.IsBillable ? GetString(Resource.String.CurrentTimeEntryEditBillableChecked) : GetString(Resource.String.CurrentTimeEntryEditBillableUnchecked);
                BillableCheckBox.Text = label;
            });

            // If project list needs to be opened?
            var settingsStore = ServiceContainer.Resolve <SettingsStore> ();

            if (settingsStore.ChooseProjectForNew && LogTimeEntriesListFragment.NewTimeEntry)
            {
                OpenProjectListActivity();
            }
            else if (LogTimeEntriesListFragment.NewTimeEntry)
            {
                DescriptionField.RequestFocus();
                ((EditTimeEntryActivity)Activity).ShowSoftKeyboard(DescriptionField.TextField, false);
                LogTimeEntriesListFragment.NewTimeEntry = false;
            }
            else
            {
                DescriptionField.ClearFocus();
            }

            // Finally set content visible.
            editTimeEntryContent.Visibility     = ViewStates.Visible;
            editTimeEntryProgressBar.Visibility = ViewStates.Gone;
        }