void addNewItem(object sender, EventArgs e) { Console.WriteLine("BtnAdd pressed"); BNRItem newItem = BNRItemStore.CreateItem(); // int lastRow = BNRItemStore.allItems.IndexOf(newItem); // // NSIndexPath ip = NSIndexPath.FromRowSection(lastRow, 0); // // NSIndexPath[] indexPaths = new NSIndexPath[] {ip}; // TableView.InsertRows(indexPaths, UITableViewRowAnimation.Automatic); DetailViewController detailViewController = new DetailViewController(true); detailViewController.EdgesForExtendedLayout = UIRectEdge.None; detailViewController.Item = newItem; UINavigationController navController = new UINavigationController(detailViewController); navController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; navController.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal; this.PresentViewController(navController, true, null); Console.WriteLine("allItems: {0}, tableViewRows: {1}", BNRItemStore.allItems.Count, TableView.NumberOfRowsInSection(0)); }
// public static string itemArchivePath() // For archiving method of saving // { // For archiving method of saving // string[] documentDirectories = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true); // For archiving method of saving // // For archiving method of saving // // Get one and only document directory from that list // For archiving method of saving // string documentDirectory = documentDirectories[0]; // For archiving method of saving // return Path.Combine(documentDirectory, "items.archive"); // For archiving method of saving // } public static void updateDBItem(BNRItem item) { string dbPath = GetDBPath(); SQLiteConnection db; db = new SQLiteConnection(dbPath); db.Update(item); db.Close(); }
public void nudgeItemValue(HomepwnerItemCell cell, double stepperValue) { NSIndexPath indexPath = TableView.IndexPathForCell(cell); BNRItem i = BNRItemStore.allItems[indexPath.Row]; i.valueInDollars = (int)stepperValue; BNRItemStore.updateDBItem(i); TableView.ReloadData(); }
public void showImageAtIndexPath(NSObject sender, HomepwnerItemCell cell) { NSIndexPath indexPath = TableView.IndexPathForCell(cell); Console.WriteLine("Going to show the image for {0}", indexPath); // Get the item for the index path BNRItem i = BNRItemStore.allItems[indexPath.Row]; string imageKey = i.imageKey; // If there is no image, we don't need to do anything if (imageKey == null || imageKey == "") { return; } UIImage img = BNRImageStore.imageForKey(imageKey); // Create a new ImageViewController and set its image ImageViewController ivc = new ImageViewController(); ivc.Image = img; ivc.PopoverSize = new CGSize(600, 600); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { // Make a rectangle that the frame of the button relative to our table view UIButton btn = sender as UIButton; CGRect rect = View.ConvertRectFromView(btn.Bounds, btn); // Present a 600 x 600 popover from the rect imagePopover = new UIPopoverController(ivc); imagePopover.PopoverContentSize = ivc.PopoverSize; imagePopover.DidDismiss += (object pSender, EventArgs e) => { imagePopover.Dismiss(true); imagePopover = null; }; imagePopover.PresentFromRect(rect, View, UIPopoverArrowDirection.Any, true); } else { this.NavigationController.PushViewController(ivc, true); } }
public static void RemoveItem(BNRItem p) { string key = p.imageKey; if (key != null) { BNRImageStore.deleteImageForKey(key); BNRImageStore.deleteImageForKey(key + ".thumbnail"); } allItems.Remove(p); string dbPath = GetDBPath(); SQLiteConnection db; db = new SQLiteConnection(dbPath); db.Delete(p); db.Close(); }
public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { // Make a detail view controller DetailViewController detailViewController = new DetailViewController(false); detailViewController.EdgesForExtendedLayout = UIRectEdge.None; // Get the selected BNRItem var items = BNRItemStore.allItems; BNRItem selectedItem = items[indexPath.Row]; // Give the detailViewController a pointer to the item object in row detailViewController.Item = selectedItem; // Push it onto the top of the navigation controller's stack this.NavigationController.PushViewController(detailViewController, true); }
public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath) { //base.CommitEditingStyle(tableView, editingStyle, indexPath); if (editingStyle == UITableViewCellEditingStyle.Delete) { UITableViewCell cell = tableView.CellAt(indexPath); if (cell != null) { cell.BackgroundColor = UIColor.White; } BNRItem itemToRemove = BNRItemStore.allItems[indexPath.Row]; BNRItemStore.RemoveItem(itemToRemove); NSIndexPath[] indexPaths = new NSIndexPath[] { indexPath }; TableView.DeleteRows(indexPaths, UITableViewRowAnimation.Automatic); Console.WriteLine("allItems: {0}, tableViewRows: {1}", BNRItemStore.allItems.Count, tableView.NumberOfRowsInSection(0)); } }
public static void moveItem(int fromIndex, int toIndex) { if (fromIndex == toIndex) { return; } BNRItem p = allItems[fromIndex]; allItems.Remove(p); allItems.Insert(toIndex, p); // Computing a new ordering value for the object that was moved double lowerBound = 0.0; // Is there an objetc before it in the array? if (toIndex > 0) { lowerBound = allItems[toIndex - 1].orderingValue; } else { lowerBound = allItems[1].orderingValue - 2.0; } double upperBound = 0.0; // Is there an object after it in the array? if (toIndex < allItems.Count - 1) { upperBound = allItems[toIndex + 1].orderingValue; } else { upperBound = allItems[toIndex - 1].orderingValue + 2.0; } double newOrderValue = (lowerBound + upperBound) / 2.0; Console.WriteLine("Moving to order {0}", newOrderValue); p.orderingValue = newOrderValue; updateDBItem(p); }
public static BNRItem CreateItem() { BNRItem p = BNRItem.RandomBNRItem(); if (allItems.Count == 0) { p.orderingValue = 1; } else { p.orderingValue = allItems[allItems.Count - 1].orderingValue + 1.0; } allItems.Add(p); string dbPath = GetDBPath(); SQLiteConnection db; db = new SQLiteConnection(dbPath); db.Insert(p); return(p); }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { Console.WriteLine("********* {0}", indexPath.ToString()); // Check for a reusable cell first, use that if it exists - before using nib // UITableViewCell cell = tableView.DequeueReusableCell("UITableViewCell"); // // if (cell == null) // // Create an instance of UITableViewCell, with default appearance // cell = new UITableViewCell(UITableViewCellStyle.Subtitle,"UITableViewCell"); // Set the text on the cell with the description of the item // that is the nth index of items, where n = row this cell // will appear in on the tableView BNRItem p = BNRItemStore.allItems[indexPath.Row]; // cell.TextLabel.Text = String.Format("Item: {0}, ${1}", p.itemName, p.valueInDollars); // cell.DetailTextLabel.Text = String.Format("SN: {0}, Added: {1}", p.serialNumber, p.dateCreated); // cell.BackgroundColor = UIColor.FromRGBA(1.0f, 1.0f, 1.0f, 0.5f); HomepwnerItemCell cell = tableView.DequeueReusableCell("HomepwnerItemCell") as HomepwnerItemCell; if (cell.nudgeValueCallback == null) { cell.nudgeValueCallback = nudgeItemValue; cell.showImageCallback = showImageAtIndexPath; } // Configure the cell cell.nameLabel.Text = p.itemName; cell.serialNumberLabel.Text = p.serialNumber; string currencySymbol = NSLocale.CurrentLocale.CurrencySymbol; cell.valueLabel.Text = String.Format("{0}{1}", currencySymbol, p.valueInDollars); if (p.valueInDollars < 0) { cell.valueLabel.TextColor = UIColor.Red; } else { cell.valueLabel.TextColor = UIColor.Black; } cell.stepper.MaximumValue = p.valueInDollars + 500; cell.stepper.MinimumValue = p.valueInDollars - 500; cell.stepper.Value = p.valueInDollars; string thumbKey = p.imageKey + ".thumbnail"; // Changed from archiving method of saving for SQL method // If there is no image, we don;t need to do anything // For archiving method of saving UIImage img = BNRImageStore.imageForKey(thumbKey); // Changed from archiving method of saving for SQL method // if (img == null) // For archiving method of saving // return; // For archiving method of saving cell.thumbnailView.Image = img; // cell.thumbnailView.Image = p.Thumbnail(); // Archiving method of saving cell.testIndexPathCallback = (ip) => { Console.WriteLine("Callback: {0}", ip.ToString()); }; cell.DoCallback(indexPath); return(cell); }