initial commit of screen lock function
This commit is contained in:
parent
759987add2
commit
447a39ec59
|
@ -20,4 +20,15 @@ enum ConstantsUI {
|
|||
static let segmentedControlSelectedTextColor = UIColor.black
|
||||
static let segmentedControlSelectedTintColor = UIColor.lightGray
|
||||
|
||||
/// colors for lock screen button in toolbar
|
||||
static let screenLockIconColor = UIColor.gray
|
||||
|
||||
/// value label font sizes
|
||||
static let valueLabelFontSizeNormal = UIFont.systemFont(ofSize: 90)
|
||||
static let valueLabelFontSizeScreenLock = UIFont.systemFont(ofSize: 120)
|
||||
|
||||
/// clock label color and font size
|
||||
static let clockLabelColor = UIColor.lightGray
|
||||
static let clockLabelFontSize = UIFont.systemFont(ofSize: 120)
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
|
||||
<capability name="Image references" minToolsVersion="12.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"/>
|
||||
|
@ -21,7 +22,7 @@
|
|||
<rect key="frame" x="0.0" y="44" width="390" height="717"/>
|
||||
<subviews>
|
||||
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" barStyle="black" translucent="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tVG-ML-9xd">
|
||||
<rect key="frame" x="0.0" y="0.0" width="390" height="44"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="390" height="54"/>
|
||||
<items>
|
||||
<barButtonItem title="Snooze" id="f3E-Tt-LBV">
|
||||
<connections>
|
||||
|
@ -39,22 +40,17 @@
|
|||
<action selector="calibrateToolbarButtonAction:" destination="9pv-A4-QxB" id="qNA-1R-UK5"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<barButtonItem title="Lock" id="wfX-50-2w6">
|
||||
<connections>
|
||||
<action selector="screenLockToolbarButtonAction:" destination="9pv-A4-QxB" id="L14-hJ-4a9"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<barButtonItem style="plain" systemItem="flexibleSpace" id="Bnf-FN-LqX"/>
|
||||
</items>
|
||||
</toolbar>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="C16-NQ-F1Y">
|
||||
<rect key="frame" x="0.0" y="44" width="390" height="541"/>
|
||||
<rect key="frame" x="0.0" y="54" width="390" height="391"/>
|
||||
<subviews>
|
||||
<label opaque="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="---" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="We3-bN-ffR">
|
||||
<rect key="frame" x="137" y="25.000000000000007" width="116" height="107.66666666666669"/>
|
||||
<gestureRecognizers/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="90"/>
|
||||
<color key="textColor" systemColor="systemGreenColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<connections>
|
||||
<outletCollection property="gestureRecognizers" destination="tYH-fG-Lky" appends="YES" id="IyM-sF-P0i"/>
|
||||
</connections>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" text="x mins ago" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uyn-2k-K74">
|
||||
<rect key="frame" x="10" y="0.0" width="102" height="26.333333333333332"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="22"/>
|
||||
|
@ -67,33 +63,53 @@
|
|||
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="---" textAlignment="center" lineBreakMode="clip" baselineAdjustment="alignBaselines" minimumScaleFactor="0.20000000000000001" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="We3-bN-ffR">
|
||||
<rect key="frame" x="20" y="25.000000000000007" width="350" height="107.66666666666669"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<gestureRecognizers/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" relation="lessThanOrEqual" constant="140" id="132-3f-vQI"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="90"/>
|
||||
<color key="textColor" systemColor="systemGreenColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0nE-AX-r0w" customClass="BloodGlucoseChartView" customModule="xdrip" customModuleProvider="target">
|
||||
<rect key="frame" x="10" y="132.66666666666666" width="380" height="408.33333333333337"/>
|
||||
<rect key="frame" x="10" y="132.66666666666666" width="380" height="258.33333333333337"/>
|
||||
<gestureRecognizers/>
|
||||
<connections>
|
||||
<outletCollection property="gestureRecognizers" destination="Fi5-iu-Usk" appends="YES" id="Rkv-hK-sLH"/>
|
||||
<outletCollection property="gestureRecognizers" destination="axt-dD-sCA" appends="YES" id="Bxm-Qp-L3P"/>
|
||||
</connections>
|
||||
</view>
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Wbt-Y0-6PL">
|
||||
<rect key="frame" x="127" y="0.6666666666666643" width="24" height="24.333333333333336"/>
|
||||
<imageReference key="image" image="lock.fill" catalog="system" symbolScale="default"/>
|
||||
<preferredSymbolConfiguration key="preferredSymbolConfiguration" configurationType="pointSize" pointSize="22" scale="default"/>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="7Wo-wd-80o" secondAttribute="trailing" constant="10" id="28x-56-97G"/>
|
||||
<constraint firstAttribute="trailing" secondItem="0nE-AX-r0w" secondAttribute="trailing" id="4Kt-zl-bbl"/>
|
||||
<constraint firstItem="Wbt-Y0-6PL" firstAttribute="leading" secondItem="uyn-2k-K74" secondAttribute="trailing" constant="15" id="8Us-MZ-OGv"/>
|
||||
<constraint firstAttribute="bottom" secondItem="0nE-AX-r0w" secondAttribute="bottom" id="C61-10-Kdo"/>
|
||||
<constraint firstItem="We3-bN-ffR" firstAttribute="leading" secondItem="C16-NQ-F1Y" secondAttribute="leading" constant="20" id="DjD-bz-O8N"/>
|
||||
<constraint firstItem="Wbt-Y0-6PL" firstAttribute="centerY" secondItem="uyn-2k-K74" secondAttribute="centerY" id="ESH-24-icv"/>
|
||||
<constraint firstAttribute="trailing" secondItem="We3-bN-ffR" secondAttribute="trailing" constant="20" id="LWb-Rj-dfs"/>
|
||||
<constraint firstItem="uyn-2k-K74" firstAttribute="top" secondItem="C16-NQ-F1Y" secondAttribute="top" id="Luq-xy-Lzu"/>
|
||||
<constraint firstItem="7Wo-wd-80o" firstAttribute="centerY" secondItem="uyn-2k-K74" secondAttribute="centerY" id="Qpl-lB-gwg"/>
|
||||
<constraint firstItem="0nE-AX-r0w" firstAttribute="leading" secondItem="C16-NQ-F1Y" secondAttribute="leading" constant="10" id="e97-Zw-ipJ"/>
|
||||
<constraint firstItem="0nE-AX-r0w" firstAttribute="top" secondItem="We3-bN-ffR" secondAttribute="bottom" id="emW-PI-WrN"/>
|
||||
<constraint firstItem="uyn-2k-K74" firstAttribute="leading" secondItem="C16-NQ-F1Y" secondAttribute="leading" constant="10" id="mYE-7c-E2l"/>
|
||||
<constraint firstItem="We3-bN-ffR" firstAttribute="centerX" secondItem="C16-NQ-F1Y" secondAttribute="centerX" id="vhA-TS-y2Z"/>
|
||||
<constraint firstAttribute="bottom" secondItem="0nE-AX-r0w" secondAttribute="bottom" id="w6l-ym-Sl2"/>
|
||||
<constraint firstItem="We3-bN-ffR" firstAttribute="top" secondItem="C16-NQ-F1Y" secondAttribute="top" constant="25" id="xak-Qv-s0j"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="x9u-yg-PXE" userLabel="segmentControlsView">
|
||||
<rect key="frame" x="0.0" y="585" width="390" height="34"/>
|
||||
<rect key="frame" x="0.0" y="445" width="390" height="34"/>
|
||||
<subviews>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="Nhe-d1-2e7">
|
||||
<rect key="frame" x="10" y="4.6666666666666288" width="370" height="25"/>
|
||||
<rect key="frame" x="10" y="4.6666666666666856" width="370" height="25"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qG7-Ub-mzA">
|
||||
<rect key="frame" x="0.0" y="0.0" width="194" height="25"/>
|
||||
|
@ -153,14 +169,14 @@
|
|||
</constraints>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="P8h-sd-0mD">
|
||||
<rect key="frame" x="0.0" y="619" width="390" height="8"/>
|
||||
<rect key="frame" x="0.0" y="479" width="390" height="8"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="8" id="j1I-lJ-Iyl"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<view userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MtJ-rx-OB9" userLabel="Statistics View">
|
||||
<rect key="frame" x="0.0" y="627" width="390" height="90"/>
|
||||
<rect key="frame" x="0.0" y="487" width="390" height="90"/>
|
||||
<subviews>
|
||||
<stackView opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="ZF3-Ii-L0R">
|
||||
<rect key="frame" x="8" y="9" width="374" height="72"/>
|
||||
|
@ -385,6 +401,25 @@
|
|||
<constraint firstAttribute="trailingMargin" secondItem="ZF3-Ii-L0R" secondAttribute="trailing" id="x6Q-4Q-45y"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ETk-QH-u1x">
|
||||
<rect key="frame" x="0.0" y="577" width="390" height="140"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="--:--" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="rSC-H3-vfk">
|
||||
<rect key="frame" x="20" y="-1.6666666666666288" width="350" height="143.33333333333334"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="120"/>
|
||||
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstItem="rSC-H3-vfk" firstAttribute="centerY" secondItem="ETk-QH-u1x" secondAttribute="centerY" id="851-Pv-rd6"/>
|
||||
<constraint firstItem="rSC-H3-vfk" firstAttribute="leading" secondItem="ETk-QH-u1x" secondAttribute="leading" constant="20" id="MBM-cg-FkS"/>
|
||||
<constraint firstAttribute="height" constant="140" id="QZb-1f-NFb"/>
|
||||
<constraint firstItem="rSC-H3-vfk" firstAttribute="centerX" secondItem="ETk-QH-u1x" secondAttribute="centerX" id="fvi-mi-iHT"/>
|
||||
<constraint firstAttribute="trailing" secondItem="rSC-H3-vfk" secondAttribute="trailing" constant="20" id="rYW-nQ-H74"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="x9u-yg-PXE" firstAttribute="top" secondItem="C16-NQ-F1Y" secondAttribute="bottom" id="WZ6-cn-zwk"/>
|
||||
|
@ -411,6 +446,8 @@
|
|||
<outlet property="chartLongPressGestureRecognizerOutlet" destination="axt-dD-sCA" id="mUZ-cu-720"/>
|
||||
<outlet property="chartOutlet" destination="0nE-AX-r0w" id="ivs-se-S3b"/>
|
||||
<outlet property="chartPanGestureRecognizerOutlet" destination="Fi5-iu-Usk" id="zn5-wp-DKt"/>
|
||||
<outlet property="clockLabelOutlet" destination="rSC-H3-vfk" id="kqu-7I-7VN"/>
|
||||
<outlet property="clockView" destination="ETk-QH-u1x" id="XuQ-dY-93L"/>
|
||||
<outlet property="cvTitleLabelOutlet" destination="PZI-Ln-kfh" id="IKV-zy-dNM"/>
|
||||
<outlet property="diffLabelOutlet" destination="7Wo-wd-80o" id="nnn-w9-1sX"/>
|
||||
<outlet property="highLabelOutlet" destination="Xlz-6g-zzD" id="DyX-x0-PwZ"/>
|
||||
|
@ -426,9 +463,12 @@
|
|||
<outlet property="pieChartLabelOutlet" destination="c1z-wL-Eye" id="tBn-RJ-oiQ"/>
|
||||
<outlet property="pieChartOutlet" destination="vm5-IB-4CY" id="t8a-2d-t5l"/>
|
||||
<outlet property="preSnoozeToolbarButtonOutlet" destination="f3E-Tt-LBV" id="HyH-Pn-tQ6"/>
|
||||
<outlet property="screenLockImageOutlet" destination="Wbt-Y0-6PL" id="TmY-3s-V27"/>
|
||||
<outlet property="screenLockToolbarButtonOutlet" destination="wfX-50-2w6" id="r70-by-pce"/>
|
||||
<outlet property="segmentedControlChartHours" destination="9LS-Vp-uGd" id="ymu-eS-Vpb"/>
|
||||
<outlet property="segmentedControlStatisticsDays" destination="Xuy-hn-ozf" id="vOk-4p-M8g"/>
|
||||
<outlet property="segmentedControlStatisticsDaysView" destination="qG7-Ub-mzA" id="shD-NU-LBm"/>
|
||||
<outlet property="segmentedControlsView" destination="x9u-yg-PXE" id="U0O-Rt-EUR"/>
|
||||
<outlet property="sensorToolbarButtonOutlet" destination="ZIM-Wf-bUy" id="kjL-rX-6ZV"/>
|
||||
<outlet property="statisticsView" destination="MtJ-rx-OB9" id="u5w-qN-5Tq"/>
|
||||
<outlet property="timePeriodLabelOutlet" destination="On3-dy-RgB" id="hAe-Kx-vnM"/>
|
||||
|
@ -436,11 +476,7 @@
|
|||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="W5J-7L-Pyd" sceneMemberID="firstResponder"/>
|
||||
<pongPressGestureRecognizer allowableMovement="10" minimumPressDuration="0.90000000000000002" id="tYH-fG-Lky">
|
||||
<connections>
|
||||
<action selector="valueLabelLongPressGestureRecognizerAction:" destination="9pv-A4-QxB" id="NlL-kQ-dpZ"/>
|
||||
</connections>
|
||||
</pongPressGestureRecognizer>
|
||||
<pongPressGestureRecognizer allowableMovement="10" minimumPressDuration="0.90000000000000002" id="tYH-fG-Lky"/>
|
||||
<panGestureRecognizer minimumNumberOfTouches="1" id="Fi5-iu-Usk">
|
||||
<connections>
|
||||
<action selector="chartPanGestureRecognizerAction:" destination="9pv-A4-QxB" id="NUY-gV-rdx"/>
|
||||
|
@ -1515,6 +1551,7 @@
|
|||
<image name="Bluetooth" width="30" height="30"/>
|
||||
<image name="Home" width="30" height="30"/>
|
||||
<image name="Settings" width="30" height="30"/>
|
||||
<image name="lock.fill" catalog="system" width="128" height="128"/>
|
||||
<systemColor name="systemGrayColor">
|
||||
<color red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</systemColor>
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
"presnooze" = "Snooze";
|
||||
"sensor" = "Sensor";
|
||||
"calibrate" = "Calibrate";
|
||||
"lock" = "Lock";
|
||||
"unlock" = "Unlock";
|
||||
"screenlocktitle" = "Enable Screen Lock?";
|
||||
"screenlockinfo" = "Click OK to enable the screen lock function. This will keep the screen awake until you move to another screen or click Unlock.\r\n\nIt is recommended that you keep the phone plugged into a charger to prevent battery drain.";
|
||||
"statusactiontitle" = "Status";
|
||||
"scanbluetoothdeviceactiontitle" = "Scan for Transmitter";
|
||||
"forgetbluetoothdeviceactiontitle" = "Forget Transmitter";
|
||||
|
|
|
@ -16,6 +16,22 @@ enum Texts_HomeView {
|
|||
return NSLocalizedString("calibrate", tableName: filename, bundle: Bundle.main, value: "Calibrate", comment: "Text in button on home screen")
|
||||
}()
|
||||
|
||||
static let lockButton:String = {
|
||||
return NSLocalizedString("lock", tableName: filename, bundle: Bundle.main, value: "Lock", comment: "Text in button on home screen")
|
||||
}()
|
||||
|
||||
static let unlockButton:String = {
|
||||
return NSLocalizedString("unlock", tableName: filename, bundle: Bundle.main, value: "Unlock", comment: "Text in button on home screen")
|
||||
}()
|
||||
|
||||
static let screenLockTitle:String = {
|
||||
return NSLocalizedString("screenlocktitle", tableName: filename, bundle: Bundle.main, value: "Enable Screen Lock?", comment: "Screen Lock Title")
|
||||
}()
|
||||
|
||||
static let screenLockInfo:String = {
|
||||
return NSLocalizedString("screenlockinfo", tableName: filename, bundle: Bundle.main, value: "Click OK to enable the screen lock function. This will keep the screen awake until you move to another screen or click Unlock.\r\n\nIt is recommended that you keep the phone plugged into a charger to prevent battery drain.", comment: "Info message to explain screen lock function")
|
||||
}()
|
||||
|
||||
static let statusActionTitle:String = {
|
||||
return NSLocalizedString("statusactiontitle", tableName: filename, bundle: Bundle.main, value: "Status", comment: "when user clicks transmitterButton, this is the first action, to show the status")
|
||||
}()
|
||||
|
|
|
@ -37,7 +37,7 @@ final class RootViewController: UIViewController {
|
|||
|
||||
} else {
|
||||
|
||||
trace("calibration : user clicks calibrate button", log: self.log, category: ConstantsLog.categoryRootView, type: .info)
|
||||
trace("calibration : user clicked the calibrate button", log: self.log, category: ConstantsLog.categoryRootView, type: .info)
|
||||
|
||||
requestCalibration(userRequested: true)
|
||||
}
|
||||
|
@ -45,18 +45,57 @@ final class RootViewController: UIViewController {
|
|||
}
|
||||
|
||||
|
||||
@IBOutlet weak var screenLockToolbarButtonOutlet: UIBarButtonItem!
|
||||
|
||||
@IBAction func screenLockToolbarButtonAction(_ sender: UIBarButtonItem) {
|
||||
|
||||
if !screenIsLocked {
|
||||
|
||||
trace("screen lock : user clicked the lock button", log: self.log, category: ConstantsLog.categoryRootView, type: .info)
|
||||
|
||||
let alertController = UIAlertController(title: Texts_HomeView.screenLockTitle, message: Texts_HomeView.screenLockInfo, preferredStyle: .alert)
|
||||
|
||||
// create buttons
|
||||
let OKAction = UIAlertAction(title: Texts_Common.Ok, style: .default) { (action:UIAlertAction!) in self.screenLockUpdate(enabled: true) }
|
||||
|
||||
let cancelAction = UIAlertAction(title: Texts_Common.Cancel, style: .cancel) { (action:UIAlertAction!) in self.screenLockUpdate(enabled: false) }
|
||||
|
||||
// add buttons to the alert
|
||||
alertController.addAction(OKAction)
|
||||
alertController.addAction(cancelAction)
|
||||
|
||||
// show alert
|
||||
self.present(alertController, animated: true, completion:nil)
|
||||
|
||||
} else {
|
||||
|
||||
trace("screen lock : user clicked the unlock button", log: self.log, category: ConstantsLog.categoryRootView, type: .info)
|
||||
|
||||
// this means the user has clicked the button whilst the screen look in already in place so let's turn the function off
|
||||
self.screenLockUpdate(enabled: false)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// outlet for label that shows how many minutes ago and so on
|
||||
@IBOutlet weak var minutesLabelOutlet: UILabel!
|
||||
|
||||
/// outlet for label that shows difference with previous reading
|
||||
@IBOutlet weak var diffLabelOutlet: UILabel!
|
||||
|
||||
/// outlet for the image of the screen lock symbol
|
||||
@IBOutlet weak var screenLockImageOutlet: UIImageView!
|
||||
|
||||
/// outlet for label that shows the current reading
|
||||
@IBOutlet weak var valueLabelOutlet: UILabel!
|
||||
|
||||
/// outlet for chart
|
||||
@IBOutlet weak var chartOutlet: BloodGlucoseChartView!
|
||||
|
||||
@IBOutlet weak var segmentedControlsView: UIView!
|
||||
|
||||
/// outlets for chart time period selector
|
||||
@IBOutlet weak var segmentedControlChartHours: UISegmentedControl!
|
||||
|
||||
|
@ -105,6 +144,7 @@ final class RootViewController: UIViewController {
|
|||
|
||||
}
|
||||
|
||||
/// an optional spacer view that we use to separate the segmented controls from the nav bar if the statistics are not shown
|
||||
@IBOutlet weak var optionalSpacerView: UIView!
|
||||
|
||||
/// outlets for statistics view
|
||||
|
@ -128,10 +168,11 @@ final class RootViewController: UIViewController {
|
|||
@IBOutlet weak var timePeriodLabelOutlet: UILabel!
|
||||
@IBOutlet weak var activityMonitorOutlet: UIActivityIndicatorView!
|
||||
|
||||
/// user long pressed the value label
|
||||
@IBAction func valueLabelLongPressGestureRecognizerAction(_ sender: UILongPressGestureRecognizer) {
|
||||
valueLabelLongPressed(sender)
|
||||
}
|
||||
|
||||
/// clock view
|
||||
@IBOutlet weak var clockView: UIView!
|
||||
@IBOutlet weak var clockLabelOutlet: UILabel!
|
||||
|
||||
|
||||
@IBAction func chartPanGestureRecognizerAction(_ sender: UIPanGestureRecognizer) {
|
||||
|
||||
|
@ -310,6 +351,16 @@ final class RootViewController: UIViewController {
|
|||
/// when was the last notification created with bgreading, setting to 1 1 1970 initially to avoid having to unwrap it
|
||||
private var timeStampLastBGNotification = Date(timeIntervalSince1970: 0)
|
||||
|
||||
/// to hold the current state of the screen keep-alive
|
||||
private var screenIsLocked: Bool = false
|
||||
|
||||
/// date formatter for the clock view
|
||||
private var clockDateFormatter = DateFormatter()
|
||||
|
||||
/// initiate a Timer object that we will use later to keep the clock view updated if the user activates the screen lock
|
||||
private var clockTimer: Timer?
|
||||
|
||||
|
||||
// MARK: - overriden functions
|
||||
|
||||
// set the status bar content colour to light to match new darker theme
|
||||
|
@ -324,11 +375,13 @@ final class RootViewController: UIViewController {
|
|||
|
||||
}
|
||||
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
|
||||
// update the screen lock status
|
||||
screenLockUpdate(enabled: false)
|
||||
|
||||
// viewWillAppear when user switches eg from Settings Tab to Home Tab - latest reading value needs to be shown on the view, and also update minutes ago etc.
|
||||
updateLabelsAndChart(overrideApplicationState: true)
|
||||
|
@ -347,8 +400,6 @@ final class RootViewController: UIViewController {
|
|||
// update statistics related outlets
|
||||
updateStatistics(animatePieChart: true, overrideApplicationState: true)
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
|
@ -356,11 +407,27 @@ final class RootViewController: UIViewController {
|
|||
// remove titles from tabbar items
|
||||
self.tabBarController?.cleanTitles()
|
||||
|
||||
// update the screen lock status
|
||||
//screenLockUpdate(enabled: false)
|
||||
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// set up the clock view
|
||||
clockDateFormatter.dateStyle = .none
|
||||
clockDateFormatter.timeStyle = .short
|
||||
clockDateFormatter.dateFormat = "HH:mm"
|
||||
clockLabelOutlet.font = ConstantsUI.clockLabelFontSize
|
||||
clockLabelOutlet.textColor = ConstantsUI.clockLabelColor
|
||||
|
||||
|
||||
// ensure the screen lock icon color as per constants file and also the screen layout
|
||||
screenLockImageOutlet.tintColor = ConstantsUI.screenLockIconColor
|
||||
screenLockUpdate(enabled: false)
|
||||
|
||||
|
||||
// this is to force update of userdefaults that are also stored in the shared user defaults
|
||||
// these are used by the today widget. After a year or so (september 2021) this can all be deleted
|
||||
UserDefaults.standard.urgentLowMarkValueInUserChosenUnit = UserDefaults.standard.urgentLowMarkValueInUserChosenUnit
|
||||
|
@ -556,7 +623,7 @@ final class RootViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
|
||||
// setup self as delegate for tabbarcontrolelr
|
||||
// setup self as delegate for tabbarcontroller
|
||||
self.tabBarController?.delegate = self
|
||||
|
||||
// setup the timer logic for updating the view regularly
|
||||
|
@ -565,9 +632,10 @@ final class RootViewController: UIViewController {
|
|||
// setup AVAudioSession
|
||||
setupAVAudioSession()
|
||||
|
||||
// user may have long pressed the value label, so the screen will not lock, when going back to background, set isIdleTimerDisabled back to false
|
||||
// user may have activated the screen lock function so that the screen stays open, when going back to background, set isIdleTimerDisabled back to false and update the UI so that it's ready to come to foreground when required.
|
||||
ApplicationManager.shared.addClosureToRunWhenAppDidEnterBackground(key: applicationManagerKeyIsIdleTimerDisabled, closure: {
|
||||
UIApplication.shared.isIdleTimerDisabled = false
|
||||
self.screenLockUpdate(enabled: false)
|
||||
})
|
||||
|
||||
// add tracing when app goes from foreground to background
|
||||
|
@ -1813,18 +1881,7 @@ final class RootViewController: UIViewController {
|
|||
|
||||
}
|
||||
|
||||
private func valueLabelLongPressed(_ sender: UILongPressGestureRecognizer) {
|
||||
if sender.state == .began {
|
||||
|
||||
// vibrate so that user knows the long press is detected
|
||||
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
||||
|
||||
// prevent screen lock
|
||||
UIApplication.shared.isIdleTimerDisabled = true
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func getCGMTransmitterDeviceName(for cgmTransmitter: CGMTransmitter) -> String? {
|
||||
|
||||
if let bluetoothTransmitter = cgmTransmitter as? BluetoothTransmitter {
|
||||
|
@ -2045,8 +2102,77 @@ final class RootViewController: UIViewController {
|
|||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
@objc private func updateClockView() {
|
||||
self.clockLabelOutlet.text = clockDateFormatter.string(from: Date())
|
||||
}
|
||||
|
||||
|
||||
// MARK: - public helper functions
|
||||
|
||||
// this function will run when the user wants the screen to lock, or whenever the view appears and it will set up the screen correctly for each mode. This must be kept public so that the App Delegate can access it when the app comes to foreground
|
||||
func screenLockUpdate(enabled: Bool = true) {
|
||||
|
||||
|
||||
if enabled {
|
||||
|
||||
// vibrate so that user knows that the keep awake has been activated
|
||||
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
||||
|
||||
// set screen lock icon color to value defined in constants file
|
||||
screenLockImageOutlet.isHidden = false
|
||||
valueLabelOutlet.font = ConstantsUI.valueLabelFontSizeScreenLock
|
||||
|
||||
// set the toolbar button text to "Unlock"
|
||||
screenLockToolbarButtonOutlet.title = Texts_HomeView.unlockButton
|
||||
|
||||
// de-clutter the screen. Hide the statistics view, controls and show the clock view
|
||||
statisticsView.isHidden = true
|
||||
segmentedControlsView.isHidden = true
|
||||
optionalSpacerView.isHidden = true
|
||||
clockView.isHidden = false
|
||||
|
||||
// set the format for the clock view, update it once and then and update the label every second after that
|
||||
updateClockView()
|
||||
|
||||
clockTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateClockView), userInfo: nil, repeats:true)
|
||||
|
||||
// prevent screen lock
|
||||
UIApplication.shared.isIdleTimerDisabled = true
|
||||
|
||||
// set the private var so that we can track the screen lock activation within the RootViewController
|
||||
screenIsLocked = true
|
||||
|
||||
trace("screen lock : screen lock / keep-awake enabled", log: self.log, category: ConstantsLog.categoryRootView, type: .info)
|
||||
|
||||
} else {
|
||||
|
||||
// hide the lock image, but the value font size back to normal
|
||||
screenLockImageOutlet.isHidden = true
|
||||
valueLabelOutlet.font = ConstantsUI.valueLabelFontSizeNormal
|
||||
|
||||
// set the toolbar button text to "Lock"
|
||||
screenLockToolbarButtonOutlet.title = Texts_HomeView.lockButton
|
||||
|
||||
// hide
|
||||
statisticsView.isHidden = !UserDefaults.standard.showStatistics
|
||||
segmentedControlsView.isHidden = false
|
||||
optionalSpacerView.isHidden = UserDefaults.standard.showStatistics
|
||||
clockView.isHidden = true
|
||||
|
||||
// destroy the timer instance so that it doesn't keep using resources and keeping the screen on
|
||||
clockTimer?.invalidate()
|
||||
|
||||
// make sure that the screen lock is deactivated
|
||||
UIApplication.shared.isIdleTimerDisabled = false
|
||||
|
||||
trace("screen lock / keep-awake disabled", log: self.log, category: ConstantsLog.categoryRootView, type: .info)
|
||||
|
||||
screenIsLocked = false
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue