Ver código fonte

Force Dark Mode

Jon Fawcett 6 anos atrás
pai
commit
ad3994534c

+ 8 - 8
LoopFollow/Base.lproj/Main.storyboard

@@ -17,19 +17,19 @@
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <stackView opaque="NO" contentMode="scaleToFill" spacing="54" translatesAutoresizingMaskIntoConstraints="NO" id="mJy-Ly-Jze">
-                                <rect key="frame" x="8" y="52" width="398" height="336"/>
+                                <rect key="frame" x="8" y="52" width="398" height="252"/>
                                 <subviews>
                                     <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="Ptf-fu-Ue4" userLabel="BGview">
-                                        <rect key="frame" x="0.0" y="0.0" width="127.33333333333333" height="336"/>
+                                        <rect key="frame" x="0.0" y="0.0" width="127.33333333333333" height="252"/>
                                         <subviews>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="BG" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vXU-IW-GOL">
-                                                <rect key="frame" x="0.0" y="0.0" width="127.33333333333333" height="223.66666666666666"/>
+                                                <rect key="frame" x="0.0" y="0.0" width="127.33333333333333" height="139.66666666666666"/>
                                                 <fontDescription key="fontDescription" type="system" weight="black" pointSize="85"/>
                                                 <nil key="textColor"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KZc-fa-qmt">
-                                                <rect key="frame" x="0.0" y="223.66666666666666" width="127.33333333333333" height="71.666666666666657"/>
+                                                <rect key="frame" x="0.0" y="139.66666666666666" width="127.33333333333333" height="71.666666666666657"/>
                                                 <subviews>
                                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="--" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4sd-6h-LSj" userLabel="Direction">
                                                         <rect key="frame" x="0.0" y="0.0" width="55.333333333333336" height="71.666666666666671"/>
@@ -46,13 +46,13 @@
                                                 </subviews>
                                             </stackView>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="MinAgo" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UkG-hw-DVo">
-                                                <rect key="frame" x="0.0" y="295.33333333333331" width="127.33333333333333" height="20.333333333333314"/>
+                                                <rect key="frame" x="0.0" y="211.33333333333331" width="127.33333333333333" height="20.333333333333343"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                                 <nil key="textColor"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="TDG-yw-5fS">
-                                                <rect key="frame" x="0.0" y="315.66666666666669" width="127.33333333333333" height="20.333333333333314"/>
+                                                <rect key="frame" x="0.0" y="231.66666666666669" width="127.33333333333333" height="20.333333333333343"/>
                                                 <subviews>
                                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Loop" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XEm-uK-Xui">
                                                         <rect key="frame" x="0.0" y="0.0" width="59.666666666666664" height="20.333333333333332"/>
@@ -71,7 +71,7 @@
                                         </subviews>
                                     </stackView>
                                     <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="kTs-7g-lp9">
-                                        <rect key="frame" x="181.33333333333337" y="0.0" width="216.66666666666663" height="336"/>
+                                        <rect key="frame" x="181.33333333333337" y="0.0" width="216.66666666666663" height="252"/>
                                         <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
                                         <prototypes>
                                             <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="LabelCell" textLabel="gif-qe-9mv" detailTextLabel="hfT-xF-eNt" style="IBUITableViewCellStyleValue1" id="GJo-f1-ajA">
@@ -103,7 +103,7 @@
                                 </subviews>
                             </stackView>
                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="51B-JU-npv" customClass="LineChartView" customModule="Charts">
-                                <rect key="frame" x="8" y="396" width="398" height="341"/>
+                                <rect key="frame" x="8" y="312" width="398" height="425"/>
                                 <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
                             </view>
                             <view autoresizesSubviews="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Nml-lr-dgQ" userLabel="BGChartFull" customClass="LineChartView" customModule="Charts">

+ 3 - 1
LoopFollow/Controllers/AlarmViewController.swift

