public override View GetView(int position, View convertView, ViewGroup parent) { LayoutInflater inflator = (LayoutInflater)this.Context.GetSystemService(Context.LayoutInflaterService); View loanView = inflator.Inflate(Resource.Layout.Loan, parent, false); TextView personName = loanView.FindViewById <TextView>(Resource.Id.loanPersonName); TextView loanAmount = loanView.FindViewById <TextView>(Resource.Id.loanAmountText); TextView loanNotes = loanView.FindViewById <TextView>(Resource.Id.loanNotes); TextView dateAddedText = loanView.FindViewById <TextView>(Resource.Id.dateAddedText); Loan loan = loans[position]; Person person = Repository.GetInstance().GetPersonById(loan.PersonId); personName.SetText(person.Name, TextView.BufferType.Normal); loanNotes.SetText(loan.Notes, TextView.BufferType.Normal); dateAddedText.SetText(loan.DateAdded.ToShortDateString(), TextView.BufferType.Normal); loanAmount.SetText( NumberFormatter.FormatBalance(loan.Amount * (loan.IsOwedToUser ? 1 : -1)), TextView.BufferType.Normal ); loanAmount.SetTextColor(loan.IsOwedToUser ? Color.Green : Color.Red); return(loanView); }
protected void UpdateRecentLoans() { ListView recentLoansList = FindViewById <ListView>(Resource.Id.recentLoansList); LoanAdapter loanAdapter = new LoanAdapter(this, Repository.GetInstance().GetRecentLoans(3)); recentLoansList.Adapter = loanAdapter; }
protected void UpdateAutocompleteNames() { Repository repository = Repository.GetInstance(); AutoCompleteTextView nameInput = FindViewById <AutoCompleteTextView>(Resource.Id.personNameInput); Dictionary <string, int> peopleBalances = repository.GetPersonBalances(); string[] peopleNames = new string[peopleBalances.Count]; peopleBalances.Keys.CopyTo(peopleNames, 0); nameInput.Adapter = new PersonNameAdapter(this, peopleNames, peopleBalances); }
protected void UpdateLoanCount() { TextView balanceText = FindViewById <TextView>(Resource.Id.balanceText); int balance = Repository.GetInstance().GetTotalAmount(); if (balance == 0) { balanceText.SetText(Resource.String.balanceEven, TextView.BufferType.Normal); balanceText.SetTextColor(Color.Orange); } else { balanceText.SetText( NumberFormatter.FormatBalance(balance), TextView.BufferType.Normal ); balanceText.SetTextColor(balance < 0 ? Color.Red : Color.Green); } }
protected void InitAddForm() { Button loanLower = FindViewById <Button>(Resource.Id.loanLowerButton), loanHigher = FindViewById <Button>(Resource.Id.loanHigherButton), loanSwitch = FindViewById <Button>(Resource.Id.loanSwitchButton); loanLower.Click += delegate { CheckFocus(); addBalance -= 100; UploadLoanAddInput(); }; loanHigher.Click += delegate { CheckFocus(); addBalance += 100; UploadLoanAddInput(); }; loanSwitch.Click += delegate { CheckFocus(); addBalance *= -1; UploadLoanAddInput(); }; EditText loanInput = FindViewById <EditText>(Resource.Id.loanAddInput); loanInput.FocusChange += delegate(object sender, View.FocusChangeEventArgs e) { if (e.HasFocus) { loanInput.SetText("", TextView.BufferType.Editable); } else { LoadInputValue(loanInput); } }; Button addLoanButton = FindViewById <Button>(Resource.Id.addLoanButton); AutoCompleteTextView nameInput = FindViewById <AutoCompleteTextView>(Resource.Id.personNameInput); TextView notesInput = FindViewById <TextView>(Resource.Id.loanNotesInput); addLoanButton.Click += delegate { Color errorCollor = new Color(255, 0, 0, 100); bool allOk = true; if (addBalance == 0) { loanInput.SetBackgroundColor(errorCollor); allOk = false; } else { loanInput.SetBackgroundColor(Color.Transparent); } if (nameInput.Text.Length == 0) { nameInput.SetBackgroundColor(errorCollor); allOk = false; } else { nameInput.SetBackgroundColor(Color.Transparent); } if (allOk) { Repository repository = Repository.GetInstance(); Person person = repository.FindPersonByName(nameInput.Text); if (person == null) { person = new Person(nameInput.Text); repository.InsertObject(person); } Loan loan = new Loan( (int)System.Math.Abs(addBalance), addBalance > 0, person, notesInput.Text ); repository.InsertObject(loan); UpdateLoanCount(); UpdateAutocompleteNames(); UpdateRecentLoans(); addBalance = 0; UploadLoanAddInput(); nameInput.SetText("", TextView.BufferType.Editable); notesInput.SetText("", TextView.BufferType.Editable); } }; UpdateAutocompleteNames(); UploadLoanAddInput(); }