Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added Arrow for expanding sections.

  • Loading branch information...
commit a15dc881d09d62ec317ef4a78f82277f58c6e064 1 parent 466c467
Robert Kozak authored
29 Dialog/DialogViewController/DialogViewDataSource.cs
... ... @@ -1,4 +1,3 @@
1   -using MonoTouch.ObjCRuntime;
2 1 //
3 2 // DialogViewDataSource.cs
4 3 //
@@ -32,14 +31,17 @@
32 31 namespace MonoMobile.MVVM
33 32 {
34 33 using System;
35   - using MonoTouch.UIKit;
36 34 using System.Drawing;
37 35 using System.Linq;
  36 + using MonoTouch.CoreAnimation;
38 37 using MonoTouch.Foundation;
  38 + using MonoTouch.ObjCRuntime;
  39 + using MonoTouch.UIKit;
39 40
40 41 public class DialogViewDataSource : UITableViewSource
41 42 {
42 43 private HeaderTapGestureRecognizer tapRecognizer;
  44 + private Selector _HeaderSelector = new Selector("headerTap");
43 45
44 46 private const float _SnapBoundary = 65;
45 47 protected DialogViewController Container;
@@ -144,9 +146,17 @@ public override UIView GetViewForHeader(UITableView tableView, int sectionIdx)
144 146
145 147 if (section.HeaderView != null)
146 148 {
147   - tapRecognizer = new HeaderTapGestureRecognizer(section, this, new Selector("headerTap"));
  149 + if (section.IsExpandable)
  150 + {
  151 + section.ArrowView.Bounds = new RectangleF(0, 0, 16, 16);
  152 + section.ArrowView.Frame = new RectangleF(5, 8, 16, 16);
  153 + section.HeaderView.Add(section.ArrowView);
  154 +
  155 + tapRecognizer = new HeaderTapGestureRecognizer(section, this, _HeaderSelector);
148 156
149   - section.HeaderView.AddGestureRecognizer(tapRecognizer);
  157 + section.HeaderView.AddGestureRecognizer(tapRecognizer);
  158 + Flip(section);
  159 + }
150 160 }
151 161 return section.HeaderView;
152 162 }
@@ -163,8 +173,19 @@ public void HeaderTap(HeaderTapGestureRecognizer recognizer)
163 173 section.ExpandState = ExpandState.Closed;
164 174 else
165 175 section.ExpandState = ExpandState.Opened;
  176 +
  177 + Flip(section);
166 178 }
167 179 }
  180 +
  181 + private void Flip(ISection section)
  182 + {
  183 + UIView.BeginAnimations(null);
  184 + UIView.SetAnimationDuration(0.18f);
  185 + section.ArrowView.Layer.Transform = section.ExpandState == ExpandState.Closed ? CATransform3D.MakeRotation((float)Math.PI * 1.5f, 0, 0, 1) : CATransform3D.MakeRotation((float)Math.PI * 2f, 0, 0, 1);
  186 +
  187 + UIView.CommitAnimations();
  188 + }
168 189
169 190 public override float GetHeightForHeader(UITableView tableView, int sectionIdx)
170 191 {
11 Dialog/Section.cs
@@ -62,7 +62,9 @@ public ExpandState ExpandState
62 62 get { return _ExpandState; }
63 63 set { SetExpandState(value); }
64 64 }
65   - public bool IsExpandable { get; set; }
  65 + public bool IsExpandable {get; set; }
  66 +
  67 + public UIImageView ArrowView { get; set; }
