Skip to content

Commit 80a6be8

Browse files
committed
Revert "Revert "added a user toggle option to prevent display from going to sleep.""
This reverts commit 0f416b5.
1 parent 0f416b5 commit 80a6be8

File tree

3 files changed

+66
-67
lines changed

3 files changed

+66
-67
lines changed

RedditRealTime/RedditRealTime/Base.lproj/Main.storyboard

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,37 @@
151151
</constraints>
152152
</tableViewCellContentView>
153153
</tableViewCell>
154+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" rowHeight="55" id="peP-yd-dWb">
155+
<rect key="frame" x="0.0" y="55" width="414" height="55"/>
156+
<autoresizingMask key="autoresizingMask"/>
157+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="peP-yd-dWb" id="U4c-FS-8CP">
158+
<rect key="frame" x="0.0" y="0.0" width="414" height="54.666666666666664"/>
159+
<autoresizingMask key="autoresizingMask"/>
160+
<subviews>
161+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Keep Display On" lineBreakMode="clip" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="F3f-pw-dop">
162+
<rect key="frame" x="20" y="11.666666666666666" width="126" height="31.333333333333336"/>
163+
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
164+
<nil key="textColor"/>
165+
<nil key="highlightedColor"/>
166+
</label>
167+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" horizontalCompressionResistancePriority="751" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gLR-rq-R4d">
168+
<rect key="frame" x="341" y="11.666666666666666" width="51" height="31.333333333333336"/>
169+
<connections>
170+
<action selector="realTimeRefreshSwitchTapped:" destination="Rzf-Od-jHG" eventType="valueChanged" id="FKT-bB-ad2"/>
171+
<action selector="willDeviceSleepSwitchTapped:" destination="Rzf-Od-jHG" eventType="valueChanged" id="lh0-it-ziJ"/>
172+
</connections>
173+
</switch>
174+
</subviews>
175+
<constraints>
176+
<constraint firstItem="F3f-pw-dop" firstAttribute="bottom" secondItem="gLR-rq-R4d" secondAttribute="bottom" id="Jvc-1A-QYa"/>
177+
<constraint firstItem="F3f-pw-dop" firstAttribute="centerY" secondItem="U4c-FS-8CP" secondAttribute="centerY" id="Ma5-K7-xF1"/>
178+
<constraint firstAttribute="bottomMargin" secondItem="F3f-pw-dop" secondAttribute="bottom" constant="1" id="Rfb-HU-agr"/>
179+
<constraint firstItem="F3f-pw-dop" firstAttribute="leading" secondItem="U4c-FS-8CP" secondAttribute="leadingMargin" id="Y3x-cm-fIm"/>
180+
<constraint firstItem="F3f-pw-dop" firstAttribute="top" secondItem="gLR-rq-R4d" secondAttribute="top" id="jUN-3s-xYk"/>
181+
<constraint firstAttribute="trailingMargin" secondItem="gLR-rq-R4d" secondAttribute="trailing" constant="4" id="kZD-ZZ-2cg"/>
182+
</constraints>
183+
</tableViewCellContentView>
184+
</tableViewCell>
154185
</cells>
155186
</tableViewSection>
156187
</sections>
@@ -168,6 +199,7 @@
168199
</navigationItem>
169200
<connections>
170201
<outlet property="realTimeRefreshSwitch" destination="2zq-v3-bPh" id="kvE-mS-Yh5"/>
202+
<outlet property="willDeviceSleepSwitch" destination="gLR-rq-R4d" id="AuF-zh-BHc"/>
171203
</connections>
172204
</tableViewController>
173205
<placeholder placeholderIdentifier="IBFirstResponder" id="RWn-rW-dGD" userLabel="First Responder" sceneMemberID="firstResponder"/>

RedditRealTime/RedditRealTime/Controller Layer/View Controllers/RealTimeSettingsTableViewController.swift

