Пример #1
0
        private void AddNewTask()
        {
            var task = m_TaskEditText.Text.Trim();

            if (string.IsNullOrWhiteSpace(task))
            {
                return;
            }

            m_DataChanged = true;
            var newTask = new TaskModel {
                Task = task
            };

            try
            {
                DataManager.SaveTask(newTask);

                var selection = 0;
                switch (Settings.SortBy)
                {
                case SortOption.Newest:
                    m_AllTasks.Insert(0, newTask);
                    SetChecks();
                    break;

                case SortOption.Oldest:
                    m_AllTasks.Add(newTask);
                    selection = m_AllTasks.Count - 1;
                    break;
                }

                m_TaskEditText.Text = string.Empty;

                RunOnUiThread(() =>
                {
                    ((TaskAdapter)ListAdapter).NotifyDataSetChanged();
                    ListView.SetSelection(selection);
                });
            }
            catch (Exception)
            {
                RunOnUiThread(() => Toast.MakeText(this, Resource.String.unable_to_save,
                                                   ToastLength.Short).Show());
            }
        }