-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62a0acc
commit 3314986
Showing
51 changed files
with
1,665 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
|
||
using Foundation; | ||
using UIKit; | ||
using System.IO; | ||
|
||
namespace Todo | ||
{ | ||
// The UIApplicationDelegate for the application. This class is responsible for launching the | ||
// User Interface of the application, as well as listening (and optionally responding) to | ||
// application events from iOS. | ||
[Register ("AppDelegate")] | ||
public partial class AppDelegate : UIApplicationDelegate | ||
{ | ||
public static TodoItemDatabase Database; | ||
|
||
public override bool FinishedLaunching (UIApplication app, NSDictionary options) | ||
{ | ||
var sqliteFilename = "TodoSQLite.db3"; | ||
string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder | ||
string libraryPath = Path.Combine (documentsPath, "..", "Library"); // Library folder | ||
var path = Path.Combine(libraryPath, sqliteFilename); | ||
|
||
// This is where we copy in the prepopulated database | ||
Console.WriteLine (path); | ||
if (!File.Exists (path)) { | ||
File.Copy (sqliteFilename, path); | ||
} | ||
|
||
|
||
var db = new ADODatabase(path); | ||
Database = new TodoItemDatabase(db); | ||
|
||
|
||
return true; | ||
} | ||
|
||
public override UIWindow Window { | ||
get; | ||
set; | ||
} | ||
|
||
// This method is invoked when the application is about to move from active to inactive state. | ||
// OpenGL applications should use this method to pause. | ||
public override void OnResignActivation (UIApplication application) | ||
{ | ||
} | ||
|
||
// This method should be used to release shared resources and it should store the application state. | ||
// If your application supports background exection this method is called instead of WillTerminate | ||
// when the user quits. | ||
public override void DidEnterBackground (UIApplication application) | ||
{ | ||
} | ||
|
||
// This method is called as part of the transiton from background to active state. | ||
public override void WillEnterForeground (UIApplication application) | ||
{ | ||
} | ||
|
||
// This method is called when the application is about to terminate. Save data, if needed. | ||
public override void WillTerminate (UIApplication application) | ||
{ | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using Mono.Data.Sqlite; | ||
using System.IO; | ||
using System.Data; | ||
|
||
namespace Todo | ||
{ | ||
public class ADODatabase : IADODatabase | ||
{ | ||
static object locker = new object (); | ||
|
||
public SqliteConnection connection; | ||
|
||
public string path; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Tasky.DL.TaskDatabase"/> TaskDatabase. | ||
/// if the database doesn't exist, it will create the database and all the tables. | ||
/// </summary> | ||
public ADODatabase(string dbPath) | ||
{ | ||
var output = ""; | ||
path = dbPath; | ||
// create the tables | ||
bool exists = File.Exists (dbPath); | ||
|
||
if (!exists) { | ||
connection = new SqliteConnection ("Data Source=" + dbPath); | ||
|
||
connection.Open (); | ||
var commands = new[] { | ||
"CREATE TABLE [TodoItem] (ID INTEGER PRIMARY KEY ASC, Name NTEXT, Notes NTEXT, Done INTEGER);" | ||
}; | ||
foreach (var command in commands) { | ||
using (var c = connection.CreateCommand ()) { | ||
c.CommandText = command; | ||
var i = c.ExecuteNonQuery (); | ||
} | ||
} | ||
} else { | ||
// already exists, do nothing. | ||
} | ||
Console.WriteLine (output); | ||
} | ||
|
||
/// <summary>Convert from DataReader to Task object</summary> | ||
TodoItem FromReader (SqliteDataReader r) { | ||
var t = new TodoItem(); | ||
t.Id = Convert.ToInt32 (r ["ID"]); | ||
t.Name = r ["Name"].ToString (); | ||
t.Notes = r ["Notes"].ToString (); | ||
t.Done = Convert.ToInt32 (r ["Done"]) == 1 ? true : false; | ||
return t; | ||
} | ||
|
||
public IEnumerable<TodoItem> GetItems() | ||
{ | ||
var tl = new List<TodoItem>(); | ||
|
||
lock (locker) { | ||
connection = new SqliteConnection ("Data Source=" + path); | ||
connection.Open (); | ||
using (var contents = connection.CreateCommand ()) { | ||
contents.CommandText = "SELECT [ID], [Name], [Notes], [Done] from [TodoItem]"; | ||
var r = contents.ExecuteReader (); | ||
while (r.Read ()) { | ||
tl.Add (FromReader(r)); | ||
} | ||
} | ||
connection.Close (); | ||
} | ||
return tl; | ||
} | ||
|
||
public IEnumerable<TodoItem> GetItemsNotDone() | ||
{ | ||
var tl = new List<TodoItem>(); | ||
|
||
lock (locker) { | ||
connection = new SqliteConnection ("Data Source=" + path); | ||
connection.Open (); | ||
using (var contents = connection.CreateCommand ()) { | ||
contents.CommandText = "SELECT [ID], [Name], [Notes], [Done] FROM [TodoItem] WHERE [Done] = 0"; | ||
var r = contents.ExecuteReader (); | ||
while (r.Read ()) { | ||
tl.Add (FromReader(r)); | ||
} | ||
} | ||
connection.Close (); | ||
} | ||
return tl; | ||
} | ||
|
||
public TodoItem GetItem(int id) | ||
{ | ||
var t = new TodoItem(); | ||
lock (locker) { | ||
connection = new SqliteConnection ("Data Source=" + path); | ||
connection.Open (); | ||
using (var command = connection.CreateCommand ()) { | ||
command.CommandText = "SELECT [ID], [Name], [Notes], [Done] from [TodoItem] WHERE [ID] = ?"; | ||
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = id }); | ||
var r = command.ExecuteReader (); | ||
while (r.Read ()) { | ||
t = FromReader (r); | ||
break; | ||
} | ||
} | ||
connection.Close (); | ||
} | ||
return t; | ||
} | ||
|
||
public int SaveItem(TodoItem item) | ||
{ | ||
int r; | ||
lock (locker) { | ||
if (item.Id != 0) { | ||
connection = new SqliteConnection ("Data Source=" + path); | ||
connection.Open (); | ||
using (var command = connection.CreateCommand ()) { | ||
command.CommandText = "UPDATE [TodoItem] SET [Name] = ?, [Notes] = ?, [Done] = ? WHERE [ID] = ?;"; | ||
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Name }); | ||
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Notes }); | ||
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.Done }); | ||
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.Id }); | ||
r = command.ExecuteNonQuery (); | ||
} | ||
connection.Close (); | ||
return r; | ||
} else { | ||
connection = new SqliteConnection ("Data Source=" + path); | ||
connection.Open (); | ||
using (var command = connection.CreateCommand ()) { | ||
command.CommandText = "INSERT INTO [TodoItem] ([Name], [Notes], [Done]) VALUES (? ,?, ?)"; | ||
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Name }); | ||
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Notes }); | ||
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.Done }); | ||
r = command.ExecuteNonQuery (); | ||
} | ||
connection.Close (); | ||
return r; | ||
} | ||
|
||
} | ||
} | ||
|
||
public int DeleteItem(int id) | ||
{ | ||
lock (locker) { | ||
int r; | ||
connection = new SqliteConnection ("Data Source=" + path); | ||
connection.Open (); | ||
using (var command = connection.CreateCommand ()) { | ||
command.CommandText = "DELETE FROM [TodoItem] WHERE [ID] = ?;"; | ||
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = id}); | ||
r = command.ExecuteNonQuery (); | ||
} | ||
connection.Close (); | ||
return r; | ||
} | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Todo | ||
{ | ||
public interface IADODatabase | ||
{ | ||
IEnumerable<TodoItem> GetItems(); | ||
|
||
TodoItem GetItem(int id); | ||
|
||
int SaveItem(TodoItem item); | ||
|
||
int DeleteItem(int id); | ||
|
||
IEnumerable<TodoItem> GetItemsNotDone(); | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace Todo | ||
{ | ||
public class TodoItem | ||
{ | ||
public TodoItem () | ||
{ | ||
} | ||
|
||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public string Notes { get; set; } | ||
public bool Done { get; set; } | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Todo | ||
{ | ||
public class TodoItemDatabase | ||
{ | ||
IADODatabase database; | ||
|
||
public TodoItemDatabase(IADODatabase database) | ||
{ | ||
this.database = database; | ||
} | ||
|
||
public TodoItem GetItem(int id) | ||
{ | ||
return database.GetItem(id); | ||
} | ||
|
||
public List<TodoItem> GetItems () | ||
{ | ||
return new List<TodoItem>(database.GetItems()); | ||
} | ||
|
||
public int SaveItem (TodoItem item) | ||
{ | ||
return database.SaveItem(item); | ||
} | ||
|
||
public int DeleteItem(TodoItem item) | ||
{ | ||
return database.DeleteItem(item.Id); | ||
} | ||
|
||
public List<TodoItem> GetItemsNotDone() { | ||
return new List<TodoItem>(database.GetItemsNotDone()); | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
|
||
</dict> | ||
</plist> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDisplayName</key> | ||
<string>TodoToday</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.conceptdevelopment.TodoToday</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.0</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>MinimumOSVersion</key> | ||
<string>8.0</string> | ||
<key>UIDeviceFamily</key> | ||
<array> | ||
<integer>1</integer> | ||
</array> | ||
<key>UIMainStoryboardFile</key> | ||
<string>MainStoryboard</string> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
</array> | ||
<key>XSAppIconAssets</key> | ||
<string>Resources/Images.xcassets/AppIcons.appiconset</string> | ||
<key>UILaunchStoryboardName</key> | ||
<string>LaunchScreen</string> | ||
<key>CFBundleURLTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleURLName</key> | ||
<string>todotoday</string> | ||
<key>CFBundleURLSchemes</key> | ||
<array> | ||
<string>todotoday</string> | ||
</array> | ||
<key>CFBundleURLTypes</key> | ||
<string>Viewer</string> | ||
</dict> | ||
</array> | ||
</dict> | ||
</plist> |
Oops, something went wrong.