Esempio n. 1
0
        async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item == null)
            {
                return;
            }

            GroceryItem item        = (GroceryItem)e.Item;
            bool        isCompleted = item.Completed;

            Debug.WriteLine("isCompleted=" + isCompleted);
            bool result = await DisplayAlert(item.Name, "Mark as " + (isCompleted ? "Pending" : "Completed") + "?", "OK", "Cancel");

            if (result)
            {
                item.Completed = !item.Completed;
                ReloadData();
                GroceryDatasource.UpdateItem(item);
            }


            Debug.WriteLine(result);

            //Deselect Item
            ((ListView)sender).SelectedItem = null;
        }
Esempio n. 2
0
 void OnResetTap(object sender, EventArgs e)
 {
     foreach (GroceryItem item in items)
     {
         item.Completed = true;
         GroceryDatasource.UpdateItem(item);
     }
     ReloadData();
 }
Esempio n. 3
0
        async Task ReloadData()
        {
            Debug.WriteLine("ON RELOAD DATA");

            grouped = new ObservableCollection <GroupedGroceryItem>();
            var groupPending = new GroupedGroceryItem()
            {
                LongName = "Pending", ShortName = "P"
            };
            var groupCompleted = new GroupedGroceryItem()
            {
                LongName = "Completed", ShortName = "C"
            };

            if (items == null)
            {
                items = await GroceryDatasource.GetData();
            }


            foreach (GroceryItem item in items)
            {
                if (item.Completed)
                {
                    groupCompleted.Add(item);
                }
                else
                {
                    groupPending.Add(item);
                }
            }

            grouped.Add(groupPending);
            grouped.Add(groupCompleted);

            Debug.WriteLine("groupPending.count=" + groupPending.Count);
            Debug.WriteLine("groupCompleted.count=" + groupCompleted.Count);

            lstView.ItemsSource = grouped;
        }