-
Notifications
You must be signed in to change notification settings - Fork 3
/
DaysViewController.cs
136 lines (117 loc) · 4.36 KB
/
DaysViewController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace Monospace2
{
/// <summary>
/// First view that users see - lists the top level of the hierarchy xml
/// </summary>
/// <remarks>
/// LOADS data from the xml files into public properties (deserialization)
/// then we pass around references to the MainViewController so other
/// ViewControllers can access the data.</remarks>
[Register]
public class DaysViewController : UITableViewController
{
private UITableView tableView;
private Database _database;
private List<SessionDate> _dates;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
_database = AppDelegate.SessionDatabase;
_dates = _database.GetDates().ToList();
UIImageView imageView = new UIImageView(UIImage.FromFile("BackgroundMonospace.png"));
imageView.Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height);
imageView.UserInteractionEnabled = true;
// no XIB !
tableView = new UITableView()
{
Delegate = new TableViewDelegate(this, _dates),
DataSource = new TableViewDataSource(this, _dates),
AutoresizingMask = UIViewAutoresizing.FlexibleHeight|
UIViewAutoresizing.FlexibleWidth,
BackgroundColor = UIColor.Clear,
Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height),
};
// Set the table view to fit the width of the app.
//tableView.SizeToFit();
// Reposition and resize the receiver
//tableView.Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height);
// Add the table view as a subview
//this.View.AddSubview(tableView);
imageView.AddSubview(tableView);
this.View.AddSubview(imageView);
}
private class TableViewDelegate : UITableViewDelegate
{
private DaysViewController _dvc;
private List<SessionDate> _dates;
public TableViewDelegate(DaysViewController controller, List<SessionDate> dates)
{
_dvc = controller;
_dates = dates;
}
/// <summary>
/// If there are subsections in the hierarchy, navigate to those
/// ASSUMES there are _never_ Categories hanging off the root in the hierarchy
/// </summary>
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
string date = _dates[indexPath.Row].Date;
Console.WriteLine("DaysViewController:TableViewDelegate.RowSelected: Label="+date);
SessionsViewController sessionsView = new SessionsViewController(date);
sessionsView.Title = date;
_dvc.NavigationController.PushViewController(sessionsView,true);
}
}
private class TableViewDataSource : UITableViewDataSource
{
static NSString kCellIdentifier = new NSString ("MyDateIdentifier");
private DaysViewController _dvc;
private List<SessionDate> _dates;
public TableViewDataSource (DaysViewController controller, List<SessionDate> dates)
{
_dvc = controller;
_dates = dates;
}
public override int RowsInSection (UITableView tableview, int section)
{
return _dates.Count;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (kCellIdentifier);
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, kCellIdentifier);
}
string date = _dates[indexPath.Row].Date;
cell.TextLabel.Text = date;
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
return cell;
}
}
private string GetDisplayDate(string date)
{
string output = date;
try
{
string[] array = date.Split('-');
int day = Convert.ToInt16(array[0]);
string month = array[1];
int year = DateTime.Now.Year;
DateTime dt1 = Convert.ToDateTime(month + " 01, 1900");
DateTime dt = new DateTime(year, dt1.Month, day);
output = String.Format("{0} {1} {2}",dt.DayOfWeek, day, dt.ToString("MMMM"));
}
catch (Exception)
{}
return output;
}
}
}