Skip to content

Commit 3314986

Browse files
committed
[today] ios 8 extension
1 parent 62a0acc commit 3314986

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1665
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,13 @@ Apps using Xamarin.iOS with the 64-bit API and targeting iOS 8 and newer.
55

66
The [Unified API](http://developer.xamarin.com/guides/cross-platform/macios/) is designed to bring 64-bit support to both Xamarin.iOS and Xamarin.Mac (as well as facilitate code-sharing between those two platforms).
77

8-
Apple requires iOS 8 apps to include a 64-bit binary from February 2015.
8+
Apple requires iOS 8 apps to include a 64-bit binary from February 2015.
9+
10+
11+
HeartRateMonitor
12+
----------------
13+
Uses Bluetooth LE APIs to communicate with a heart rate monitor and display the value on the screen. Stores data in iOS 8's Health app via HealthKit.
14+
15+
TodoToday
16+
---------
17+
Todo list application with an iOS 8 Today Extension for the notification screen (showing how many items left to-do). Uses ADO.NET for the data access.

TodoToday/Todo/AppDelegate.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Linq;
3+
using System.Collections.Generic;
4+
5+
using Foundation;
6+
using UIKit;
7+
using System.IO;
8+
9+
namespace Todo
10+
{
11+
// The UIApplicationDelegate for the application. This class is responsible for launching the
12+
// User Interface of the application, as well as listening (and optionally responding) to
13+
// application events from iOS.
14+
[Register ("AppDelegate")]
15+
public partial class AppDelegate : UIApplicationDelegate
16+
{
17+
public static TodoItemDatabase Database;
18+
19+
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
20+
{
21+
var sqliteFilename = "TodoSQLite.db3";
22+
string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder
23+
string libraryPath = Path.Combine (documentsPath, "..", "Library"); // Library folder
24+
var path = Path.Combine(libraryPath, sqliteFilename);
25+
26+
// This is where we copy in the prepopulated database
27+
Console.WriteLine (path);
28+
if (!File.Exists (path)) {
29+
File.Copy (sqliteFilename, path);
30+
}
31+
32+
33+
var db = new ADODatabase(path);
34+
Database = new TodoItemDatabase(db);
35+
36+
37+
return true;
38+
}
39+
40+
public override UIWindow Window {
41+
get;
42+
set;
43+
}
44+
45+
// This method is invoked when the application is about to move from active to inactive state.
46+
// OpenGL applications should use this method to pause.
47+
public override void OnResignActivation (UIApplication application)
48+
{
49+
}
50+
51+
// This method should be used to release shared resources and it should store the application state.
52+
// If your application supports background exection this method is called instead of WillTerminate
53+
// when the user quits.
54+
public override void DidEnterBackground (UIApplication application)
55+
{
56+
}
57+
58+
// This method is called as part of the transiton from background to active state.
59+
public override void WillEnterForeground (UIApplication application)
60+
{
61+
}
62+
63+
// This method is called when the application is about to terminate. Save data, if needed.
64+
public override void WillTerminate (UIApplication application)
65+
{
66+
}
67+
}
68+
}
69+
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
using Mono.Data.Sqlite;
7+
using System.IO;
8+
using System.Data;
9+
10+
namespace Todo
11+
{
12+
public class ADODatabase : IADODatabase
13+
{
14+
static object locker = new object ();
15+
16+
public SqliteConnection connection;
17+
18+
public string path;
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="Tasky.DL.TaskDatabase"/> TaskDatabase.
22+
/// if the database doesn't exist, it will create the database and all the tables.
23+
/// </summary>
24+
public ADODatabase(string dbPath)
25+
{
26+
var output = "";
27+
path = dbPath;
28+
// create the tables
29+
bool exists = File.Exists (dbPath);
30+
31+
if (!exists) {
32+
connection = new SqliteConnection ("Data Source=" + dbPath);
33+
34+
connection.Open ();
35+
var commands = new[] {
36+
"CREATE TABLE [TodoItem] (ID INTEGER PRIMARY KEY ASC, Name NTEXT, Notes NTEXT, Done INTEGER);"
37+
};
38+
foreach (var command in commands) {
39+
using (var c = connection.CreateCommand ()) {
40+
c.CommandText = command;
41+
var i = c.ExecuteNonQuery ();
42+
}
43+
}
44+
} else {
45+
// already exists, do nothing.
46+
}
47+
Console.WriteLine (output);
48+
}
49+
50+
/// <summary>Convert from DataReader to Task object</summary>
51+
TodoItem FromReader (SqliteDataReader r) {
52+
var t = new TodoItem();
53+
t.Id = Convert.ToInt32 (r ["ID"]);
54+
t.Name = r ["Name"].ToString ();
55+
t.Notes = r ["Notes"].ToString ();
56+
t.Done = Convert.ToInt32 (r ["Done"]) == 1 ? true : false;
57+
return t;
58+
}
59+
60+
public IEnumerable<TodoItem> GetItems()
61+
{
62+
var tl = new List<TodoItem>();
63+
64+
lock (locker) {
65+
connection = new SqliteConnection ("Data Source=" + path);
66+
connection.Open ();
67+
using (var contents = connection.CreateCommand ()) {
68+
contents.CommandText = "SELECT [ID], [Name], [Notes], [Done] from [TodoItem]";
69+
var r = contents.ExecuteReader ();
70+
while (r.Read ()) {
71+
tl.Add (FromReader(r));
72+
}
73+
}
74+
connection.Close ();
75+
}
76+
return tl;
77+
}
78+
79+
public IEnumerable<TodoItem> GetItemsNotDone()
80+
{
81+
var tl = new List<TodoItem>();
82+
83+
lock (locker) {
84+
connection = new SqliteConnection ("Data Source=" + path);
85+
connection.Open ();
86+
using (var contents = connection.CreateCommand ()) {
87+
contents.CommandText = "SELECT [ID], [Name], [Notes], [Done] FROM [TodoItem] WHERE [Done] = 0";
88+
var r = contents.ExecuteReader ();
89+
while (r.Read ()) {
90+
tl.Add (FromReader(r));
91+
}
92+
}
93+
connection.Close ();
94+
}
95+
return tl;
96+
}
97+
98+
public TodoItem GetItem(int id)
99+
{
100+
var t = new TodoItem();
101+
lock (locker) {
102+
connection = new SqliteConnection ("Data Source=" + path);
103+
connection.Open ();
104+
using (var command = connection.CreateCommand ()) {
105+
command.CommandText = "SELECT [ID], [Name], [Notes], [Done] from [TodoItem] WHERE [ID] = ?";
106+
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = id });
107+
var r = command.ExecuteReader ();
108+
while (r.Read ()) {
109+
t = FromReader (r);
110+
break;
111+
}
112+
}
113+
connection.Close ();
114+
}
115+
return t;
116+
}
117+
118+
public int SaveItem(TodoItem item)
119+
{
120+
int r;
121+
lock (locker) {
122+
if (item.Id != 0) {
123+
connection = new SqliteConnection ("Data Source=" + path);
124+
connection.Open ();
125+
using (var command = connection.CreateCommand ()) {
126+
command.CommandText = "UPDATE [TodoItem] SET [Name] = ?, [Notes] = ?, [Done] = ? WHERE [ID] = ?;";
127+
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Name });
128+
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Notes });
129+
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.Done });
130+
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.Id });
131+
r = command.ExecuteNonQuery ();
132+
}
133+
connection.Close ();
134+
return r;
135+
} else {
136+
connection = new SqliteConnection ("Data Source=" + path);
137+
connection.Open ();
138+
using (var command = connection.CreateCommand ()) {
139+
command.CommandText = "INSERT INTO [TodoItem] ([Name], [Notes], [Done]) VALUES (? ,?, ?)";
140+
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Name });
141+
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Notes });
142+
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.Done });
143+
r = command.ExecuteNonQuery ();
144+
}
145+
connection.Close ();
146+
return r;
147+
}
148+
149+
}
150+
}
151+
152+
public int DeleteItem(int id)
153+
{
154+
lock (locker) {
155+
int r;
156+
connection = new SqliteConnection ("Data Source=" + path);
157+
connection.Open ();
158+
using (var command = connection.CreateCommand ()) {
159+
command.CommandText = "DELETE FROM [TodoItem] WHERE [ID] = ?;";
160+
command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = id});
161+
r = command.ExecuteNonQuery ();
162+
}
163+
connection.Close ();
164+
return r;
165+
}
166+
}
167+
}
168+
}
169+

TodoToday/Todo/Data/IADODatabase.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Todo
5+
{
6+
public interface IADODatabase
7+
{
8+
IEnumerable<TodoItem> GetItems();
9+
10+
TodoItem GetItem(int id);
11+
12+
int SaveItem(TodoItem item);
13+
14+
int DeleteItem(int id);
15+
16+
IEnumerable<TodoItem> GetItemsNotDone();
17+
}
18+
}
19+

TodoToday/Todo/Data/TodoItem.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
5+
namespace Todo
6+
{
7+
public class TodoItem
8+
{
9+
public TodoItem ()
10+
{
11+
}
12+
13+
public int Id { get; set; }
14+
public string Name { get; set; }
15+
public string Notes { get; set; }
16+
public bool Done { get; set; }
17+
}
18+
}
19+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Todo
6+
{
7+
public class TodoItemDatabase
8+
{
9+
IADODatabase database;
10+
11+
public TodoItemDatabase(IADODatabase database)
12+
{
13+
this.database = database;
14+
}
15+
16+
public TodoItem GetItem(int id)
17+
{
18+
return database.GetItem(id);
19+
}
20+
21+
public List<TodoItem> GetItems ()
22+
{
23+
return new List<TodoItem>(database.GetItems());
24+
}
25+
26+
public int SaveItem (TodoItem item)
27+
{
28+
return database.SaveItem(item);
29+
}
30+
31+
public int DeleteItem(TodoItem item)
32+
{
33+
return database.DeleteItem(item.Id);
34+
}
35+
36+
public List<TodoItem> GetItemsNotDone() {
37+
return new List<TodoItem>(database.GetItemsNotDone());
38+
}
39+
}
40+
}
41+

