예제 #1
0
        public virtual void RebindTags (TimeEntryTagsView tagsView)
        {
            List<String> tagList = new List<String> ();
            String t;

            if (tagsView == null || tagsView.IsLoading) {
                return;
            }

            if (tagsView.Count == 0) {
                EditText.Text = String.Empty;
                return;
            }

            foreach (String tagText in tagsView.Data) {
                t = tagText.Length > TagMaxLength ? tagText.Substring (0, TagMaxLength - 1).Trim () + "…" : tagText;
                if (tagText.Length > 0) {
                    tagList.Add (t);
                }
            }
            // The extra whitespace prevents the ImageSpans and the text they are over
            // to break at different positions, leaving zero linespacing on edge cases.
            var tags = new SpannableStringBuilder (String.Join (" ", tagList) + " ");

            int x = 0;
            foreach (String tagText in tagList) {
                tags.SetSpan (new ImageSpan (MakeTagChip (tagText)), x, x + tagText.Length, SpanTypes.ExclusiveExclusive);
                x = x + tagText.Length + 1;
            }
            EditText.SetText (tags, EditText.BufferType.Spannable);
        }
예제 #2
0
        public EditTimeEntryViewController (TimeEntryModel model)
        {
            this.model = model;

            tagsView = new TimeEntryTagsView (model.Id);

            timerController = new TimerNavigationController (model);
        }
예제 #3
0
        public EditTimeEntryViewController(TimeEntryModel model)
        {
            this.model = model;

            tagsView = new TimeEntryTagsView(model.Id);

            timerController = new TimerNavigationController(model);
        }
예제 #4
0
        public void TestInvalidTimeEntry()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(Guid.Empty);
                await WaitForLoaded(view);

                Assert.AreEqual(0, view.Count);
            });
        }
        public void TestInvalidTimeEntry ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (Guid.Empty);
                await WaitForLoaded (view);

                Assert.AreEqual (0, view.Count);
            });
        }
예제 #6
0
        public override void OnDestroyView()
        {
            if (tagsView != null)
            {
                tagsView.Updated -= OnTimeEntryTagsUpdated;
                tagsView          = null;
            }

            base.OnDestroyView();
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (tagsView != null)
         {
             tagsView.Updated -= OnTagsUpdated;
             tagsView          = null;
         }
     }
     base.Dispose(disposing);
 }
예제 #8
0
        public void TestInitialState()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                Assert.AreEqual(2, view.Count);
                Assert.AreEqual(
                    MakeTagsArray(DefaultTag, "Tag #2"),
                    view.Data.ToArray()
                    );
            });
        }
        public void TestInitialState ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                Assert.AreEqual (2, view.Count);
                Assert.AreEqual (
                    MakeTagsArray (DefaultTag, "Tag #2"),
                    view.Data.ToArray ()
                );
            });
        }
예제 #10
0
        public void TestAddInvalidManyToMany ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                await DataStore.PutAsync (new TimeEntryTagData () {
                    TimeEntryId = timeEntry.Id,
                    TagId = Guid.Empty,
                });

                Assert.AreEqual (2, view.Count);
            });
        }
예제 #11
0
        public void TestDeleteTag()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                await DataStore.DeleteAsync(tag2);

                Assert.AreEqual(1, view.Count);
                Assert.AreEqual(
                    MakeTagsArray(DefaultTag),
                    view.Data.ToArray()
                    );
            });
        }
예제 #12
0
        public void TestAddInvalidManyToMany()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                await DataStore.PutAsync(new TimeEntryTagData()
                {
                    TimeEntryId = timeEntry.Id,
                    TagId       = Guid.Empty,
                });

                Assert.AreEqual(2, view.Count);
            });
        }
예제 #13
0
            protected override void OnDataSourceChanged()
            {
                if (tagsView != null && (DataSource == null || DataSource.Id == tagsView.TimeEntryId))
                {
                    tagsView.Updated -= OnTagsUpdated;
                    tagsView          = null;
                }

                if (DataSource != null)
                {
                    tagsView          = new TimeEntryTagsView(DataSource.Id);
                    tagsView.Updated += OnTagsUpdated;
                }

                base.OnDataSourceChanged();
            }
