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 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);
        }
Beispiel #3
0
        public async void ContinueTimeEntry(int index)
        {
            // Get data holder
            var timeEntryHolder = GetHolderFromIndex(index);

            if (timeEntryHolder == null)
            {
                return;
            }

            var timeEntry = timeEntryHolder.TimeEntryData;

            if (timeEntry.State == TimeEntryState.Running)
            {
                await TimeEntryModel.StopAsync(timeEntryHolder.TimeEntryData);

                ServiceContainer.Resolve <ITracker> ().SendTimerStopEvent(TimerStopSource.App);
            }
            else
            {
                await TimeEntryModel.ContinueTimeEntryDataAsync(timeEntryHolder.TimeEntryData);

                ServiceContainer.Resolve <ITracker> ().SendTimerStartEvent(TimerStartSource.AppContinue);
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public async Task RemoveItemWithUndoAsync(ITimeEntryHolder timeEntryHolder)
        {
            if (timeEntryHolder == null)
            {
                return;
            }

            // Remove previous if exists
            if (lastRemovedItem != null)
            {
                await RemoveItemPermanentlyAsync(lastRemovedItem);
            }

            if (timeEntryHolder.Data.State == TimeEntryState.Running)
            {
                await TimeEntryModel.StopAsync(timeEntryHolder.Data);
            }
            lastRemovedItem = timeEntryHolder;

            // Remove item only from list
            subject.OnNext(new TimeEntryMessage(timeEntryHolder.Data, DataAction.Delete));

            // Create Undo timer
            if (undoTimer != null)
            {
                undoTimer.Elapsed -= OnUndoTimeFinished;
                undoTimer.Close();
            }
            // Using the correct timer.
            undoTimer           = new System.Timers.Timer((UndoSecondsInterval + 1) * 1000);
            undoTimer.AutoReset = false;
            undoTimer.Elapsed  += OnUndoTimeFinished;
            undoTimer.Start();
        }
        public async Task <TimeEntryData> ContinueTimeEntryAsync(int index)
        {
            var newTimeEntry    = new TimeEntryData();
            var timeEntryHolder = Collection.ElementAt(index) as ITimeEntryHolder;

            if (timeEntryHolder == null)
            {
                return(newTimeEntry);
            }

            if (timeEntryHolder.Data.State == TimeEntryState.Running)
            {
                newTimeEntry = await TimeEntryModel.StopAsync(timeEntryHolder.Data);

                ServiceContainer.Resolve <ITracker>().SendTimerStopEvent(TimerStopSource.App);
            }
            else
            {
                newTimeEntry = await TimeEntryModel.ContinueAsync(timeEntryHolder.Data);

                ServiceContainer.Resolve <ITracker>().SendTimerStartEvent(TimerStartSource.AppContinue);
            }

            return(newTimeEntry);
        }
        private async void StopTimeEntry(TimeEntryModel model)
        {
            await model.StopAsync();

            // Ping analytics
            ServiceContainer.Resolve <ITracker> ().SendTimerStopEvent(TimerStopSource.App);
        }
        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);
            }
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
        private static async Task FindAndStopRunning()
        {
            var userId    = ServiceContainer.Resolve <AuthManager> ().GetUserId();
            var dataStore = ServiceContainer.Resolve <IDataStore> ();

            // Find running tasks:
            var runningEntries = await dataStore.Table <TimeEntryData> ()
                                 .Where(r => r.State == TimeEntryState.Running && r.DeletedAt == null && r.UserId == userId)
                                 .ToListAsync()
                                 .ConfigureAwait(false);

            var stopTasks = runningEntries.Select(data => TimeEntryModel.StopAsync(data));
            await Task.WhenAll(stopTasks).ConfigureAwait(false);

            // Ping analytics
            ServiceContainer.Resolve <ITracker> ().SendTimerStopEvent(TimerStopSource.Notification);
        }
Beispiel #11
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);
            }
        }
        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);
            });
        }
Beispiel #13
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;
            }
        }
Beispiel #14
0
        public async Task RemoveItemWithUndoAsync(int index)
        {
            // Get data holder
            var timeEntryHolder = GetHolderFromIndex(index);

            if (timeEntryHolder == null)
            {
                return;
            }

            // Remove previous if exists
            if (LastRemovedItem != null)
            {
                await RemoveItemPermanentlyAsync(LastRemovedItem);
            }

            if (timeEntryHolder.State == TimeEntryState.Running)
            {
                await TimeEntryModel.StopAsync(timeEntryHolder.TimeEntryData);
            }
            LastRemovedItem = timeEntryHolder;

            // Remove item only from list
            await RemoveTimeEntryHolderAsync(timeEntryHolder);

            // Create Undo timer
            if (undoTimer != null)
            {
                undoTimer.Elapsed -= OnUndoTimeFinished;
                undoTimer.Close();
            }
            // Using the correct timer.
            undoTimer           = new System.Timers.Timer((UndoSecondsInterval + 1) * 1000);
            undoTimer.AutoReset = false;
            undoTimer.Elapsed  += OnUndoTimeFinished;
            undoTimer.Start();
        }
 private async void StopTimeEntry (TimeEntryModel model)
 {
     await model.StopAsync ();
 }
 private async void StopTimeEntry(TimeEntryModel model)
 {
     await model.StopAsync();
 }
Beispiel #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;
            }
        }
Beispiel #18
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;
            }
        }