Example #1
0
        public void AddAndPrintTest()
        {
            TodoApp todoApp = new TodoApp();

            todoApp.UseTestEnvironment();

            // Retrieve output to command line, redirect it to the String Writer
            using (StringWriter sw = new StringWriter())
            {
                // Set the console to print to sw
                Console.SetOut(sw);

                todoApp.Add("This is a test");
                string expected = "#1 This is a test\r\n";

                Assert.AreEqual(expected, sw.ToString());
            }

            using (StringWriter sw = new StringWriter())
            {
                // Set the console to print to sw
                Console.SetOut(sw);

                todoApp.Add("another item");
                string expectedPrint = "#2 another item\r\n#1 This is a test\r\n#2 another item\r\n";
                todoApp.Print();

                Assert.AreEqual(expectedPrint, sw.ToString());
            }
        }
Example #2
0
        public static bool SetupTodoList(StackPage stackPage, Func <ButtonRow, Task> action)
        {
            var hasTodoList = false;
            var header      = stackPage.GetRow <HeaderRow>("TodoLists");

            if (header != null)
            {
                var rows     = stackPage.GetHeaderSectionRows(header);
                var rowIndex = 0;

                stackPage.AddIndexBefore = false;
                stackPage.AddIndex       = header;

                foreach (var serviceNode in ServiceNodeManager.Current.ServiceNodes)
                {
                    var todo = TodoApp.Current.GetTodo(serviceNode);
                    if (todo != null)
                    {
                        foreach (var todoList in todo.TodoLists)
                        {
                            hasTodoList = true;
                            if (!(rowIndex < rows.Count && rows[rowIndex] is ButtonRow button && button.Tag is TodoList))
                            {
                                button = stackPage.AddButtonRow(null, action);
                            }

                            var name = TodoApp.GetTodoListName(todoList);

                            if (button.Label.Text != name)
                            {
                                button.Label.Text = name;
                            }

                            button.RowLayout.SetAccentColor(serviceNode.AccentColor);
                            button.Tag = todoList;

                            stackPage.AddIndex = button;
                            ++rowIndex;
                        }
                    }
                }

                for (var i = rowIndex; i < rows.Count; i++)
                {
                    if (rows[i] is ButtonRow button && button.Tag is TodoList)
                    {
                        stackPage.RemoveView(button);
                    }
                }
            }

            return(hasTodoList);
        }