예제 #14
0
        public void TestRenameTag()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                tag2.Name = "A tag";
                await DataStore.PutAsync(tag2);

                Assert.AreEqual(2, view.Count);
                Assert.AreEqual(
                    MakeTagsArray("A tag", DefaultTag),
                    view.Data.ToArray()
                    );
            });
        }
예제 #15
0
        public void TestDeleteManyToMany()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                var inter = await GetByRemoteId <TimeEntryTagData> (1);
                await DataStore.DeleteAsync(inter);

                Assert.AreEqual(1, view.Count);
                Assert.AreEqual(
                    MakeTagsArray("Tag #2"),
                    view.Data.ToArray()
                    );
            });
        }
            protected override void OnDataSourceChanged()
            {
                if (tagsView != null)
                {
                    tagsView.Updated -= OnTagsUpdated;
                    tagsView          = null;
                }

                if (DataSource != null)
                {
                    tagsView          = new TimeEntryTagsView(DataSource.Id);
                    tagsView.Updated += OnTagsUpdated;
                }

                RebindTags();

                base.OnDataSourceChanged();
            }
예제 #17
0
        public void TestNonDefault()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                Assert.IsTrue(view.HasNonDefault);

                var inter = await GetByRemoteId <TimeEntryTagData> (2);
                await DataStore.DeleteAsync(inter);

                Assert.IsFalse(view.HasNonDefault);

                inter = await GetByRemoteId <TimeEntryTagData> (1);
                await DataStore.DeleteAsync(inter);

                Assert.IsFalse(view.HasNonDefault);
            });
        }
예제 #18
0
        public virtual void RebindTags(TimeEntryTagsView tagsView)
        {
            List <String> tagList = new List <String> ();
            String        t;

            if (tagsView == null || tagsView.IsLoading)
            {
                return;
            }

            if (tagsView.Count == 0)
            {
                EditText.Text = String.Empty;
                return;
            }

            foreach (String tagText in tagsView.Data)
            {
                t = tagText.Length > TagMaxLength?tagText.Substring(0, TagMaxLength - 1).Trim() + "…" : tagText;

                if (tagText.Length > 0)
                {
                    tagList.Add(t);
                }
            }
            // The extra whitespace prevents the ImageSpans and the text they are over
            // to break at different positions, leaving zero linespacing on edge cases.
            var tags = new SpannableStringBuilder(String.Join(" ", tagList) + " ");

            int x = 0;

            foreach (String tagText in tagList)
            {
                tags.SetSpan(new ImageSpan(MakeTagChip(tagText)), x, x + tagText.Length, SpanTypes.ExclusiveExclusive);
                x = x + tagText.Length + 1;
            }
            EditText.SetText(tags, EditText.BufferType.Spannable);
        }
예제 #19
0
        public void TestAddManyToMany ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                var updateTask = WaitForUpdates (view);

                await DataStore.PutAsync (new TimeEntryTagData () {
                    TimeEntryId = timeEntry.Id,
                    TagId = tag3.Id,
                });

                // Wait for the tag to be loaded and the view be updated:
                await updateTask;

                Assert.AreEqual (3, view.Count);
                Assert.AreEqual (
                    MakeTagsArray (DefaultTag, "Tag #2", "Tag #3"),
                    view.Data.ToArray ()
                );
            });
        }
예제 #20
0
        public void TestAddManyToManyForOther()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                var updateTask = WaitForUpdates(view);

                await DataStore.PutAsync(new TimeEntryTagData()
                {
                    TimeEntryId = Guid.NewGuid(),
                    TagId       = tag3.Id,
                });

                // Wait to be sure the view has had a chance to ignore this relation:
                await Task.WhenAny(updateTask, Task.Delay(10));

                Assert.AreEqual(2, view.Count);
                Assert.AreEqual(
                    MakeTagsArray(DefaultTag, "Tag #2"),
                    view.Data.ToArray()
                    );
            });
        }
예제 #21
0
        public void TestAddManyToMany()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                var updateTask = WaitForUpdates(view);

                await DataStore.PutAsync(new TimeEntryTagData()
                {
                    TimeEntryId = timeEntry.Id,
                    TagId       = tag3.Id,
                });

                // Wait for the tag to be loaded and the view be updated:
                await updateTask;

                Assert.AreEqual(3, view.Count);
                Assert.AreEqual(
                    MakeTagsArray(DefaultTag, "Tag #2", "Tag #3"),
                    view.Data.ToArray()
                    );
            });
        }
