Skip to content
Permalink
Browse files
MyDailyTaskManagerUpdate
  • Loading branch information
Amassoma George Oyindenyefa Felix committed Nov 18, 2020
0 parents commit f794d72feec4877084201cd6a3edc31d22d7c881
Show file tree
Hide file tree
Showing 338 changed files with 114,192 additions and 0 deletions.

Large diffs are not rendered by default.

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyDailyTaskManger.AddTaskPage"
Title="Add new Task"
>

<StackLayout BackgroundColor="White">
<StackLayout BackgroundColor="RoyalBlue" Padding="0, 0,0,25">
<Label
HorizontalTextAlignment="Center" FontSize="Title"
Text="Add task"
Margin="0, 25,0,0"
TextColor="White"
/>
</StackLayout>
<StackLayout Margin="20, 30,20,0">
<Label HorizontalTextAlignment="Center" FontSize="Large" Text="Please enter task detals below">

</Label>


<StackLayout>
<Entry x:Name="title" MaxLength="100" Placeholder="enter title" />

<Editor x:Name="details" AutoSize="TextChanges" MaxLength="140" Placeholder="Enter details" />

</StackLayout>

<Button Clicked="HandleForm" TextColor="WhiteSmoke" BackgroundColor="RoyalBlue" Text="Add Task" />


</StackLayout>


</StackLayout>

</ContentPage>
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using MyDailyTaskManger.Models;
using Xamarin.Forms;
using Newtonsoft.Json;
using System.IO;

namespace MyDailyTaskManger
{
public partial class AddTaskPage : ContentPage
{
private String FileName;

public AddTaskPage()
{
InitializeComponent();
FileName = null;
}

public async void HandleForm(object sender, EventArgs eventArgs)
{
var task = new Task();
task.title = this.title.Text;
task.detail = this.details.Text;
task.dateCreated = DateTime.Now.ToString();


if (null != this.FileName)
{
string FullFileName = Path.Combine(App.FolderPath, this.FileName);
task.fileName = FullFileName;
string json = JsonConvert.SerializeObject(task);
File.WriteAllText(FullFileName, json);

bool ok = await DisplayAlert(
"Success",
$"{this.FileName} File updated",
"Done",
"Contine update"
);

if (ok == true)
{
ViewTaskPage page = new ViewTaskPage(task);
// page.BindingContext = task;

await Navigation.PushAsync(page);
}


} else
{
this.FileName = $"{Path.GetRandomFileName()}.task.txt";
string FullFileName = Path.Combine(App.FolderPath, this.FileName);
task.fileName = FullFileName;
string json = JsonConvert.SerializeObject(task);
File.WriteAllText(FullFileName, json);

bool ok = await DisplayAlert(
"Success",
$"{this.FileName} File Created",
"Done",
"Contine update"
);
if (ok == true)
{
ViewTaskPage page = new ViewTaskPage(task);
// page.BindingContext = task;

await Navigation.PushAsync(page);
}
}



}
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyDailyTaskManger.App">
<Application.Resources>

</Application.Resources>
</Application>
@@ -0,0 +1,32 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using System.IO;

namespace MyDailyTaskManger
{
public partial class App : Application
{
public static String FolderPath { get; private set; }

public App()
{
InitializeComponent();
FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
MainPage = new NavigationPage(new MainPage());
}

protected override void OnStart()
{
}

protected override void OnSleep()
{
}

protected override void OnResume()
{
}

}
}
@@ -0,0 +1,3 @@
using Xamarin.Forms.Xaml;

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyDailyTaskManger.ListTasksPage">

<ListView x:Name="listView" ItemsSource="{Binding Tasks}" ItemSelected="OnItemSelected">
<!--Built in Cells-->
<ListView.ItemTemplate>
<DataTemplate>
<TextCell TextColor="DarkRed" Text="{Binding title}"
Detail="{Binding dateCreated}" />
</DataTemplate>
</ListView.ItemTemplate>

</ListView>
</ContentPage>
@@ -0,0 +1,65 @@
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);
}

}
}
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyDailyTaskManger.MainPage">

<StackLayout BackgroundColor="White">
<StackLayout BackgroundColor="RoyalBlue" Padding="0, 0,0,25">
<Label
HorizontalTextAlignment="Center" FontSize="Title"
Text="My Daily Task Manager"
Margin="0, 25,0,0"
TextColor="White"
/>
</StackLayout>
<StackLayout Margin="20, 30,20,0">
<Label HorizontalTextAlignment="Center" FontSize="Large" Text="Easily manage your daily tasks and routines">

</Label>

<Image Margin="0,30,0,0" WidthRequest="120" Source="mtm" />

<Button Clicked="GoToListTaskPage" TextColor="WhiteSmoke" BackgroundColor="RoyalBlue" Text="List Tasks" />

<Button Clicked="GoToAddTaskPage" TextColor="WhiteSmoke" BackgroundColor="CadetBlue" Text="Add new Task" />
</StackLayout>


</StackLayout>

</ContentPage>
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace MyDailyTaskManger
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}



void GoToListTaskPage(object sender, EventArgs e)
{
ListTasksPage taskPage = new ListTasksPage();
Navigation.PushAsync(taskPage);
}

public void GoToAddTaskPage(object sender, EventArgs e)
{
Navigation.PushAsync(new AddTaskPage());
}


}
}
@@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".

These files will be deployed with your package and will be accessible using Android's
AssetManager, like this:

public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

InputStream input = Assets.Open ("my_asset.txt");
}
}

Additionally, some Android functions will automatically load asset files:

Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
@@ -0,0 +1,33 @@
using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace MyDailyTaskManger.Droid
{
[Activity(Label = "MyDailyTaskManger", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(savedInstanceState);

Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

0 comments on commit f794d72

Please sign in to comment.