예제 #1
0
        private async void OnActionButtonClicked(object sender, EventArgs e)
        {
            // Protect from double clicks
            if (isProcessingAction)
            {
                return;
            }

            isProcessingAction = true;
            try {
                var entry = ActiveTimeEntry;
                if (entry == null)
                {
                    return;
                }

                // Make sure that we work on the copy of the entry to not affect the rest of the logic.
                entry = new TimeEntryModel(new TimeEntryData(entry.Data));

                var showProjectSelection = false;

                try {
                    if (entry.State == TimeEntryState.New && entry.StopTime.HasValue)
                    {
                        await entry.StoreAsync();
                    }
                    else if (entry.State == TimeEntryState.Running)
                    {
                        await entry.StopAsync();
                    }
                    else
                    {
                        var startTask = entry.StartAsync();

                        var userId = ServiceContainer.Resolve <AuthManager> ().GetUserId();
                        if (userId.HasValue && ChooseProjectForNew && entry.Project == null)
                        {
                            var store     = ServiceContainer.Resolve <IDataStore> ();
                            var countTask = store.CountUserAccessibleProjects(userId.Value);

                            // Wait for the start and count to finish
                            await Task.WhenAll(startTask, countTask);

                            if (countTask.Result > 0)
                            {
                                showProjectSelection = true;
                            }
                        }
                        else
                        {
                            await startTask;
                        }
                    }
                } catch (Exception ex) {
                    var log = ServiceContainer.Resolve <Logger> ();
                    log.Warning(LogTag, ex, "Failed to change time entry state.");
                }

                if (showProjectSelection)
                {
                    new ChooseTimeEntryProjectDialogFragment(entry).Show(activity.SupportFragmentManager, "projects_dialog");
                }

                var bus = ServiceContainer.Resolve <MessageBus> ();
                bus.Send(new UserTimeEntryStateChangeMessage(this, entry));
            } finally {
                isProcessingAction = false;
            }
        }
예제 #2
0
        private async void OnActionButtonClicked (object sender, EventArgs e)
        {
            // Protect from double clicks
            if (isProcessingAction)
                return;

            isProcessingAction = true;
            try {
                var entry = ActiveTimeEntry;
                if (entry == null)
                    return;

                // Make sure that we work on the copy of the entry to not affect the rest of the logic.
                entry = new TimeEntryModel (new TimeEntryData (entry.Data));

                var showProjectSelection = false;

                try {
                    if (entry.State == TimeEntryState.New && entry.StopTime.HasValue) {
                        await entry.StoreAsync ();
                    } else if (entry.State == TimeEntryState.Running) {
                        await entry.StopAsync ();
                    } else {
                        var startTask = entry.StartAsync ();

                        var userId = ServiceContainer.Resolve<AuthManager> ().GetUserId ();
                        if (userId.HasValue && ChooseProjectForNew && entry.Project == null) {
                            var store = ServiceContainer.Resolve<IDataStore> ();
                            var countTask = store.CountUserAccessibleProjects (userId.Value);

                            // Wait for the start and count to finish
                            await Task.WhenAll (startTask, countTask);

                            if (countTask.Result > 0)
                                showProjectSelection = true;
                        } else {
                            await startTask;
                        }
                    }
                } catch (Exception ex) {
                    var log = ServiceContainer.Resolve<Logger> ();
                    log.Warning (LogTag, ex, "Failed to change time entry state.");
                }

                if (showProjectSelection) {
                    new ChooseTimeEntryProjectDialogFragment (entry).Show (activity.SupportFragmentManager, "projects_dialog");
                }

                var bus = ServiceContainer.Resolve<MessageBus> ();
                bus.Send (new UserTimeEntryStateChangeMessage (this, entry));
            } finally {
                isProcessingAction = false;
            }
        }