Example #3
0
        public InputViewModel(TodoApp todoApp)
        {
            _todoApp = todoApp;

            Input      = new ReactiveProperty <string>();
            AddCommand = new ReactiveCommand()
                         .WithSubscribe(AddTodoItem)
                         .AddTo(Disposables);

            CompleteAllCommand = new ReactiveCommand()
                                 .WithSubscribe(() => _todoApp.CompleteAll())
                                 .AddTo(Disposables);
        }
 public TodoItemsViewModel(TodoApp todoApp, IMessageBroker messageBroker)
 {
     _todoApp       = todoApp;
     _messageBroker = messageBroker;
     TodoItems      = _messageBroker.ToObservable <TargetViewChangedEvent>()
                      .Select(x => x.TargetViewType)
                      .Select(x => (IEnumerable <TodoItem>)(x switch
     {
         TargetViewType.All => _todoApp.AllTodoItems,
         TargetViewType.Active => _todoApp.ActiveTodoItems,
         TargetViewType.Completed => _todoApp.CompletedTodoitems,
         _ => throw new InvalidOperationException(),
     }))
Example #5
0
        void UpdateList()
        {
            UpdateButtons();

            var header = GetRow <HeaderRow>("Title");

            header.Label.Text = TodoApp.GetTodoListName(TodoList);

            UpdateTasks(TodoTaskStatusTypes.Open, "OpenTasks", _openTasks, "NoOpenTasks");
            if (_edit)
            {
                UpdateTasks(TodoTaskStatusTypes.Closed, "ClosedTasks", _closedTasks, "NoClosedTasks");
            }
        }
        public CommandsViewModel(TodoApp todoApp, IMessageBroker messageBroker)
        {
            ChangeTargetViewTypeCommand = new ReactiveCommand <TargetViewType>()
                                          .WithSubscribe(x => messageBroker.Publish(new TargetViewChangedEvent(x)))
                                          .AddTo(Disposables);

            TargetViewType = ChangeTargetViewTypeCommand.ToReadOnlyReactivePropertySlim()
                             .AddTo(Disposables);
            CountOfItemsLeft = todoApp.AllTodoItems
                               .ObserveElementProperty(x => x.Completed)
                               .Select(_ => todoApp.ActiveTodoItems.Count)
                               .ToReadOnlyReactivePropertySlim()
                               .AddTo(Disposables);

            ClearCompletedCommand = new ReactiveCommand()
                                    .WithSubscribe(() => todoApp.ClearCompletedItems())
                                    .AddTo(Disposables);
        }
        public MainPageViewModel(TodoApp todoApp)
        {
            this.TodoApp = todoApp;

            this.AddCommand = new DelegateCommand(async() =>
            {
                await this.TodoApp.InsertTodoItemAsync(new TodoItem {
                    Text = this.Text
                });
                this.Text = "";
                await this.TodoApp.LoadTodoItemsAsync();
            }, () => !string.IsNullOrWhiteSpace(this.Text) && this.TodoApp.IsAuthenticated)
                              .ObservesProperty(() => this.Text);

            this.RefreshCommand = new DelegateCommand(async() =>
            {
                await this.TodoApp.SyncAsync();
                await this.TodoApp.LoadTodoItemsAsync();
                this.IsRefreshing = false;
            });
        }
Example #8
0
        static void Main(string[] args)
        {
            TodoApp todoApp;

            Console.WriteLine("- console - to use System.Console as input/output");
            Console.WriteLine("- inmemory - to use in-memory input / output");
            Console.WriteLine("- file - to use file input / output");

            var choice = Console.ReadLine();

            switch (choice.ToLower())
            {
            case "console":
                var consoleIO = new ConsoleInputOutput();

                todoApp = new TodoApp(consoleIO);
                break;

            case "inmemory":
                var inputs     = new string[] { "buy a milk", "go to dentist" };
                var inMemoryIO = new MemoryInputOutput(inputs);

                todoApp = new TodoApp(inMemoryIO);
                break;

            case "file":
                var fileIO = new FileInputOutput();

                todoApp = new TodoApp(fileIO);
                break;

            default:
                throw new Exception("bad choice");
            }

            while (true)
            {
                Console.WriteLine("Available commands: add, print");
                choice = Console.ReadLine();

                switch (choice.ToLower())
                {
                case "add":
                    try
                    {
                        todoApp.Add();
                    }
                    catch (NotImplementedException)
                    {
                        Console.WriteLine("Option is not supported yet");
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                    break;

                case "print":
                    try
                    {
                        todoApp.Print();
                    }
                    catch (NotImplementedException)
                    {
                        Console.WriteLine("Option is not supported yet");
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                    break;

                default: continue;
                }
            }
        }
Example #9
0
 public void Remove(TodoApp todoApp)
 {
     _context.TodoApps.Remove(todoApp);
 }
Example #10
0
 public void Update(TodoApp todoApp)
 {
     _context.TodoApps.Update(todoApp);
 }
Example #11
0
 public void Add(TodoApp todoApp)
 {
     _context.TodoApps.Add(todoApp);
 }
Example #12
0
        public TodoListPage(TodoList todoList, bool edit) : base("TodoListPage")
        {
            Subscribe <QueryTodoListEvent>(QueryTodoList);

            if (edit)
            {
                Subscribe <TodoListNameChangedEvent>(ListName);
                Subscribe <TodoListDeletetEvent>(GroupDeleted);
            }

            TodoList = todoList;
            _edit    = edit;


            var header = AddTitleRow(null);

            header.Identifier = "Title";
            var title = TodoApp.GetTodoListName(todoList);

            header.Label.Text = title;
            SetTitle(title);

            UpdateSecretKeyButton();

            var items = todoList.GetTasks(TodoTaskStatusTypes.Open, TodoListSortMethod.ByTimestampDesc);

            AddHeaderRow("OpenTasks");

            if (items.Count > 0)
            {
                foreach (var item in items)
                {
                    var b = AddTaskButtonRow(item);
                    _openTasks.Add(b);
                }
            }
            else
            {
                AddInfoRow("NoOpenTasks");
            }

            AddFooterRow();

            if (!_edit)
            {
                AddHeaderRow("More");

                var button = AddButtonRow("TodoListView.Add", NewTask);
                //add.Margin = new Thickness(40, 0, 0, 0);
                button.RowStyle           = Theme.SubmitButton;
                button.FontIcon.IsVisible = false;
                button.SetDetailViewIcon(Icons.Plus);
                //add.IsEnabled = !todoList.HasMissingSecretKeys;

                button = AddButtonRow("Edit", Edit);
                button.SetDetailViewIcon(Icons.Pencil);

                button = AddButtonRow("Reload", Reload);
                button.SetDetailViewIcon(Icons.Sync);
                AddFooterRow();
            }

            if (_edit)
            {
                items = todoList.GetTasks(TodoTaskStatusTypes.Closed, TodoListSortMethod.ByTimestampDesc);

                AddHeaderRow("ClosedTasks");
                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        var b = AddTaskButtonRow(item);
                        _closedTasks.Add(b);
                    }
                }
                else
                {
                    AddInfoRow("NoClosedTasks");
                }
                AddFooterRow();

                AddHeaderRow("UsersSection");

                var button = AddButtonRow("ViewUsers", Users);
                button.SetDetailViewIcon(Icons.Users);
                button = AddButtonRow("Invite", Invite);
                button.SetDetailViewIcon(Icons.UserPlus);

                AddFooterRow();

                AddHeaderRow("NameHeader");

                _nameEntry = AddEntryRow(todoList.Name, "Name");
                _nameEntry.SetDetailViewIcon(Icons.Pencil);
                _nameButton          = AddSubmitButtonRow("NameButton", Name);
                _nameButton.RowStyle = Theme.SubmitButton;

                Status.AddBusyView(_nameEntry.Edit);
                Status.AddBusyView(_nameButton);
                AddFooterRow();

                AddHeaderRow("Common.SubmitAccount");
                _submitAccount = AddRow(new SubmitAccountButtonRow <GroupSubmitAccount>(this, () => todoList.ServiceNode.GetSubmitAccounts <GroupSubmitAccount>(todoList.Index), todoList.ListId.ToString()));
                AddInfoRow("Common.SubmitAccountInfo");
                AddFooterRow();

                AddHeaderRow("DeleteHeader");

                var del = AddButtonRow("DeleteButton", Delete);
                del.RowStyle = Theme.CancelButton;
                del.SetDetailViewIcon(Icons.TrashAlt);

                Status.AddBusyView(del);

                AddFooterRow();
            }
        }
Example #13
0
 public AddCommand()
 {
     todoApp  = TodoApp.Default();
     renderer = new TodoRenderer(todoApp);
 }