Esempio n. 1
0
        public async Task ContinueTimeEntry(Guid timeEntryId)
        {
            var entryModel = new TimeEntryModel(timeEntryId);
            await TimeEntryModel.StartAsync(entryModel.Data);

            ServiceContainer.Resolve <ITracker>().SendTimerStartEvent(TimerStartSource.WidgetStart);
        }
Esempio n. 2
0
        public async void StartStopTimeEntry()
        {
            if (isActing) {
                return;
            }
            isActing = true;

            try {
                if (currentTimeEntry != null && currentTimeEntry.State == TimeEntryState.Running) {
                    await currentTimeEntry.StopAsync ();

                    // Ping analytics
                    ServiceContainer.Resolve<ITracker>().SendTimerStopEvent (TimerStopSource.Widget);
                } else if (timeEntryManager != null) {
                    currentTimeEntry = (TimeEntryModel)timeEntryManager.Draft;
                    if (currentTimeEntry == null) {
                        return;
                    }
                    await currentTimeEntry.StartAsync ();

                    // Show new screen on platform
                    widgetUpdateService.ShowNewTimeEntryScreen (currentTimeEntry);

                    // Ping analytics
                    ServiceContainer.Resolve<ITracker>().SendTimerStartEvent (TimerStartSource.WidgetNew);
                }
            } finally {
                isActing = false;
            }
        }
        private async void OnActionButtonTouchUpInside(object sender, EventArgs e)
        {
            if (isActing)
            {
                return;
            }
            isActing = true;

            try {
                if (currentTimeEntry != null && currentTimeEntry.State == TimeEntryState.Running)
                {
                    await currentTimeEntry.StopAsync();
                }
                else if (timeEntryManager != null)
                {
                    currentTimeEntry = (TimeEntryModel)timeEntryManager.Draft;
                    if (currentTimeEntry == null)
                    {
                        return;
                    }

                    await currentTimeEntry.StartAsync();

                    var controllers = new List <UIViewController> (parentController.NavigationController.ViewControllers);
                    controllers.Add(new EditTimeEntryViewController(currentTimeEntry));
                    if (ServiceContainer.Resolve <SettingsStore> ().ChooseProjectForNew)
                    {
                        controllers.Add(new ProjectSelectionViewController(currentTimeEntry));
                    }
                    parentController.NavigationController.SetViewControllers(controllers.ToArray(), true);
                }
            } finally {
                isActing = false;
            }
        }
Esempio n. 4
0
        public async void StartStopTimeEntry()
        {
            if (isActing)
            {
                return;
            }
            isActing = true;

            try {
                if (currentTimeEntry != null && currentTimeEntry.State == TimeEntryState.Running)
                {
                    await currentTimeEntry.StopAsync();

                    // Ping analytics
                    ServiceContainer.Resolve <ITracker>().SendTimerStopEvent(TimerStopSource.Widget);
                }
                else if (timeEntryManager != null)
                {
                    currentTimeEntry = (TimeEntryModel)timeEntryManager.Draft;
                    if (currentTimeEntry == null)
                    {
                        return;
                    }
                    await currentTimeEntry.StartAsync();

                    // Show new screen on platform
                    widgetUpdateService.ShowNewTimeEntryScreen(currentTimeEntry);

                    // Ping analytics
                    ServiceContainer.Resolve <ITracker>().SendTimerStartEvent(TimerStartSource.WidgetNew);
                }
            } finally {
                isActing = false;
            }
        }
        private async void OnActionButtonTouchUpInside (object sender, EventArgs e)
        {
            if (isActing)
                return;
            isActing = true;

            try {
                if (currentTimeEntry != null && currentTimeEntry.State == TimeEntryState.Running) {
                    await currentTimeEntry.StopAsync ();
                } else if (timeEntryManager != null) {
                    currentTimeEntry = (TimeEntryModel)timeEntryManager.Draft;
                    if (currentTimeEntry == null)
                        return;

                    await currentTimeEntry.StartAsync ();

                    var controllers = new List<UIViewController> (parentController.NavigationController.ViewControllers);
                    controllers.Add (new EditTimeEntryViewController (currentTimeEntry));
                    if (ServiceContainer.Resolve<SettingsStore> ().ChooseProjectForNew) {
                        controllers.Add (new ProjectSelectionViewController (currentTimeEntry));
                    }
                    parentController.NavigationController.SetViewControllers (controllers.ToArray (), true);
                }
            } finally {
                isActing = false;
            }
        }
        public void TestUserLogout()
        {
            RunAsync(async delegate {
                var te1 = TimeEntryModel.GetDraft();
                te1     = await TimeEntryModel.StartAsync(te1);

                Assert.AreEqual(te1.Id, ActiveManager.ActiveTimeEntry.Id);
                Assert.AreEqual(user.Id, ActiveManager.ActiveTimeEntry.UserId);

                ActiveManager.PropertyChanged += (sender, e) => {
                    Assert.AreEqual(ActiveManager.ActiveTimeEntry.UserId, Guid.Empty);
                    Assert.AreEqual(ActiveManager.ActiveTimeEntry.State, TimeEntryState.New);
                };
                ServiceContainer.Resolve <AuthManager> ().Forget();
            });
        }
