Skip to content

Commit

Permalink
[Refactoring] Fixed an issue causing the Comment list to hide comment…
Browse files Browse the repository at this point in the history
…s at the bottom of the screen. Sort comments by date. Fixed an issue causing a newly submitted Comment not to be visible in the UI.
  • Loading branch information
joerghartmann committed Aug 17, 2023
1 parent 95924c2 commit 3cc4ecc
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 143 deletions.
198 changes: 104 additions & 94 deletions ios/AlarmApp/AlarmApp/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

34 changes: 16 additions & 18 deletions ios/AlarmApp/AlarmApp/Controller/AlarmDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class AlarmDetailsViewController: UIViewController, AlarmUpdate {
@IBOutlet var textLabel: MaterialLabel!
@IBOutlet var openDeviceButton: UIButton!
@IBOutlet weak var segmentedControl: UISegmentedControl!
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var newCommentButton: UIButton!

private var cancellableSet = Set<AnyCancellable>()
private var summaryController: UIViewController?
private var summaryController: AlarmSummaryViewController?
private var commentsController: CommentListViewController?

@Published
var alarm: C8yAlarm?
Expand All @@ -44,10 +44,15 @@ class AlarmDetailsViewController: UIViewController, AlarmUpdate {
self.newCommentButton.layer.shadowOpacity = 0.4
self.newCommentButton.layer.shadowRadius = 2
self.newCommentButton.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
self.$alarm.sink { value in
self.$alarm.sink { [self] value in
if let a = value {
self.textLabel.text = a.text
self.openDeviceButton.setTitle(a.source?.name, for: [])
// update the comment list when a new comment was submitted
if let commentController = self.commentsController {
commentController.data = a[C8yComment.identifier] as? [C8yComment] ?? []
commentController.tableView.reloadData()
}
}
}
.store(in: &self.cancellableSet)
Expand All @@ -56,23 +61,12 @@ class AlarmDetailsViewController: UIViewController, AlarmUpdate {
// MARK: - Actions

@IBAction func onContentsChanged(_ sender: UISegmentedControl) {
if let child = summaryController {
child.willMove(toParent: nil)
child.removeFromParent()
child.view.removeFromSuperview()
summaryController = nil
}
if sender.selectedSegmentIndex == 1 {
let child = UIStoryboard.createCommentListViewController()
if let vc = child {
vc.data = self.alarm?[C8yComment.identifier] as? [C8yComment] ?? []
self.containerView.addSubview(vc.view)
self.addChild(vc)
vc.didMove(toParent: self)
summaryController = vc
}
self.commentsController?.view.superview?.isHidden = false
self.summaryController?.view.superview?.isHidden = true
} else {
self.performSegue(withIdentifier: UIStoryboardSegue.embedAlarmSummary, sender: sender)
self.summaryController?.view.superview?.isHidden = false
self.commentsController?.view.superview?.isHidden = true
}
}

Expand All @@ -87,6 +81,10 @@ class AlarmDetailsViewController: UIViewController, AlarmUpdate {
destination?.alarm = self.alarm
destination?.delegate = self
self.summaryController = destination
} else if segue.identifier == UIStoryboardSegue.embedCommentList {
let destination = segue.destination as? CommentListViewController
destination?.data = self.alarm?[C8yComment.identifier] as? [C8yComment] ?? []
self.commentsController = destination
} else if segue.identifier == UIStoryboardSegue.toNewComment {
let destination = segue.destination as? NewCommentViewController
destination?.alarm = self.alarm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CommentListViewController: UITableViewController {
let emptyItem = EmptyCommentsItem()
tableView.backgroundView = emptyItem
tableView.backgroundView?.isHidden = true
self.data = data.sorted { $0.time?.localizedCaseInsensitiveCompare($1.time ?? "") == ComparisonResult.orderedDescending }
self.tableView.reloadData()
}

Expand Down
1 change: 1 addition & 0 deletions ios/AlarmApp/AlarmApp/Extensions/UIStoryboardSegue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ extension UIStoryboardSegue {
static var toAlarmsView: String = "toAlarmsView"
static var embedWelcomeList: String = "embedWelcomeList"
static var embedAlarmSummary: String = "embedAlarmSummary"
static var embedCommentList: String = "embedCommentList"
static var toNewComment: String = "toNewComment"
}
43 changes: 22 additions & 21 deletions ios/AlarmApp/AlarmApp/Views/AlarmListItem.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -16,44 +17,44 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="113"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Device" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="12" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="x20-6b-dkC" userLabel="deviceLabel" customClass="MaterialLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="16" y="8" width="382" height="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Device" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="12" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="x20-6b-dkC" userLabel="deviceLabel" customClass="MaterialLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="16" y="8" width="382" height="47"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" name="onBackground"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" ambiguous="YES" text="Text" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" minimumFontSize="12" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="B1c-yI-w42" userLabel="textLabel" customClass="MaterialLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="16" y="29" width="382" height="14.5"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" text="Text" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" minimumFontSize="12" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="B1c-yI-w42" userLabel="textLabel" customClass="MaterialLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="16" y="59" width="382" height="18"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" name="onBackground"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="Frb-dZ-1N6">
<rect key="frame" x="16" y="51.5" width="382" height="53.5"/>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="Frb-dZ-1N6">
<rect key="frame" x="16" y="85" width="382" height="20"/>
<subviews>
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Yec-8r-cZ6">
<rect key="frame" x="0.0" y="0.0" width="382" height="53.5"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Yec-8r-cZ6">
<rect key="frame" x="0.0" y="0.0" width="382" height="20"/>
<subviews>
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="h6y-hY-F5G" userLabel="severityContainer" customClass="DecoratedLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="72" height="53.5"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="h6y-hY-F5G" userLabel="severityContainer" customClass="DecoratedLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="72" height="20"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="72" id="AbC-zk-Meb"/>
</constraints>
</view>
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DRw-OI-gb7" userLabel="statusContainer" customClass="DecoratedLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="80" y="0.0" width="104" height="53.5"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="DRw-OI-gb7" userLabel="statusContainer" customClass="DecoratedLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="80" y="0.0" width="104" height="20"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="104" id="hM0-vP-aEe"/>
</constraints>
</view>
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="539-tE-KAB" userLabel="commentContainer" customClass="DecoratedLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="192" y="0.0" width="153.5" height="53.5"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="539-tE-KAB" userLabel="commentContainer" customClass="DecoratedLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="192" y="0.0" width="55" height="20"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zjr-EM-Ayx" userLabel="timeLabel" customClass="MaterialLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="353.5" y="-0.5" width="28.5" height="53.5"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zjr-EM-Ayx" userLabel="timeLabel" customClass="MaterialLabel" customModule="AlarmApp" customModuleProvider="target">
<rect key="frame" x="351" y="0.0" width="31" height="20"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" name="onBackground"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -107,13 +108,13 @@
</objects>
<designables>
<designable name="B1c-yI-w42">
<size key="intrinsicContentSize" width="24" height="14.5"/>
<size key="intrinsicContentSize" width="29" height="18"/>
</designable>
<designable name="x20-6b-dkC">
<size key="intrinsicContentSize" width="46" height="17"/>
<size key="intrinsicContentSize" width="54" height="20.5"/>
</designable>
<designable name="zjr-EM-Ayx">
<size key="intrinsicContentSize" width="28.5" height="13.5"/>
<size key="intrinsicContentSize" width="31" height="14.5"/>
</designable>
</designables>
<resources>
Expand Down

0 comments on commit 3cc4ecc

Please sign in to comment.