Skip to content

Commit eaf0a66

Browse files
Tosin AfolabiTosin Afolabi
authored andcommitted
[Refactor] Cleaning bits of Code Smell discovered.
* RealTImeVC needs a proper refactoring * But once again i int get paid enough for this shit yooo
1 parent f24d88e commit eaf0a66

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

HopperBus/Controllers/RealTimeViewController.swift

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ class RealTimeViewController: GAITrackedViewController {
253253

254254
extension RealTimeViewController: UIPickerViewDelegate, UIPickerViewDataSource {
255255

256+
var pickerViewComponentLabelHeight: CGFloat {
257+
return UIFont.systemFontOfSize(UIFont.systemFontSize()).lineHeight * 2 * UIScreen.mainScreen().scale
258+
}
259+
256260
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
257261
return 2
258262
}
@@ -270,16 +274,10 @@ extension RealTimeViewController: UIPickerViewDelegate, UIPickerViewDataSource {
270274
}
271275

272276
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
273-
var label : UILabel
277+
278+
let label : UILabel
274279
if view == nil {
275-
let height = UIFont.systemFontOfSize(UIFont.systemFontSize()).lineHeight * 2 * UIScreen.mainScreen().scale
276-
label = UILabel(frame: CGRectMake(0, 0, 0, height))
277-
label.textAlignment = .Center
278-
label.numberOfLines = 2
279-
label.lineBreakMode = .ByTruncatingTail
280-
label.autoresizingMask = .FlexibleWidth
281-
label.textColor = UIColor.whiteColor()
282-
label.font = UIFont(name: "Avenir-Book", size: 17.0)
280+
label = createPickerViewLabel()
283281
} else {
284282
label = view as! UILabel
285283
}
@@ -307,11 +305,22 @@ extension RealTimeViewController: UIPickerViewDelegate, UIPickerViewDataSource {
307305
}
308306

309307
func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
310-
return UIFont.systemFontOfSize(UIFont.systemFontSize()).lineHeight * 2 * UIScreen.mainScreen().scale
308+
return pickerViewComponentLabelHeight
309+
}
310+
311+
func createPickerViewLabel() -> UILabel {
312+
let label = UILabel(frame: CGRectMake(0, 0, 0, pickerViewComponentLabelHeight))
313+
label.textAlignment = .Center
314+
label.numberOfLines = 2
315+
label.lineBreakMode = .ByTruncatingTail
316+
label.autoresizingMask = .FlexibleWidth
317+
label.textColor = .whiteColor()
318+
label.font = UIFont(name: "Avenir-Book", size: 17.0)
319+
return label
311320
}
312321
}
313322

314-
// Mark: - RealTimeViewModel Delegate
323+
// Mark: - RealTimeViewModel Delegate
315324

316325
extension RealTimeViewController: RealTimeViewModelDelegate {
317326

HopperBus/Models/RouteViewModelContainer.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,3 @@ class RouteViewModelContainer {
7676
}
7777
}
7878
}
79-
80-
extension NSDate {
81-
class func currentTimeAsString() -> String {
82-
let dateFormatter = NSDateFormatter()
83-
dateFormatter.timeStyle = .ShortStyle
84-
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
85-
dateFormatter.dateFormat = "HH:mm"
86-
return dateFormatter.stringFromDate(NSDate())
87-
}
88-
}

HopperBus/Utility/Extensions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,12 @@ extension NSDate {
203203
let components2 = NSCalendar.currentCalendar().components(componentFlags, fromDate:secondDate)
204204
return ( (components1.year == components2.year) && (components1.month == components2.month) && (components1.day == components2.day) )
205205
}
206+
207+
class func currentTimeAsString() -> String {
208+
let dateFormatter = NSDateFormatter()
209+
dateFormatter.timeStyle = .ShortStyle
210+
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
211+
dateFormatter.dateFormat = "HH:mm"
212+
return dateFormatter.stringFromDate(NSDate())
213+
}
206214
}

0 commit comments

Comments
 (0)