Skip to content

Commit

Permalink
Add suport for website
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Muniz Azevedo Filho committed Oct 10, 2023
1 parent 9512710 commit 7e669e4
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 37 deletions.
8 changes: 8 additions & 0 deletions Airports.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
324E23EF2AD0FAFD00198221 /* launch_animation.json in Resources */ = {isa = PBXBuildFile; fileRef = 324E23EE2AD0FAFD00198221 /* launch_animation.json */; };
324E23F12AD0FB4000198221 /* LaunchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324E23F02AD0FB4000198221 /* LaunchView.swift */; };
324E23F52AD104D900198221 /* AirportInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324E23F42AD104D900198221 /* AirportInfoView.swift */; };
32829CBE2AD50E3200BF7C92 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32829CBD2AD50E3200BF7C92 /* WebView.swift */; };
32829CC02AD50E5500BF7C92 /* DetailRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32829CBF2AD50E5500BF7C92 /* DetailRow.swift */; };
32A1490B2ACBA30600D8E87A /* airports.json in Resources */ = {isa = PBXBuildFile; fileRef = 32A1490A2ACBA30600D8E87A /* airports.json */; };
32AB3B502ACA7C3E007C7528 /* AirportsApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32AB3B4F2ACA7C3E007C7528 /* AirportsApp.swift */; };
32AB3B522ACA7C3E007C7528 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32AB3B512ACA7C3E007C7528 /* ContentView.swift */; };
Expand Down Expand Up @@ -39,6 +41,8 @@
324E23EE2AD0FAFD00198221 /* launch_animation.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = launch_animation.json; sourceTree = "<group>"; };
324E23F02AD0FB4000198221 /* LaunchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchView.swift; sourceTree = "<group>"; };
324E23F42AD104D900198221 /* AirportInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AirportInfoView.swift; sourceTree = "<group>"; };
32829CBD2AD50E3200BF7C92 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
32829CBF2AD50E5500BF7C92 /* DetailRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailRow.swift; sourceTree = "<group>"; };
32A1490A2ACBA30600D8E87A /* airports.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = airports.json; sourceTree = "<group>"; };
32AB3B4C2ACA7C3E007C7528 /* Airports.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Airports.app; sourceTree = BUILT_PRODUCTS_DIR; };
32AB3B4F2ACA7C3E007C7528 /* AirportsApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AirportsApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,6 +85,8 @@
32FABEC82ACA868C008CEFE0 /* AirportListView.swift */,
324E23F02AD0FB4000198221 /* LaunchView.swift */,
324E23F42AD104D900198221 /* AirportInfoView.swift */,
32829CBD2AD50E3200BF7C92 /* WebView.swift */,
32829CBF2AD50E5500BF7C92 /* DetailRow.swift */,
);
path = Screens;
sourceTree = "<group>";
Expand Down Expand Up @@ -264,6 +270,8 @@
buildActionMask = 2147483647;
files = (
324E23F52AD104D900198221 /* AirportInfoView.swift in Sources */,
32829CC02AD50E5500BF7C92 /* DetailRow.swift in Sources */,
32829CBE2AD50E3200BF7C92 /* WebView.swift in Sources */,
32FABEC32ACA8530008CEFE0 /* Airport.swift in Sources */,
32FABEC92ACA868C008CEFE0 /* AirportListView.swift in Sources */,
32AB3B522ACA7C3E007C7528 /* ContentView.swift in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion Airports/Models/Airport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ struct Airport: Codable, Identifiable, Equatable {
let type: String
let lat: Float
let country: Country
let website: String?

enum CodingKeys: String, CodingKey {
case id = "iata"
case lon, country, isOpen, name, continent, type, lat
case lon, country, isOpen, name, continent, type, lat, website
}
}

Expand Down
73 changes: 46 additions & 27 deletions Airports/Screens/AirportInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,34 @@ import SwiftUI

struct AirportInfoView: View {
let airport: Airport
@State private var isSheetPresented = false

var body: some View {
NavigationStack {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 10) {
HStack {
Text("Name:")
.font(.headline)
Text(airport.name)
}
HStack {
HStack {
Text("Identifier:")
.font(.headline)
Text(airport.id)
}
HStack {
Text("Continent:")
.font(.headline)
Text(airport.continent.rawValue)
}
}
HStack {
Text("Coordinates:")
.font(.headline)
Text("Lat: \(airport.lat)")
Text("Lon: \(airport.lon)")
}
}.padding()

DetailRow(
label: "Name",
value: airport.name,
icon: Image(systemName: "airplane")
)
DetailRow(
label: "Identifier",
value: airport.id,
icon: Image(systemName: "barcode.viewfinder")
)
DetailRow(
label: "Continent",
value: airport.continent.name,
icon: Image(systemName: "map")
)
DetailRow(
label: "Coordinates",
value: "Lat: \(airport.lat) Lon: \(airport.lon)",
icon: Image(systemName: "mappin.and.ellipse")
)
}
.padding()
Map(position: .constant(.region(MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: Double(airport.lat),
Expand All @@ -50,7 +48,27 @@ struct AirportInfoView: View {
}
.mapStyle(.hybrid)
}
}.navigationTitle(airport.name)
}
.navigationTitle(airport.name)
.toolbar {
if let _ = airport.website {
Button(action: {
isSheetPresented.toggle()
}) {
Image(systemName: "plus")
.foregroundColor(.primary)
}
}
}
.sheet(isPresented: $isSheetPresented) {
if let website = airport.website {
WebView(urlString: website)
.frame(
maxWidth: .infinity,
maxHeight: .infinity
)
}
}
}
}

Expand All @@ -72,6 +90,7 @@ private extension Airport {
country: .init(
iso: "GT",
name: "Guatemala"
)
),
website: nil
)
}
30 changes: 22 additions & 8 deletions Airports/Screens/AirportListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ struct AirportListView: View {
NavigationLink {
AirportInfoView(airport: airport)
} label: {
Text(airport.name)
HStack {
Text(airport.name)
Spacer()
Image(systemName: "airplane")
.foregroundColor(.primary)
}
}
}
}
.tint(.primary)
}
}
}
Expand All @@ -26,15 +32,23 @@ struct AirportListView: View {
.onAppear(perform: loadData)
.searchable(text: $searchText) {
ForEach(searchResults) { sectionItem in
Section(header: Text(sectionItem.continent.name)) {
ForEach(sectionItem.subsections) { subsection in
HStack {
Text(subsection.country.name)
Spacer()
Text(subsection.country.iso)
Section(header: Text(sectionItem.continent.name)
.padding(8)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)) {
ForEach(sectionItem.subsections) { subsection in
HStack {
Text(subsection.country.name)
.fontWeight(.medium)
Spacer()
Text(subsection.country.iso)
.font(.subheadline)
.foregroundColor(.gray)
}
.padding(.vertical, 5)
}
}
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions Airports/Screens/DetailRow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import SwiftUI

struct DetailRow: View {
var label: String
var value: String
var icon: Image

var body: some View {
HStack(spacing: 20) {
icon
.resizable()
.frame(width: 20, height: 20)
.foregroundColor(.primary)
VStack(alignment: .leading) {
Text(label)
.font(.subheadline)
.foregroundColor(.gray)
Text(value)
.font(.headline)
}
Spacer()
}
}
}
18 changes: 18 additions & 0 deletions Airports/Screens/WebView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import SwiftUI
import WebKit

struct WebView: UIViewRepresentable {
let urlString: String

func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView()
return webView
}

func updateUIView(_ uiView: WKWebView, context: Context) {
if let url = URL(string: urlString) {
let request = URLRequest(url: url)
uiView.load(request)
}
}
}
3 changes: 2 additions & 1 deletion Airports/airports.json
Original file line number Diff line number Diff line change
Expand Up @@ -59758,7 +59758,8 @@
"country": {
"iso": "BR",
"name": "Brazil"
}
},
"website": "https://www.aenabrasil.com.br/pt/aeroportos/aeroporto-internacional-do-recife-guararapes-gilberto-freyre/index.html"
},
{
"iata": "SDU",
Expand Down

0 comments on commit 7e669e4

Please sign in to comment.