コード例 #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.menu_index_view_items, null);

            Toolbar toolbar = view.FindViewById <Toolbar>(Resource.Id.toolbar_menu_items);

            toolbar.SetTitle(Resource.String.menuItemDialogTitle);

            SetHasOptionsMenu(true);

            ((AppCompatActivity)Activity).SetSupportActionBar(toolbar);

            Android.Support.V7.App.ActionBar actionBar = ((AppCompatActivity)Activity).SupportActionBar;
            if (actionBar != null)
            {
                actionBar.SetDisplayHomeAsUpEnabled(true);
                actionBar.SetHomeButtonEnabled(true);
                actionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_clear_white);
            }

            int id    = Arguments.GetInt("id");
            int resId = Arguments.GetInt("resId");

            if (id > 0 && resId > 0)
            {
                LibBookingService.Dtos.Restaurant restaurant = _restaurantFacade.FindById(resId).Result;
                //LibBookingService.Dtos.Restaurant restaurant = new LibBookingService.Dtos.Restaurant
                //{
                //    Id = 1,
                //    CompanyId = 2,
                //    Name = "Restaurant 1",
                //    PhoneNo = "01429354096",
                //    AddressStreet = "21 Restaurant Road",
                //    AddressTown = "Hartlepool",
                //    AddressCounty = "Cleveland",
                //    AddressPostalCode = "TS248GX",
                //    MenuItems = new List<MenuItem>
                //    {
                //        new MenuItem { Id = 4, Description = "A fresh bowl of caesar salad", Price = 4.38, ImageId = 4, Name = "Caesar Salad", DietInfo = new List<DietInfo> { new DietInfo { Name = "Vegan", Id = 2 } }, Types = new List<MenuItemType> { new MenuItemType { Id = 1, Name = "Starter" } } },
                //        new MenuItem { Id = 5, Description = null, Price = 3.59, ImageId = 5, Name = "Chocolate Fudge Cake", DietInfo = new List<DietInfo> { new DietInfo { Name = "Contains Dairy", Id = 4 } }, Types = new List<MenuItemType> { new MenuItemType { Id = 3, Name = "Dessert" }, new MenuItemType { Id = 4, Name = "Special" } } },
                //        new MenuItem { Id = 2, Description = "A fresh cod fillet served with thick cut chips and mushy peas", Price = 6.00, ImageId = 2, Name = "Fish and Chips", DietInfo = new List<DietInfo> { }, Types = new List<MenuItemType> { new MenuItemType { Id = 2, Name = "Main" } } }
                //    }
                //};

                RecyclerView recyclerView = view.FindViewById <RecyclerView>(Resource.Id.menu_index_view_item_types);
                recyclerView.SetLayoutManager(new LinearLayoutManager(Activity));

                List <MenuItem> menuItems = restaurant.MenuItems.ToList();
                menuItems = menuItems.Where(m => m.Types.Where(t => t.Id == id).Any()).ToList();

                RestaurantMenuItemDialogAdapter adapter = new RestaurantMenuItemDialogAdapter(menuItems);
                recyclerView.SetAdapter(adapter);
            }

            return(view);
        }
コード例 #2
0
        private async Task GetValues()
        {
            int id = Arguments.GetInt("id");

            if (id > 0)
            {
                booking = await _bookingFacade.FindById(id);

                restaurant = await _restaurantFacade.FindById(booking.RestaurantId);
            }
        }
