Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed small bug with date picker #385

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
47 changes: 12 additions & 35 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,8 +82,8 @@ class DatePickerView: UIView {

private func setupTimeTypeSegmentedControl() {
styleSegmentedControl(timeTypeSegmentedControl)
setSegmentedControlOptions(timeTypeSegmentedControl, options: [leaveAtElement.title, arriveByElement.title])
timeTypeSegmentedControl.selectedSegmentIndex = leaveAtElement.index
setSegmentedControlOptions(timeTypeSegmentedControl, options: [leaveNowElement.title,leaveAtElement.title, arriveByElement.title])
timeTypeSegmentedControl.selectedSegmentIndex = leaveNowElement.index
timeTypeSegmentedControl.addTarget(
self,
action: #selector(timeTypeSegmentedControlValueChanged(segmentControl:)),
Expand All @@ -95,18 +93,6 @@ class DatePickerView: UIView {
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 +140,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 +171,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 +180,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 @@ -213,9 +196,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) {
Expand All @@ -226,10 +206,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