Lines changed: 33 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,23 @@ import UIKit
1111
class RealTimeSettingsTableViewController: UITableViewController {
1212

1313
@IBOutlet weak var realTimeRefreshSwitch: UISwitch!
14+
@IBOutlet weak var willDeviceSleepSwitch: UISwitch!
15+
1416
var redditModel = MetaRedditModel()
1517

1618
var realTimeEnabled: Bool {
1719
get { return UserDefaults.standard.bool(forKey: "RealTimeEnabled") }
1820
set { UserDefaults.standard.set(newValue, forKey: "RealTimeEnabled") }
1921
}
2022

23+
var willDeviceSleep: Bool {
24+
get { return UserDefaults.standard.bool(forKey: "DeviceSleepEnabled") }
25+
set {
26+
UserDefaults.standard.set(newValue, forKey: "DeviceSleepEnabled")
27+
UIApplication.shared.isIdleTimerDisabled = newValue
28+
}
29+
}
30+
2131
fileprivate func checkForRealTime() {
2232
if realTimeEnabled {
2333
realTimeRefreshSwitch.isOn = true
@@ -26,6 +36,14 @@ class RealTimeSettingsTableViewController: UITableViewController {
2636
}
2737
}
2838

39+
fileprivate func checkForDeviceSleep() {
40+
if willDeviceSleep {
41+
willDeviceSleepSwitch.isOn = true
42+
} else {
43+
willDeviceSleepSwitch.isOn = false
44+
}
45+
}
46+
2947
override func viewDidLoad() {
3048
super.viewDidLoad()
3149

@@ -36,7 +54,7 @@ class RealTimeSettingsTableViewController: UITableViewController {
3654
// self.navigationItem.rightBarButtonItem = self.editButtonItem
3755

3856
checkForRealTime()
39-
57+
checkForDeviceSleep()
4058
}
4159

4260
@IBAction func realTimeRefreshSwitchTapped(_ sender: Any) {
@@ -47,72 +65,21 @@ class RealTimeSettingsTableViewController: UITableViewController {
4765
}
4866
}
4967

50-
51-
// MARK: - Table view data source
52-
53-
override func numberOfSections(in tableView: UITableView) -> Int {
54-
// #warning Incomplete implementation, return the number of sections
55-
return 1
56-
}
57-
58-
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
59-
// #warning Incomplete implementation, return the number of rows
60-
return 1
61-
}
62-
63-
/*
64-
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
65-
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
66-
67-
// Configure the cell...
68-
69-
return cell
70-
}
71-
*/
72-
73-
/*
74-
// Override to support conditional editing of the table view.
75-
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
76-
// Return false if you do not want the specified item to be editable.
77-
return true
78-
}
79-
*/
80-
81-
/*
82-
// Override to support editing the table view.
83-
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
84-
if editingStyle == .delete {
85-
// Delete the row from the data source
86-
tableView.deleteRows(at: [indexPath], with: .fade)
87-
} else if editingStyle == .insert {
88-
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
89-
}
90-
}
91-
*/
92-
93-
/*
94-
// Override to support rearranging the table view.
95-
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
96-
97-
}
98-
*/
99-
100-
/*
101-
// Override to support conditional rearranging of the table view.
102-
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
103-
// Return false if you do not want the item to be re-orderable.
104-
return true
68+
@IBAction func willDeviceSleepSwitchTapped(_ sender: Any) {
69+
if willDeviceSleepSwitch.isOn {
70+
presentKeepDisplayOnAlert()
71+
willDeviceSleep = true
72+
} else {
73+
willDeviceSleep = false
74+
}
10575
}
106-
*/
107-
108-
/*
109-
// MARK: - Navigation
110-
111-
// In a storyboard-based application, you will often want to do a little preparation before navigation
112-
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
113-
// Get the new view controller using segue.destination.
114-
// Pass the selected object to the new view controller.
76+
77+
func presentKeepDisplayOnAlert() {
78+
let alert = UIAlertController(title: "Warning", message: "Leaving this option enabled for long periods of time can have an adverse effect on battery life and in rare cases cause display retention. Use at your own risk.", preferredStyle: .alert)
79+
80+
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
81+
82+
self.present(alert, animated: true)
11583
}
116-
*/
11784

11885
}

RedditRealTime/RedditRealTime/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>1.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>9</string>
22+
<string>11</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UILaunchStoryboardName</key>

0 commit comments

Comments
 (0)