@@ -152,7 +152,9 @@ class AlarmViewController: FormViewController {
     
     override func viewDidLoad() {
         super.viewDidLoad()
-
+        if UserDefaultsRepository.forceDarkMode.value {
+            overrideUserInterfaceStyle = .dark
+        }
         buildSnoozeAll()
         buildTemporaryAlert()
         buildUrgentLow()

+ 4 - 1
LoopFollow/Controllers/MainViewController.swift

@@ -103,7 +103,10 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
     
     override func viewDidLoad() {
         super.viewDidLoad()
-        
+        if UserDefaultsRepository.forceDarkMode.value {
+            overrideUserInterfaceStyle = .dark
+            self.tabBarController?.overrideUserInterfaceStyle = .dark
+        }
         // Disable the snoozer tab unless an alarm is active
         let tabBarControllerItems = self.tabBarController?.tabBar.items
         if let arrayOfTabBarItems = tabBarControllerItems as! AnyObject as? NSArray{

+ 3 - 0
LoopFollow/Controllers/NightScoutViewController.swift

@@ -18,6 +18,9 @@ class NightscoutViewController: UIViewController {
     
     override func viewDidLoad() {
         super.viewDidLoad()
+        if UserDefaultsRepository.forceDarkMode.value {
+            overrideUserInterfaceStyle = .dark
+        }
         guard let myUrl = URL(string: UserDefaultsRepository.url.value) else { return  }
         
 

+ 13 - 0
LoopFollow/Controllers/SettingsViewController.swift

@@ -15,6 +15,9 @@ class SettingsViewController: FormViewController {
     
     override func viewDidLoad() {
         super.viewDidLoad()
+        if UserDefaultsRepository.forceDarkMode.value {
+            overrideUserInterfaceStyle = .dark
+        }
         
 
         form +++ Section("Nightscout Settings")
@@ -27,6 +30,16 @@ class SettingsViewController: FormViewController {
                 UserDefaultsRepository.url.value = value.lowercased()
                 }
         +++ Section("General Settings")
+            <<< SwitchRow("forceDarkMode") { row in
+            row.title = "Always Use Dark Mode (Restart App)"
+            row.value = UserDefaultsRepository.forceDarkMode.value
+            }.onChange { [weak self] row in
+                guard let value = row.value else { return }
+                
+                if value {
+                    UserDefaultsRepository.forceDarkMode.value = value
+                }
+            }
             <<< SwitchRow("screenlockSwitchState") { row in
                 row.title = "Keep Screen Active"
                 row.value = UserDefaultsRepository.screenlockSwitchState.value

+ 3 - 1
LoopFollow/Controllers/SnoozeViewController.swift

@@ -117,7 +117,9 @@ class SnoozeViewController: UIViewController {
     
     override func viewDidLoad() {
         super.viewDidLoad()
-        
+        if UserDefaultsRepository.forceDarkMode.value {
+            overrideUserInterfaceStyle = .dark
+        }
         SnoozeButton.layer.cornerRadius = 5
         SnoozeButton.contentEdgeInsets = UIEdgeInsets(top: 10,left: 10,bottom: 10,right: 10)
         

+ 1 - 0
LoopFollow/repository/UserDefaults.swift

@@ -27,6 +27,7 @@ class UserDefaultsRepository {
     static let backgroundRefresh = UserDefaultsValue<Bool>(key: "backgroundRefresh", default: true)
     static let appBadge = UserDefaultsValue<Bool>(key: "appBadge", default: true)
     static let dimScreenWhenIdle = UserDefaultsValue<Int>(key: "dimScreenWhenIdle", default: 0)
+    static let forceDarkMode = UserDefaultsValue<Bool>(key: "forceDarkMode", default: true)
     static let screenlockSwitchState = UserDefaultsValue<Bool>(
         key: "screenlockSwitchState",
         default: UIApplication.shared.isIdleTimerDisabled,