-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// LocationManager.swift | ||
// Weather App | ||
// | ||
// Created by John Suman on 2023/08/28. | ||
// | ||
|
||
import Foundation | ||
import CoreLocation | ||
|
||
class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { | ||
let manager = CLLocationManager() | ||
|
||
@Published var location: CLLocationCoordinate2D? | ||
@Published var isLoading = false | ||
|
||
override init() { | ||
super.init() | ||
manager.delegate = self | ||
} | ||
|
||
func requestLocation() { | ||
isLoading = true | ||
manager.requestLocation() | ||
} | ||
|
||
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | ||
location = locations.first?.coordinate | ||
isLoading = false | ||
} | ||
|
||
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { | ||
print("Error getting location", error) | ||
isLoading = false | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "1024x1024.png", | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// ContentView.swift | ||
// Weather App | ||
// | ||
// Created by John Suman on 2023/08/28. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
@StateObject var locationManager = LocationManager() | ||
|
||
var body: some View { | ||
VStack { | ||
|
||
if let location = locationManager.location { | ||
Text("Your coordinates are: \(location.longitude), \(location.latitude)") | ||
} else { | ||
if locationManager.isLoading { | ||
LoadingView() | ||
} else { | ||
WelcomeView() | ||
.environmentObject(locationManager) | ||
} | ||
} | ||
|
||
|
||
} | ||
.background(/*@START_MENU_TOKEN@*//*@PLACEHOLDER=View@*/Color(hue: 0.673, saturation: 0.885, brightness: 0.441)/*@END_MENU_TOKEN@*/) | ||
.preferredColorScheme(/*@START_MENU_TOKEN@*/.dark/*@END_MENU_TOKEN@*/) | ||
|
||
} | ||
} | ||
|
||
#Preview { | ||
ContentView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// LoadingView.swift | ||
// Weather App | ||
// | ||
// Created by John Suman on 2023/08/28. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct LoadingView: View { | ||
var body: some View { | ||
ProgressView() | ||
.progressViewStyle(CircularProgressViewStyle(tint: .white)) | ||
.frame(maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, maxHeight: .infinity) | ||
} | ||
} | ||
|
||
#Preview { | ||
LoadingView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// WelcomeView.swift | ||
// Weather App | ||
// | ||
// Created by John Suman on 2023/08/28. | ||
// | ||
|
||
import SwiftUI | ||
import CoreLocationUI | ||
|
||
struct WelcomeView: View { | ||
@EnvironmentObject var locationManager: LocationManager | ||
|
||
var body: some View { | ||
VStack { | ||
VStack(spacing: 20) { | ||
Text("Welcome to the Weather App") | ||
.bold() | ||
.font(.title) | ||
Text("Please share your current location to get the weather in your spot") | ||
.padding() | ||
} | ||
.multilineTextAlignment(.center) | ||
.padding() | ||
|
||
LocationButton(.shareCurrentLocation) { | ||
locationManager.requestLocation() | ||
} | ||
.cornerRadius(30) | ||
.symbolVariant(.fill) | ||
.foregroundColor(.white) | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
} | ||
} | ||
|
||
#Preview { | ||
WelcomeView() | ||
} |