/// <summary> /// Called when the activity is first displayed /// Initialise the main view and the action bar and determine what should be displayed /// </summary> /// <param name="savedInstanceState"></param> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.ShoppingScreen); // Initialise the action bar SetSupportActionBar(FindViewById <Toolbar>(Resource.Id.toolbar)); // Create a toast item to display feedback toast = Toast.MakeText(this, "", ToastLength.Short); // We are now making a list PersistentStorage.IsShopping = true; // Create the views that are going to display the data ListView currentItemsView = FindViewById <ListView>(Resource.Id.shoppingItems); ListView basketItemsView = FindViewById <ListView>(Resource.Id.basketItems); // Wrap up these views to add touch handling currentList = new CurrentListWrapper(this, currentItemsView, basketItemsView, CurrentListTitle); basketList = new ShoppingBasketListWrapper(this, basketItemsView, currentItemsView, BasketListTitle); // Hook into the basket view being shown event currentList.RevealActive += (object sender, EventArgs args) => { SupportActionBar.Title = basketList.ToolbarTitle; }; // Handle the swiping of a current item currentList.ItemSwiped += (object sender, ListViewWrapper <ListItem> .SwipeItemEventArgs <ListItem> args) => { int itemsMoved = ShoppingController.CurrentItemSwiped(args.Item, args.WasFlung); if (itemsMoved > 1) { toast.SetText(string.Format("{0} {1} put in basket", itemsMoved, args.Item.Item.Name)); } else { toast.SetText(string.Format("{0} put in basket", args.Item.Item.Name)); } toast.Show(); currentList.DataSetChanged(); basketList.DataSetChanged(); }; // Hook into the current list view being shown event basketList.RevealActive += (object sender, EventArgs args) => { SupportActionBar.Title = currentList.ToolbarTitle; }; // Handle the swiping of a basket item basketList.ItemSwiped += (object sender, ListViewWrapper <ListItem> .SwipeItemEventArgs <ListItem> args) => { int itemsMoved = ShoppingController.BasketItemSwiped(args.Item, args.WasFlung); if (itemsMoved > 1) { toast.SetText(string.Format("{0} {1} removed from basket", itemsMoved, args.Item.Item.Name)); } else { toast.SetText(string.Format("{0} removed from basket", args.Item.Item.Name)); } toast.Show(); currentList.DataSetChanged(); basketList.DataSetChanged(); }; // Always start showing the current list basketItemsView.Visibility = Android.Views.ViewStates.Gone; currentItemsView.TranslationX = 0; SupportActionBar.Title = currentList.ToolbarTitle; }
/// <summary> /// Called when the activity is first displayed /// Initialise the main view and the action bar and determine what should be displayed /// </summary> /// <param name="savedInstanceState"></param> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.ListingScreen); // Initialise the action bar // TODO Wrap this up in a class Toolbar toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); SupportActionBar.SetDisplayShowTitleEnabled(false); toolbarTitle = toolbar.FindViewById <TextView>(Resource.Id.toolbar_title); toolbarSubtitle = toolbar.FindViewById <TextView>(Resource.Id.toolbar_subtitle); // Create a toast item to display feedback toast = Toast.MakeText(this, "", ToastLength.Short); // We are now making a list PersistentStorage.IsShopping = false; // Create the views that are going to display the data ListView availableItemsView = FindViewById <ListView>(Resource.Id.availableItems); ListView currentItemsView = FindViewById <ListView>(Resource.Id.shoppingItems); // Wrap up these views to add touch handling currentList = new CurrentListWrapper(this, currentItemsView, availableItemsView, CurrentListTitle); availableList = new AvailableListWrapper(this, availableItemsView, currentItemsView, AvailableItemsTitle, new ItemSort(new ItemSort.SortState[] { ItemSort.SortState.Grouped, ItemSort.SortState.Alphabetic, ItemSort.SortState.Unsorted }, ItemSort.SortState.Grouped, AvailableItemsTitle)); // Hook into the available items view being shown event currentList.RevealActive += (object sender, EventArgs args) => { toolbarTitle.Text = availableList.ToolbarTitle; toolbarSubtitle.Text = ""; }; // Handle the swiping of a current item currentList.ItemSwiped += (object sender, ListViewWrapper <ListItem> .SwipeItemEventArgs <ListItem> args) => { int itemsMoved = ListingController.CurrentItemSwiped(args.Item, args.WasFlung); if (itemsMoved > 1) { toast.SetText(string.Format("{0} {1} removed from list", itemsMoved, args.Item.Item.Name)); } else { toast.SetText(string.Format("{0} removed from list", args.Item.Item.Name)); } toast.Show(); currentList.DataSetChanged(); }; // Hook into the current items view being shown event availableList.RevealActive += (object sender, EventArgs args) => { // SupportActionBar.Title = currentList.ToolbarTitle; toolbarTitle.Text = currentList.ToolbarTitle; toolbarSubtitle.Text = "unnamed list"; }; // Handle the swiping of an available item availableList.ItemSwiped += (object sender, ListViewWrapper <object> .SwipeItemEventArgs <object> args) => { Item itemAdded = ( Item )args.Item; int itemsMoved = ListingController.AvailableItemSwiped(itemAdded, args.WasFlung); if (itemsMoved > 1) { toast.SetText(string.Format("{0} {1} added to list", itemsMoved, itemAdded.Name)); } else { toast.SetText(string.Format("{0} added to list", itemAdded.Name)); } toast.Show(); currentList.DataSetChanged(); }; // currentItemsView.LongClickable = true; currentItemsView.ItemLongClick += (object sender, AdapterView.ItemLongClickEventArgs args) => { toast.SetText("Current items long clicked"); toast.Show(); }; // Always start showing the available items list currentItemsView.Visibility = Android.Views.ViewStates.Gone; availableItemsView.TranslationX = 0; // SupportActionBar.Title = availableList.ToolbarTitle; toolbarTitle.Text = availableList.ToolbarTitle; }