diff --git a/Sticky Links.xcodeproj/project.pbxproj b/Sticky Links.xcodeproj/project.pbxproj index c4356f6..ad1108b 100644 --- a/Sticky Links.xcodeproj/project.pbxproj +++ b/Sticky Links.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 18FA0757270DED8100AEC7D8 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18FA0756270DED8100AEC7D8 /* Colors.swift */; }; B26DCA1C27062C0A0088032C /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = B26DCA1B27062C0A0088032C /* README.md */; }; B290640827040F81004250FA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B290640727040F81004250FA /* AppDelegate.swift */; }; B290640A27040F81004250FA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B290640927040F81004250FA /* SceneDelegate.swift */; }; @@ -20,6 +21,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 18FA0756270DED8100AEC7D8 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = ""; }; B26DCA1B27062C0A0088032C /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; B290640427040F81004250FA /* Sticky Links.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Sticky Links.app"; sourceTree = BUILT_PRODUCTS_DIR; }; B290640727040F81004250FA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -81,6 +83,7 @@ isa = PBXGroup; children = ( B290642627041685004250FA /* CategoryViewController.swift */, + 18FA0756270DED8100AEC7D8 /* Colors.swift */, B290640B27040F81004250FA /* LinksViewController.swift */, B29064242704152A004250FA /* WebViewController.swift */, ); @@ -178,6 +181,7 @@ B290641227040F81004250FA /* Sticky_Links.xcdatamodeld in Sources */, B290640C27040F81004250FA /* LinksViewController.swift in Sources */, B290640827040F81004250FA /* AppDelegate.swift in Sources */, + 18FA0757270DED8100AEC7D8 /* Colors.swift in Sources */, B29064252704152A004250FA /* WebViewController.swift in Sources */, B290642727041685004250FA /* CategoryViewController.swift in Sources */, B290640A27040F81004250FA /* SceneDelegate.swift in Sources */, diff --git a/Sticky Links.xcodeproj/project.xcworkspace/xcuserdata/alleypereira.xcuserdatad/UserInterfaceState.xcuserstate b/Sticky Links.xcodeproj/project.xcworkspace/xcuserdata/alleypereira.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..3175a63 Binary files /dev/null and b/Sticky Links.xcodeproj/project.xcworkspace/xcuserdata/alleypereira.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Sticky Links.xcodeproj/xcuserdata/alleypereira.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Sticky Links.xcodeproj/xcuserdata/alleypereira.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..52d9f09 --- /dev/null +++ b/Sticky Links.xcodeproj/xcuserdata/alleypereira.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + + diff --git a/Sticky Links.xcodeproj/xcuserdata/alleypereira.xcuserdatad/xcschemes/xcschememanagement.plist b/Sticky Links.xcodeproj/xcuserdata/alleypereira.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..b6cd563 --- /dev/null +++ b/Sticky Links.xcodeproj/xcuserdata/alleypereira.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Sticky Links.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Sticky Links/Assets.xcassets/Colors/Contents.json b/Sticky Links/Assets.xcassets/Colors/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Sticky Links/Assets.xcassets/Colors/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sticky Links/Assets.xcassets/Colors/PrimaryBackgroundColor.colorset/Contents.json b/Sticky Links/Assets.xcassets/Colors/PrimaryBackgroundColor.colorset/Contents.json new file mode 100644 index 0000000..0dc55c1 --- /dev/null +++ b/Sticky Links/Assets.xcassets/Colors/PrimaryBackgroundColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "0.953", + "green" : "0.945", + "red" : "0.937" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "0.239", + "green" : "0.157", + "red" : "0.145" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sticky Links/Assets.xcassets/Colors/TextColors.colorset/Contents.json b/Sticky Links/Assets.xcassets/Colors/TextColors.colorset/Contents.json new file mode 100644 index 0000000..97fee71 --- /dev/null +++ b/Sticky Links/Assets.xcassets/Colors/TextColors.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "0.000", + "green" : "0.000", + "red" : "0.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sticky Links/Controllers/CategoryViewController.swift b/Sticky Links/Controllers/CategoryViewController.swift index 25a1767..81ed36d 100644 --- a/Sticky Links/Controllers/CategoryViewController.swift +++ b/Sticky Links/Controllers/CategoryViewController.swift @@ -15,17 +15,31 @@ class CategoryViewController: UITableViewController { let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext let request : NSFetchRequest = Category.fetchRequest() - - @IBOutlet weak var searchBar: UISearchBar! - + @IBOutlet weak var outletSwitch: UISwitch! + + @IBAction func darkAction(_ sender: Any) { + if outletSwitch.isOn { + view.window?.overrideUserInterfaceStyle = .dark + UserDefaults.standard.set(true, forKey: "DarkMode") + } else { + view.window?.overrideUserInterfaceStyle = .light + UserDefaults.standard.set(false, forKey: "DarkMode") + } + + } + override func viewDidLoad() { super.viewDidLoad() print(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)) loadCategory() + + outletSwitch.isOn = UserDefaults.standard.value(forKey: "DarkMode") as? Bool ?? false } } + + //MARK: Table View Methods extension CategoryViewController{ diff --git a/Sticky Links/Controllers/Colors.swift b/Sticky Links/Controllers/Colors.swift new file mode 100644 index 0000000..2efdeca --- /dev/null +++ b/Sticky Links/Controllers/Colors.swift @@ -0,0 +1,14 @@ +// +// Colors.swift +// Sticky Links +// +// Created by Alley Pereira on 06/10/21. +// + +import UIKit + +extension UIColor { + + static let primaryBackgroundColor: UIColor = UIColor(named: "PrimaryBackgroundColor")! + static let primaryTextColor: UIColor = UIColor(named: "TextColors")! +} diff --git a/Sticky Links/Controllers/LinksViewController.swift b/Sticky Links/Controllers/LinksViewController.swift index 6e4b367..fb67472 100644 --- a/Sticky Links/Controllers/LinksViewController.swift +++ b/Sticky Links/Controllers/LinksViewController.swift @@ -27,6 +27,7 @@ class LinksViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. + view.backgroundColor = UIColor.primaryBackgroundColor } } diff --git a/Sticky Links/SceneDelegate.swift b/Sticky Links/SceneDelegate.swift index 2622087..97a8ccb 100644 --- a/Sticky Links/SceneDelegate.swift +++ b/Sticky Links/SceneDelegate.swift @@ -17,6 +17,36 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). guard let _ = (scene as? UIWindowScene) else { return } + + setupUserInterfaceStyle() + } + + func setupUserInterfaceStyle() { + + var darkModeIsEnabled: Bool! + + if let darkModeFromUserDefault = UserDefaults.standard.value(forKey: "DarkMode") as? Bool { + + darkModeIsEnabled = darkModeFromUserDefault + + } else { + + switch UITraitCollection.current.userInterfaceStyle { + case .light: + UserDefaults.standard.set(false, forKey: "DarkMode") + darkModeIsEnabled = false + case .dark: + UserDefaults.standard.set(true, forKey: "DarkMode") + darkModeIsEnabled = true + default: + UserDefaults.standard.set(false, forKey: "DarkMode") + darkModeIsEnabled = false + } + + } + + window?.overrideUserInterfaceStyle = darkModeIsEnabled ? .dark : .light + } func sceneDidDisconnect(_ scene: UIScene) { diff --git a/Sticky Links/View/Base.lproj/Main.storyboard b/Sticky Links/View/Base.lproj/Main.storyboard index 11daf02..09385f1 100644 --- a/Sticky Links/View/Base.lproj/Main.storyboard +++ b/Sticky Links/View/Base.lproj/Main.storyboard @@ -3,6 +3,7 @@ + @@ -16,9 +17,12 @@ + + + @@ -26,14 +30,14 @@ - + - + + @@ -177,6 +187,7 @@ + @@ -186,6 +197,15 @@ + + + + + + + + + @@ -202,6 +222,7 @@ + @@ -216,6 +237,12 @@ + + + + + +