66 68
67 69 public new IRoot Root { get { return Parent as IRoot; } }
68 70
@@ -83,7 +85,8 @@ public Section() : this((string)null)
83 85 public Section(string caption) : base(caption)
84 86 {
85 87 Elements = new ObservableCollection<IElement>();
86   -
  88 + ArrowView = new UIImageView(UIImage.FromResource(null, "ArrowDown.png"));
  89 +
87 90 // if (DataTemplate != null)
88 91 // {
89 92 // DataTemplate.BindProperties();
@@ -249,7 +252,7 @@ public void SetExpandState(ExpandState state)
249 252 if (_ExpandState != state)
250 253 {
251 254 _ExpandState = state;
252   -
  255 +
253 256 if (Root != null && IsExpandable)
254 257 {
255 258 if (_HiddenElements == null)
@@ -269,7 +272,7 @@ public void SetExpandState(ExpandState state)
269 272 }
270 273
271 274
272   - Root.TableView.ReloadSections(new NSIndexSet((uint)Index), UITableViewRowAnimation.Fade);
  275 + Root.TableView.ReloadSections(new NSIndexSet((uint)Index), UITableViewRowAnimation.None);
273 276 Root.TableView.EndUpdates();
274 277 }
275 278 }
BIN  Images/ArrowDown.png
3  Interfaces/ISection.cs
@@ -56,7 +56,8 @@ public interface ISection : IThemeable, IDisposable, IInitializable
56 56 string FooterText { get; set; }
57 57 UIView HeaderView { get; set; }
58 58 UIView FooterView { get; set; }
59   -
  59 + UIImageView ArrowView { get; set; }
  60 +
60 61 bool IsExpandable { get; set;}
61 62 ExpandState ExpandState { get; set; }
62 63
3  MonoMobile.MVVM.csproj
@@ -355,5 +355,8 @@
355 355 <EmbeddedResource Include="Images\checkmark.png">
356 356 <LogicalName>checkmark.png</LogicalName>
357 357 </EmbeddedResource>
  358 + <EmbeddedResource Include="Images\ArrowDown.png">
  359 + <LogicalName>ArrowDown.png</LogicalName>
  360 + </EmbeddedResource>
