Permalink
Browse files

iOS: convert to MonoTouch.Dialog

  • Loading branch information...
1 parent 705bb1c commit 0422abd790c03e7fc35d490240aa9bf8c83254f2 @conceptdev conceptdev committed Apr 3, 2012
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MonoTouch.UIKit;
+using MonoTouch.Dialog;
+using MonoTouch.Foundation;
+using Tasky.BL;
+
+namespace Tasky.AL
+{
+ // This is our subclass of the fixed-size Source that allows editing
+ public class EditingSource : DialogViewController.Source {
+ public EditingSource (DialogViewController dvc) : base (dvc) {}
+
+ public override bool CanEditRow (UITableView tableView, NSIndexPath indexPath)
+ {
+ // Trivial implementation: we let all rows be editable, regardless of section or row
+ return true;
+ }
+
+ public override UITableViewCellEditingStyle EditingStyleForRow (UITableView tableView, NSIndexPath indexPath)
+ {
+ // trivial implementation: show a delete button always
+ return UITableViewCellEditingStyle.Delete;
+ }
+
+ public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
+ {
+ //
+ // In this method, we need to actually carry out the request
+ //
+ var section = Container.Root [indexPath.Section];
+ var element = section [indexPath.Row] as StringElement;
+ section.Remove (element);
+
+ var dvc = Container as Tasky.Screens.iPhone.Home.controller_iPhone;
+ dvc.DeleteTaskRow (indexPath.Row);
+ }
+ }
+}
+
@@ -1,14 +0,0 @@
-using System;
-using Tasky.BL;
-
-namespace Tasky.AL {
- public class TaskClickedEventArgs : EventArgs {
- public Task Task { get; set; }
-
- public TaskClickedEventArgs (Task task) : base ()
- {
- Task = task;
- }
- }
-}
-
@@ -1,91 +0,0 @@
-using System;
-using MonoTouch.UIKit;
-using System.Collections.Generic;
-using Tasky.BL;
-
-namespace Tasky.AL {
- public class TaskTableSource : UITableViewSource {
- public event EventHandler<TaskClickedEventArgs> TaskClicked;
- public event EventHandler<TaskClickedEventArgs> TaskDeleted;
-
- protected string cellId = "TaskCell";
-
-
- public IList<Task> Tasks
- {
- get { return tasks; }
- set { tasks = value; }
- }
- protected IList<Task> tasks = new List<Task>();
-
- public TaskTableSource (IList<Task> tasks) : base ()
- {
- this.tasks = tasks;
- }
-
- public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
- {
- UITableViewCell cell = tableView.DequeueReusableCell(cellId);
-
- if(cell == null) {
- cell = new UITableViewCell(UITableViewCellStyle.Value1, cellId);
- }
-
- cell.TextLabel.Text = tasks[indexPath.Row].Name;
- cell.DetailTextLabel.Text = tasks[indexPath.Row].Notes;
-
- return cell;
- }
-
- public override int RowsInSection (UITableView tableview, int section)
- {
- return tasks.Count;
- }
-
- public override int NumberOfSections (UITableView tableView)
- {
- return 1;
- }
-
- public override void RowSelected (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
- {
- RaiseTaskClicked(indexPath.Row);
- }
-
- public override bool CanEditRow (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
- {
- return true;
- }
-
- public override UITableViewCellEditingStyle EditingStyleForRow (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
- {
- return UITableViewCellEditingStyle.Delete;
- }
-
- public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, MonoTouch.Foundation.NSIndexPath indexPath)
- {
- if(editingStyle == UITableViewCellEditingStyle.Delete) {
- RaiseTaskDeleted(indexPath.Row);
- }
- }
-
- protected void RaiseTaskClicked(int row)
- {
- // raise the event in a thread-safe way
- var handler = TaskClicked;
- if(handler != null) {
- handler(this, new TaskClickedEventArgs(tasks[row]));
- }
- }
-
- protected void RaiseTaskDeleted(int row)
- {
- // raise the event in a thread-safe way
- var handler = TaskDeleted;
- if(handler != null) {
- handler(this, new TaskClickedEventArgs(tasks[row]));
- }
- }
- }
-}
-
@@ -1,14 +1,17 @@
using System;
+using System.Collections.Generic;
+using System.Linq;
using MonoTouch.UIKit;
+using MonoTouch.Dialog;
using Tasky.AL;
using Tasky.BL;
namespace Tasky.Screens.iPhone.Home {
- public class controller_iPhone : UITableViewController {
- AL.TaskTableSource tableSource = null;
+ public class controller_iPhone : DialogViewController {
+ List<Task> tasks;
TaskDetails.Screen detailsScreen = null;
- public controller_iPhone () : base ()
+ public controller_iPhone () : base (UITableViewStyle.Plain, null)
{
Initialize ();
Title = "Tasky";
@@ -36,16 +39,26 @@ public override void ViewWillAppear (bool animated)
protected void PopulateTable()
{
- tableSource = new Tasky.AL.TaskTableSource(BL.Managers.TaskManager.GetTasks());
- tableSource.TaskDeleted += (object sender, TaskClickedEventArgs e) => { DeleteTaskRow(e.Task.ID); };
- tableSource.TaskClicked += (object sender, TaskClickedEventArgs e) => { ShowTaskDetails(e.Task); };
- TableView.Source = tableSource;
+ tasks = BL.Managers.TaskManager.GetTasks().ToList ();
+ Root = new RootElement("Tasky") {
+ new Section() {
+ from t in tasks
+ select (Element) new StringElement(t.Name, t.Notes)
+ }
+ };
}
-
- protected void DeleteTaskRow(int id)
+ public override void Selected (MonoTouch.Foundation.NSIndexPath indexPath)
+ {
+ var task = tasks[indexPath.Row];
+ ShowTaskDetails(task);
+ }
+ public override Source CreateSizingSource (bool unevenRows)
+ {
+ return new EditingSource (this);
+ }
+ public void DeleteTaskRow(int rowId)
{
- BL.Managers.TaskManager.DeleteTask(id);
- PopulateTable();
+ BL.Managers.TaskManager.DeleteTask(tasks[rowId].ID);
}
}
}
@@ -58,6 +58,7 @@
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="monotouch" />
+ <Reference Include="MonoTouch.Dialog-1" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
@@ -70,8 +71,7 @@
<Compile Include="Screens\iPhone\TaskDetails\Screen.designer.cs">
<DependentUpon>Screen.cs</DependentUpon>
</Compile>
- <Compile Include="AL\TaskTableSource.cs" />
- <Compile Include="AL\TaskClickedEventArgs.cs" />
+ <Compile Include="AL\EditingSource.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

0 comments on commit 0422abd

Please sign in to comment.