Created
September 20, 2012 06:36
-
-
Save darbio/3754280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using MonoTouch.Foundation; | |
using MonoTouch.UIKit; | |
using IQX.TAS.View.Mobile; | |
using MonoTouch.AtmHud; | |
namespace IQX.TAS.View.iOS | |
{ | |
[Register ("AppDelegate")] | |
public partial class AppDelegate : UIApplicationDelegate | |
{ | |
// class-level declarations | |
UIWindow _window; | |
UINavigationController _tasksNav; | |
UISplitViewController _split; | |
static AtmHud _hud; | |
public static AtmHud HUD { | |
get { | |
if (_hud == null) { | |
_hud = new AtmHud((AtmHudDelegate) null); | |
} | |
return _hud; | |
} | |
private set { | |
_hud = value; | |
} | |
} | |
public override bool FinishedLaunching (UIApplication app, NSDictionary options) | |
{ | |
// create the navigation controller | |
_tasksNav = new UINavigationController(new TasksViewController()); | |
// create a new window instance based on the screen size | |
_window = new UIWindow (UIScreen.MainScreen.Bounds); | |
// set the window's navigation controller based upon the device | |
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { | |
_window.RootViewController = _tasksNav; | |
} | |
else { | |
_split = new UISplitViewController () { | |
Delegate = new SplitDelegate() | |
}; | |
_split.ViewControllers = new UIViewController[] { | |
_tasksNav, | |
new BlankViewController() | |
}; | |
_window.RootViewController = _split; | |
} | |
// make the window visible | |
_window.MakeKeyAndVisible (); | |
// add the hud to the appdelegate | |
_window.AddSubview (HUD.View); | |
return true; | |
} | |
class SplitDelegate : UISplitViewControllerDelegate | |
{ | |
public override bool ShouldHideViewController (UISplitViewController svc, UIViewController viewController, UIInterfaceOrientation inOrientation) | |
{ | |
return false; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MonoTouch.Dialog; | |
using MonoTouch.UIKit; | |
using IQX.TAS.View.Mobile; | |
using System.Threading; | |
using System.Drawing; | |
using MonoTouch.AtmHud; | |
namespace IQX.TAS.View.iOS | |
{ | |
public class SettingsInputDialogViewController : DialogViewController | |
{ | |
public SettingsInputDialogViewController () : base (null, true) | |
{ | |
this.ModalInPopover = true; | |
this.ModalPresentationStyle = MonoTouch.UIKit.UIModalPresentationStyle.FormSheet; | |
this.ModalTransitionStyle = MonoTouch.UIKit.UIModalTransitionStyle.CoverVertical; | |
} | |
EntryElement usernameElement = new EntryElement("Username", "e.g. jsmith", null, false); | |
EntryElement passwordElement = new EntryElement("Password", "", null, true); | |
EntryElement domainElement = new EntryElement("Domain", "e.g. iqx", null, false); | |
EntryElement serviceElement = new EntryElement("Service URL", "e.g. http://server/_vti_bin/service.svc", null, false); | |
AtmHud hud = new AtmHud((AtmHudDelegate) null); | |
public override void ViewWillAppear (bool animated) | |
{ | |
// Set up the hud | |
hud.SetFixedSize (new SizeF (200, 100)); | |
// Set up the view | |
this.Root = new RootElement("Setup required") | |
{ | |
new Section() | |
{ | |
usernameElement, | |
passwordElement, | |
domainElement | |
}, | |
new Section() | |
{ | |
serviceElement | |
} | |
}; | |
// Set up nav buttons | |
this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem("Reset", UIBarButtonItemStyle.Plain, null, null); | |
this.NavigationItem.LeftBarButtonItem.Clicked += LeftButtonTapped; | |
this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIImage.FromFile ("Resource/Save.png"), UIBarButtonItemStyle.Done, null, null); | |
this.NavigationItem.RightBarButtonItem.Clicked += RightButtonTapped; | |
// Call the base | |
base.ViewWillAppear (animated); | |
} | |
void RightButtonTapped (object sender, EventArgs e) | |
{ | |
// Disable button and set to saving optic | |
ToggleButtonLoading(this.NavigationItem.RightBarButtonItem); | |
// Save the settings | |
ApplicationSession.Instance.Settings.Username = usernameElement.Value; | |
ApplicationSession.Instance.Settings.Password = passwordElement.Value; | |
ApplicationSession.Instance.Settings.Domain = domainElement.Value; | |
ApplicationSession.Instance.Settings.GatewayUrl = serviceElement.Value; | |
// Check that settings are correct on async thread | |
DismissThread(); | |
} | |
void LeftButtonTapped (object sender, EventArgs e) | |
{ | |
// Get defaults from service URL | |
} | |
void DismissThread() | |
{ | |
var threadStart = new ThreadStart(Dismiss); | |
var thread = new Thread(threadStart); | |
thread.Start(); | |
} | |
void Dismiss() | |
{ | |
#if DEBUG | |
// REMOVE Simulate a web service call | |
Thread.Sleep(5000); | |
#endif | |
BeginInvokeOnMainThread(delegate() { | |
if (ApplicationSession.Instance.Settings.IsValid) { | |
this.NavigationController.DismissViewController(true, null); | |
AppDelegate.HUD.SetCaption ("Success"); | |
AppDelegate.HUD.SetActivity(false); | |
AppDelegate.HUD.SetImage (UIImage.FromFile ("Resource/Checkmark.png")); | |
AppDelegate.HUD.Update (); | |
AppDelegate.HUD.HideAfter (1); | |
} else { | |
ToggleButtonLoading(this.NavigationItem.RightBarButtonItem); | |
} | |
}); | |
} | |
void ToggleButtonLoading(UIBarButtonItem btn) | |
{ | |
BeginInvokeOnMainThread(delegate() { | |
btn.Enabled = !btn.Enabled; | |
if (!btn.Enabled) { | |
AppDelegate.HUD.Show (); | |
AppDelegate.HUD.SetCaption ("Checking settings..."); | |
AppDelegate.HUD.SetActivity (true); | |
AppDelegate.HUD.Update(); | |
} else { | |
AppDelegate.HUD.SetCaption ("Oops... Please check and try again..."); | |
AppDelegate.HUD.SetActivity(false); | |
AppDelegate.HUD.SetImage (UIImage.FromFile ("Resource/Error.png")); | |
AppDelegate.HUD.Update (); | |
AppDelegate.HUD.HideAfter (2); | |
} | |
}); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MonoTouch.Dialog; | |
using IQX.TAS.View.Mobile; | |
using MonoTouch.UIKit; | |
namespace IQX.TAS.View.iOS | |
{ | |
public class TasksViewController : DialogViewController | |
{ | |
public TasksViewController () : base (null, true) | |
{ | |
} | |
public override void ViewWillAppear (bool animated) | |
{ | |
this.Root = new RootElement("Tasks"); | |
// Show settings wizard if not setup | |
if (!ApplicationSession.Instance.Settings.IsConfigured) { | |
this.ParentViewController.PresentViewController(new SetupNavigationController (new SettingsInputDialogViewController()), true, null); | |
} | |
base.ViewWillAppear (animated); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment