Segmented control styling now move to ConstantsUI.swift. Statistics days to use also moved to Home Screen

This commit is contained in:
Paul Plant 2021-05-06 13:28:04 +02:00
parent 4c1b747016
commit f1a377dac0
3 changed files with 149 additions and 33 deletions

View File

@ -12,4 +12,12 @@ 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
static let segmentedControlFont = UIFont.systemFont(ofSize: 10)
static let segmentedControlBackgroundColor = UIColor.init(white: 0.05, alpha: 1)
static let segmentedControlBorderWidth: CGFloat = 0.0
static let segmentedControlNormalTextColor = UIColor.gray
static let segmentedControlSelectedTextColor = UIColor.black
static let segmentedControlSelectedTintColor = UIColor.lightGray
}

View File

@ -101,32 +101,61 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="x9u-yg-PXE">
<rect key="frame" x="0.0" y="593" width="390" height="34"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="Nhe-d1-2e7">
<rect key="frame" x="189" y="6" width="191" height="22"/>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="Nhe-d1-2e7">
<rect key="frame" x="10" y="6" width="370" height="22"/>
<subviews>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" apportionsSegmentWidthsByContent="YES" segmentControlStyle="plain" translatesAutoresizingMaskIntoConstraints="NO" id="9LS-Vp-uGd">
<rect key="frame" x="0.0" y="0.0" width="191" height="23"/>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qG7-Ub-mzA">
<rect key="frame" x="0.0" y="0.0" width="194" height="22"/>
<subviews>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" apportionsSegmentWidthsByContent="YES" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="Xuy-hn-ozf">
<rect key="frame" x="0.0" y="0.0" width="194" height="23"/>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<segments>
<segment title="Today"/>
<segment title="1d"/>
<segment title="7d"/>
<segment title="30d"/>
<segment title="90d"/>
</segments>
<color key="selectedSegmentTintColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<action selector="statisticsDaysChanged:" destination="9pv-A4-QxB" eventType="valueChanged" id="Bjo-mU-B96"/>
</connections>
</segmentedControl>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="22" id="B42-pC-AfL"/>
<constraint firstAttribute="trailing" secondItem="Xuy-hn-ozf" secondAttribute="trailing" id="QWd-g8-loY"/>
<constraint firstItem="Xuy-hn-ozf" firstAttribute="leading" secondItem="qG7-Ub-mzA" secondAttribute="leading" id="iqj-Qp-UZ4"/>
<constraint firstItem="Xuy-hn-ozf" firstAttribute="top" secondItem="qG7-Ub-mzA" secondAttribute="top" id="jtW-gF-x0v"/>
<constraint firstAttribute="bottom" secondItem="Xuy-hn-ozf" secondAttribute="bottom" id="l9p-sL-yv3"/>
</constraints>
</view>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" apportionsSegmentWidthsByContent="YES" segmentControlStyle="plain" selectedSegmentIndex="1" translatesAutoresizingMaskIntoConstraints="NO" id="9LS-Vp-uGd">
<rect key="frame" x="214" y="0.0" width="156" height="23"/>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<segments>
<segment title="2h"/>
<segment title="4h"/>
<segment title="3h"/>
<segment title="6h"/>
<segment title="12h"/>
<segment title="24h"/>
</segments>
<color key="selectedSegmentTintColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<action selector="indexChanged:" destination="9pv-A4-QxB" eventType="valueChanged" id="wIA-Nf-ke2"/>
<action selector="chartHoursChanged:" destination="9pv-A4-QxB" eventType="valueChanged" id="u3m-7t-iOS"/>
</connections>
</segmentedControl>
</subviews>
<constraints>
<constraint firstItem="qG7-Ub-mzA" firstAttribute="top" secondItem="Nhe-d1-2e7" secondAttribute="top" id="MjJ-nf-Zvr"/>
<constraint firstAttribute="height" constant="22" id="QmU-pO-lNN"/>
<constraint firstItem="qG7-Ub-mzA" firstAttribute="leading" secondItem="Nhe-d1-2e7" secondAttribute="leading" id="aMu-dw-PHP"/>
<constraint firstAttribute="bottom" secondItem="qG7-Ub-mzA" secondAttribute="bottom" id="kLZ-yE-xmp"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" white="0.050000000000000003" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="Nhe-d1-2e7" firstAttribute="leading" secondItem="x9u-yg-PXE" secondAttribute="leading" constant="10" id="JQW-9I-ceH"/>
<constraint firstAttribute="trailing" secondItem="Nhe-d1-2e7" secondAttribute="trailing" constant="10" id="R8E-s8-2gf"/>
<constraint firstAttribute="height" constant="34" id="t1J-yU-usJ"/>
<constraint firstItem="Nhe-d1-2e7" firstAttribute="centerY" secondItem="x9u-yg-PXE" secondAttribute="centerY" id="vZU-6X-8GM"/>
@ -344,7 +373,7 @@
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" white="0.050000000000000003" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="ZF3-Ii-L0R" firstAttribute="centerY" secondItem="MtJ-rx-OB9" secondAttribute="centerY" id="ThK-6J-pNb"/>
<constraint firstItem="ZF3-Ii-L0R" firstAttribute="leading" secondItem="MtJ-rx-OB9" secondAttribute="leadingMargin" id="pfd-vL-nLE"/>
@ -392,6 +421,8 @@
<outlet property="pieChartOutlet" destination="vm5-IB-4CY" id="t8a-2d-t5l"/>
<outlet property="preSnoozeButtonOutlet" destination="fSY-nc-amN" id="T25-Z1-3Ad"/>
<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="sensorButtonOutlet" destination="zWo-AR-qJE" id="uuB-WI-JKe"/>
<outlet property="statisticsView" destination="MtJ-rx-OB9" id="u5w-qN-5Tq"/>
<outlet property="timePeriodLabelOutlet" destination="On3-dy-RgB" id="hAe-Kx-vnM"/>

