예제 #1
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            while (true)
            {
                if (this.NavigationService.RemoveBackEntry() == null)
                {
                    break;
                }
            }

            progressBar = new PerformanceProgressBar();
            progressBar.IsIndeterminate = true;
            ServiceLocator.Dispatcher = new DispatchAdapter();
            courseViewModel = new CoursesViewModel();
            _courses.ItemsSource = courseViewModel.listContent;
            _courses.SelectionChanged -= lstCourses_SelectionChanged;
            _courses.SelectionChanged += new SelectionChangedEventHandler(lstCourses_SelectionChanged);

            ServiceLocator.Messenger.Subscribe<BaseViewMessage>(m =>
            {
                switch (m.Content.message)
                {
                    case BaseViewMessage.MessageTypes.CONNECTION_ERROR:
                        ServiceLocator.Dispatcher.invoke(() =>
                        {
                            ToastPrompt toast = new ToastPrompt();
                            toast.Message = "Erro de conexão";
                            toast.Show();
                            if (ContentPanel.Children.Contains(progressBar))
                                this.ContentPanel.Children.Remove(progressBar);
                            _courses.SelectedIndex = -1;
                        });
                        break;
                    case BaseViewMessage.MessageTypes.CLASS_CONNECTION_OK:
                        ServiceLocator.Dispatcher.invoke(() =>
                        {
                            ServiceLocator.Dispatcher.invoke(() =>
                            {
                                NavigationService.Navigate(new Uri("/Views/ClassPage.xaml", UriKind.Relative));
                            });
                        });
                        break;
                    case BaseViewMessage.MessageTypes.COURSE_CONNECTION_OK:
                        ServiceLocator.Dispatcher.invoke(() =>
                        {
                            //TODO refresh.
                        });
                        break;
                    default:
                        break;
                }
            });
        }
예제 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.SimpleList);
            coursesViewModel = new CoursesViewModel();
            FindViewById<TextView>(Resource.Id.screen_title).Text = "Cursos Disponíveis";
            ListView list = FindViewById<ListView>(Resource.Id.list);
            adapter = new SimpleListAdapter<Course>(this, coursesViewModel.listContent);
            list.Adapter = adapter;
            list.ItemClick += new EventHandler<Android.Widget.AdapterView.ItemClickEventArgs>(list_ItemClick);

            actionBar = SupportActionBar;
            actionBar.SetHomeButtonEnabled(false);
            actionBar.SetDisplayHomeAsUpEnabled(false);
            actionBar.SetDisplayUseLogoEnabled(false);
            actionBar.SetDisplayShowHomeEnabled(false);
            actionBar.Title = "Cursos";

            ServiceLocator.Messenger.Subscribe<BaseViewMessage>(m =>
            {
                switch (m.Content.message)
                {
                    case BaseViewMessage.MessageTypes.CONNECTION_ERROR:
                        ServiceLocator.Dispatcher.invoke(() =>
                        {
                            Toast.MakeText(this, "Erro de conexão", ToastLength.Short).Show();
                            dialog.Dismiss();
                        });
                        break;
                    case BaseViewMessage.MessageTypes.CLASS_CONNECTION_OK:
                        ServiceLocator.Dispatcher.invoke(() =>
                        {
                            ServiceLocator.Dispatcher.invoke(() =>
                            {
                                intent = new Intent(this, typeof(ClassActivity));
                                StartActivity(intent);
                            });
                        });
                        break;
                    case BaseViewMessage.MessageTypes.COURSE_CONNECTION_OK:
                        ServiceLocator.Dispatcher.invoke(() =>
                        {
                            //TODO refresh.
                        });
                        break;
                    default:
                        break;
                }
            });
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad();
			navController = this.NavigationController;
			this.NavigationController.NavigationBar.Hidden = true;
			coursesViewModel = new CoursesViewModel();

			table = new UITableView(new RectangleF (
				0,50, this.View.Frame.Width,
				this.View.Frame.Height));
			table.AutoresizingMask = UIViewAutoresizing.All;
			table.Source = new TableViewSource2(coursesViewModel.listContent);
			Add(table);

			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.CLASS_CONNECTION_OK:
					ServiceLocator.Dispatcher.invoke(() =>
					{
						navController.PushViewController(classViewController,true);
					});
					break;
				case BaseViewMessage.MessageTypes.COURSE_CONNECTION_OK:
					ServiceLocator.Dispatcher.invoke(() =>
					{
						//TODO refresh.
					});
					break;
				default:
					break;
				}
			});
		}