@@ -32,40 +32,46 @@ class OrderDetailsViewController: UIViewController {
3232 }
3333
3434 func configureTableView( ) {
35+ tableView. estimatedSectionHeaderHeight = Constants . sectionHeight
36+ tableView. estimatedSectionFooterHeight = Constants . rowHeight
3537 tableView. estimatedRowHeight = Constants . rowHeight
3638 tableView. rowHeight = UITableViewAutomaticDimension
3739 configureSections ( )
3840 configureNibs ( )
3941 }
4042
4143 func configureSections( ) {
42- let summarySection = Section ( title: nil , footer: nil , rows: [ . summary] )
43- let customerNoteSection = Section ( title: NSLocalizedString ( " CUSTOMER PROVIDED NOTE " , comment: " Customer note section title " ) , footer: nil , rows: [ . customerNote] )
44+ let summarySection = Section ( leftTitle: nil , rightTitle: nil , footer: nil , rows: [ . summary] )
45+
46+ let productLeftTitle = NSLocalizedString ( " PRODUCT " , comment: " Product section title " )
47+ let productRightTitle = NSLocalizedString ( " QTY " , comment: " Quantity abbreviation for section title " )
48+ let productListSection = Section ( leftTitle: productLeftTitle, rightTitle: productRightTitle, footer: nil , rows: [ . productList] )
49+
50+ let customerNoteSection = Section ( leftTitle: NSLocalizedString ( " CUSTOMER PROVIDED NOTE " , comment: " Customer note section title " ) , rightTitle: nil , footer: nil , rows: [ . customerNote] )
4451
4552 let infoFooter = billingIsHidden ? NSLocalizedString ( " Show billing " , comment: " Footer text to show the billing cell " ) : NSLocalizedString ( " Hide billing " , comment: " Footer text to hide the billing cell " )
4653 let infoRows : [ Row ] = billingIsHidden ? [ . shippingAddress] : [ . shippingAddress, . billingAddress, . billingPhone, . billingEmail]
47- let infoSection = Section ( title : NSLocalizedString ( " CUSTOMER INFORMATION " , comment: " Customer info section title " ) , footer: infoFooter, rows: infoRows)
54+ let infoSection = Section ( leftTitle : NSLocalizedString ( " CUSTOMER INFORMATION " , comment: " Customer info section title " ) , rightTitle : nil , footer: infoFooter, rows: infoRows)
4855
4956 var noteRows : [ Row ] = [ . addOrderNote]
5057 if let notes = order. notes {
5158 for _ in notes {
5259 noteRows. append ( . orderNote)
5360 }
5461 }
55- let orderNotesSection = Section ( title : NSLocalizedString ( " ORDER NOTES " , comment: " Order notes section title " ) , footer: nil , rows: noteRows)
62+ let orderNotesSection = Section ( leftTitle : NSLocalizedString ( " ORDER NOTES " , comment: " Order notes section title " ) , rightTitle : nil , footer: nil , rows: noteRows)
5663
57- let paymentSection = Section ( title : NSLocalizedString ( " PAYMENT " , comment: " Payment section title " ) , footer: nil , rows: [ . payment] )
64+ let paymentSection = Section ( leftTitle : NSLocalizedString ( " PAYMENT " , comment: " Payment section title " ) , rightTitle : nil , footer: nil , rows: [ . payment] )
5865
5966 // FIXME: this is temporary
6067 // the API response always sends customer note data
6168 // if there is no customer note it sends an empty string
6269 // but order has customerNote as an optional property right now
63- guard let customerNote = order. customerNote,
64- !customerNote. isEmpty else {
65- sections = [ summarySection, infoSection, paymentSection, orderNotesSection]
70+ guard let customerNote = order. customerNote, !customerNote. isEmpty else {
71+ sections = [ summarySection, productListSection, infoSection, paymentSection, orderNotesSection]
6672 return
6773 }
68- sections = [ summarySection, customerNoteSection, infoSection, paymentSection, orderNotesSection]
74+ sections = [ summarySection, productListSection , customerNoteSection, infoSection, paymentSection, orderNotesSection]
6975 }
7076
7177 func configureNibs( ) {
@@ -76,6 +82,8 @@ class OrderDetailsViewController: UIViewController {
7682 }
7783 }
7884
85+ let headerNib = UINib ( nibName: TwoColumnSectionHeaderView . reuseIdentifier, bundle: nil )
86+ tableView. register ( headerNib, forHeaderFooterViewReuseIdentifier: TwoColumnSectionHeaderView . reuseIdentifier)
7987 let footerNib = UINib ( nibName: ShowHideSectionFooter . reuseIdentifier, bundle: nil )
8088 tableView. register ( footerNib, forHeaderFooterViewReuseIdentifier: ShowHideSectionFooter . reuseIdentifier)
8189 }
@@ -100,16 +108,25 @@ extension OrderDetailsViewController: UITableViewDataSource {
100108 }
101109
102110 func tableView( _ tableView: UITableView , heightForHeaderInSection section: Int ) -> CGFloat {
103- guard let _ = sections [ section] . title else {
111+ if sections [ section] . leftTitle == nil {
104112 // iOS 11 table bug. Must return a tiny value to collapse `nil` or `empty` section headers.
105113 return CGFloat . leastNonzeroMagnitude
106114 }
107115
108116 return UITableViewAutomaticDimension
109117 }
110118
111- func tableView( _ tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
112- return sections [ section] . title
119+ func tableView( _ tableView: UITableView , viewForHeaderInSection section: Int ) -> UIView ? {
120+ guard let leftText = sections [ section] . leftTitle else {
121+ return nil
122+ }
123+
124+ guard let cell = tableView. dequeueReusableHeaderFooterView ( withIdentifier: TwoColumnSectionHeaderView . reuseIdentifier) as? TwoColumnSectionHeaderView else {
125+ fatalError ( )
126+ }
127+ cell. configure ( leftText: leftText, rightText: sections [ section] . rightTitle)
128+
129+ return cell
113130 }
114131
115132 func tableView( _ tableView: UITableView , heightForFooterInSection section: Int ) -> CGFloat {
@@ -118,7 +135,7 @@ extension OrderDetailsViewController: UITableViewDataSource {
118135 return CGFloat . leastNonzeroMagnitude
119136 }
120137
121- return Constants . rowHeight
138+ return UITableViewAutomaticDimension
122139 }
123140
124141 func tableView( _ tableView: UITableView , viewForFooterInSection section: Int ) -> UIView ? {
@@ -135,6 +152,7 @@ extension OrderDetailsViewController: UITableViewDataSource {
135152 let sections = IndexSet ( integer: section)
136153 tableView. reloadSections ( sections, with: . fade)
137154 }
155+
138156 return cell
139157 }
140158}
@@ -158,6 +176,8 @@ extension OrderDetailsViewController {
158176 switch cell {
159177 case let cell as SummaryTableViewCell :
160178 cell. configure ( with: viewModel)
179+ case let cell as ProductListTableViewCell :
180+ cell. configure ( with: viewModel)
161181 case let cell as CustomerNoteTableViewCell :
162182 cell. configure ( with: viewModel)
163183 case let cell as CustomerInfoTableViewCell where row == . shippingAddress:
@@ -283,16 +303,19 @@ extension OrderDetailsViewController: MFMailComposeViewControllerDelegate {
283303private extension OrderDetailsViewController {
284304 struct Constants {
285305 static let rowHeight = CGFloat ( 38 )
306+ static let sectionHeight = CGFloat ( 44 )
286307 }
287308
288309 private struct Section {
289- let title : String ?
310+ let leftTitle : String ?
311+ let rightTitle : String ?
290312 let footer : String ?
291313 let rows : [ Row ]
292314 }
293315
294316 private enum Row {
295317 case summary
318+ case productList
296319 case customerNote
297320 case shippingAddress
298321 case billingAddress
@@ -306,6 +329,8 @@ private extension OrderDetailsViewController {
306329 switch self {
307330 case . summary:
308331 return SummaryTableViewCell . reuseIdentifier
332+ case . productList:
333+ return ProductListTableViewCell . reuseIdentifier
309334 case . customerNote:
310335 return CustomerNoteTableViewCell . reuseIdentifier
311336 case . shippingAddress:
0 commit comments