protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Sets up the database for the first time (if needed) Data.AvorDB.SetupDatabaseIfNeeded(Assets); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); toolbar.Title = "Avor"; //Toolbar will now take on default Action Bar characteristics SetSupportActionBar(toolbar); var db = new Data.AvorDB(); var adapter = new Adapters.MainMenuAdapter(this, db); var listView = FindViewById <ListView>(Resource.Id.myListView); listView.Adapter = adapter; listView.ItemClick += (s, e) => { var entry = adapter.GetItemModel(e.Position); var intent = new Intent(this, typeof(ProductActivity)); intent.PutExtra(ProductActivity.CategoryIDKey, entry.ID); intent.PutExtra(ProductActivity.CategoryTitleKey, entry.Title); StartActivity(intent); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the layout resource SetContentView(Resource.Layout.MyCart); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); toolbar.Title = "My Shopping Cart"; //Toolbar will now take on default Action Bar characteristics SetSupportActionBar(toolbar); var rootLayout = FindViewById <LinearLayout>(Resource.Id.rootLayout); var db = new Data.AvorDB(); var adapter = new Adapters.CartAdapter(this, db); var listView = FindViewById <ListView>(Resource.Id.myListView); listView.Adapter = adapter; listView.ItemClick += (s, e) => { adapter.DeleteItem(e.Position); }; var checkoutBtn = FindViewById <Button>(Resource.Id.checkoutBtn); checkoutBtn.Click += (s, e) => { if (adapter.Count == 0) { Toast.MakeText(this, "Please select at least 1 product", ToastLength.Short) .Show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("Confirm") .SetMessage("Are you sure you want to checkout?\n" + $"Total : € {adapter.GetSum().ToString("0.##")}") .SetPositiveButton("Yes", delegate { db.Checkout(); adapter.ClearItems(); Snackbar.Make(rootLayout, "Successfully checkedout", Snackbar.LengthShort) .Show(); }) .SetNegativeButton("No", delegate { }) .Show(); } }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the layout resource SetContentView(Resource.Layout.Category); var categoryId = Intent.GetIntExtra(CategoryIDKey, 0); var categoryTitle = Intent.GetStringExtra(CategoryTitleKey); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); toolbar.Title = categoryTitle; //Toolbar will now take on default Action Bar characteristics SetSupportActionBar(toolbar); var rootLayout = FindViewById <LinearLayout>(Resource.Id.rootLayout); var db = new Data.AvorDB(); _adapter = new Adapters.ProductAdapter(this, db, categoryId); var listView = FindViewById <ListView>(Resource.Id.myListView); listView.Adapter = _adapter; listView.ItemClick += (s, e) => { var entry = _adapter.GetItemModel(e.Position); db.AddCartProduct(entry); // TODO: Go to my shopping item page... Snackbar.Make(rootLayout, $"Added {entry.Title}", Snackbar.LengthShort) .SetAction("UNDO", (view) => { db.DeleteCartProduct(entry); }) .Show(); /* Don't forget to show it */ }; }