Skip to content

Commit

Permalink
new sharing modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan committed Mar 13, 2020
1 parent 52f3b14 commit dcee16e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 41 deletions.
8 changes: 6 additions & 2 deletions Arrival-iOS2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
34EF38B123CC2692000DE4AF /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EF38B023CC2692000DE4AF /* HomeView.swift */; };
34EF38B323CC2AC1000DE4AF /* StationChooserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EF38B223CC2AC1000DE4AF /* StationChooserView.swift */; };
64BB2D2FF3AB6F51B9399F08 /* Pods_Arrival_iOS2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 74ACA5CF5B67BD66D8845E5D /* Pods_Arrival_iOS2.framework */; };
C509BA83241BEC1A00920BC5 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = C509BA82241BEC1A00920BC5 /* SearchBar.swift */; };
C5166C3923F610AC001F0254 /* TermsOfSeriviceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5166C3823F610AB001F0254 /* TermsOfSeriviceView.swift */; };
C51B3EDD23ED26330021EBE0 /* KNearestNeighborsClassifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = C51B3EDC23ED26330021EBE0 /* KNearestNeighborsClassifier.swift */; };
C524E7B223FAEC87002BC9A5 /* moment.swift in Sources */ = {isa = PBXBuildFile; fileRef = C524E7B023FAEC85002BC9A5 /* moment.swift */; };
Expand Down Expand Up @@ -52,6 +53,7 @@
34EF38B223CC2AC1000DE4AF /* StationChooserView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StationChooserView.swift; sourceTree = "<group>"; };
74ACA5CF5B67BD66D8845E5D /* Pods_Arrival_iOS2.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Arrival_iOS2.framework; sourceTree = BUILT_PRODUCTS_DIR; };
751A431627D2482AE13CFE9F /* Pods-Arrival-iOS2Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Arrival-iOS2Tests.release.xcconfig"; path = "Target Support Files/Pods-Arrival-iOS2Tests/Pods-Arrival-iOS2Tests.release.xcconfig"; sourceTree = "<group>"; };
C509BA82241BEC1A00920BC5 /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
C512BCC423E4FBA80079F49C /* TimePlayground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = TimePlayground.playground; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
C5166C3823F610AB001F0254 /* TermsOfSeriviceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TermsOfSeriviceView.swift; sourceTree = "<group>"; };
C51B3EDC23ED26330021EBE0 /* KNearestNeighborsClassifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KNearestNeighborsClassifier.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -186,6 +188,7 @@
C5166C3823F610AB001F0254 /* TermsOfSeriviceView.swift */,
C5B5A53523FA62B00046CCF5 /* TripComponentView.swift */,
C5B5A53623FA62B00046CCF5 /* TripDetailView.swift */,
C509BA82241BEC1A00920BC5 /* SearchBar.swift */,
C5B5A53923FA642D0046CCF5 /* TripWaitTimeView.swift */,
C5612DCC23FE3B58002A8E20 /* Helpers.swift */,
C52F1EBA240C13C900503995 /* ShareScreen.swift */,
Expand Down Expand Up @@ -357,6 +360,7 @@
C568C40023D8B99400AB9E67 /* Station.swift in Sources */,
C5B5A53A23FA642D0046CCF5 /* TripWaitTimeView.swift in Sources */,
C568C40623D95FA800AB9E67 /* LoginView.swift in Sources */,
C509BA83241BEC1A00920BC5 /* SearchBar.swift in Sources */,
C5DF911523F87EA800701D3F /* NoNetworkView.swift in Sources */,
C5B5A53823FA62B00046CCF5 /* TripDetailView.swift in Sources */,
C524E7B223FAEC87002BC9A5 /* moment.swift in Sources */,
Expand Down Expand Up @@ -514,7 +518,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.34;
MARKETING_VERSION = 1.34.1;
PRODUCT_BUNDLE_IDENTIFIER = com.ronanfuruta.arrival;
PRODUCT_NAME = Arrival;
SWIFT_VERSION = 5.0;
Expand All @@ -537,7 +541,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.34;
MARKETING_VERSION = 1.34.1;
PRODUCT_BUNDLE_IDENTIFIER = com.ronanfuruta.arrival;
PRODUCT_NAME = Arrival;
SWIFT_VERSION = 5.0;
Expand Down
4 changes: 2 additions & 2 deletions Arrival-iOS2/AppData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ class AppData: NSObject, ObservableObject,CLLocationManagerDelegate {
return Color.green
case "orange", "OR-N".lowercased(), "OR-S".lowercased() :
return Color.orange
case "purple", "PR-N".lowercased(), "PR-N".lowercased() :
case "purple", "PR-N".lowercased(), "PR-S".lowercased() :
return Color.purple
case "blue", "BL-N".lowercased(), "BL-N".lowercased() :
case "blue", "BL-N".lowercased(), "BL-S".lowercased() :
return Color.blue
case "white","WT-N".lowercased(), "WT-S".lowercased() :
return Color(UIColor.systemIndigo)
Expand Down
20 changes: 9 additions & 11 deletions Arrival-iOS2/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct HomeView: View {
}

}.sheet(isPresented: self.$fromModalDisplayed) {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 0) {
HStack(alignment: .center) {
Text("From Station")
.font(.largeTitle)
Expand All @@ -85,12 +85,13 @@ struct HomeView: View {
Text("Close")
}
}
VStack(alignment: .leading) {

VStack(alignment: .leading, spacing: 0) {
/*
TextField("Search for a Station", text: self.$fromStationSearch)
.padding()
.background(Color.inputBackground)
.cornerRadius(10)
.cornerRadius(10)*/
SearchBar(text: self.$fromStationSearch).padding(0).padding([.leading, .trailing], -10)
Spacer().frame(height: 10)
Text("suggested")
.font(.subheadline)
Expand Down Expand Up @@ -128,7 +129,7 @@ struct HomeView: View {
Text(stationDisplay(self.appData.toStation.name)).font(.headline)
}.lineLimit(1)
}.sheet(isPresented: self.$toModalDisplayed) {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 0) {
HStack(alignment: .center) {
Text("To Station")
.font(.largeTitle)
Expand All @@ -140,13 +141,10 @@ struct HomeView: View {
Text("Close")
}
}
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 0) {

TextField("Search for a Station", text: self.$fromStationSearch)
.padding()
.background(Color.inputBackground)
.cornerRadius(10)
Spacer().frame(height: 10)
SearchBar(text: self.$fromStationSearch).padding(0).padding([.leading, .trailing], -10)
Spacer().frame(height: 10)
Text("suggested")
.font(.subheadline)
List { ForEach(self.appData.toStationSuggestions.filter {
Expand Down
38 changes: 38 additions & 0 deletions Arrival-iOS2/SearchBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Foundation
import UIKit
import SwiftUI

struct SearchBar: UIViewRepresentable {

@Binding var text: String

class Coordinator: NSObject, UISearchBarDelegate {

@Binding var text: String

init(text: Binding<String>) {
_text = text
}

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
text = searchText
}
}
func makeCoordinator() -> SearchBar.Coordinator {
return Coordinator(text: $text)
}

func makeUIView(context: UIViewRepresentableContext<SearchBar>) -> UISearchBar {
let searchBar = UISearchBar(frame: .zero)
searchBar.searchBarStyle = .minimal
searchBar.placeholder = "Search for a station"
searchBar.delegate = context.coordinator
searchBar.autocapitalizationType = .none
searchBar.layoutMargins = UIEdgeInsets(top: 0.0, left: 5.0, bottom: 0.0, right: 0.0)
return searchBar
}

func updateUIView(_ uiView: UISearchBar, context: UIViewRepresentableContext<SearchBar>) {
uiView.text = text
}
}
84 changes: 58 additions & 26 deletions Arrival-iOS2/TripDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct TripDetailView: View {
@State var showShareSheet = false
@State var shareString = ""
@State var boarded = false
@State var shareActionSheet = false
@State var shareUrl: URL = URL(string:"https://google.com")!
@EnvironmentObject private var appData: AppData
func intalize() {
Expand All @@ -32,7 +33,7 @@ struct TripDetailView: View {
if (boardTime.isSameOrBefore(moment())) {
self.boarded = true
}

print(routeTime, destinationTIme.format(), originTIme.format(), "route time", wait)
self.routeTime = routeTime.stringValue + " min"

Expand Down Expand Up @@ -82,7 +83,7 @@ struct TripDetailView: View {
if (self.boarded) {
TripWaitTimeView(type: "boarded", time: self.boardWait).padding(.top)
} else {
TripWaitTimeView(type: "board", time: self.boardWait).padding(.top)
TripWaitTimeView(type: "board", time: self.boardWait).padding(.top)
}
} else {
TripWaitTimeView(type: "transfer", time: leg.transferWait ?? "").padding(.top)
Expand All @@ -98,46 +99,77 @@ struct TripDetailView: View {
}
Spacer()
Button(action: {
guard let link = URL(string: "https://arrival.city/trip/" + self.tripToShow.tripId) else { return }
let dynamicLinksDomainURIPrefix = "https://link.arrival.city"
let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix)
linkBuilder!.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.ronanfuruta.arrival")
linkBuilder!.iOSParameters!.appStoreID = "1497229798"
linkBuilder!.socialMetaTagParameters = DynamicLinkSocialMetaTagParameters()
linkBuilder!.socialMetaTagParameters!.title = self.shareString
linkBuilder!.socialMetaTagParameters!.descriptionText = "Tap to view trip details"
linkBuilder!.socialMetaTagParameters!.imageURL = URL(string: "https://arrival.city/images/logo.png")
guard let longDynamicLink = linkBuilder!.url else { return }
print("The long URL is: \(longDynamicLink)")

self.shareUrl = longDynamicLink
self.showShareSheet = true
Analytics.logEvent("sharing_trip_link", parameters: [
"url": longDynamicLink as! NSObject
])




self.shareActionSheet = true

}) {
HStack {
Spacer()
Text("SHARE ETA")
Text("SHARE TRIP")
.font(.body)
.fontWeight(.bold)
.multilineTextAlignment(.center)
.lineLimit(nil)
Spacer()
}.padding(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
}.background(/*@START_MENU_TOKEN@*/Color.blue/*@END_MENU_TOKEN@*/).cornerRadius(/*@START_MENU_TOKEN@*/10.0/*@END_MENU_TOKEN@*/).foregroundColor(/*@START_MENU_TOKEN@*/.white/*@END_MENU_TOKEN@*/).sheet(isPresented: $showShareSheet) {
}.background(/*@START_MENU_TOKEN@*/Color.blue/*@END_MENU_TOKEN@*/).cornerRadius(/*@START_MENU_TOKEN@*/10.0/*@END_MENU_TOKEN@*/).foregroundColor(/*@START_MENU_TOKEN@*/.white/*@END_MENU_TOKEN@*/).actionSheet(isPresented: $shareActionSheet) {
ActionSheet(title: Text("Choose how you want to share your trip"), message: Text("By destination: 5:00 ETA at Rockridge Station. \nBy train: 10min untill Antioch train at Balboa Park."), buttons: [.default(Text("ETA at destination"), action: {
print("sharing eta at destination")
let originTIme = moment(self.tripToShow.originTime + " " + self.tripToShow.originDate, dateFormateDate)
let destinationTIme = moment(self.tripToShow.destinatonTime + " " + self.tripToShow.destinatonDate, dateFormateDate)
self.shareString = destinationTIme.format("h:mma") + " eta at " + self.tripToShow.legs[self.tripToShow.legs.count - 1].destination + " station"

guard let link = URL(string: "https://arrival.city/trip/" + self.tripToShow.tripId) else { return }
let dynamicLinksDomainURIPrefix = "https://link.arrival.city"
let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix)
linkBuilder!.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.ronanfuruta.arrival")
linkBuilder!.iOSParameters!.appStoreID = "1497229798"
linkBuilder!.socialMetaTagParameters = DynamicLinkSocialMetaTagParameters()
linkBuilder!.socialMetaTagParameters!.title = self.shareString
linkBuilder!.socialMetaTagParameters!.descriptionText = "Tap to view trip details"
linkBuilder!.socialMetaTagParameters!.imageURL = URL(string: "https://arrival.city/images/logo.png")
guard let longDynamicLink = linkBuilder!.url else { return }
print("The long URL is: \(longDynamicLink)")

self.shareUrl = longDynamicLink
self.showShareSheet = true
Analytics.logEvent("sharing_trip_link", parameters: [
"url": longDynamicLink as! NSObject,
"type": "destination eta" as! NSObject
])

}), .default(Text("ETD of train"), action: {
print("sharing etd of train")
let originTIme = moment(self.tripToShow.originTime + " " + self.tripToShow.originDate, dateFormateDate)
let destinationTIme = moment(self.tripToShow.destinatonTime + " " + self.tripToShow.destinatonDate, dateFormateDate)
self.shareString = "\(self.boardWait) until \(self.tripToShow.legs[0].trainDestination) train at \(self.tripToShow.legs[0].origin)"
print("share string,", self.shareString)
guard let link = URL(string: "https://arrival.city/trip/" + self.tripToShow.tripId) else { return }
let dynamicLinksDomainURIPrefix = "https://link.arrival.city"
let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix)
linkBuilder!.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.ronanfuruta.arrival")
linkBuilder!.iOSParameters!.appStoreID = "1497229798"
linkBuilder!.socialMetaTagParameters = DynamicLinkSocialMetaTagParameters()
linkBuilder!.socialMetaTagParameters!.title = self.shareString
linkBuilder!.socialMetaTagParameters!.descriptionText = "Tap to view trip details"
linkBuilder!.socialMetaTagParameters!.imageURL = URL(string: "https://arrival.city/images/logo.png")
guard let longDynamicLink = linkBuilder!.url else { return }
print("The long URL is: \(longDynamicLink)")

self.shareUrl = longDynamicLink
self.showShareSheet = true
Analytics.logEvent("sharing_trip_link", parameters: [
"url": longDynamicLink as! NSObject,
"type": "train etd" as! NSObject
])
}), .cancel()])
}.sheet(isPresented: $showShareSheet) {

ShareSheet(sharing: [self.shareUrl])
}
Spacer().frame(height: 4.0)

}.padding().onAppear {

self.intalize()

}
Expand Down

0 comments on commit dcee16e

Please sign in to comment.