@@ -11,13 +11,23 @@ import UIKit
1111class 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}
0 commit comments