TodoToday/Todo/Entitlements.plist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
6+
</dict>
7+
</plist>

TodoToday/Todo/Info.plist

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDisplayName</key>
6+
<string>TodoToday</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>com.conceptdevelopment.TodoToday</string>
9+
<key>CFBundleShortVersionString</key>
10+
<string>1.0</string>
11+
<key>CFBundleVersion</key>
12+
<string>1.0</string>
13+
<key>LSRequiresIPhoneOS</key>
14+
<true/>
15+
<key>MinimumOSVersion</key>
16+
<string>8.0</string>
17+
<key>UIDeviceFamily</key>
18+
<array>
19+
<integer>1</integer>
20+
</array>
21+
<key>UIMainStoryboardFile</key>
22+
<string>MainStoryboard</string>
23+
<key>UIRequiredDeviceCapabilities</key>
24+
<array>
25+
<string>armv7</string>
26+
</array>
27+
<key>UISupportedInterfaceOrientations</key>
28+
<array>
29+
<string>UIInterfaceOrientationPortrait</string>
30+
</array>
31+
<key>XSAppIconAssets</key>
32+
<string>Resources/Images.xcassets/AppIcons.appiconset</string>
33+
<key>UILaunchStoryboardName</key>
34+
<string>LaunchScreen</string>
35+
<key>CFBundleURLTypes</key>
36+
<array>
37+
<dict>
38+
<key>CFBundleURLName</key>
39+
<string>todotoday</string>
40+
<key>CFBundleURLSchemes</key>
41+
<array>
42+
<string>todotoday</string>
43+
</array>
44+
<key>CFBundleURLTypes</key>
45+
<string>Viewer</string>
46+
</dict>
47+
</array>
48+
</dict>
49+
</plist>

0 commit comments

Comments
 (0)