diff --git a/Zockerhoehle/Base.lproj/Main.storyboard b/Zockerhoehle/Base.lproj/Main.storyboard index bb8a284..afdc4fc 100644 --- a/Zockerhoehle/Base.lproj/Main.storyboard +++ b/Zockerhoehle/Base.lproj/Main.storyboard @@ -268,8 +268,8 @@ - - - + + @@ -334,8 +334,8 @@ - - - - - - - - - + + + + @@ -374,12 +370,10 @@ - - @@ -411,12 +405,12 @@ - + - + @@ -497,8 +491,5 @@ - - - diff --git a/Zockerhoehle/ViewController/AddEntryPopUpViewController.swift b/Zockerhoehle/ViewController/AddEntryPopUpViewController.swift index d009b3a..8ad6f53 100644 --- a/Zockerhoehle/ViewController/AddEntryPopUpViewController.swift +++ b/Zockerhoehle/ViewController/AddEntryPopUpViewController.swift @@ -15,20 +15,20 @@ class AddEntryPopUpViewController: UIViewController { @IBOutlet weak var icon: UIImageView! @IBOutlet weak var category: UISegmentedControl! - @IBOutlet weak var wishlistIcon: UIImageView! @IBOutlet weak var name: UITextField! @IBOutlet weak var addButton: UIButtonX! + @IBOutlet weak var wishlist: UISwitch! override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.category.selectedSegmentIndex = 0 - if (!self.isVideogame && !self.isWishlist) { + if (!self.isVideogame) { self.category.selectedSegmentIndex = 1 } - self.wishlistIcon.isHidden = !self.isWishlist + self.wishlist.isOn = self.isWishlist self.icon.image = self.console?.logo?.image @@ -50,16 +50,19 @@ class AddEntryPopUpViewController: UIViewController { if self.isVideogame { let game = Game(entity: Game.entity(), insertInto: CDManager.shared.viewContext) + print("Created New Game") game.name = name - game.console = console + game.inWishlist = self.wishlist.isOn + game.console = self.console - print("Added Game '\(game.name)'") + print("Added Game '\(game.name)' onWishlist \(self.wishlist.isOn)") }else{ let accessory = Accessory(entity: Accessory.entity(), insertInto: CDManager.shared.viewContext) accessory.name = name accessory.console = console + accessory.inWishlist = wishlist.isOn - print("Added Accessory '\(accessory.name)'") + print("Added Accessory '\(accessory.name)' onWishlist \(wishlist.isOn)") } self.dismiss(animated: true) diff --git a/Zockerhoehle/ViewController/ConsoleLibraryViewController.swift b/Zockerhoehle/ViewController/ConsoleLibraryViewController.swift index f42df2a..89b6b87 100644 --- a/Zockerhoehle/ViewController/ConsoleLibraryViewController.swift +++ b/Zockerhoehle/ViewController/ConsoleLibraryViewController.swift @@ -54,6 +54,7 @@ class ConsoleLibraryViewController: UIViewController { } addPopup.console = self.console + addPopup.isWishlist = self.showWishlist addPopup.isVideogame = self.category.selectedSegmentIndex == 0 } @@ -114,7 +115,7 @@ extension ConsoleLibraryViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if self.category.selectedSegmentIndex == 0 { let gameCell = tableView.dequeueReusableCell(withIdentifier: "gameCell") as! GameCell - + gameCell.game = self.videoGamesInLibrary[self.showWishlist]?[indexPath.row] return gameCell @@ -152,38 +153,60 @@ extension ConsoleLibraryViewController: UITableViewDelegate { bought.image = #imageLiteral(resourceName: "cave") bought.backgroundColor = #colorLiteral(red: 0.4666666687, green: 0.7647058964, blue: 0.2666666806, alpha: 1) + var actions : [UIContextualAction] = [] if (self.showWishlist) { - return UISwipeActionsConfiguration(actions: [bought]) + actions.append(bought) } - return UISwipeActionsConfiguration(actions: []) + let swipeConf = UISwipeActionsConfiguration(actions: actions) + swipeConf.performsFirstActionWithFullSwipe = false + + return swipeConf } // Delete console item from library func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - /*let selectedItem = self.consoleItemsToDisplay()[indexPath.row] let delete = UIContextualAction(style: .destructive, title: "Delete") { (action, view, actionDone) in + + var nso : NSManagedObject? = .none + var name : String? + if self.category.selectedSegmentIndex == 0 { + nso = self.videoGamesInLibrary[self.showWishlist]?[indexPath.row] + name = self.videoGamesInLibrary[self.showWishlist]?[indexPath.row].name + + }else{ + nso = self.accessoriesinLibrary[self.showWishlist]?[indexPath.row] + name = self.accessoriesinLibrary[self.showWishlist]?[indexPath.row].name + } + let deleteWarning = UIAlertController( title: "Aus Zockerhöhle entfernen", - message: "Willst du '\("N/A")' wirklich aus der Zockerhöhle tragen?", + message: "Willst du '\(name ?? "N/A")' wirklich aus der Zockerhöhle tragen?", preferredStyle: .alert) deleteWarning.addAction(UIAlertAction(title: "Ja", style: .destructive, handler: { (action) in actionDone(true) - - //FlockeWS.deleteEntry(by: selectedItem.id); - //GameCollection.shared.removeGameItem(from: self.currentConsole!, item: selectedItem) + if nso != nil { + CDManager.shared.viewContext.delete(nso!) + } })) deleteWarning.addAction(UIAlertAction(title: "Nein", style: .cancel, handler: { (action) in actionDone(false) })) + + self.present(deleteWarning, animated: true, completion: nil) - }*/ + + + } - //delete.image = #imageLiteral(resourceName: "delete") - //delete.backgroundColor = #colorLiteral(red: 0.7450980544, green: 0.1568627506, blue: 0.07450980693, alpha: 1) + delete.image = #imageLiteral(resourceName: "delete") + delete.backgroundColor = #colorLiteral(red: 0.7450980544, green: 0.1568627506, blue: 0.07450980693, alpha: 1) - return UISwipeActionsConfiguration(actions: [])//delete]) + let swipeConf = UISwipeActionsConfiguration(actions: [delete]) + swipeConf.performsFirstActionWithFullSwipe = false + + return swipeConf } }