Skip to content

Commit

Permalink
[today] ios 8 extension
Browse files Browse the repository at this point in the history
  • Loading branch information
conceptdev committed Oct 31, 2014
1 parent 62a0acc commit 3314986
Show file tree
Hide file tree
Showing 51 changed files with 1,665 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ Apps using Xamarin.iOS with the 64-bit API and targeting iOS 8 and newer.

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).

Apple requires iOS 8 apps to include a 64-bit binary from February 2015.
Apple requires iOS 8 apps to include a 64-bit binary from February 2015.


HeartRateMonitor
----------------
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.

TodoToday
---------
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.
69 changes: 69 additions & 0 deletions TodoToday/Todo/AppDelegate.cs
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)
{
}
}
}

169 changes: 169 additions & 0 deletions TodoToday/Todo/Data/ADODatabase_Implementation.cs
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;
}
}
}
}

19 changes: 19 additions & 0 deletions TodoToday/Todo/Data/IADODatabase.cs
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();
}
}

19 changes: 19 additions & 0 deletions TodoToday/Todo/Data/TodoItem.cs
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; }
}
}

41 changes: 41 additions & 0 deletions TodoToday/Todo/Data/TodoItemDatabase.cs
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());
}
}
}

7 changes: 7 additions & 0 deletions TodoToday/Todo/Entitlements.plist
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>
49 changes: 49 additions & 0 deletions TodoToday/Todo/Info.plist
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>
Loading

0 comments on commit 3314986

Please sign in to comment.