From 896525376e9fac4c416dce5304fe7313a591213a Mon Sep 17 00:00:00 2001 From: Craig Dunn Date: Tue, 26 Jun 2012 16:11:51 +1000 Subject: [PATCH] [TaskyPro] iOS PCL example works in MonoDevelop BUT requires you edit Microsoft.Portable.Csharp.targets to force the PCL to compile against .NET4 --- TaskyPro/TaskyiOS/AppDelegate.cs | 21 ++++++++++++++++++- .../Screens/iPhone/Home/controller_iPhone.cs | 8 +++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/TaskyPro/TaskyiOS/AppDelegate.cs b/TaskyPro/TaskyiOS/AppDelegate.cs index aa7f321..5cd372a 100644 --- a/TaskyPro/TaskyiOS/AppDelegate.cs +++ b/TaskyPro/TaskyiOS/AppDelegate.cs @@ -3,6 +3,9 @@ using System.Linq; using MonoTouch.Foundation; using MonoTouch.UIKit; +using Tasky.BL.Managers; +using Tasky.DL.SQLite; +using System.IO; namespace Tasky { [Register ("AppDelegate")] @@ -11,9 +14,15 @@ public partial class AppDelegate : UIApplicationDelegate { UIWindow window; UINavigationController navController; UITableViewController homeViewController; - + + public static AppDelegate Current { get; private set; } + public TaskManager TaskMgr { get; set; } + Connection conn; + public override bool FinishedLaunching (UIApplication app, NSDictionary options) { + Current = this; + // create a new window instance based on the screen size window = new UIWindow (UIScreen.MainScreen.Bounds); @@ -39,6 +48,16 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) UIBarButtonItem.Appearance.SetTitleTextAttributes(ta, UIControlState.Normal); + var sqliteFilename = "TaskDB.db3"; + // we need to put in /Library/ on iOS5.1 to meet Apple's iCloud terms + // (they don't want non-user-generated data in Documents) + string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder + string libraryPath = Path.Combine (documentsPath, "../Library/"); // Library folder + var path = Path.Combine(libraryPath, sqliteFilename); + conn = new Connection(path); + TaskMgr = new TaskManager(conn); + + // push the view controller onto the nav controller and show the window navController.PushViewController(homeViewController, false); window.RootViewController = navController; diff --git a/TaskyPro/TaskyiOS/Screens/iPhone/Home/controller_iPhone.cs b/TaskyPro/TaskyiOS/Screens/iPhone/Home/controller_iPhone.cs index 7e0e89e..b85e16f 100644 --- a/TaskyPro/TaskyiOS/Screens/iPhone/Home/controller_iPhone.cs +++ b/TaskyPro/TaskyiOS/Screens/iPhone/Home/controller_iPhone.cs @@ -43,14 +43,14 @@ public void SaveTask() currentTask.Name = taskDialog.Name; currentTask.Notes = taskDialog.Notes; currentTask.Done = taskDialog.Done; - BL.Managers.TaskManager.SaveTask(currentTask); + AppDelegate.Current.TaskMgr.SaveTask(currentTask); NavigationController.PopViewControllerAnimated (true); context.Dispose (); // per documentation } public void DeleteTask () { if (currentTask.ID >= 0) - BL.Managers.TaskManager.DeleteTask (currentTask.ID); + AppDelegate.Current.TaskMgr.DeleteTask (currentTask.ID); NavigationController.PopViewControllerAnimated (true); } @@ -66,7 +66,7 @@ public override void ViewWillAppear (bool animated) protected void PopulateTable () { - tasks = BL.Managers.TaskManager.GetTasks ().ToList (); + tasks = AppDelegate.Current.TaskMgr.GetTasks ().ToList (); var newTask = MonoTouch.Foundation.NSBundle.MainBundle.LocalizedString ("", ""); Root = new RootElement ("Tasky") { new Section() { @@ -86,7 +86,7 @@ public override Source CreateSizingSource (bool unevenRows) } public void DeleteTaskRow(int rowId) { - BL.Managers.TaskManager.DeleteTask(tasks[rowId].ID); + AppDelegate.Current.TaskMgr.DeleteTask(tasks[rowId].ID); } } } \ No newline at end of file