Skip to content

Commit

Permalink
Merge pull request #385 from cuappdev/cindy/datePickerFix
Browse files Browse the repository at this point in the history
  • Loading branch information
rs929 authored Jun 2, 2024
2 parents f2949d2 + acb43b4 commit b6a23dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target 'TCAT' do
pod 'GoogleMaps'

# Networking + Data
pod 'Apollo'
pod 'Apollo', '~> 1.9.3'
pod 'SwiftyJSON', '~> 5.0'
pod 'FutureNova', :git => 'https://github.com/cuappdev/ios-networking.git'
pod 'Wormholy', :configurations => ['Debug']
Expand Down
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ PODS:
- Zip (1.1.0)

DEPENDENCIES:
- Apollo
- Apollo (~> 1.9.3)
- DZNEmptyDataSet (from `https://github.com/cuappdev/DZNEmptyDataSet.git`)
- Firebase
- FirebaseCrashlytics
Expand Down Expand Up @@ -234,6 +234,6 @@ SPEC CHECKSUMS:
Wormholy: ab1c8c2f02f58587a0941deb0088555ffbf039a1
Zip: 8877eede3dda76bcac281225c20e71c25270774c

PODFILE CHECKSUM: 2bc2917c9852873acd565e06b273a1884fa7d20b
PODFILE CHECKSUM: a3b80dd04ea30998a17c032f2730e21ee8517238

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
55 changes: 12 additions & 43 deletions TCAT/Views/DatePickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ class DatePickerView: UIView {

private weak var delegate: DatePickerViewDelegate?
private let leaveNowElement = SegmentControlElement(title: Constants.General.datepickerLeaveNow, index: 0)
private let leaveAtElement = SegmentControlElement(title: Constants.General.datepickerLeaveAt, index: 0)
private let arriveByElement = SegmentControlElement(title: Constants.General.datepickerArriveBy, index: 1)
private let leaveAtElement = SegmentControlElement(title: Constants.General.datepickerLeaveAt, index: 1)
private let arriveByElement = SegmentControlElement(title: Constants.General.datepickerArriveBy, index: 2)

// MARK: - View vars

private var cancelButton: UIButton = UIButton()
private var datepicker: UIDatePicker = UIDatePicker()
private var doneButton: UIButton = UIButton()
private var leaveNowSegmentedControl: UISegmentedControl = UISegmentedControl()
private var timeTypeSegmentedControl: UISegmentedControl = UISegmentedControl()

// MARK: - Init
Expand All @@ -47,7 +46,6 @@ class DatePickerView: UIView {

setupDatePicker()
setupTimeTypeSegmentedControl()
setupLeaveNowSegmentedControl()
setupCancelButton()
setupDoneButton()

Expand Down Expand Up @@ -84,29 +82,12 @@ class DatePickerView: UIView {

private func setupTimeTypeSegmentedControl() {
styleSegmentedControl(timeTypeSegmentedControl)
setSegmentedControlOptions(timeTypeSegmentedControl, options: [leaveAtElement.title, arriveByElement.title])
timeTypeSegmentedControl.selectedSegmentIndex = leaveAtElement.index
timeTypeSegmentedControl.addTarget(
self,
action: #selector(timeTypeSegmentedControlValueChanged(segmentControl:)),
for: .valueChanged
)
setSegmentedControlOptions(timeTypeSegmentedControl, options: [leaveNowElement.title,leaveAtElement.title, arriveByElement.title])
timeTypeSegmentedControl.selectedSegmentIndex = leaveNowElement.index

addSubview(timeTypeSegmentedControl)
}

private func setupLeaveNowSegmentedControl() {
styleSegmentedControl(leaveNowSegmentedControl)
setSegmentedControlOptions(leaveNowSegmentedControl, options: [leaveNowElement.title])
leaveNowSegmentedControl.addTarget(
self,
action: #selector(leaveNowSegmentedControlValueChanged(segmentControl:)),
for: .valueChanged
)

addSubview(leaveNowSegmentedControl)
}

private func setupCancelButton() {
cancelButton.titleLabel?.font = .getFont(.regular, size: 17.0)
cancelButton.setTitleColor(Colors.metadataIcon, for: .normal)
Expand Down Expand Up @@ -154,19 +135,12 @@ class DatePickerView: UIView {
make.trailing.equalTo(doneButton)
make.top.equalTo(doneButton.snp.bottom).offset(spaceBtButtonAndSegmentedControl)
make.height.equalTo(segmentedControlHeight)
make.leading.equalTo(leaveNowSegmentedControl.snp.trailing).offset(spaceBtSegmentControls)
}

leaveNowSegmentedControl.snp.makeConstraints { make in
make.leading.equalTo(cancelButton)
make.top.equalTo(timeTypeSegmentedControl)
make.height.equalTo(segmentedControlHeight)
make.width.equalTo(timeTypeSegmentedControl.snp.width).multipliedBy(segmentedControlSizeRatio)
}

datepicker.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.top.equalTo(leaveNowSegmentedControl.snp.bottom).offset(spaceBtSegmentControlAndDatePicker)
make.leading.equalToSuperview().inset(90)
make.top.equalTo(timeTypeSegmentedControl.snp.bottom).offset(spaceBtSegmentControlAndDatePicker)
make.height.equalTo(datePickerHeight)
make.bottom.equalTo(safeAreaLayoutGuide)
}
Expand All @@ -192,7 +166,7 @@ class DatePickerView: UIView {

@objc private func doneButtonPressed() {
var searchTimeType: SearchType = .leaveNow
if leaveNowSegmentedControl.selectedSegmentIndex != leaveNowElement.index {
if timeTypeSegmentedControl.selectedSegmentIndex != leaveNowElement.index {
switch timeTypeSegmentedControl.selectedSegmentIndex {
case arriveByElement.index:
searchTimeType = .arriveBy
Expand All @@ -201,6 +175,10 @@ class DatePickerView: UIView {
default:
break
}
} else {
//If the user for some reason changes the date/time on datepicker, but selects leaveNow
//we change the date/time on datepicker to be the current date/time
datepicker.date = Date()
}

delegate?.saveDatePickerDate(for: datepicker.date, searchType: searchTimeType)
Expand All @@ -212,12 +190,6 @@ class DatePickerView: UIView {

// MARK: - Segment Controls

@objc private func timeTypeSegmentedControlValueChanged(segmentControl: UISegmentedControl) {
if timeTypeSegmentedControl.selectedSegmentIndex == arriveByElement.index {
leaveNowSegmentedControl.selectedSegmentIndex = UISegmentedControl.noSegment
}
}

@objc private func leaveNowSegmentedControlValueChanged(segmentControl: UISegmentedControl) {
datepicker.date = Date()
}
Expand All @@ -226,10 +198,7 @@ class DatePickerView: UIView {

@objc private func datepickerValueChanged(datepicker: UIDatePicker) {
if Time.compare(date1: datepicker.date, date2: Date()) == ComparisonResult.orderedSame {
leaveNowSegmentedControl.selectedSegmentIndex = leaveNowElement.index
timeTypeSegmentedControl.selectedSegmentIndex = leaveAtElement.index
} else {
leaveNowSegmentedControl.selectedSegmentIndex = UISegmentedControl.noSegment
timeTypeSegmentedControl.selectedSegmentIndex = leaveNowElement.index
}
}

Expand Down

0 comments on commit b6a23dd

Please sign in to comment.