Esempio n. 7
0
        public async Task StartStopTimeEntry()
        {
            if (activeTimeEntryManager.IsRunning)
            {
                await TimeEntryModel.StopAsync(activeTimeEntryManager.ActiveTimeEntry);

                ServiceContainer.Resolve <ITracker>().SendTimerStopEvent(TimerStopSource.Widget);
            }
            else
            {
                var startedEntry = await TimeEntryModel.StartAsync(TimeEntryModel.GetDraft());

                // Show new screen on platform
                widgetUpdateService.ShowNewTimeEntryScreen(new TimeEntryModel(startedEntry));
                ServiceContainer.Resolve <ITracker>().SendTimerStartEvent(TimerStartSource.WidgetNew);
            }
        }
Esempio n. 8
0
        public static async Task StartStopTimeEntry (Context ctx)
        {
            var manager = ServiceContainer.Resolve<ActiveTimeEntryManager> ();
            if (manager.Active == null) {
                return;
            }

            var active = new TimeEntryModel (manager.Active);
            if (manager.Active.State == TimeEntryState.Running) {
                await active.StopAsync ();
                ServiceContainer.Resolve<ITracker> ().SendTimerStopEvent (TimerStopSource.Watch);
            } else {
                active.Data.Description = ctx.Resources.GetString (Resource.String.WearEntryDefaultDescription);
                await active.StartAsync ();
                ServiceContainer.Resolve<ITracker> ().SendTimerStartEvent (TimerStartSource.WatchStart);
            }
        }
        public void TestActiveEntryAfterStartStop()
        {
            RunAsync(async delegate {
                var te1 = TimeEntryModel.GetDraft();
                Assert.AreEqual(te1.State, TimeEntryState.New);

                te1 = await TimeEntryModel.StartAsync(te1);

                Assert.AreEqual(te1.Id, ActiveManager.ActiveTimeEntry.Id);
                Assert.IsTrue(ActiveManager.IsRunning);
                Assert.AreEqual(te1.State, TimeEntryState.Running);

                te1 = await TimeEntryModel.StopAsync(te1);

                Assert.AreNotEqual(te1.Id, ActiveManager.ActiveTimeEntry.Id);
                Assert.IsFalse(ActiveManager.IsRunning);
                Assert.AreEqual(te1.State, TimeEntryState.Finished);
            });
        }
Esempio n. 10
0
        public static async Task StartStopTimeEntry(Context ctx)
        {
            var manager = ServiceContainer.Resolve <ActiveTimeEntryManager> ();
            var active  = manager.ActiveTimeEntry;

            if (manager.ActiveTimeEntry.State == TimeEntryState.Running)
            {
                await TimeEntryModel.StopAsync(active);

                ServiceContainer.Resolve <ITracker> ().SendTimerStopEvent(TimerStopSource.Watch);
            }
            else
            {
                active.Description = ctx.Resources.GetString(Resource.String.WearEntryDefaultDescription);
                await TimeEntryModel.StartAsync(active);

                ServiceContainer.Resolve <ITracker> ().SendTimerStartEvent(TimerStartSource.WatchStart);
            }
        }
