Ejemplo n.º 1
0
    protected async override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);

      // Set our view from the "main" layout resource
      SetContentView(Resource.Layout.view_expenses);

      progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar);

      viewModel = ServiceContainer.Resolve<ExpensesViewModel>();
      viewModel.IsBusyChanged = (busy) =>
      {
        progressBar.Visibility = busy ? ViewStates.Visible : ViewStates.Gone;
      };

      ListAdapter = new ExpenseAdapter(this, viewModel);
     
      ListView.ItemLongClick += async (sender, args) =>
      {
        await viewModel.ExecuteDeleteExpenseCommand(viewModel.Expenses[args.Position]);
        RunOnUiThread(() => ((ExpenseAdapter)ListAdapter).NotifyDataSetChanged());
      };

      if (!viewModel.IsSynced)
      {
        await Authenticate();
        await viewModel.ExecuteSyncExpensesCommand();
        RunOnUiThread(() => ((ExpenseAdapter)ListAdapter).NotifyDataSetChanged());
      }
      
    }
    public async override void ViewDidLoad()
    {
      base.ViewDidLoad();
      

      viewModel = ServiceContainer.Resolve<ExpensesViewModel>();

      viewModel.IsBusyChanged = (busy) =>
      {
        if (busy)
          RefreshControl.BeginRefreshing();
        else
          RefreshControl.EndRefreshing();
      };


      this.RefreshControl = new UIRefreshControl();

      RefreshControl.ValueChanged += async (sender, args) =>
      {
        if (viewModel.IsBusy)
          return;

        await viewModel.ExecuteSyncExpensesCommand();
        TableView.ReloadData();
      };

      TableView.Source = new ExpensesSource(viewModel, this);
      NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, delegate
      {
        NavigationController.PushViewController(new ExpenseViewController(null), true);
      });

      await Authenticate();
      await viewModel.ExecuteSyncExpensesCommand();
      TableView.ReloadData();
    }