Skip to content

Commit

Permalink
finish refactor and dark theme adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasJorgeHubert committed May 23, 2023
1 parent b9a049c commit 977f200
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 32 deletions.
4 changes: 4 additions & 0 deletions eUberUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
C9CFFE8B2A15410900708A15 /* LocationSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CFFE8A2A15410900708A15 /* LocationSearchView.swift */; };
C9CFFE8D2A15447800708A15 /* LocationSearchResultCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CFFE8C2A15447800708A15 /* LocationSearchResultCell.swift */; };
C9CFFE8F2A154F1900708A15 /* LocationSearchViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CFFE8E2A154F1900708A15 /* LocationSearchViewModel.swift */; };
C9DD5C842A1D0B4500B357DB /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DD5C832A1D0B4500B357DB /* Color.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -71,6 +72,7 @@
C9CFFE8A2A15410900708A15 /* LocationSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearchView.swift; sourceTree = "<group>"; };
C9CFFE8C2A15447800708A15 /* LocationSearchResultCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearchResultCell.swift; sourceTree = "<group>"; };
C9CFFE8E2A154F1900708A15 /* LocationSearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearchViewModel.swift; sourceTree = "<group>"; };
C9DD5C832A1D0B4500B357DB /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Color.swift; path = eUberUI/Core/Trips/View/Color.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -197,6 +199,7 @@
isa = PBXGroup;
children = (
C9AA5E772A1CFA5600824737 /* Double.swift */,
C9DD5C832A1D0B4500B357DB /* Color.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -407,6 +410,7 @@
C9AA5E762A1C113E00824737 /* RideType.swift in Sources */,
C9CFFE7D2A151D2400708A15 /* HomeView.swift in Sources */,
C9CFFE812A151F7400708A15 /* LocationManager.swift in Sources */,
C9DD5C842A1D0B4500B357DB /* Color.swift in Sources */,
C9CFFE502A1517A200708A15 /* eUberUI.xcdatamodeld in Sources */,
C9CFFE8F2A154F1900708A15 /* LocationSearchViewModel.swift in Sources */,
C9AA5E782A1CFA5600824737 /* Double.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.130",
"green" : "0.130",
"red" : "0.130"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions eUberUI/Assets.xcassets/Colors/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.130",
"green" : "0.130",
"red" : "0.130"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.921",
"green" : "0.921",
"red" : "0.921"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.261",
"green" : "0.261",
"red" : "0.261"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
2 changes: 1 addition & 1 deletion eUberUI/Core/Home/View/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct HomeView: View {
.padding(.leading)
.padding(.top, 4)
}
if mapState == .locationSelected {
if mapState == .locationSelected || mapState == .polylineAdded {
RideRequestView()
.transition(.move(edge: .bottom))
}
Expand Down
4 changes: 2 additions & 2 deletions eUberUI/Core/Home/View/MapViewActionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct MapViewActionButton: View {
print("DEBUG: No input")
case .searchingForLocation:
mapState = .noInput
case .locationSelected:
case .locationSelected, .polylineAdded:
viewModel.selectedEUberLocation = nil
mapState = .noInput
}
Expand All @@ -46,7 +46,7 @@ struct MapViewActionButton: View {
switch state {
case .noInput:
return "line.3.horizontal"
case .searchingForLocation, .locationSelected:
case .searchingForLocation, .locationSelected, .polylineAdded:
return "arrow.left"
}
}
Expand Down
27 changes: 3 additions & 24 deletions eUberUI/Core/Home/View/UberMapViewRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct UberMapViewRepresentable: UIViewRepresentable {
case .noInput:
context.coordinator.clearMapViewAndRecenterOnUserLocation()
break
case .searchingForLocation:
case .searchingForLocation, .polylineAdded:
break
case .locationSelected:
if let coordinate = locationViewModel.selectedEUberLocation?.coordinate {
Expand Down Expand Up @@ -97,8 +97,9 @@ extension UberMapViewRepresentable {

func configurePolyline(withDestinationCoordinate coordinate: CLLocationCoordinate2D) {
guard let userLocationCoordinate = self.userLocationCoordinate else { return }
getDestinationRoute(from: userLocationCoordinate, to: coordinate) { route in
self.parent.locationViewModel.getDestinationRoute(from: userLocationCoordinate, to: coordinate) { route in
self.parent.mapView.addOverlay(route.polyline)
self.parent.mapState = .polylineAdded
let rect = self.parent.mapView.mapRectThatFits(
route.polyline.boundingMapRect,
edgePadding: .init(
Expand All @@ -113,28 +114,6 @@ extension UberMapViewRepresentable {
}
}

func getDestinationRoute(
from userLocation: CLLocationCoordinate2D,
to destination: CLLocationCoordinate2D,
completion: @escaping(MKRoute) -> Void
) {
let userPlacemark = MKPlacemark(coordinate: userLocation)
let userDestination = MKPlacemark(coordinate: destination)
let request = MKDirections.Request()
request.source = MKMapItem(placemark: userPlacemark)
request.destination = MKMapItem(placemark: userDestination)
let direction = MKDirections(request: request)

direction.calculate { response, error in
if let error = error {
print("DEBUG: Failed to get direction with error \(error.localizedDescription)")
}

guard let route = response?.routes.first else { return }
completion(route)
}
}

func clearMapViewAndRecenterOnUserLocation() {
parent.mapView.removeAnnotations(parent.mapView.annotations)
parent.mapView.removeOverlays(parent.mapView.overlays)
Expand Down
2 changes: 1 addition & 1 deletion eUberUI/Core/LocationSearch/View/LocationSearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct LocationSearchView: View {
}
}
}
.background(.white)
.background(Color.theme.backgroundColor)
.opacity(0.9)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class LocationSearchViewModel: NSObject, ObservableObject {

@Published var resuls = [MKLocalSearchCompletion]()
@Published var selectedEUberLocation: EUberLocation?
@Published var pickupTime: String?
@Published var dropOffTime: String?

private let searchCompleter = MKLocalSearchCompleter()

Expand Down Expand Up @@ -71,6 +73,37 @@ class LocationSearchViewModel: NSObject, ObservableObject {
return type.computePrice(for: tripDistanceInMeters)
}

func getDestinationRoute(
from userLocation: CLLocationCoordinate2D,
to destination: CLLocationCoordinate2D,
completion: @escaping(MKRoute) -> Void
) {
let userPlacemark = MKPlacemark(coordinate: userLocation)
let userDestination = MKPlacemark(coordinate: destination)
let request = MKDirections.Request()
request.source = MKMapItem(placemark: userPlacemark)
request.destination = MKMapItem(placemark: userDestination)
let direction = MKDirections(request: request)

direction.calculate { response, error in
if let error = error {
print("DEBUG: Failed to get direction with error \(error.localizedDescription)")
}

guard let route = response?.routes.first else { return }
self.configurePickupAndDropOffTimes(with: route.expectedTravelTime)
completion(route)
}
}

func configurePickupAndDropOffTimes(with expectedTravelTime: Double) {
let formatter = DateFormatter()
formatter.dateFormat = "hh:mm a"

pickupTime = formatter.string(from: Date())
dropOffTime = formatter.string(from: Date() + expectedTravelTime)
}

}

// MARK: - MKLocalSearchCompleterDelegate
Expand Down
18 changes: 18 additions & 0 deletions eUberUI/Core/Trips/View/Color.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Color.swift
// eUberUI
//
// Created by Lucas Hubert on 23/05/23.
//

import SwiftUI

extension Color {
static let theme = ColorTheme()
}

struct ColorTheme {
let backgroundColor = Color("BackgroundColor")
let secondaryBackgroundColor = Color("SecondaryBackgroundColor")
let primaryTextColor = Color("PrimaryTextColor")
}
9 changes: 5 additions & 4 deletions eUberUI/Core/Trips/View/RideRequestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct RideRequestView: View {

Spacer()

Text("01:30 PM")
Text(locationViewModel.pickupTime ?? "-")
.font(.system(size: 14, weight: .bold))
.foregroundColor(.gray)
}
Expand All @@ -60,7 +60,7 @@ struct RideRequestView: View {

Spacer()

Text("01:40 PM")
Text(locationViewModel.dropOffTime ?? "-")
.font(.system(size: 14, weight: .bold))
.foregroundColor(.gray)
}
Expand Down Expand Up @@ -101,7 +101,8 @@ struct RideRequestView: View {
}
.padding(.top, 8)
.frame(width: 112, height: 140)
.background(Color(rideType == selectedRideType ? .systemYellow : .systemGroupedBackground))
.foregroundColor(rideType == selectedRideType ? .black : Color.theme.primaryTextColor)
.background(rideType == selectedRideType ? .yellow : Color.theme.secondaryBackgroundColor)
.scaleEffect(rideType == selectedRideType ? 1.1 : 1.0)
.cornerRadius(10)
.onTapGesture {
Expand Down Expand Up @@ -152,7 +153,7 @@ struct RideRequestView: View {

}
.padding(.bottom, 24)
.background(.white)
.background(Color.theme.backgroundColor)
.cornerRadius(16)
}
}
Expand Down

0 comments on commit 977f200

Please sign in to comment.