Screen lock logic changes. UIAlert updated. Comments added to ConstantsUI

This commit is contained in:
Paul Plant 2021-05-26 19:01:35 +02:00
parent a96dac80ac
commit b43d2b8db4
4 changed files with 32 additions and 11 deletions

View File

@ -12,23 +12,30 @@ enum ConstantsUI {
/// color to use for disclosure indicator in settings views
static let disclosureIndicatorColor = UIColor.gray
/// define the formatting to be used to style the segmented controls on the home screen
/// segmentedControl font size
static let segmentedControlFont = UIFont.systemFont(ofSize: 11)
/// segmentedControl background color
static let segmentedControlBackgroundColor = UIColor.init(white: 0.05, alpha: 1)
/// segmentedControl border width
static let segmentedControlBorderWidth: CGFloat = 0.0
/// segmentedControl font color
static let segmentedControlNormalTextColor = UIColor.gray
/// segmentedControl font color when selected
static let segmentedControlSelectedTextColor = UIColor.black
/// segmentedControl background color when selected
static let segmentedControlSelectedTintColor = UIColor.lightGray
/// colors for lock screen button in toolbar
static let screenLockIconColor = UIColor.gray
/// value label font sizes
/// value label font size when the screen is in normal operation mode
static let valueLabelFontSizeNormal = UIFont.systemFont(ofSize: 90)
/// value label font bigger size when the screen is in screen lock mode
static let valueLabelFontSizeScreenLock = UIFont.systemFont(ofSize: 120)
/// clock label color and font size
/// clock label font color. It shouldn't be too white or it could be distracting at night.
static let clockLabelColor = UIColor.lightGray
/// clock label font size (ideally should be set to the same as the bigger valueLabel font size
static let clockLabelFontSize = UIFont.systemFont(ofSize: 120)
}

View File

@ -4,7 +4,7 @@
"lock" = "Lock";
"unlock" = "Unlock";
"screenlocktitle" = "Screen Lock Enabled";
"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.";
"screenlockinfo" = "This will keep the screen awake until you move to another app 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";

View File

@ -29,7 +29,7 @@ enum Texts_HomeView {
}()
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")
return NSLocalizedString("screenlockinfo", tableName: filename, bundle: Bundle.main, value: "This will keep the screen awake until you move to another app 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 = {

View File

@ -362,7 +362,9 @@ final class RootViewController: UIViewController {
updateLabelsAndChart(overrideApplicationState: true)
// show the statistics view as required. If not, hide it and show the spacer view to keep segmentedControlChartHours separated a bit more away from the main Tab bar
statisticsView.isHidden = !UserDefaults.standard.showStatistics
if !screenIsLocked {
statisticsView.isHidden = !UserDefaults.standard.showStatistics
}
segmentedControlStatisticsDaysView.isHidden = !UserDefaults.standard.showStatistics
optionalSpacerView.isHidden = UserDefaults.standard.showStatistics
@ -2081,6 +2083,9 @@ final class RootViewController: UIViewController {
trace("screen lock : user clicked the lock button", log: self.log, category: ConstantsLog.categoryRootView, type: .info)
// vibrate so that user knows that the keep awake has been activated
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
let alertController = UIAlertController(title: Texts_HomeView.screenLockTitle, message: Texts_HomeView.screenLockInfo, preferredStyle: .alert)
// create buttons
@ -2096,6 +2101,9 @@ final class RootViewController: UIViewController {
trace("screen lock : user clicked the unlock button", log: self.log, category: ConstantsLog.categoryRootView, type: .info)
// vibrate so that user knows that the keep awake has been deactivated
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
// 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)
@ -2109,13 +2117,18 @@ final class RootViewController: UIViewController {
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
// set the value label font size to big
valueLabelOutlet.font = ConstantsUI.valueLabelFontSizeScreenLock
// set the clock label font size to big (force ConstantsUI implementation)
clockLabelOutlet.font = ConstantsUI.clockLabelFontSize
// set clock label color
clockLabelOutlet.textColor = ConstantsUI.clockLabelColor
// set the toolbar button text to "Unlock"
screenLockToolbarButtonOutlet.title = Texts_HomeView.unlockButton
@ -2125,12 +2138,13 @@ final class RootViewController: UIViewController {
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
// set the format for the clock view and update it to show the current time
updateClockView()
// set a timer instance to update the clock view label every second
clockTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateClockView), userInfo: nil, repeats:true)
// prevent screen lock
// prevent screen dim/lock
UIApplication.shared.isIdleTimerDisabled = true
// set the private var so that we can track the screen lock activation within the RootViewController