diff --git a/Notare.xcodeproj/project.pbxproj b/Notare.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index 24b06b6..2930651 --- a/Notare.xcodeproj/project.pbxproj +++ b/Notare.xcodeproj/project.pbxproj @@ -7,6 +7,11 @@ objects = { /* Begin PBXBuildFile section */ + 1385C2952411B804002FAA2C /* ThemeSelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1385C2942411B804002FAA2C /* ThemeSelectionViewController.swift */; }; + 13E26AD3241088A800D2BC08 /* ThemeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13E26AD2241088A800D2BC08 /* ThemeProtocol.swift */; }; + 13E26AD52410896300D2BC08 /* DarkTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13E26AD42410896300D2BC08 /* DarkTheme.swift */; }; + 13E26AD724108B5300D2BC08 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13E26AD624108B5300D2BC08 /* Theme.swift */; }; + 13E26AD924108D9100D2BC08 /* LightTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13E26AD824108D9100D2BC08 /* LightTheme.swift */; }; 1FB17190240DC53B00F8EC0F /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FB1718F240DC53B00F8EC0F /* DetailViewController.swift */; }; 1FB17195240DE8DF00F8EC0F /* Notes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FB17194240DE8DF00F8EC0F /* Notes.swift */; }; 1FC510B9240D8C54006BD691 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FC510B8240D8C54006BD691 /* AppDelegate.swift */; }; @@ -18,6 +23,11 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1385C2942411B804002FAA2C /* ThemeSelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeSelectionViewController.swift; sourceTree = ""; }; + 13E26AD2241088A800D2BC08 /* ThemeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeProtocol.swift; sourceTree = ""; }; + 13E26AD42410896300D2BC08 /* DarkTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DarkTheme.swift; sourceTree = ""; }; + 13E26AD624108B5300D2BC08 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = ""; }; + 13E26AD824108D9100D2BC08 /* LightTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightTheme.swift; sourceTree = ""; }; 1FB1718F240DC53B00F8EC0F /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = ""; }; 1FB17194240DE8DF00F8EC0F /* Notes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notes.swift; sourceTree = ""; }; 1FC510B5240D8C54006BD691 /* Notare.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Notare.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -75,8 +85,13 @@ 1FB17194240DE8DF00F8EC0F /* Notes.swift */, 1FC510BC240D8C54006BD691 /* ViewController.swift */, 1FB1718F240DC53B00F8EC0F /* DetailViewController.swift */, + 1385C2942411B804002FAA2C /* ThemeSelectionViewController.swift */, 1FC510BE240D8C54006BD691 /* Main.storyboard */, 1FC510C6240D8C58006BD691 /* Info.plist */, + 13E26AD2241088A800D2BC08 /* ThemeProtocol.swift */, + 13E26AD42410896300D2BC08 /* DarkTheme.swift */, + 13E26AD824108D9100D2BC08 /* LightTheme.swift */, + 13E26AD624108B5300D2BC08 /* Theme.swift */, ); path = Notare; sourceTree = ""; @@ -153,10 +168,15 @@ buildActionMask = 2147483647; files = ( 1FC510BD240D8C54006BD691 /* ViewController.swift in Sources */, + 13E26AD724108B5300D2BC08 /* Theme.swift in Sources */, 1FC510B9240D8C54006BD691 /* AppDelegate.swift in Sources */, 1FC510BB240D8C54006BD691 /* SceneDelegate.swift in Sources */, + 13E26AD924108D9100D2BC08 /* LightTheme.swift in Sources */, + 13E26AD3241088A800D2BC08 /* ThemeProtocol.swift in Sources */, 1FB17190240DC53B00F8EC0F /* DetailViewController.swift in Sources */, + 13E26AD52410896300D2BC08 /* DarkTheme.swift in Sources */, 1FB17195240DE8DF00F8EC0F /* Notes.swift in Sources */, + 1385C2952411B804002FAA2C /* ThemeSelectionViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Notare/Base.lproj/Main.storyboard b/Notare/Base.lproj/Main.storyboard old mode 100644 new mode 100755 index d426f79..0a0d79f --- a/Notare/Base.lproj/Main.storyboard +++ b/Notare/Base.lproj/Main.storyboard @@ -7,7 +7,7 @@ - + @@ -33,15 +33,19 @@ - - - - - - + + + + + + + + + + @@ -54,7 +58,7 @@ - + @@ -67,13 +71,18 @@ - + + + + + + - + @@ -88,9 +97,20 @@ Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. - + + + + + + + + + + + + @@ -114,51 +134,15 @@ + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -181,7 +165,7 @@ - + @@ -196,40 +180,434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + - - + + - + - - + + + + diff --git a/Notare/DarkTheme.swift b/Notare/DarkTheme.swift new file mode 100755 index 0000000..96bcae0 --- /dev/null +++ b/Notare/DarkTheme.swift @@ -0,0 +1,14 @@ +// +// DarkTheme.swift +// Notare +// +// Created by conner on 3/3/20. +// Copyright © 2020 conner. All rights reserved. +// +import UIKit + +class DarkTheme: ThemeProtocol { + var fontColor: UIColor = UIColor.white + var buttonColor: UIColor = UIColor.systemGreen + var backgroundColor: UIColor = UIColor.black +} diff --git a/Notare/DetailViewController.swift b/Notare/DetailViewController.swift old mode 100644 new mode 100755 index 37c17d3..ad0dfdc --- a/Notare/DetailViewController.swift +++ b/Notare/DetailViewController.swift @@ -9,7 +9,15 @@ import UIKit class DetailViewController: UIViewController { + @IBOutlet var detailView: UIView! @IBOutlet weak var detailTextView: UITextView! + @IBOutlet weak var cancelButton: UIBarButtonItem! + @IBOutlet weak var saveButton: UIBarButtonItem! + @IBAction func shareTapped(_ sender: UIBarButtonItem) { + let activityVC = UIActivityViewController(activityItems: [detailTextView.text ?? ""], applicationActivities: nil) + activityVC.popoverPresentationController?.sourceView = self.view + self.present(activityVC, animated: true, completion: nil) + } var text: String = "" @@ -20,49 +28,39 @@ class DetailViewController: UIViewController { detailTextView.text = text self.navigationItem.largeTitleDisplayMode = .never - } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) detailTextView.becomeFirstResponder() // function to bring up software keyboard by automatically selecting text view + setTheme() } func setText(t: String) { text = t - - // verifying to see if the view is loaded before we perform any modifications - - if isViewLoaded { - // modify text view after view has loaded - detailTextView.text = t - } + if isViewLoaded { detailTextView.text = t } } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) - masterView.newRowText = detailTextView.text detailTextView.resignFirstResponder() - } @IBAction func saveTapped(_ sender: UIBarButtonItem) { navigationController?.popViewController(animated: true) + masterView.newRowText = detailTextView.text viewWillDisappear(true) } @IBAction func cancelTapped(_ sender: UIBarButtonItem) { navigationController?.popViewController(animated: true) } - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + + func setTheme() { + detailTextView.backgroundColor = Theme.current.backgroundColor + detailTextView.textColor = Theme.current.fontColor + cancelButton.tintColor = Theme.current.buttonColor + saveButton.tintColor = Theme.current.buttonColor + detailView.backgroundColor = Theme.current.backgroundColor } - */ - } diff --git a/Notare/Info.plist b/Notare/Info.plist old mode 100644 new mode 100755 diff --git a/Notare/LightTheme.swift b/Notare/LightTheme.swift new file mode 100755 index 0000000..fdd2793 --- /dev/null +++ b/Notare/LightTheme.swift @@ -0,0 +1,15 @@ +// +// LightTheme.swift +// Notare +// +// Created by conner on 3/3/20. +// Copyright © 2020 conner. All rights reserved. +// + +import UIKit + +class LightTheme: ThemeProtocol { + var fontColor: UIColor = UIColor.black + var buttonColor: UIColor = UIColor.systemBlue + var backgroundColor: UIColor = UIColor.white +} diff --git a/Notare/Notes.swift b/Notare/Notes.swift old mode 100644 new mode 100755 index cdf6698..d5c5326 --- a/Notare/Notes.swift +++ b/Notare/Notes.swift @@ -4,7 +4,7 @@ // // Created by Bree Jeune on 3/2/20. // Copyright © 2020 Young. All rights reserved. -// +// maodmd import Foundation diff --git a/Notare/Resources/AppDelegate.swift b/Notare/Resources/AppDelegate.swift old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-20@2x.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-20@2x.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-20@3x.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-20@3x.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-29@2x.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-29@2x.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-29@3x.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-29@3x.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-40@2x.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-40@2x.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-40@3x.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-40@3x.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/AppIcon.appiconset/ios-marketing.png b/Notare/Resources/Assets.xcassets/AppIcon.appiconset/ios-marketing.png old mode 100644 new mode 100755 diff --git a/Notare/Resources/Assets.xcassets/Contents.json b/Notare/Resources/Assets.xcassets/Contents.json old mode 100644 new mode 100755 diff --git a/Notare/Resources/Base.lproj/LaunchScreen.storyboard b/Notare/Resources/Base.lproj/LaunchScreen.storyboard old mode 100644 new mode 100755 diff --git a/Notare/Resources/SceneDelegate.swift b/Notare/Resources/SceneDelegate.swift old mode 100644 new mode 100755 diff --git a/Notare/Theme.swift b/Notare/Theme.swift new file mode 100755 index 0000000..7ac65ae --- /dev/null +++ b/Notare/Theme.swift @@ -0,0 +1,13 @@ +// +// Theme.swift +// Notare +// +// Created by conner on 3/4/20. +// Copyright © 2020 Young. All rights reserved. +// + +import Foundation +import UIKit +class Theme { + static var current: ThemeProtocol = LightTheme() +} diff --git a/Notare/ThemeProtocol.swift b/Notare/ThemeProtocol.swift new file mode 100755 index 0000000..623b043 --- /dev/null +++ b/Notare/ThemeProtocol.swift @@ -0,0 +1,14 @@ +// +// ThemeProtocol.swift +// Notare +// +// Created by conner on 3/3/20. +// Copyright © 2020 conner. All rights reserved. +// +import UIKit + +protocol ThemeProtocol { + var fontColor: UIColor { get set } + var buttonColor: UIColor { get set } + var backgroundColor: UIColor { get set } +} diff --git a/Notare/ThemeSelectionViewController.swift b/Notare/ThemeSelectionViewController.swift new file mode 100755 index 0000000..eedc1eb --- /dev/null +++ b/Notare/ThemeSelectionViewController.swift @@ -0,0 +1,131 @@ +// +// ThemeSelectionViewController.swift +// Notare +// +// Created by conner on 3/5/20. +// Copyright © 2020 Young. All rights reserved. +// + +import UIKit + +class ThemeSelectionViewController: UIViewController { + var darkMode = Bool() + var lightMode = Bool() + @IBOutlet weak var donebutton: UIBarButtonItem! + @IBOutlet weak var darkThemeSwitch: UISwitch! + @IBOutlet weak var lightThemeSwitch: UISwitch! + @IBOutlet weak var DarkLabel: UILabel! + @IBOutlet weak var lightLabel: UILabel! + @IBOutlet weak var fontLabel: UILabel! + @IBOutlet weak var buttonLabel: UILabel! + @IBOutlet weak var backgroundLabel: UILabel! + @IBOutlet weak var topBar: UINavigationItem! + + var colors: [UIColor] = [ + .systemRed, + .systemOrange, + .systemYellow, + .systemGreen, + .systemBlue, + .systemIndigo, + .systemPurple, + .white, + .black + ] + + var identifiers: [String] = [ + "red", + "orange", + "yellow", + "green", + "blue", + "indigo", + "purple", + "white", + "black" + ] + + @IBAction func colorTapped(_ sender: UIButton) { + if sender.accessibilityLabel == "font" { + for index in 0...identifiers.count { + if sender.accessibilityIdentifier == identifiers[index] { + Theme.current.fontColor = colors[index] + return; + } + } + } + if sender.accessibilityLabel == "button" { + for index in 0...identifiers.count { + if sender.accessibilityIdentifier == identifiers[index] { + Theme.current.buttonColor = colors[index] + return; + } + } + } + if sender.accessibilityLabel == "background" { + for index in 0...identifiers.count { + if sender.accessibilityIdentifier == identifiers[index] { + Theme.current.backgroundColor = colors[index] + return; + } + } + } + } + + override func viewDidLoad() { + super.viewDidLoad() + let darkDefault = UserDefaults.standard + let lightDefault = UserDefaults.standard + darkMode = darkDefault.bool(forKey: "darkDefault") + lightMode = lightDefault.bool(forKey: "lightDefault") + if darkMode { + darkThemeSwitch.isOn = true + lightThemeSwitch.isOn = false + Theme.current = DarkTheme() + setTheme() + } else { + lightThemeSwitch.isOn = true + darkThemeSwitch.isOn = false + Theme.current = LightTheme() + setTheme() + } + } + + @IBAction func darkSwitched(_ sender: Any) { + darkThemeSwitch.isOn = true + lightThemeSwitch.isOn = false + let darkDefault = UserDefaults.standard + darkDefault.set(true, forKey: "darkDefault") + let lightDefault = UserDefaults.standard + lightDefault.set(false, forKey: "lightDefault") + Theme.current = DarkTheme() + navigationController?.navigationBar.barStyle = .black + setTheme() + } + + @IBAction func lightSwitched(_ sender: Any) { + lightThemeSwitch.isOn = true + darkThemeSwitch.isOn = false + let darkDefault = UserDefaults.standard + darkDefault.set(false, forKey: "darkDefault") + let lightDefault = UserDefaults.standard + lightDefault.set(true, forKey: "lightDefault") + Theme.current = LightTheme() + navigationController?.navigationBar.barStyle = .default + setTheme() + } + @IBAction func doneTapped(_ sender: Any) { + navigationController?.popViewController(animated: true) + } + + func setTheme() { + self.view.backgroundColor = Theme.current.backgroundColor + DarkLabel.textColor = Theme.current.fontColor + lightLabel.textColor = Theme.current.fontColor + fontLabel.textColor = Theme.current.fontColor + buttonLabel.textColor = Theme.current.fontColor + backgroundLabel.textColor = Theme.current.fontColor + topBar.titleView?.tintColor = Theme.current.fontColor + donebutton.tintColor = Theme.current.buttonColor + } +} diff --git a/Notare/ViewController.swift b/Notare/ViewController.swift old mode 100644 new mode 100755 index 7de2e0b..9669810 --- a/Notare/ViewController.swift +++ b/Notare/ViewController.swift @@ -8,200 +8,174 @@ import UIKit - -// adding a protocol to get class to conform to UITableViewDataSource and UITableViewDelegate class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { - // making table view a property inside view controller + // MARK: Outlets + @IBOutlet weak var addNote: UIBarButtonItem! + @IBOutlet weak var editButton: UIBarButtonItem! + @IBOutlet weak var paintButton: UIBarButtonItem! @IBOutlet weak var tableView: UITableView! + @IBOutlet weak var toolbar: UIToolbar! - // creating a new instance of the variable "data" in order to get a data source for table view + @IBOutlet weak var sortButton: UIBarButtonItem! + // MARK: Initial Variables var data: [String] = [] - var notes: [Note] = [] - - var selectedRow: Int = -1 - var newRowText: String = "" - - - let searchController = UISearchController(searchResultsController: nil) + var selectedRow = -1 + var newRowText = "" - var filteredNotes: [Note] = [] // will hold the results of the user search - - var isSearchBarEmpty: Bool { - return searchController.searchBar.text?.isEmpty ?? true - } - - - // to save data to a file - we have to start UserDefault saving code and modify it using File URL + // filteredNotes holds results for notes search + var filteredNotes: [Note] = [] + let searchController = UISearchController(searchResultsController: nil) + var isSearchBarEmpty: Bool { return searchController.searchBar.text?.isEmpty ?? true } var fileURL: URL! - // runs when all user interface elements are loaded + // MARK: viewDidLoad override func viewDidLoad() { super.viewDidLoad() - - //setting the tableview as the data source tableView.delegate = self tableView.dataSource = self - self.title = "Notare" - self.navigationItem.largeTitleDisplayMode = .always - - // file URL + setFileURL() + loadNotes() + setupSearchController() + setTheme() + } + + // MARK: sortTapped + @IBAction func sortTapped(_ sender: Any) { + let sortedNotes = data.sorted(by: {$0 < $1}) + data = sortedNotes + tableView.reloadData() + } + + // MARK: setFileURL + func setFileURL() { let baseURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) fileURL = baseURL.appendingPathComponent("notes.txt") - - loadNotes() // calls the load notes function from persistence when loading/opening up app - - - - // informs the search controller of any text changes within the UI search bar + } + // MARK: loadNotes + func loadNotes() { + if let loadedNotes: [String] = NSArray(contentsOf: fileURL) as? [String] { + data = loadedNotes + tableView.reloadData() + } + } + // MARK: Search Functionality + func setupSearchController() { searchController.searchResultsUpdater = self - // the current view will show the results and not obscure view searchController.obscuresBackgroundDuringPresentation = false - // placeholder text searchController.searchBar.placeholder = "Search Notes" navigationItem.searchController = searchController - // closes the search bar when the user navigates to another view controller definesPresentationContext = true - } - - // *********** + + func filterContentForSearchText(_ searchText: String, category: Note.Category? = nil) { + filteredNotes = notes.filter { (note: Note) -> Bool in + return note.name.lowercased().contains(searchText.lowercased()) + } + tableView.reloadData() + }} + + extension ViewController: UISearchResultsUpdating { + func updateSearchResults(for searchController: UISearchController) { + let searchBar = searchController.searchBar + filterContentForSearchText(searchBar.text!) + tableView.reloadData() + } + + // MARK: viewWillAppear override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if selectedRow == -1 { - return + if selectedRow != -1 { + data[selectedRow] = newRowText + if newRowText == "" { + data.remove(at: selectedRow) + } + tableView.reloadData() + saveNotes() } - data[selectedRow] = newRowText - if newRowText == "" { - data.remove(at: selectedRow) + setTheme() + } + // MARK: saveNotes + func saveNotes() { + let arrayDirectory = NSArray(array: data) + do { + try arrayDirectory.write(to: fileURL) + } catch { + print("Error in saveNotes()") } - tableView.reloadData() - saveNotes() } - // *********** - - // IBAction to call createNewNote method + // MARK: Plus Button @IBAction func createNewNoteButton(_ sender: UIBarButtonItem) { - createNewNote() - } - - // IBAction to call editNote method - @IBAction func editNote(_ sender: UIBarButtonItem) { - - } - - - // method for creating new notes - - func createNewNote() { - - if tableView.isEditing { - return - } - - let name: String = "" // gives note a string title based on user input - data.insert(name, at: 0) // indexes new note at the beginning of the index of "data" array - - let indexPath: IndexPath = IndexPath(row: 0, section: 0) // creates a new row after adding a new note to array - tableView.insertRows(at: [indexPath], with: .automatic) // animates the creation of a new row - - // identifies selected row when segue is triggered / connected to prepare for segue method + if tableView.isEditing { return } + let name: String = "" + data.insert(name, at: 0) + let indexPath = IndexPath(row: 0, section: 0) + tableView.insertRows(at: [indexPath], with: .automatic) tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none) - self.performSegue(withIdentifier: "detailNotes", sender: nil) - tableView.reloadData() } - //numberOfRowsInSection method - how many rows are going to be in the table view? func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return data.count // setting number of rows based on the count of elements in the array "data" + return data.count } - //CellForRowAt method - creating cell, applying data from array and returning a UITableView cell based on the index path of the array "data" - - // add guard let / if let to check and make sure cell is not nil before running code - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "noteCell", for: indexPath) - cell.textLabel?.text = data[indexPath.row] //setting the text for the cell based on the text label property -// IndexPath contains the row and the section of the table view whose cell we are creating + cell.textLabel?.text = data[indexPath.row] + // MARK: Cell Themeing + cell.backgroundColor = Theme.current.backgroundColor + cell.textLabel?.textColor = Theme.current.fontColor return cell } - // when edit button is selected, puts table into editing mode - allows for deletion + // MARK: Edit button Functions override func setEditing(_ editing: Bool, animated: Bool) { super.setEditing(editing, animated: animated) tableView.setEditing(editing, animated: animated) } - - - // deletes rows when in edit mode and updates the "data" array after deletion - // also adds animation effect when deleting + @IBAction func editNote(_ sender: UIBarButtonItem) { + self.navigationItem.leftBarButtonItem = editButtonItem + } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { data.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .fade) tableView.reloadData() } - // uses the delagate to find which row was selected - + // Segue on row select func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { self.performSegue(withIdentifier: "detailNotes", sender: nil) - } + // MARK: prepare for segue override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - let detailView: DetailViewController = segue.destination as! DetailViewController - selectedRow = tableView.indexPathForSelectedRow!.row // always making sure you have a selected row before transistion to detail view controller screen - detailView.masterView = self - detailView.setText(t: data[selectedRow]) // sending selected cell text/data to the detail view - } - - // saving the notes using persistence - - func saveNotes() { - -// creating NSArray instead of using user defaults - let arrayDirectory = NSArray(array: data) - do { - try arrayDirectory.write(to: fileURL) - } catch { - print("Error") + if segue.identifier == "detailNotes" { + let detailView: DetailViewController = segue.destination as! DetailViewController + selectedRow = tableView.indexPathForSelectedRow!.row // always making sure you have a selected row before transistion to detail view controller screen + detailView.masterView = self + detailView.setText(t: data[selectedRow]) // sending selected cell text/data to the detail view + } else if segue.identifier == "themeSelection" { + } } - - func loadNotes() { - // if the value being created is not "nil" then execute the code inside of the { } - // getting value from user defaults and typecasting it as a string array - if let loadedNotes: [String] = NSArray(contentsOf: fileURL) as? [String] { - data = loadedNotes - tableView.reloadData() - } - - } - func filterContentForSearchText(_ searchText: String, - category: Note.Category? = nil) { - filteredNotes = notes.filter { (note: Note) -> Bool in - return note.name.lowercased().contains(searchText.lowercased()) - } - - tableView.reloadData() + + func setTheme() { + self.view.backgroundColor = Theme.current.backgroundColor + paintButton.tintColor = Theme.current.buttonColor + tableView.backgroundColor = Theme.current.backgroundColor + //editButton.tintColor = Theme.current.buttonColor + addNote.tintColor = Theme.current.buttonColor + toolbar.barTintColor = Theme.current.backgroundColor + toolbar.backgroundColor = Theme.current.backgroundColor + sortButton.tintColor = Theme.current.buttonColor + tableView.reloadData() + } - -} - -extension ViewController: UISearchResultsUpdating { - func updateSearchResults(for searchController: UISearchController) { - // TODO - } - - - }