358 361 </ItemGroup>
359 362 </Project>
364 Samples/Views/MovieListView.cs
@@ -22,66 +22,66 @@ namespace Samples
22 22 // [EnableSearch(true, IncrementalSearch = true)]
23 23 public class MovieListView: View, INotifyPropertyChanged
24 24 {
25   -// [Section(Order = 2)]
26   -//// [EnableSearch(true, IncrementalSearch = false)]
27   -//// public List<ISection> Search(ISection[] sections, string searchText)
28   -//// {
29   -//// var result = new List<ISection>();
30   -////
31   -//// foreach(var section in sections)
32   -//// foreach(var element in section.Elements)
33   -//// {
34   -//// if (element.Caption.Contains(searchText))
35   -//// result.Add(new Section() { element });
36   -//// }
37   -////
38   -//// return result;
39   -//// }
40   -//
41   -// private View1 _View1 = new View1();
42   -// private View2 _View2 = new View2();
43   -//
44   -// [Multiline]
45   -// [DefaultValue("Test Entry. This is a sample of some very long text.")]
46   -// // [Theme(typeof(CorkStyle))]
47   -// public string TestEntry2 { get; set; }
48   -//
49   -// [DefaultValue(true)]
50   -// //[Checkbox]
51   -// public bool TestBool { get; set; }
52   -//
53   -// [Date]
54   -// // [Theme(typeof(MarbledTheme))]
55   -// public DateTime Date {get; set;}
56   -//
57   -// [Time]
58   -// // [Theme(typeof(GraniteStyle))]
59   -// public DateTime Time {get; set;}
60   -//
61   -// [Password("Enter passsword")]
62   -// [DefaultValue("Test String")]
63   -// public string MyString
64   -// {
65   -// get;
66   -// set;
67   -// }
68   -//
69   -// [Section]
70   -// [Root(ViewType = typeof(MovieView))]
71   -// // [List(ViewType = typeof(MovieView))]//, ThemeType = typeof(WoodenTheme))]
72   -// public ObservableCollection<MovieViewModel> Movies
73   -// {
74   -// get;
75   -// set;
76   -// }
77   -//
78   -// [LoadMore]
79   -// public void Activity()
80   -// {
81   -// Thread.Sleep(1500);
82   -// }
  25 + // [EnableSearch(true, IncrementalSearch = false)]
  26 + public List<ISection> Search(ISection[] sections, string searchText)
  27 + {
  28 + var result = new List<ISection>();
  29 +
  30 + foreach(var section in sections)
  31 + foreach(var element in section.Elements)
  32 + {
  33 + if (element.Caption.Contains(searchText))
  34 + result.Add(new Section() { element });
  35 + }
  36 +
  37 + return result;
  38 + }
  39 +
  40 + private View1 _View1 = new View1();
  41 + private View2 _View2 = new View2();
  42 +
  43 + [Section("Test Section", "",Order = 2, IsExpandable = true)]
  44 + [Multiline]
  45 + [DefaultValue("Test Entry. This is a sample of some very long text.")]
  46 + // [Theme(typeof(CorkStyle))]
  47 + public string TestEntry2 { get; set; }
  48 +
  49 + [DefaultValue(true)]
  50 + //[Checkbox]
  51 + public bool TestBool { get; set; }
  52 +
  53 + [Date]
  54 + // [Theme(typeof(MarbledTheme))]
  55 + public DateTime Date {get; set;}
  56 +
  57 + [Time]
  58 + // [Theme(typeof(GraniteStyle))]
  59 + public DateTime Time {get; set;}
83 60
84   - [Section("Using a DataTemplate", "This is a footer", IsExpandable = true, ExpandState = ExpandState.Closed)]
  61 + [Password("Enter passsword")]
  62 + [DefaultValue("Test String")]
  63 + public string MyString
  64 + {
  65 + get;
  66 + set;
  67 + }
  68 +
  69 + [Section]
  70 + [Root(ViewType = typeof(MovieView))]
  71 + // [List(ViewType = typeof(MovieView))]//, ThemeType = typeof(WoodenTheme))]
  72 + public ObservableCollection<MovieViewModel> Movies
  73 + {
  74 + get;
  75 + set;
  76 + }
  77 +
  78 + [LoadMore]
  79 + public void Activity()
  80 + {
  81 + Thread.Sleep(1500);
  82 + }
  83 +
  84 + [Section("Using a DataTemplate", "This is a footer")]
85 85 [Root(ViewType = typeof(MovieView))]
86 86 [NavbarButton(UIBarButtonSystemItem.Add)]
87 87 public ObservableCollection<MovieViewModel> Movies2
@@ -118,138 +118,138 @@ public string TestEntry
118 118 set;// { Set(()=>TestEntry, value); }
119 119 }
120 120
121   -// [Section]
122   -// [Root(CellStyle = UITableViewCellStyle.Subtitle)]
123   -// [Caption("Root Address")]
124   -// public AddressView AddressView
125   -// {
126   -// get;// { return Get(()=>AddressView, new AddressView() {Number = "4751", Street ="Wilshire Blvd", City ="LA", State="CA", Zip ="90010" }); }
127   -// set;// { Set(()=>AddressView, value); }
128   -// }
129   -//
130   -// private IView _DynamicView;
131   -// [Section(Order = 10)]
132   -// [Root]
133   -// public IView DynamicView
134   -// {
135   -// get { return _DynamicView; }
136   -// set
137   -// {
138   -// _DynamicView = value;
139   -// if (PropertyChanged != null)
140   -// PropertyChanged(this, new PropertyChangedEventArgs("DynamicView"));
141   -// } // { Set(()=>DynamicView, value); }
142   -// }
143   -//
144   -// [MultiSelection]
145   -// public List<string> MovieClasses { get; set; }
146   -//
147   -// [Section]
148   -// // [CellStyle(typeof(ClearStyle))]
149   -// //[CellStyle(typeof(ButtonCellStyle))]
150   -// public View WebSamples
151   -// {
152   -// get;// { return Get(()=>WebSamples, new WebSamples()); }
153   -// set;// { Set(()=>WebSamples, value); }
154   -// }
155   -//
156   -// private bool _CanChangeStyle;
157   -// [Checkmark]
158   -// public bool CanChangeStyle
159   -// {
160   -// get { return _CanChangeStyle; }
161   -// set
162   -// {
163   -// if (_CanChangeStyle != value)
164   -// {
165   -// _CanChangeStyle = value;
166   -// if (PropertyChanged != null)
167   -// PropertyChanged(this, new PropertyChangedEventArgs("CanChangeStyle"));
168   -// }
169   -// }
170   -// }
171   -//
172   -// [Button]
173   -// [Section(Order = 11)]
174   -// public void ChangeDynamicView()
175   -// {
176   -// if(DynamicView.GetType() == typeof(View1))
177   -// DynamicView = _View2;
178   -// else
179   -// DynamicView = _View1;
180   -// }
181   -//
182   -// [Button("CanChangeStyle", CommandOption = CommandOption.Hide)]
183   -// public void ChangeStyle()
184   -// {
185   -//
186   -// }
187   -//// [List]
188   -//// [Section("", "This Address is the same as Root Address above")]
189   -//// public AddressView InlineAddress
190   -//// {
191   -//// get { return Get(()=>AddressView); }
192   -//// set { Set(()=>AddressView, value); }
193   -//// }
194   -//
195   -// [Section]
196   -// [Root]
197   -// public InterestingView InterestingStuff
198   -// {
199   -// get;// { return Get(()=>InterestingStuff, new InterestingView()); }
200   -// set;// { Set(()=>InterestingStuff, value); }
201   -// }
202   -//
203   -// // [PullToRefresh]
204   -// public void RefreshData()
  121 + [Section]
  122 + [Root(CellStyle = UITableViewCellStyle.Subtitle)]
  123 + [Caption("Root Address")]
  124 + public AddressView AddressView
  125 + {
  126 + get;// { return Get(()=>AddressView, new AddressView() {Number = "4751", Street ="Wilshire Blvd", City ="LA", State="CA", Zip ="90010" }); }
  127 + set;// { Set(()=>AddressView, value); }
  128 + }
  129 +
  130 + private IView _DynamicView;
  131 + [Section(Order = 10)]
  132 + [Root]
  133 + public IView DynamicView
  134 + {
  135 + get { return _DynamicView; }
  136 + set
  137 + {
  138 + _DynamicView = value;
  139 + if (PropertyChanged != null)
  140 + PropertyChanged(this, new PropertyChangedEventArgs("DynamicView"));
  141 + } // { Set(()=>DynamicView, value); }
  142 + }
  143 +
  144 + [MultiSelection]
  145 + public List<string> MovieClasses { get; set; }
  146 +
  147 + [Section]
  148 + // [CellStyle(typeof(ClearStyle))]
  149 + //[CellStyle(typeof(ButtonCellStyle))]
  150 + public View WebSamples
  151 + {
  152 + get;// { return Get(()=>WebSamples, new WebSamples()); }
  153 + set;// { Set(()=>WebSamples, value); }
  154 + }
  155 +
  156 + private bool _CanChangeStyle;
  157 + [Checkmark]
  158 + public bool CanChangeStyle
  159 + {
  160 + get { return _CanChangeStyle; }
  161 + set
  162 + {
  163 + if (_CanChangeStyle != value)
  164 + {
  165 + _CanChangeStyle = value;
  166 + if (PropertyChanged != null)
  167 + PropertyChanged(this, new PropertyChangedEventArgs("CanChangeStyle"));
  168 + }
  169 + }
  170 + }
  171 +
  172 + [Button]
  173 + [Section(Order = 11)]
  174 + public void ChangeDynamicView()
  175 + {
  176 + if(DynamicView.GetType() == typeof(View1))
  177 + DynamicView = _View2;
  178 + else
  179 + DynamicView = _View1;
  180 + }
  181 +
  182 + [Button("CanChangeStyle", CommandOption = CommandOption.Hide)]
  183 + public void ChangeStyle()
  184 + {
  185 +
  186 + }
  187 +// [List]
  188 +// [Section("", "This Address is the same as Root Address above")]
  189 +// public AddressView InlineAddress
