Esempio n. 1
0
 public override void OnAttachedToWindow()
 {
     base.OnAttachedToWindow();
     if (CurrentExpense != null && CurrentExpense.Id != 0)
     {
         expenseViewModel.LoadPhotoAsync(CurrentExpense).ContinueWith(_ => {
             activity.RunOnUiThread(() => {
                 if (expenseViewModel.Photo != null)
                 {
                     if (expenseViewModel.Photo.Image != null)
                     {
                         imageBitmap = BitmapFactory.DecodeByteArray(expenseViewModel.Photo.Image, 0, expenseViewModel.Photo.Image.Length);
                         imageBitmap = Extensions.ResizeBitmap(imageBitmap, Constants.MaxWidth, Constants.MaxHeight);
                     }
                     expensePhoto.SetImageBitmap(imageBitmap);
                     expenseAddPhoto.Visibility = ViewStates.Gone;
                 }
                 else
                 {
                     expensePhoto.SetImageBitmap(null);
                     expenseAddPhoto.Visibility = ViewStates.Visible;
                 }
             });
         });
         expenseType.SetSelection(expenseTypes.ToList().IndexOf(CurrentExpense.Category));
         expenseAmount.Text       = CurrentExpense.Cost.ToString("0.00");
         expenseDescription.Text  = CurrentExpense.Description;
         deleteExpense.Visibility = CurrentExpense.Id != 0 ? ViewStates.Visible : ViewStates.Gone;
     }
     else
     {
         expenseViewModel.Photo = null;
         expensePhoto.SetImageBitmap(null);
         expenseAmount.Text      = "0.00";
         expenseDescription.Text = string.Empty;
         expenseType.SetSelection(0);
         expenseAddPhoto.Visibility = ViewStates.Visible;
         deleteExpense.Visibility   = ViewStates.Gone;
     }
 }