コード例 #3
0
        private async Task GetValues()
        {
            int id = Arguments.GetInt("id");

            if (id > 0)
            {
                restaurant = await _restaurantFacade.FindById(id);

                types = await _menuItemTypeFacade.Get();
            }
        }
        private void Setup()
        {
            int id = Arguments.GetInt("id");

            if (id > 0)
            {
                LibBookingService.Dtos.Restaurant restaurant = _restaurantFacade.FindById(id).Result;
                //LibBookingService.Dtos.Restaurant restaurant = new LibBookingService.Dtos.Restaurant
                //{
                //    Id = 1,
                //    CompanyId = 2,
                //    Name = "Restaurant 1",
                //    PhoneNo = "01429354096",
                //    AddressStreet = "21 Restaurant Road",
                //    AddressTown = "Hartlepool",
                //    AddressCounty = "Cleveland",
                //    AddressPostalCode = "TS248GX",
                //    MenuItems = new List<MenuItem>
                //    {
                //        new MenuItem { Id = 4, Description = "A fresh bowl of caesar salad", Price = 4.38, ImageId = 4, Name = "Caesar Salad", DietInfo = new List<DietInfo> { new DietInfo { Name = "Vegan", Id = 2 } }, Types = new List<MenuItemType> { new MenuItemType { Id = 1, Name = "Starter" } } },
                //        new MenuItem { Id = 5, Description = null, Price = 3.59, ImageId = 5, Name = "Chocolate Fudge Cake", DietInfo = new List<DietInfo> { new DietInfo { Name = "Contains Dairy", Id = 4 } }, Types = new List<MenuItemType> { new MenuItemType { Id = 3, Name = "Dessert" }, new MenuItemType { Id = 4, Name = "Special" } } },
                //        new MenuItem { Id = 2, Description = "A fresh cod fillet served with thick cut chips and mushy peas", Price = 6.00, ImageId = 2, Name = "Fish and Chips", DietInfo = new List<DietInfo> { }, Types = new List<MenuItemType> { new MenuItemType { Id = 2, Name = "Main" }, new MenuItemType { Id = 4, Name = "Special" } } }
                //    }
                //};

                IEnumerable <MenuItemType> types = _menuItemTypeFacade.Get().Result;
                //IEnumerable<MenuItemType> types = new List<MenuItemType>
                //{
                //    new MenuItemType { Id = 1, Name = "Starter" },
                //    new MenuItemType { Id = 2, Name = "Main" },
                //    new MenuItemType { Id = 3, Name = "Dessert" },
                //    new MenuItemType { Id = 4, Name = "Special" }
                //}.AsEnumerable();

                newBooking.RestaurantId = restaurant.Id;

                view.FindViewById <TextView>(Resource.Id.booking_new_restaurant_name).Text    = restaurant.Name;
                view.FindViewById <TextView>(Resource.Id.booking_new_restaurant_address).Text = restaurant.AddressStreet + ", " + restaurant.AddressTown + ", " + restaurant.AddressCounty + ", " + restaurant.AddressPostalCode;

                Spinner time          = view.FindViewById <Spinner>(Resource.Id.booking_new_time);
                Spinner paymentMethod = view.FindViewById <Spinner>(Resource.Id.booking_new_payment_method);

                List <TimeSpan> times = GetTimes();

                List <PaymentMethod> paymentMethods = new List <PaymentMethod>
                {
                    new PaymentMethod {
                        Name = "Please select a payment method"
                    }
                };
                paymentMethods.AddRange(_paymentFacade.GetPaymentMethod().Result);

                var timeAdapter = new ArrayAdapter <TimeSpan>(Activity, Android.Resource.Layout.SimpleSpinnerDropDownItem, times);
                timeAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                time.Adapter = timeAdapter;

                var paymentMethodAdapter = new ArrayAdapter <PaymentMethod>(Activity, Android.Resource.Layout.SimpleSpinnerDropDownItem, paymentMethods);
                paymentMethodAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                paymentMethod.Adapter = paymentMethodAdapter;

                int initialSpinnerPosition = time.SelectedItemPosition;
                time.ItemSelected += (sender, args) =>
                {
                    if (args.Position != initialSpinnerPosition)
                    {
                        newBooking.StartTime = times[args.Position];
                    }
                };

                paymentMethod.ItemSelected += (sender, args) =>
                {
                    if (args.Position != initialSpinnerPosition)
                    {
                        newPayment.PaymentMethod = paymentMethods[args.Position];
                    }
                };

                LinearLayout layoutContainer = view.FindViewById <LinearLayout>(Resource.Id.booking_new_container);

                //Dictionary<MenuItemType, IEnumerable<MenuItem>> categories = new Dictionary<MenuItemType, IEnumerable<MenuItem>>();

                //foreach (var type in types)
                //{
                //    categories.Add(type, restaurant.MenuItems.Where(m => m.Types.Where(t => t.Id == type.Id).Any()));
                //}

                //foreach (KeyValuePair<MenuItemType, IEnumerable<MenuItem>> entry in categories)
                //{
                //    TextView lbl = new TextView(Activity);
                //    lbl.Text = entry.Key.Name;

                //    LinearLayout menuItem = new LinearLayout(Activity);
                //    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent);
                //    menuItem.LayoutParameters = layoutParams;
                //    menuItem.WeightSum = 4;

                //}

                miCounts = new Dictionary <MenuItem, int>();

                foreach (var mi in restaurant.MenuItems)
                {
                    View menuItem = LayoutInflater.From(Activity).Inflate(Resource.Layout.booking_new_menu, null);
                    LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent)
                    {
                        TopMargin = 16
                    };
                    menuItem.LayoutParameters = layout;

                    menuItem.FindViewById <TextView>(Resource.Id.booking_new_menu_item).Text = mi.Name + " - " + String.Join(", ", mi.Types.Select(t => t.Name));
                    miCounts.Add(mi, 0);

                    TextView    miCount = menuItem.FindViewById <TextView>(Resource.Id.booking_new_menu_item_count);
                    FrameLayout miMinus = menuItem.FindViewById <FrameLayout>(Resource.Id.booking_new_menu_item_remove);
                    FrameLayout miAdd   = menuItem.FindViewById <FrameLayout>(Resource.Id.booking_new_menu_item_add);

                    miAdd.Click += delegate
                    {
                        miCounts[mi] += 1;
                        miCount.Text  = miCounts[mi].ToString();
                    };

                    miMinus.Click += delegate
                    {
                        if (miCounts[mi] > 0)
                        {
                            miCounts[mi] = miCounts[mi] - 1;
                        }

                        miCount.Text = miCounts[mi].ToString();
                    };

                    layoutContainer.AddView(menuItem);
                }
            }
        }