205 190 // {
206   -// for(var index = 0; index < 100; index++)
207   -// System.Threading.Thread.Sleep(50);
  191 +// get { return Get(()=>AddressView); }
  192 +// set { Set(()=>AddressView, value); }
208 193 // }
209   -//
210   -// public HoneyDoListView HoneyDoList { get; set; }
211   -// [List]
212   -// public Genre Genre { get; set; }
  194 +
  195 + [Section]
  196 + [Root]
  197 + public InterestingView InterestingStuff
  198 + {
  199 + get;// { return Get(()=>InterestingStuff, new InterestingView()); }
  200 + set;// { Set(()=>InterestingStuff, value); }
  201 + }
  202 +
  203 + // [PullToRefresh]
  204 + public void RefreshData()
  205 + {
  206 + for(var index = 0; index < 100; index++)
  207 + System.Threading.Thread.Sleep(50);
  208 + }
  209 +
  210 + public HoneyDoListView HoneyDoList { get; set; }
  211 + [List]
  212 + public Genre Genre { get; set; }
213 213
214 214 public MovieListView()
215 215 {
216 216 DataContext = new MovieListViewModel();// { TestEntry = "TestEntry string" };
217 217
218 218
219   -// HoneyDoList = new HoneyDoListView();
220   -//
221   -// var enumType = typeof(Genre);
222   -// var enumItems = from field in enumType.GetFields()
223   -// where field.IsLiteral
224   -// select EnumExtensions.GetDescriptionValue(field.Name, enumType);
225   -//
226   -// MovieClasses = new List<string>(enumItems.ToList());
227   -//
228   -// Movies = new ObservableCollection<MovieViewModel>();
229   -// var dataModel = new MovieDataModel();
230   -// dataModel.Load();
231   -// Movies =dataModel.Movies;
232   -// MyString = "Test string";
233   -//
234   -//InterestingStuff = new InterestingView();
235   -//
236   -// Location = new CLLocationCoordinate2D(-33.867139,151.207114);
237   -//
238   -//DynamicView = new View1();
239   -// AddressView = new AddressView() {Number = "4751", Street ="Wilshire Blvd", City ="LA", State="CA", Zip ="90010" };
240   -// WebSamples = new WebSamples();
  219 + HoneyDoList = new HoneyDoListView();
  220 +
  221 + var enumType = typeof(Genre);
  222 + var enumItems = from field in enumType.GetFields()
  223 + where field.IsLiteral
  224 + select EnumExtensions.GetDescriptionValue(field.Name, enumType);
  225 +
  226 + MovieClasses = new List<string>(enumItems.ToList());
  227 +
  228 + Movies = new ObservableCollection<MovieViewModel>();
  229 + var dataModel = new MovieDataModel();
  230 + dataModel.Load();
  231 + Movies =dataModel.Movies;
  232 + MyString = "Test string";
  233 +
  234 +InterestingStuff = new InterestingView();
  235 +
  236 + Location = new CLLocationCoordinate2D(-33.867139,151.207114);
  237 +
  238 +DynamicView = new View1();
  239 + AddressView = new AddressView() {Number = "4751", Street ="Wilshire Blvd", City ="LA", State="CA", Zip ="90010" };
  240 + WebSamples = new WebSamples();
  241 +
  242 +//// foreach(var movie in dataModel.Movies)
  243 +//// {
  244 +//// Movies.Add(new MovieView() { DataContext = movie });
  245 +//// }
241 246 //
242   -////// foreach(var movie in dataModel.Movies)
243   -////// {
244   -////// Movies.Add(new MovieView() { DataContext = movie });
245   -////// }
246   -////
247   -////Movies2 = Movies;
248   -//
249   -// Time = DateTime.Now;
250   -// Date = DateTime.Now;
251   -//
252   -// CanChangeStyle = true;
  247 +//Movies2 = Movies;
  248 +
  249 + Time = DateTime.Now;
  250 + Date = DateTime.Now;
  251 +
  252 + CanChangeStyle = true;
253 253 }
254 254
255 255

0 comments on commit a15dc88

Please sign in to comment.
Something went wrong with that request. Please try again.