Skip to content

Commit

Permalink
Merge pull request #16 from All3yp/main
Browse files Browse the repository at this point in the history
Implemented dark mode on app
  • Loading branch information
Samridh29 authored Oct 6, 2021
2 parents 4bdfd86 + a5fa4fd commit b54921e
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Sticky Links.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -20,6 +21,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
18FA0756270DED8100AEC7D8 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
B26DCA1B27062C0A0088032C /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -81,6 +83,7 @@
isa = PBXGroup;
children = (
B290642627041685004250FA /* CategoryViewController.swift */,
18FA0756270DED8100AEC7D8 /* Colors.swift */,
B290640B27040F81004250FA /* LinksViewController.swift */,
B29064242704152A004250FA /* WebViewController.swift */,
);
Expand Down Expand Up @@ -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 */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "DD32DD28-DE2B-4E29-AD8A-274635042C47"
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Sticky Links.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
6 changes: 6 additions & 0 deletions Sticky Links/Assets.xcassets/Colors/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
20 changes: 17 additions & 3 deletions Sticky Links/Controllers/CategoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,31 @@ class CategoryViewController: UITableViewController {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let request : NSFetchRequest<Category> = 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{
Expand Down
14 changes: 14 additions & 0 deletions Sticky Links/Controllers/Colors.swift
Original file line number Diff line number Diff line change
@@ -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")!
}
1 change: 1 addition & 0 deletions Sticky Links/Controllers/LinksViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class LinksViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = UIColor.primaryBackgroundColor
}
}

Expand Down
30 changes: 30 additions & 0 deletions Sticky Links/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
37 changes: 32 additions & 5 deletions Sticky Links/View/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<device id="retina6_5" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -16,24 +17,27 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<color key="sectionIndexColor" name="TextColors"/>
<color key="sectionIndexBackgroundColor" name="PrimaryBackgroundColor"/>
<searchBar key="tableHeaderView" contentMode="redraw" text="" id="szk-Ml-o5U">
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<color key="barTintColor" name="PrimaryBackgroundColor"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="X4Q-zs-uTj" id="pMA-Ru-Gsd"/>
</connections>
</searchBar>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="LinkCell" id="Jgs-ap-hfS">
<rect key="frame" x="0.0" y="88.666666030883789" width="414" height="43.666667938232422"/>
<rect key="frame" x="0.0" y="88.666666030883789" width="414" height="43.333332061767578"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Jgs-ap-hfS" id="D2V-ZO-8DE">
<rect key="frame" x="0.0" y="0.0" width="384.33333333333331" height="43.666667938232422"/>
<rect key="frame" x="0.0" y="0.0" width="384.33333333333331" height="43.333332061767578"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yif-eD-zTA" userLabel="Bookmark Link Button">
<rect key="frame" x="337.33333333333331" y="6.0000000000000018" width="41" height="31.666666666666671"/>
<rect key="frame" x="337.33333333333331" y="5.9999999999999982" width="41" height="31.333333333333329"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" image="bookmark" catalog="system"/>
<connections>
Expand All @@ -48,6 +52,7 @@
<constraint firstItem="yif-eD-zTA" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="D2V-ZO-8DE" secondAttribute="leading" constant="20" symbolic="YES" id="p64-Fu-9aV"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" name="PrimaryBackgroundColor"/>
</tableViewCell>
</prototypes>
<connections>
Expand Down Expand Up @@ -147,10 +152,14 @@
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" id="Dec-hu-VuE">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<searchBar key="tableHeaderView" contentMode="redraw" id="u6J-Vx-bbb">
<color key="backgroundColor" name="PrimaryBackgroundColor"/>
<color key="sectionIndexColor" name="TextColors"/>
<color key="sectionIndexBackgroundColor" name="PrimaryBackgroundColor"/>
<searchBar key="tableHeaderView" contentMode="redraw" text="" id="u6J-Vx-bbb">
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" name="PrimaryBackgroundColor"/>
<color key="barTintColor" name="PrimaryBackgroundColor"/>
<textInputTraits key="textInputTraits"/>
</searchBar>
<prototypes>
Expand All @@ -170,13 +179,15 @@
</connections>
</button>
</subviews>
<color key="backgroundColor" name="PrimaryBackgroundColor"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="kmH-hp-50L" secondAttribute="bottom" constant="6" id="8k1-JY-dtE"/>
<constraint firstAttribute="trailing" secondItem="kmH-hp-50L" secondAttribute="trailing" constant="6" id="DE6-qN-Gpe"/>
<constraint firstItem="kmH-hp-50L" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="ctg-Xh-Rr2" secondAttribute="leading" constant="20" symbolic="YES" id="lc6-ET-jY3"/>
<constraint firstItem="kmH-hp-50L" firstAttribute="top" secondItem="ctg-Xh-Rr2" secondAttribute="top" constant="6" id="pRa-n9-aP9"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" name="PrimaryBackgroundColor"/>
</tableViewCell>
</prototypes>
<connections>
Expand All @@ -186,6 +197,15 @@
</tableView>
<toolbarItems/>
<navigationItem key="navigationItem" title="Categories" id="GEY-ir-NSG">
<barButtonItem key="leftBarButtonItem" id="VnW-Kb-Fjy">
<switch key="customView" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="NbN-7x-rF8">
<rect key="frame" x="20" y="6.6666666666666679" width="51" height="31.000000000000004"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="darkAction:" destination="FBQ-C6-Eyw" eventType="valueChanged" id="SXA-I6-dfM"/>
</connections>
</switch>
</barButtonItem>
<rightBarButtonItems>
<barButtonItem systemItem="add" id="0xG-VA-zJm">
<connections>
Expand All @@ -202,6 +222,7 @@
</navigationItem>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="outletSwitch" destination="NbN-7x-rF8" id="1Aa-gi-9jV"/>
<outlet property="searchBar" destination="u6J-Vx-bbb" id="2mU-4m-76N"/>
<segue destination="X4Q-zs-uTj" kind="show" identifier="CategorySegue" id="vBw-Pn-hjt"/>
</connections>
Expand All @@ -216,6 +237,12 @@
<image name="bookmark" catalog="system" width="112" height="128"/>
<image name="magnifyingglass" catalog="system" width="128" height="115"/>
<image name="square.and.arrow.up" catalog="system" width="115" height="128"/>
<namedColor name="PrimaryBackgroundColor">
<color red="0.93699997663497925" green="0.94499999284744263" blue="0.95300000905990601" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</namedColor>
<namedColor name="TextColors">
<color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</namedColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
Expand Down

0 comments on commit b54921e

Please sign in to comment.