Skip to content

Commit

Permalink
Fixed #32
Browse files Browse the repository at this point in the history
  • Loading branch information
c22dev committed Sep 15, 2024
1 parent fc55370 commit 5e47836
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
37 changes: 37 additions & 0 deletions Geranium/Libs/Addon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,34 @@ extension UIApplication {
present(alert: alertController)
}

// bad programming practices but im lazy

func DualTextFieldAlert(title: String, message: String, textFieldPlaceHolder: String, secondTextFieldPlaceHolder: String, completion: @escaping (String?, String?) -> Void) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)

alertController.addTextField { (textField) in
textField.placeholder = textFieldPlaceHolder
textField.keyboardType = .decimalPad
}

alertController.addTextField { (textField) in
textField.placeholder = secondTextFieldPlaceHolder
textField.keyboardType = .decimalPad
}

let okAction = UIAlertAction(title: "OK", style: .default) { _ in
let latText = alertController.textFields?[0].text
let longText = alertController.textFields?[1].text
completion(latText, longText)
}

let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(okAction)
alertController.addAction(cancelAction)

presentDual(alertController: alertController)
}

func change(title: String = "Error", body: String) {
DispatchQueue.main.async {
currentUIAlertController?.title = title
Expand All @@ -222,6 +250,15 @@ extension UIApplication {
}
}

func presentDual(alertController: UIAlertController) {
if var topController = self.windows.first?.rootViewController {
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
topController.present(alertController, animated: true)
}
}

func respringDeprecated() {
let app = self
// Credit to Amy While for this respring bug
Expand Down
31 changes: 12 additions & 19 deletions Geranium/LocSim/LocSimView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ struct LocSimView: View {
@State private var long: Double = 0.0
@State private var tappedCoordinate: EquatableCoordinate? = nil
@State private var bookmarkSheetTggle: Bool = false
@State private var appliedCust: Bool = false
@State private var latTemp = ""
@State private var longTemp = ""
var body: some View {
if #available(iOS 16.0, *) {
NavigationStack {
Expand Down Expand Up @@ -64,7 +61,18 @@ struct LocSimView: View {
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
appliedCust.toggle()
UIApplication.shared.DualTextFieldAlert(
title: "Enter Coordinates",
message: "The location will be simulated on device\nPro tip: Press wherever on the map to move there.",
textFieldPlaceHolder: "Latitude",
secondTextFieldPlaceHolder: "Longitude"
) { latText, longText in
if let lat = Double(latText ?? ""), let long = Double(longText ?? "") {
LocSimManager.startLocSim(location: .init(latitude: lat, longitude: long))
} else {
UIApplication.shared.alert(body: "Those are invalid coordinates mate !")
}
}
}) {
Image(systemName: "mappin")
.resizable()
Expand Down Expand Up @@ -110,23 +118,8 @@ struct LocSimView: View {
}
}
}
.alert("Enter your coordinates", isPresented: $appliedCust) {
TextField("Latitude", text: $latTemp)
TextField("Longitude", text: $longTemp)
Button("OK", action: submit)
} message: {
Text("The location will be simulated on device\nPro tip: Press wherever on the map to move there.")
}
.sheet(isPresented: $bookmarkSheetTggle) {
BookMarkSlider(lat: $lat, long: $long)
}
}
func submit() {
if !latTemp.isEmpty, !longTemp.isEmpty {
LocSimManager.startLocSim(location: .init(latitude: Double(latTemp) ?? 0.0, longitude: Double(longTemp) ?? 0.0))
}
else {
UIApplication.shared.alert(body: "Those are empty coordinates mate !")
}
}
}
5 changes: 5 additions & 0 deletions Geranium/Translations/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -3369,6 +3369,7 @@
}
},
"Enter your coordinates" : {
"extractionState" : "stale",
"localizations" : {
"fr" : {
"stringUnit" : {
Expand Down Expand Up @@ -4493,6 +4494,7 @@
}
},
"Latitude" : {
"extractionState" : "stale",
"localizations" : {
"fr" : {
"stringUnit" : {
Expand Down Expand Up @@ -4841,6 +4843,7 @@
}
},
"Longitude" : {
"extractionState" : "stale",
"localizations" : {
"fr" : {
"stringUnit" : {
Expand Down Expand Up @@ -5271,6 +5274,7 @@
}
},
"OK" : {
"extractionState" : "stale",
"localizations" : {
"fr" : {
"stringUnit" : {
Expand Down Expand Up @@ -6907,6 +6911,7 @@
}
},
"The location will be simulated on device\nPro tip: Press wherever on the map to move there." : {
"extractionState" : "stale",
"localizations" : {
"fr" : {
"stringUnit" : {
Expand Down

0 comments on commit 5e47836

Please sign in to comment.