예제 #1
0
		//
		// This method is invoked when the application has loaded and is ready to run. In this 
		// method you should instantiate the window, load the UI into it and then make the window
		// visible.
		//
		// You have 17 seconds to return from this method, or iOS will terminate your application.
		//
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			userDao = new UserDao ();
			courseDao = new CourseDao ();
			this.window = new UIWindow (UIScreen.MainScreen.Bounds);
			var rootNavigationController = new UINavigationController ();

			if (userDao.tokenExists () && courseDao.existCourses ()) 
			{
				CoursesViewController courseView = new CoursesViewController();
				rootNavigationController.PushViewController(courseView,false);
			} 
			else 
			{
				MonoMobilisViewController loginView = new MonoMobilisViewController();
				rootNavigationController.PushViewController(loginView,false);
			}

			//MonoMobilisViewController loginView = new MonoMobilisViewController();
			//rootNavigationController.PushViewController(loginView,false);

			this.window.RootViewController = rootNavigationController;
			this.window.MakeKeyAndVisible();
			ServiceLocator.Dispatcher = new DispatchAdapter(this);
			return true;
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			this.NavigationController.NavigationBar.Hidden = true;
			loginViewModel = new LoginViewModel();

			this.submit.TouchUpInside += (sender, e) => 
			{
				dialog = new UILoadingView("Carregando","Por favor aguarde");
				dialog.Show();
				loginViewModel.submitLoginData(login.Text,password.Text);
			};

			ServiceLocator.Messenger.Subscribe<BaseViewMessage>(m => 
			{
				switch (m.Content.message) 
				{
				case BaseViewMessage.MessageTypes.CONNECTION_ERROR:
					ServiceLocator.Dispatcher.invoke(() =>
					{
						if (dialog != null) 
						{
							dialog.DismissWithClickedButtonIndex(0,true);
						}
						new UIAlertView("Erro","Nao foi possivel se conectar com o servidor",null,"Fechar",null).Show();
					});
					break;
				case BaseViewMessage.MessageTypes.LOGIN_CONNECTION_OK:
					getCourses();
					break;
				case BaseViewMessage.MessageTypes.COURSE_CONNECTION_OK:
					ServiceLocator.Dispatcher.invoke(() =>
					{
						coursesPage = new CoursesViewController();
						this.NavigationController.PushViewController(this.coursesPage,true);
					});
					break;
				default:
					break;
				}            
			});
		}