Skip to content

Commit

Permalink
Merge pull request #23 from rckim77/develop
Browse files Browse the repository at this point in the history
Version 2.20.0
  • Loading branch information
rckim77 authored Jun 17, 2020
2 parents ca989a1 + 078772c commit 61a2663
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 184 deletions.
16 changes: 10 additions & 6 deletions Daydream.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
94380ACD203BAE1D00684863 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 94380ACB203BAE1D00684863 /* Main.storyboard */; };
94380ACF203BAE1D00684863 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 94380ACE203BAE1D00684863 /* Assets.xcassets */; };
94380AD2203BAE1D00684863 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 94380AD0203BAE1D00684863 /* LaunchScreen.storyboard */; };
94600FBA24987B8300E605FD /* JSONCustomDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94600FB924987B8300E605FD /* JSONCustomDecoder.swift */; };
94600FBC2499734600E605FD /* RandomCity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94600FBB2499734600E605FD /* RandomCity.swift */; };
94673BAC225075AA00EC04FD /* DesignableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94673BAB225075AA00EC04FD /* DesignableView.swift */; };
947EC6522043F28F004A911D /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 947EC6512043F28F004A911D /* Extensions.swift */; };
947EC656204667EB004A911D /* MapCardCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 947EC655204667EB004A911D /* MapCardCell.swift */; };
Expand Down Expand Up @@ -82,6 +84,8 @@
94380ACE203BAE1D00684863 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
94380AD1203BAE1D00684863 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
94380AD3203BAE1D00684863 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
94600FB924987B8300E605FD /* JSONCustomDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONCustomDecoder.swift; sourceTree = "<group>"; };
94600FBB2499734600E605FD /* RandomCity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RandomCity.swift; sourceTree = "<group>"; };
94673BAB225075AA00EC04FD /* DesignableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignableView.swift; sourceTree = "<group>"; };
947EC6512043F28F004A911D /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
947EC655204667EB004A911D /* MapCardCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapCardCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -205,6 +209,7 @@
94B7DB5C205EEBBB0040D61C /* NetworkService.swift */,
94A9CCCD24904636008551B6 /* Routes.swift */,
94A9CCBD2489C366008551B6 /* Agent.swift */,
94600FB924987B8300E605FD /* JSONCustomDecoder.swift */,
94A9CCBF2489ED2D008551B6 /* NetworkError.swift */,
);
path = Networking;
Expand All @@ -223,6 +228,7 @@
94E9F32A2492E12900B1D003 /* PlaceCollection.swift */,
94E9F3282492BEF600B1D003 /* ResultsCollection.swift */,
94A9CCCB248F50F7008551B6 /* Article.swift */,
94600FBB2499734600E605FD /* RandomCity.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -385,28 +391,24 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Daydream/Pods-Daydream-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework",
"${BUILT_PRODUCTS_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework",
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework",
"${BUILT_PRODUCTS_DIR}/SVProgressHUD/SVProgressHUD.framework",
"${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMSessionFetcher.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleToolboxForMac.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SVProgressHUD.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -513,6 +515,7 @@
9481EC5A204B358C00863A5A /* SightsCardCell.swift in Sources */,
94380AC8203BAE1D00684863 /* AppDelegate.swift in Sources */,
947EC656204667EB004A911D /* MapCardCell.swift in Sources */,
94600FBA24987B8300E605FD /* JSONCustomDecoder.swift in Sources */,
9434BA4C247998D4004294F0 /* MapReviewCard.swift in Sources */,
94E108712484AF5A0091D043 /* CellLoadingView.swift in Sources */,
94AE9B852094DAF500450399 /* LoadingViewController.swift in Sources */,
Expand All @@ -528,6 +531,7 @@
94B7DB5D205EEBBB0040D61C /* NetworkService.swift in Sources */,
94E108752486DB480091D043 /* EateryView.swift in Sources */,
947EC658204673BF004A911D /* ShadowView.swift in Sources */,
94600FBC2499734600E605FD /* RandomCity.swift in Sources */,
94673BAC225075AA00EC04FD /* DesignableView.swift in Sources */,
94E9F32B2492E12900B1D003 /* PlaceCollection.swift in Sources */,
9409090A205F4613002A65EF /* MapViewController.swift in Sources */,
Expand Down Expand Up @@ -635,7 +639,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -697,7 +701,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down
2 changes: 1 addition & 1 deletion Daydream/CardCells/EateriesCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EateriesCardCell: UITableViewCell {
static let errorHeight: CGFloat = 185
private let errorSectionHeight: CGFloat = 100

private lazy var titleLabel = CardLabel(textStyle: .title1, text: "Top Eateries")
private let titleLabel = CardLabel(textStyle: .title1, text: "Top Eateries")
private lazy var infoButton: UIButton = {
let button = UIButton(type: .system)
button.configureWithSystemIcon("info.circle.fill")
Expand Down
3 changes: 2 additions & 1 deletion Daydream/CardCells/EateryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class EateryView: UIView {
}()
private let gradientView = GradientView()
private let titleLabel = CardLabel()
private let networkService = NetworkService()

private var layoutType: LayoutType = .middle
private weak var delegate: EateryViewDelegate?
Expand Down Expand Up @@ -128,7 +129,7 @@ final class EateryView: UIView {
guard let id = eatery.eatableId else {
return
}
cancellable = NetworkService().loadGooglePhoto(placeId: id)
cancellable = networkService.loadGooglePhoto(placeId: id)
.sink(receiveCompletion: { _ in }, receiveValue: { [weak self] image in
guard let strongSelf = self else {
return
Expand Down
3 changes: 2 additions & 1 deletion Daydream/CardCells/SightView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class SightView: UIView {
}

private let loadingView = CellLoadingView()
private let networkService = NetworkService()
private lazy var backgroundImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
Expand Down Expand Up @@ -128,7 +129,7 @@ final class SightView: UIView {
businessStatusButton.isHidden = businessStatus == .operational

updateLayers()
cancellable = NetworkService().loadGooglePhoto(placeId: sight.placeId)
cancellable = networkService.loadGooglePhoto(placeId: sight.placeId)
.sink(receiveCompletion: { _ in }, receiveValue: { [weak self] image in
guard let strongSelf = self else {
return
Expand Down
2 changes: 1 addition & 1 deletion Daydream/CardCells/SightsCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SightsCardCell: UITableViewCell {
static let errorHeight: CGFloat = 185
private let errorSectionHeight: CGFloat = 100

private lazy var titleLabel = CardLabel(textStyle: .title1, text: "Top Sights")
private let titleLabel = CardLabel(textStyle: .title1, text: "Top Sights")
private lazy var sightsSectionView: UIView = {
let view = UIView()
view.addRoundedCorners(radius: 8)
Expand Down
4 changes: 2 additions & 2 deletions Daydream/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.19.0</string>
<string>2.20.0</string>
<key>CFBundleVersion</key>
<string>5</string>
<string>6</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
Expand Down
58 changes: 25 additions & 33 deletions Daydream/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
import GoogleMaps
import GooglePlaces
import SnapKit
import Combine

// swiftlint:disable type_body_length
final class MapViewController: UIViewController {
Expand All @@ -31,6 +32,7 @@ final class MapViewController: UIViewController {
}

private let networkService = NetworkService()
private var loadPlaceCancellable: AnyCancellable?

// contains close and dark mode buttons (and creates frame for gradient)
private lazy var containerView: UIView = {
Expand Down Expand Up @@ -204,34 +206,24 @@ final class MapViewController: UIViewController {

dynamicMarker.tracksInfoWindowChanges = true

networkService.getPlace(id: placeId, completion: { [weak self] result in
guard let strongSelf = self else {
return
}
switch result {
case .success(let place):
dynamicMarker.snippet = strongSelf.createSnippet(for: place)
dynamicMarker.tracksInfoWindowChanges = false
strongSelf.place = place
DispatchQueue.main.async {
strongSelf.displayReviews(place.reviews, index: 0)
}
case .failure(let error):
strongSelf.logErrorEvent(error)
}
})
}

// MARK: - Marker-specific methods

private func createSnippet(for place: Place) -> String {
var snippet = place.formattedAddress

if let phoneNumber = place.internationalPhoneNumber {
snippet += "\n\(phoneNumber)"
guard let url = GooglePlaceDetailsRoute(placeId: placeId)?.url else {
return
}

return snippet
loadPlaceCancellable = networkService.loadPlaceWithReviews(placeDetailsUrl: url)
.sink(receiveCompletion: { [weak self] completion in
if case let Subscribers.Completion.failure(error) = completion {
self?.logErrorEvent(error)
}
}, receiveValue: { [weak self] place in
guard let strongSelf = self else {
return
}
dynamicMarker.snippet = place.formattedAddress
dynamicMarker.tracksInfoWindowChanges = false
strongSelf.place = place
strongSelf.displayReviews(place.reviews, index: 0)
})
}

// MARK: - Review-specific methods
Expand Down Expand Up @@ -268,11 +260,11 @@ final class MapViewController: UIViewController {
DispatchQueue.main.asyncAfter(deadline: .now() + 6) {
UIView.animate(withDuration: 0.7, animations: {
self.reviewCard.alpha = 0
}, completion: { finished in
if finished {
self.currentReviewIndex = index
self.loadReviewContent(reviews[index])
self.startDisplayingReviews(reviews, index: index + 1)
}, completion: { [weak self] finished in
if let strongSelf = self, finished {
strongSelf.currentReviewIndex = index
strongSelf.loadReviewContent(reviews[index])
strongSelf.startDisplayingReviews(reviews, index: index + 1)
}
})
}
Expand All @@ -281,8 +273,8 @@ final class MapViewController: UIViewController {
} else {
UIView.animate(withDuration: 0.8, animations: {
self.reviewCard.alpha = 0
}, completion: { _ in
self.reviewCard.isHidden = true
}, completion: { [weak self] _ in
self?.reviewCard.isHidden = true
})
}
}
Expand Down
12 changes: 12 additions & 0 deletions Daydream/Models/RandomCity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// RandomCity.swift
// Daydream
//
// Created by Raymond Kim on 6/16/20.
// Copyright © 2020 Raymond Kim. All rights reserved.
//

struct RandomCity: Codable {
let city: String
let country: String
}
17 changes: 14 additions & 3 deletions Daydream/Networking/Agent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@
import Foundation
import Combine

/// Abstraction for the initial steps for most network calls that deserialize JSON from a URL or URL request.
struct Agent {

/// Use this function to execute requests with an optional decoder if you need to use
/// a custom one. In the future, you can use a tryMap instead of map to get access to
/// the response object to do things such as status code validation.
func run<T: Decodable>(_ url: URL, _ decoder: JSONDecoder = JSONDecoder()) -> AnyPublisher<T, Error> {
static func run<T: Decodable>(_ url: URL, _ decoder: JSONDecoder = JSONCustomDecoder()) -> AnyPublisher<T, Error> {
return URLSession.shared
.dataTaskPublisher(for: url)
.map { $0.data }
.decode(type: T.self, decoder: decoder)
.receive(on: DispatchQueue.main)
.eraseToAnyPublisher() // without this, it'll return a mess of nested types
.eraseToAnyPublisher()
}

/// Use this function to execute requests with an optional decoder if you need to use
/// a custom one. In the future, you can use a tryMap instead of map to get access to
/// the response object to do things such as status code validation.
static func run<T: Decodable>(_ urlRequest: URLRequest, _ decoder: JSONDecoder = JSONCustomDecoder()) -> AnyPublisher<T, Error> {
return URLSession.shared
.dataTaskPublisher(for: urlRequest)
.map { $0.data }
.decode(type: T.self, decoder: decoder)
.eraseToAnyPublisher()
}
}
16 changes: 16 additions & 0 deletions Daydream/Networking/JSONCustomDecoder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// JSONCustomDecoder.swift
// Daydream
//
// Created by Raymond Kim on 6/16/20.
// Copyright © 2020 Raymond Kim. All rights reserved.
//

import Foundation

final class JSONCustomDecoder: JSONDecoder {
override init() {
super.init()
keyDecodingStrategy = .convertFromSnakeCase
}
}
2 changes: 2 additions & 0 deletions Daydream/Networking/NetworkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ enum NetworkError: Error {
case malformedPhotoField
case photoMetadataMissing
case routeError
case noMapUrl
case invalidPlaceFields
case unknown // e.g., 3rd party function returns nil data and nil error
}
Loading

0 comments on commit 61a2663

Please sign in to comment.