Esempio n. 11
0
        private async void OnActionButtonTouchUpInside(object sender, EventArgs e)
        {
            if (isActing)
            {
                return;
            }
            isActing = true;

            try {
                if (currentTimeEntry != null && currentTimeEntry.State == TimeEntryState.Running)
                {
                    await TimeEntryModel.StopAsync(currentTimeEntry);

                    // Ping analytics
                    ServiceContainer.Resolve <ITracker>().SendTimerStopEvent(TimerStopSource.App);
                }
                else if (timeEntryManager != null)
                {
                    currentTimeEntry = (TimeEntryModel)timeEntryManager.ActiveTimeEntry;
                    if (currentTimeEntry == null)
                    {
                        return;
                    }

                    OBMExperimentManager.Send(OBMExperimentManager.HomeEmptyState, "startButton", "click");
                    await TimeEntryModel.StartAsync(currentTimeEntry);

                    var controllers = new List <UIViewController> (parentController.NavigationController.ViewControllers);
                    controllers.Add(new EditTimeEntryViewController((TimeEntryModel)currentTimeEntry));
                    if (ServiceContainer.Resolve <SettingsStore> ().ChooseProjectForNew)
                    {
                        controllers.Add(new ProjectSelectionViewController((TimeEntryModel)currentTimeEntry));
                    }
                    parentController.NavigationController.SetViewControllers(controllers.ToArray(), true);

                    // Ping analytics
                    ServiceContainer.Resolve <ITracker>().SendTimerStartEvent(TimerStartSource.AppNew);
                }
            } finally {
                isActing = false;
            }
        }
        public async Task <TimeEntryData> StartStopTimeEntry()
        {
            // Protect from double clicks?
            if (IsProcessingAction)
            {
                return(activeTimeEntryManager.ActiveTimeEntry);
            }

            IsProcessingAction = true;

            var active = activeTimeEntryManager.ActiveTimeEntry;

            active = active.State == TimeEntryState.Running ? await TimeEntryModel.StopAsync(active) : await TimeEntryModel.StartAsync(active);

            IsProcessingAction = false;

            if (active.State == TimeEntryState.Running)
            {
                ServiceContainer.Resolve <ITracker>().SendTimerStartEvent(TimerStartSource.AppNew);
            }
            else
            {
                ServiceContainer.Resolve <ITracker>().SendTimerStopEvent(TimerStopSource.App);
            }

            // Welcome wizard isn't needed after a time entry is started / stopped.
            ServiceContainer.Resolve <ISettingsStore> ().ShowWelcome = false;

            return(active);
        }
Esempio n. 13
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;
            }
        }
Esempio n. 14
0
        private async void OnActionButtonTouchUpInside (object sender, EventArgs e)
        {
            if (isActing) {
                return;
            }
            isActing = true;

            try {
                if (currentTimeEntry != null && currentTimeEntry.State == TimeEntryState.Running) {
                    await currentTimeEntry.StopAsync ();

                    // Ping analytics
                    ServiceContainer.Resolve<ITracker>().SendTimerStopEvent (TimerStopSource.App);
                } else if (timeEntryManager != null) {
                    currentTimeEntry = (TimeEntryModel)timeEntryManager.Draft;
                    if (currentTimeEntry == null) {
                        return;
                    }

                    OBMExperimentManager.Send (OBMExperimentManager.HomeEmptyState, "startButton", "click");
                    await currentTimeEntry.StartAsync ();

                    var controllers = new List<UIViewController> (parentController.NavigationController.ViewControllers);
                    controllers.Add (new EditTimeEntryViewController (currentTimeEntry));
                    if (ServiceContainer.Resolve<SettingsStore> ().ChooseProjectForNew) {
                        controllers.Add (new ProjectSelectionViewController (currentTimeEntry));
                    }
                    parentController.NavigationController.SetViewControllers (controllers.ToArray (), true);

                    // Ping analytics
                    ServiceContainer.Resolve<ITracker>().SendTimerStartEvent (TimerStartSource.AppNew);
                }
            } finally {
                isActing = false;
            }
        }
Esempio n. 15
0
        public async Task <TimeEntryData> StartStopTimeEntry()
        {
            // Protect from double clicks?
            if (IsProcessingAction)
            {
                return(activeTimeEntryManager.ActiveTimeEntry);
            }

            IsProcessingAction = true;

            var active = activeTimeEntryManager.ActiveTimeEntry;

            active = active.State == TimeEntryState.Running ? await TimeEntryModel.StopAsync(active) : await TimeEntryModel.StartAsync(active);

            IsProcessingAction = false;

            if (active.State == TimeEntryState.Running)
            {
                ServiceContainer.Resolve <ITracker>().SendTimerStartEvent(TimerStartSource.AppNew);
            }
            else
            {
                ServiceContainer.Resolve <ITracker>().SendTimerStopEvent(TimerStopSource.App);
            }

            return(active);
        }
Esempio n. 16
0
 public static async Task ContinueTimeEntry (Guid timeEntryId)
 {
     var entryModel = new TimeEntryModel (timeEntryId);
     await entryModel.StartAsync ();
     ServiceContainer.Resolve<ITracker> ().SendTimerStartEvent (TimerStartSource.WatchContinue);
 }
Esempio n. 17
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;
            }
        }