private void OnModelChanged(ModelChangedMessage msg)
 {
     if (msg.Model == currentEntry)
     {
         // Listen for changes regarding current running entry
         if (msg.PropertyName == TimeEntryModel.PropertyState ||
             msg.PropertyName == TimeEntryModel.PropertyStartTime ||
             msg.PropertyName == TimeEntryModel.PropertyStopTime ||
             msg.PropertyName == TimeEntryModel.PropertyDeletedAt)
         {
             if (currentEntry.State == TimeEntryState.Finished || currentEntry.DeletedAt.HasValue)
             {
                 currentEntry = TimeEntryModel.GetDraft();
             }
             Rebind();
         }
     }
     else if (msg.Model is TimeEntryModel)
     {
         // When some other time entry becomes Running we need to switch over to that
         if (msg.PropertyName == TimeEntryModel.PropertyState ||
             msg.PropertyName == TimeEntryModel.PropertyIsShared)
         {
             var entry = (TimeEntryModel)msg.Model;
             if (entry.State == TimeEntryState.Running && ForCurrentUser(entry))
             {
                 currentEntry = entry;
                 Rebind();
             }
         }
     }
 }
            public MainPagerAdapter(Context ctx, FragmentManager fm) : base(fm)
            {
                this.ctx = ctx;

                currentTimeEntry = TimeEntryModel.FindRunning() ?? TimeEntryModel.GetDraft();

                var bus = ServiceContainer.Resolve <MessageBus> ();

                subscriptionModelChanged   = bus.Subscribe <ModelChangedMessage> (OnModelChanged);
                subscriptionSettingChanged = bus.Subscribe <SettingChangedMessage> (OnSettingChanged);
            }
Exemple #3
0
        private async Task UpdateRunningTimeEntry()
        {
            var store  = ServiceContainer.Resolve <IDataStore> ();
            var teList = await store.Table <TimeEntryData> ()
                         .Where(r => r.State == TimeEntryState.Running && r.DeletedAt == null)
                         .OrderByDescending(r => r.StartTime)
                         .ToListAsync();

            ActiveTimeEntry = teList.Any() ? teList.FirstOrDefault() : TimeEntryModel.GetDraft();
            IsRunning       = ActiveTimeEntry.State == TimeEntryState.Running;
        }
        public void OnStart()
        {
            currentEntry = TimeEntryModel.FindRunning() ?? TimeEntryModel.GetDraft();

            // Start listening for changes model changes
            var bus = ServiceContainer.Resolve <MessageBus> ();

            subscriptionModelChanged = bus.Subscribe <ModelChangedMessage> (OnModelChanged);

            canRebind = true;
            Rebind();
        }
        private void OnDeleteImageButtonClick(object sender, EventArgs e)
        {
            if (TimeEntry == null)
            {
                return;
            }

            TimeEntry.Delete();
            TimeEntry = TimeEntryModel.GetDraft();

            Toast.MakeText(Activity, Resource.String.CurrentTimeEntryEditDeleteToast, ToastLength.Short).Show();
        }
Exemple #6
0
        protected override void Rebind()
        {
            if (TimeEntry == null || !CanRebind)
            {
                return;
            }

            if (TimeEntry.State == TimeEntryState.Finished || TimeEntry.DeletedAt.HasValue)
            {
                TimeEntry = TimeEntryModel.GetDraft();
            }

            base.Rebind();
        }
        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();
            });
        }
Exemple #8
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);
            }
        }
        public static async Task <EditTimeEntryViewModel> Init(Guid timeEntryId)
        {
            TimeEntryData  data;
            List <TagData> tagList;

            if (timeEntryId == Guid.Empty)
            {
                data    = TimeEntryModel.GetDraft();
                tagList = await GetDefaultTagList(data.WorkspaceId);
            }
            else
            {
                data = await TimeEntryModel.GetTimeEntryDataAsync(timeEntryId);

                tagList = await ServiceContainer.Resolve <IDataStore> ().GetTimeEntryTags(timeEntryId);
            }

            return(new EditTimeEntryViewModel(data, tagList));
        }
        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);
            });
        }
Exemple #11
0
        private void OnActionButtonTouchUpInside(object sender, EventArgs e)
        {
            if (currentTimeEntry == null)
            {
                currentTimeEntry = TimeEntryModel.GetDraft();
                currentTimeEntry.Start();

                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);
            }
            else
            {
                currentTimeEntry.Stop();
            }
        }
Exemple #12
0
        public static async Task <EditTimeEntryViewModel> Init(Guid timeEntryId)
        {
            TimeEntryData  data;
            List <TagData> tagList;

            if (timeEntryId == Guid.Empty)
            {
                data    = TimeEntryModel.GetDraft();
                tagList = await GetDefaultTagList(data.WorkspaceId);
            }
            else
            {
                data = await TimeEntryModel.GetTimeEntryDataAsync(timeEntryId);

                var tagsView = await TimeEntryTagCollectionView.Init(timeEntryId);

                tagList = tagsView.Data.ToList();
            }

            return(new EditTimeEntryViewModel(data, tagList));
        }
            private void OnModelChanged(ModelChangedMessage msg)
            {
                // Protect against Java side being GCed
                if (Handle == IntPtr.Zero)
                {
                    return;
                }

                if (msg.Model == currentTimeEntry)
                {
                    // Listen for changes regarding current running entry
                    if (msg.PropertyName == TimeEntryModel.PropertyState ||
                        msg.PropertyName == TimeEntryModel.PropertyStopTime ||
                        msg.PropertyName == TimeEntryModel.PropertyDeletedAt)
                    {
                        if (currentTimeEntry.State == TimeEntryState.Finished || currentTimeEntry.DeletedAt.HasValue)
                        {
                            currentTimeEntry = TimeEntryModel.GetDraft();
                        }
                        NotifyDataSetChanged();
                    }
                }
                else if (msg.Model is TimeEntryModel)
                {
                    // When some other time entry becomes IsRunning we need to switch over to that
                    if (msg.PropertyName == TimeEntryModel.PropertyState ||
                        msg.PropertyName == TimeEntryModel.PropertyIsShared)
                    {
                        var entry = (TimeEntryModel)msg.Model;
                        if (entry.State == TimeEntryState.Running && ForCurrentUser(entry))
                        {
                            currentTimeEntry = entry;
                            NotifyDataSetChanged();
                        }
                    }
                }
            }
Exemple #14
0
        public override void OnStart()
        {
            TimeEntry = TimeEntryModel.FindRunning() ?? TimeEntryModel.GetDraft();

            base.OnStart();
        }
Exemple #15
0
 private void OnTimeEntryStateChanged(StartStopMessage msg)
 {
     if (msg?.TimeEntry != null)
     {
         ActiveTimeEntry = msg.TimeEntry.State == TimeEntryState.Running ? msg.TimeEntry : TimeEntryModel.GetDraft();
         IsRunning       = msg.TimeEntry.State == TimeEntryState.Running;
     }
 }