-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAddTaskViewController.fs
60 lines (44 loc) · 2.25 KB
/
AddTaskViewController.fs
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
namespace Tasky
open System
open MonoTouch.UIKit
open MonoTouch.Foundation
open System.Drawing
open Data
type AddTaskViewController (task:task, isNew:bool) =
inherit UIViewController ()
new() = new AddTaskViewController ({Id = 0L; Description = ""; Complete = false}, true)
override this.ViewDidLoad () =
base.ViewDidLoad ()
let addView = new UIView(this.View.Bounds, BackgroundColor = UIColor.White)
let description = new UITextField(RectangleF(20.f, 64.f, 280.f, 50.f),
Text = task.Description,
Placeholder = "Task description",
ClearButtonMode = UITextFieldViewMode.WhileEditing)
addView.Add description
let completeLabel = new UILabel(RectangleF(20.f, 114.f, 100.f, 30.f), Text = "Complete ")
addView.Add completeLabel
let completeCheckbox = new UISwitch(RectangleF(120.f, 114.f, 200.f, 30.f))
completeCheckbox.SetState(task.Complete,false)
completeCheckbox.TouchDragInside.AddHandler (fun sender eventargs -> task.Complete <- completeCheckbox.On)
addView.Add completeCheckbox
let addedLabel = new UILabel(RectangleF(20.f, 214.f, 280.f, 50.f),
TextAlignment = UITextAlignment.Center)
addView.Add addedLabel
let addUpdateButton = UIButton.FromType(UIButtonType.RoundedRect, Frame = RectangleF(20.f, 164.f, 280.f, 50.f))
addUpdateButton.TouchUpInside.AddHandler
(fun _ _ ->
let taskDescription =
match description.Text.Trim() with
| "" -> "New task"
| _ -> description.Text
match isNew with
| true ->
Data.AddTask taskDescription
addedLabel.Text <- "Added!"
| false ->
Data.UpdateTask task.Id taskDescription completeCheckbox.On
addedLabel.Text <- "Updated!")
addUpdateButton.SetTitle("Save", UIControlState.Normal)
addView.Add addUpdateButton
description.TouchDown.AddHandler (fun _ _ -> addedLabel.Text <- "")
this.View.Add addView