예제 #22
0
        public void TestReplaceManyToMany()
        {
            RunAsync(async delegate {
                var view = new TimeEntryTagsView(timeEntry.Id);
                await WaitForLoaded(view);

                var inter = await GetByRemoteId <TimeEntryTagData> (2);
                await DataStore.DeleteAsync(inter);
                await DataStore.PutAsync(new TimeEntryTagData()
                {
                    TimeEntryId = timeEntry.Id,
                    TagId       = tag2.Id,
                });

                // We're not awaitng on the updated event as the view should update immediatelly as the TagData
                // should still be cached.

                Assert.AreEqual(2, view.Count);
                Assert.AreEqual(
                    MakeTagsArray(DefaultTag, "Tag #2"),
                    view.Data.ToArray()
                    );
            });
        }
예제 #23
0
        public void TestAddManyToManyForOther ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                var updateTask = WaitForUpdates (view);

                await DataStore.PutAsync (new TimeEntryTagData () {
                    TimeEntryId = Guid.NewGuid (),
                    TagId = tag3.Id,
                });

                // Wait to be sure the view has had a chance to ignore this relation:
                await Task.WhenAny (updateTask, Task.Delay (10));

                Assert.AreEqual (2, view.Count);
                Assert.AreEqual (
                    MakeTagsArray (DefaultTag, "Tag #2"),
                    view.Data.ToArray ()
                );
            });
        }
예제 #24
0
        public override void OnDestroyView ()
        {
            if (tagsView != null) {
                tagsView.Updated -= OnTimeEntryTagsUpdated;
                tagsView = null;
            }

            base.OnDestroyView ();
        }
예제 #25
0
        public void TestReplaceManyToMany ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                var inter = await GetByRemoteId<TimeEntryTagData> (2);
                await DataStore.DeleteAsync (inter);
                await DataStore.PutAsync (new TimeEntryTagData () {
                    TimeEntryId = timeEntry.Id,
                    TagId = tag2.Id,
                });

                // We're not awaitng on the updated event as the view should update immediatelly as the TagData
                // should still be cached.

                Assert.AreEqual (2, view.Count);
                Assert.AreEqual (
                    MakeTagsArray (DefaultTag, "Tag #2"),
                    view.Data.ToArray ()
                );
            });
        }
예제 #26
0
        public void TestRenameTag ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                tag2.Name = "A tag";
                await DataStore.PutAsync (tag2);

                Assert.AreEqual (2, view.Count);
                Assert.AreEqual (
                    MakeTagsArray ("A tag", DefaultTag),
                    view.Data.ToArray ()
                );
            });
        }
예제 #27
0
        public void TestMarkDeletedTag ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                tag2.DeletedAt = Time.UtcNow;
                await DataStore.PutAsync (tag2);

                Assert.AreEqual (1, view.Count);
                Assert.AreEqual (
                    MakeTagsArray (DefaultTag),
                    view.Data.ToArray ()
                );
            });
        }
예제 #28
0
        public void TestMarkDeletedManyToMany ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                var inter = await GetByRemoteId<TimeEntryTagData> (1);
                inter.DeletedAt = Time.UtcNow;
                await DataStore.PutAsync (inter);

                Assert.AreEqual (1, view.Count);
                Assert.AreEqual (
                    MakeTagsArray ("Tag #2"),
                    view.Data.ToArray ()
                );
            });
        }
예제 #29
0
        public void TestNonDefault ()
        {
            RunAsync (async delegate {
                var view = new TimeEntryTagsView (timeEntry.Id);
                await WaitForLoaded (view);

                Assert.IsTrue (view.HasNonDefault);

                var inter = await GetByRemoteId<TimeEntryTagData> (2);
                await DataStore.DeleteAsync (inter);

                Assert.IsFalse (view.HasNonDefault);

                inter = await GetByRemoteId<TimeEntryTagData> (1);
                await DataStore.DeleteAsync (inter);

                Assert.IsFalse (view.HasNonDefault);
            });
        }