//Method which modifies both the DataBase table and the list of tasks protected void Save() { //Creating the current displayed task for saving int priority; if (low.Checked == true) { priority = 1; } else if (mediu.Checked == true) { priority = 2; } else { priority = 3; } Task newTask = new Task(name.Text, description.Text, check, new DateTime(date.Year, date.Month + 1, date.DayOfMonth, time.CurrentHour.IntValue(), time.CurrentMinute.IntValue(), 00), priority); //Checking whether the task has to be saved or it has to update another task if (MainActivity.items.Exists(t => t.name.Equals(name.Text))) { //Delete the task from the database TaskRepository.UpdateTask(newTask); //Finding the index in the list of tasks int position = 0; for (int i = 0; i < MainActivity.items.Count; i++) { if (MainActivity.items[i].name.Equals(name.Text)) { position = i; break; } } //Update the task from the list of tasks MainActivity.items[position].description = description.Text; MainActivity.items[position].deadline = new DateTime(date.Year, date.Month + 1, date.DayOfMonth, time.CurrentHour.IntValue(), time.CurrentMinute.IntValue(), 00); MainActivity.items[position].priority = priority; MainActivity.items[position].status = check; } else { //Save the task to DataBase TaskRepository.SaveTask(newTask); //Save the task to list of tasks MainActivity.items.Add(newTask); } Finish(); }
public override View GetView(int position, View convertView, ViewGroup parent) { View view = convertView; // re-use an existing view, if one is available if (view == null) // otherwise create a new one { view = context.LayoutInflater.Inflate(Resource.Layout.ListView, null); } view.FindViewById <TextView>(Resource.Id.textName).Text = items[position].name; //Set texts TextView textName = view.FindViewById <TextView>(Resource.Id.textName); TextView date = view.FindViewById <TextView>(Resource.Id.textDate); CheckBox check = view.FindViewById <CheckBox>(Resource.Id.checkBoxItem); textName.Text = items[position].name; date.Text = items[position].deadline.ToString(); check.Checked = items[position].status; if (items[position].priority == 1) { textName.SetBackgroundColor(Android.Graphics.Color.ParseColor("#13b60d")); date.SetBackgroundColor(Android.Graphics.Color.ParseColor("#13b60d")); } else if (items[position].priority == 2) { textName.SetBackgroundColor(Android.Graphics.Color.ParseColor("#d45611")); date.SetBackgroundColor(Android.Graphics.Color.ParseColor("#d45611")); } else { textName.SetBackgroundColor(Android.Graphics.Color.ParseColor("#e11f1f")); date.SetBackgroundColor(Android.Graphics.Color.ParseColor("#e11f1f")); } check.CheckedChange += (sender, e) => { //Update items[position].status = check.Checked; Task aux = new Task(items[position].name, items[position].description, items[position].status, items[position].deadline, items[position].priority); TaskRepository.UpdateTask(aux); }; return(view); }