Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
MyTaskManger/ListTasksPage.xaml.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
65 lines (53 sloc)
1.94 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.ComponentModel; | |
using System.IO; | |
using System.Linq; | |
using MyDailyTaskManger.Models; | |
using Newtonsoft.Json; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Xaml; | |
namespace MyDailyTaskManger | |
{ | |
public partial class ListTasksPage : ContentPage | |
{ | |
List<Task> listOfTasks; | |
public ObservableCollection<Task> Tasks { get; set; } | |
public ListTasksPage() | |
{ | |
this.Tasks = new ObservableCollection<Task>(); | |
this.BindingContext = this.Tasks; | |
InitializeComponent(); | |
this.listOfTasks = new List<Task>(); | |
LoadAllFilesAndDeserialize(); | |
} | |
private void LoadAllFilesAndDeserialize() | |
{ | |
var files = Directory.EnumerateFiles(App.FolderPath, "*.task.txt"); | |
if (files.Count() > 0) | |
{ | |
foreach (var filename in files) | |
{ | |
String name = filename; | |
String serializedText = File.ReadAllText(filename); | |
Task deSerializedTask = JsonConvert.DeserializeObject<Task>(serializedText); | |
if (null == deSerializedTask.fileName) | |
{ | |
deSerializedTask.fileName = filename; | |
} | |
listOfTasks.Add(deSerializedTask); | |
this.Tasks.Add(deSerializedTask); | |
} | |
this.listView.ItemsSource = this.listOfTasks.OrderBy(d => d.dateCreated).ToList(); | |
} | |
} | |
public void OnItemSelected(object sender, SelectedItemChangedEventArgs e) | |
{ | |
// int pos = e.SelectedItemIndex; | |
Task taskSelected = (Task) e.SelectedItem; | |
ViewTaskPage viewTaskPage = new ViewTaskPage(taskSelected); | |
Navigation.PushAsync(viewTaskPage); | |
} | |
} | |
} |