コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);

            var recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView1);

            var layoutManager = new LinearLayoutManager(this);

            recyclerView.SetLayoutManager(layoutManager);

            var input = Assets.Open("Data.json");

            using (var streamReader = new StreamReader(input))
            {
                var content = streamReader.ReadToEnd();
                var items   = JsonConvert.DeserializeObject <List <Order> >(content);
                adapter = new AdapterOrder(items, true);
                recyclerView.SetAdapter(adapter);
            }

            FindViewById <ImageButton>(Resource.Id.imagebtn_cart).Click += delegate
            {
                var intent = new Intent(this, typeof(Cart));
                intent.PutExtra("quantitys", adapter.Orders.Select(x => x.Quantity.ToString()).ToArray());

                StartActivity(intent);
            };
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.activity_order);

            // retrieve orders from shared preferences
            var localOrders = Application.Context.GetSharedPreferences("MyOrders", FileCreationMode.Private);
            var ordersJson  = localOrders.GetString("orders", null);

            Console.WriteLine(ordersJson);
            if (ordersJson == null)
            {
                orders = new List <Order>();
            }
            else
            {
                orders = JsonConvert.DeserializeObject <List <Order> >(ordersJson);
            }

            this.orderRecyclerView = FindViewById <RecyclerView>(Resource.Id.order_recyclerView);

            this.layoutManager = new LinearLayoutManager(this);
            this.orderRecyclerView.SetLayoutManager(this.layoutManager);
            AdapterOrder adapterOrder = new AdapterOrder(orders);

            this.orderRecyclerView.SetAdapter(adapterOrder);

            this.txt_total_price = FindViewById <TextView>(Resource.Id.total_price);
            double double_total_price = 0;

            for (int i = 0; i < orders.Count; i++)
            {
                double price = orders[i].price * orders[i].serve;
                double_total_price += price;
            }

            txt_total_price.Text = "$ " + double_total_price;
        }
コード例 #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Cart);

            var recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView1);

            var layoutManager = new LinearLayoutManager(this);

            recyclerView.SetLayoutManager(layoutManager);

            var quantitys = Intent.GetStringArrayExtra("quantitys");

            var input = Assets.Open("Data.json");

            using (var streamReader = new StreamReader(input))
            {
                var content = streamReader.ReadToEnd();
                var items   = JsonConvert.DeserializeObject <List <Order> >(content);

                var index = 0;

                foreach (var item in items)
                {
                    item.Quantity = int.Parse(quantitys[index]);
                    index++;
                }

                var itemsSelected = items.Where(x => x.Quantity != 0).ToList();

                FindViewById <TextView>(Resource.Id.tv_sum).Text = $"Price = {itemsSelected.Sum(x => x.PricePerUnit * x.Quantity)}";

                var adapter = new AdapterOrder(itemsSelected, false);
                recyclerView.SetAdapter(adapter);
            }
        }