View File

@ -59,27 +59,52 @@ final class RootViewController: UIViewController {
/// outlets for chart time period selector
@IBOutlet weak var segmentedControlChartHours: UISegmentedControl!
@IBAction func indexChanged(_ sender: Any) {
@IBAction func chartHoursChanged(_ sender: Any) {
// update the chart period in hours
switch segmentedControlChartHours.selectedSegmentIndex
{
case 0:
UserDefaults.standard.chartWidthInHours = 2
UserDefaults.standard.chartWidthInHours = 3
case 1:
UserDefaults.standard.chartWidthInHours = 4
UserDefaults.standard.chartWidthInHours = 5
case 2:
UserDefaults.standard.chartWidthInHours = 6
case 3:
UserDefaults.standard.chartWidthInHours = 12
case 4:
case 3:
UserDefaults.standard.chartWidthInHours = 24
default:
break
}
}
// create a view outlet (with the statistics day control inside) so that we can show/hide it as necessary
@IBOutlet weak var segmentedControlStatisticsDaysView: UIView!
@IBOutlet weak var segmentedControlStatisticsDays: UISegmentedControl!
@IBAction func statisticsDaysChanged(_ sender: Any) {
// update the days to use for statistics calculations
switch segmentedControlStatisticsDays.selectedSegmentIndex
{
case 0:
UserDefaults.standard.daysToUseStatistics = 0
case 1:
UserDefaults.standard.daysToUseStatistics = 1
case 2:
UserDefaults.standard.daysToUseStatistics = 7
case 3:
UserDefaults.standard.daysToUseStatistics = 30
case 4:
UserDefaults.standard.daysToUseStatistics = 90
default:
break
}
}
/// outlets for statistics view
@IBOutlet weak var statisticsView: UIView!
@IBOutlet weak var pieChartOutlet: PieChart!
@ -307,6 +332,7 @@ final class RootViewController: UIViewController {
// show the statistics view as required. If not, hide it
statisticsView.isHidden = !UserDefaults.standard.showStatistics
segmentedControlStatisticsDaysView.isHidden = !UserDefaults.standard.showStatistics
// update statistics related outlets
updateStatistics(animatePieChart: true, overrideApplicationState: true)
@ -333,39 +359,82 @@ final class RootViewController: UIViewController {
UserDefaults.standard.highMarkValueInUserChosenUnit = UserDefaults.standard.highMarkValueInUserChosenUnit
UserDefaults.standard.bloodGlucoseUnitIsMgDl = UserDefaults.standard.bloodGlucoseUnitIsMgDl
// update the segmented control of the chart hours
switch UserDefaults.standard.chartWidthInHours
{
case 2:
case 3:
segmentedControlChartHours.selectedSegmentIndex = 0
case 4:
segmentedControlChartHours.selectedSegmentIndex = 1
case 6:
segmentedControlChartHours.selectedSegmentIndex = 2
segmentedControlChartHours.selectedSegmentIndex = 1
case 12:
segmentedControlChartHours.selectedSegmentIndex = 3
segmentedControlChartHours.selectedSegmentIndex = 2
case 24:
segmentedControlChartHours.selectedSegmentIndex = 4
segmentedControlChartHours.selectedSegmentIndex = 3
default:
break
}
// update the segmented control of the statistics days
switch UserDefaults.standard.daysToUseStatistics
{
case 0:
segmentedControlStatisticsDays.selectedSegmentIndex = 0
case 1:
segmentedControlStatisticsDays.selectedSegmentIndex = 1
case 7:
segmentedControlStatisticsDays.selectedSegmentIndex = 2
case 30:
segmentedControlStatisticsDays.selectedSegmentIndex = 3
case 90:
segmentedControlStatisticsDays.selectedSegmentIndex = 4
default:
break
}
//segmentedControlChartHours.setTitle("hello", forSegmentAt: 1)
// format the segmented control of the chart hours if possible (should normally be ok)
if #available(iOS 13.0, *) {
// set the basic formatting. We basically want it to dissapear into the background
segmentedControlChartHours.backgroundColor = ConstantsUI.segmentedControlBackgroundColor
segmentedControlChartHours.tintColor = ConstantsUI.segmentedControlBackgroundColor
segmentedControlChartHours.layer.borderWidth = ConstantsUI.segmentedControlBorderWidth
// format the unselected segments
segmentedControlChartHours.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: ConstantsUI.segmentedControlNormalTextColor, NSAttributedString.Key.font: ConstantsUI.segmentedControlFont], for:.normal)
// format the selected segment
segmentedControlChartHours.selectedSegmentTintColor = ConstantsUI.segmentedControlSelectedTintColor
segmentedControlChartHours.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: ConstantsUI.segmentedControlSelectedTextColor, NSAttributedString.Key.font: ConstantsUI.segmentedControlFont], for:.selected)
}
// format the segmented control of the chart hours if possible (should normally be ok)
if #available(iOS 13.0, *) {
// set the basic formatting. We basically want it to dissapear into the background
segmentedControlChartHours.backgroundColor = UIColor.black
segmentedControlChartHours.tintColor = UIColor.black
segmentedControlChartHours.layer.borderWidth = 0
segmentedControlStatisticsDays.backgroundColor = ConstantsUI.segmentedControlBackgroundColor
segmentedControlStatisticsDays.tintColor = ConstantsUI.segmentedControlBackgroundColor
segmentedControlStatisticsDays.layer.borderWidth = ConstantsUI.segmentedControlBorderWidth
// format the unselected segments
segmentedControlChartHours.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.gray], for:.normal)
segmentedControlStatisticsDays.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: ConstantsUI.segmentedControlNormalTextColor, NSAttributedString.Key.font: ConstantsUI.segmentedControlFont], for:.normal)
// format the selected segment
segmentedControlChartHours.selectedSegmentTintColor = UIColor.lightGray
segmentedControlChartHours.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.black], for:.selected)
segmentedControlStatisticsDays.selectedSegmentTintColor = ConstantsUI.segmentedControlSelectedTintColor
segmentedControlStatisticsDays.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: ConstantsUI.segmentedControlSelectedTextColor, NSAttributedString.Key.font: ConstantsUI.segmentedControlFont], for:.selected)
}
// enable or disable the buttons 'sensor' and 'calibrate' on top, depending on master or follower
@ -420,6 +489,9 @@ final class RootViewController: UIViewController {
// see if the user has changed the chart x axis timescale
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.KeysCharts.chartWidthInHours.rawValue, options: .new, context: nil)
// see if the user has changed the statistic days to use
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.daysToUseStatistics.rawValue, options: .new, context: nil)
// bg reading notification and badge, and multiplication factor
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.showReadingInNotification.rawValue, options: .new, context: nil)
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.showReadingInAppBadge.rawValue, options: .new, context: nil)
@ -960,7 +1032,7 @@ final class RootViewController: UIViewController {
// first check keyValueObserverTimeKeeper
switch keyPathEnum {
case UserDefaults.Key.isMaster, UserDefaults.Key.multipleAppBadgeValueWith10, UserDefaults.Key.showReadingInAppBadge, UserDefaults.Key.bloodGlucoseUnitIsMgDl :
case UserDefaults.Key.isMaster, UserDefaults.Key.multipleAppBadgeValueWith10, UserDefaults.Key.showReadingInAppBadge, UserDefaults.Key.bloodGlucoseUnitIsMgDl, UserDefaults.Key.daysToUseStatistics :
// transmittertype change triggered by user, should not be done within 200 ms
if !keyValueObserverTimeKeeper.verifyKey(forKey: keyPathEnum.rawValue, withMinimumDelayMilliSeconds: 200) {
@ -1005,7 +1077,12 @@ final class RootViewController: UIViewController {
// redraw chart is necessary
updateChartWithResetEndDate()
case UserDefaults.Key.daysToUseStatistics:
// refresh statistics calculations/view is necessary
updateStatistics(animatePieChart: true, overrideApplicationState: false)
default:
break