Example #1
0
        private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);

            alert.SetTitle("Do you want to delete this payment?");

            alert.SetPositiveButton("Yes", (senderAlert, args) =>
            {
                friendsToPayment.Remove(friendsToPayment[e.Position]);
                var adapterPayemnt = new PaymentAddAdapter(this, friendsToPayment);

                listView.Adapter = adapterPayemnt;
                try
                {
                    editText.Text = friendsToPayment.Where(s => s.Item2 > 0).Sum(s => s.Item2).ToString();
                }
                catch (Exception)
                {
                    Toast.MakeText(this, "Sum to big!", ToastLength.Short).Show();
                }
                //apter = new FriendsCustomAdapter(this, users);
                //tData = FindViewById<ListView>(Resource.Id.listViewFriends);
                //tData.Adapter = adapter;
            });

            alert.SetNegativeButton("No", (senderAlert, args) => {
            });
            //run the alert in UI thread to display in the screen
            RunOnUiThread(() => {
                alert.Show();
            });
        }
Example #2
0
        void OnDialogClosed(object sender, decimal e)
        {
            var item = friendsToPayment.Where(s => s.Item1 == friendString).FirstOrDefault();

            if (null != item)
            {
                var t = Tuple.Create <string, decimal>(friendString, item.Item2 + e);
                friendsToPayment.Remove(item);
                friendsToPayment.Add(t);
            }
            else
            {
                friendsToPayment.Add(Tuple.Create <string, decimal>(friendString, e));
            }
            friendsToPayment.Sort((x, y) => x.Item2.CompareTo(y.Item2));
            //friendsToPayment = friendsToPayment.OrderBy(s => s.Item2).ToList();
            var adapterPayemnt = new PaymentAddAdapter(this, friendsToPayment);

            listView.Adapter = adapterPayemnt;
            spinner.SetSelection(0);
            try
            {
                editText.Text = Math.Max(friendsToPayment.Where(s => s.Item2 > 0).Sum(s => s.Item2), friendsToPayment.Where(s => s.Item2 < 0).Sum(s => Math.Abs(s.Item2))).ToString();
            }
            catch (Exception)
            {
                Toast.MakeText(this, "Sum to big!", ToastLength.Short).Show();
            }
        }
Example #3
0
        private async void getPayments()
        {
            if (paymentItem != null)
            {
                payments = await DatabaseManager.DefaultManager.GetPaymentUsersForPaymentAsync(paymentItem);

                var friends_List = new List <UserItem>(friends);

                foreach (var pay in payments)
                {
                    var item = friends_List.Find(i => i.Id == pay.UserId);

                    Tuple <string, decimal> tup;
                    if (item != null)
                    {
                        tup = new Tuple <string, decimal>(item.Name, pay.Amount);
                        if (!friendsToPayment.Exists(s => s.Item1 == tup.Item1))
                        {
                            friendsToPayment.Add(tup);
                        }
                    }
                }

                var adapterPayemnt = new PaymentAddAdapter(this, friendsToPayment);
                listView.Adapter    = adapterPayemnt;
                listView.ItemClick += ListView_ItemClick;
            }
        }