/// <summary>
        /// Creates the UIViewController that will be pushed by this RootElement
        /// </summary>
        protected virtual UIViewController MakeViewController()
        {
            if (createOnSelected != null)
            {
                return(createOnSelected(this));
            }

            var dvc = new DialogViewController(this, true)
            {
                Autorotate = true
            };

            if (ToolbarButtons != null)
            {
                dvc.SetToolbarItems(ToolbarButtons.ToArray(), true);
            }

            //		dvc.EditButtonItem = EditButton;
            return(dvc);
        }
		public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
		{
			Console.WriteLine ("[AppDelegate] FinishedLaunching");

			UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval (UIApplication.BackgroundFetchIntervalMinimum);
			Window = new UIWindow (UIScreen.MainScreen.Bounds);

			_downloader = new Downloader ();
			_downloader.Finished = FinishedDownload;
			_downloads = new Section ("Downloads") {
			}; 

			string templateurl = "http://pokeprice.local/api/v1/card/image/BLW/{0}";
			string zipurl = "http://pokeprice.local/api/v1/card/zip/{0}";
			string httpurl = "http://pokeprice.local/api/v1/http/{0}";
			string redirecturl = "http://pokeprice.local/api/v1/http/redirect/infinite/0";
			string scollections = "AOR,AQ,AR,B2,BCR,BEST,BKT,BLW,BS,CG,CL,DCR,DEX,DF,DP,DR,DRV,DRX,DS,DX,EM,EPO,EX,FFI,FLF,FO,G1,G2,GE,HL,HP,HS,JU,KSS,LA,LC,LM,LTR,MA,MCD2011,MCD2012,MD,MT,N1,N2,N3,N4,NINTENDOBLACK,NVI,NXD,PHF,PK,PL,PLB,PLF,PLS,POP1,POP2,POP3,POP4,POP5,POP6,POP7,POP8,POP9,PR-BLW,PR-DP,PR-HS,PR-XY,PRC,RG,ROS,RR,RS,RU,SF,SI,SK,SS,SV,SW,TM,TR,TRR,UD,UF,UL,VICTORY,WIZARDSBLACK,XY";
			string[] collections = scollections.Split (',');

			#if REMOTE
			templateurl = templateurl.Replace("http://pokeprice.local", "https://pokeprice.com");
			zipurl = zipurl.Replace("http://pokeprice.local", "https://pokeprice.com");
			httpurl = httpurl.Replace("http://pokeprice.local", "https://pokeprice.com");
			redirecturl = redirecturl.Replace("http://pokeprice.local", "https://pokeprice.com");
			#endif

			var enable = new BooleanElement ("Enabled", true);
			enable.ValueChanged += (sender, e) => {
				_downloader.Enabled = enable.Value;
			};

			var globalprogress = new StringElement ("");
			var root = new RootElement ("Root") {
				new Section ("Management"){
					enable,
					globalprogress
				},
				_downloads
			};

			_downloader.Progress += (progress) => {
				float percent = (progress.Written / (float)progress.Total) * 100;
				int ipercent = (int)percent;
				string caption = string.Format("{0} {1} {2}% ({3} / {4})", 
					"Global", 
					progress.State.ToString(),
					ipercent,
					progress.Written,
					progress.Total
				);
				InvokeOnMainThread(() => {
					globalprogress.Caption = caption;
					globalprogress
						.GetImmediateRootElement()
						.Reload(globalprogress, UITableViewRowAnimation.Automatic);
				});
			};
			
			_sample = new DialogViewController (root);

			var add = new UIBarButtonItem ("Add", 
				UIBarButtonItemStyle.Bordered, 
				 (sender, e) => {
					string url = string.Format(templateurl, 1);
				 Add(url);
			});
			
			var addall = new UIBarButtonItem ("All", 
				UIBarButtonItemStyle.Bordered, 
				 (sender, e) => {
					for(int i=1; i<80; i++) {
						string url = string.Format(templateurl, i);
					 Add(url);
					}
				});
			
			var zips = new UIBarButtonItem ("Z", 
				UIBarButtonItemStyle.Bordered, 
				 (sender, e) => {
					foreach(string coll in collections) {
						string url = string.Format(zipurl, coll);
					 Add(url);
					}
				});


			var s404 = new UIBarButtonItem ("4", 
				UIBarButtonItemStyle.Bordered, 
				 (sender, e) => {
					string url = string.Format(httpurl, 404);
					 Add(url);
				});

			var s500 = new UIBarButtonItem ("5", 
				UIBarButtonItemStyle.Bordered, 
				 (sender, e) => {
					string url = string.Format(httpurl, 500);
					 Add(url);
				});

			var s301 = new UIBarButtonItem ("3", 
				UIBarButtonItemStyle.Bordered, 
				 (sender, e) => {
					string url = string.Format(httpurl, 301);
					 Add(url);
				});


			var s301p = new UIBarButtonItem ("3+", 
				UIBarButtonItemStyle.Bordered, 
				 (sender, e) => {
					string url = string.Format(redirecturl, 301);
					 Add(url);
				});

			var reset = new UIBarButtonItem ("Reset", 
				UIBarButtonItemStyle.Bordered, 
				async (sender, e) => {
					await _downloader.Reset();
					Sync();
				});

			var sync = new UIBarButtonItem ("S", 
				UIBarButtonItemStyle.Bordered, 
				(sender, e) => {
					Sync();
				});


			Navigation = new UINavigationController ();
			Window.RootViewController = Navigation;
			Window.MakeKeyAndVisible ();

			Navigation.PushViewController (_sample, false);

			_sample.SetToolbarItems (new [] { add, addall, zips, s404, s500, s301, s301p, reset, sync}, true);
			Navigation.SetToolbarHidden (false, true);

			return true;
		}