|
|
|
|
@ -6,17 +6,135 @@ |
|
|
|
|
// |
|
|
|
|
|
|
|
|
|
import SwiftUI |
|
|
|
|
import CoreImage.CIFilterBuiltins |
|
|
|
|
import LeStorage |
|
|
|
|
|
|
|
|
|
extension String : Identifiable { |
|
|
|
|
public var id: String { self } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct BroadcastView: View { |
|
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
|
let context = CIContext() |
|
|
|
|
let filter = CIFilter.qrCodeGenerator() |
|
|
|
|
@State private var urlToShow: String? |
|
|
|
|
@State private var tvMode: Bool = false |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
@Bindable var tournament = tournament |
|
|
|
|
List { |
|
|
|
|
Section { |
|
|
|
|
Toggle(isOn: $tournament.isPrivate) { |
|
|
|
|
Text("Tournoi privée") |
|
|
|
|
} |
|
|
|
|
} footer: { |
|
|
|
|
Text("Le tournoi sera masqué sur le site \(URLs.main.rawValue)") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
LabeledContent { |
|
|
|
|
actionForURL(URLs.main.url) |
|
|
|
|
} label: { |
|
|
|
|
Text("Lien Padel Club") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let club = tournament.club(), let clubURL = club.shareURL() { |
|
|
|
|
LabeledContent { |
|
|
|
|
actionForURL(clubURL) |
|
|
|
|
} label: { |
|
|
|
|
Text("Lien du club") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let url = tournament.shareURL() { |
|
|
|
|
LabeledContent { |
|
|
|
|
actionForURL(url) |
|
|
|
|
} label: { |
|
|
|
|
Text("Lien du tournoi") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let url = tournament.broadcastURL() { |
|
|
|
|
LabeledContent { |
|
|
|
|
actionForURL(url) |
|
|
|
|
} label: { |
|
|
|
|
Text("Lien TV") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} header: { |
|
|
|
|
Text("Liens à partager") |
|
|
|
|
.textCase(nil) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
.navigationTitle("Diffusion") |
|
|
|
|
.navigationBarTitleDisplayMode(.inline) |
|
|
|
|
.toolbarBackground(.visible, for: .navigationBar) |
|
|
|
|
.sheet(item: $urlToShow) { urlToShow in |
|
|
|
|
Image(uiImage: generateQRCode(from: urlToShow)) |
|
|
|
|
.interpolation(.none) |
|
|
|
|
.resizable() |
|
|
|
|
.scaledToFit() |
|
|
|
|
.frame(width: 300, height: 300) |
|
|
|
|
.onAppear { |
|
|
|
|
UIPasteboard.general.string = urlToShow |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.onChange(of: tournament.isPrivate) { |
|
|
|
|
_save() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _save() { |
|
|
|
|
do { |
|
|
|
|
try dataStore.tournaments.addOrUpdate(instance: tournament) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func generateQRCode(from string: String) -> UIImage { |
|
|
|
|
filter.message = Data(string.utf8) |
|
|
|
|
|
|
|
|
|
if let outputImage = filter.outputImage { |
|
|
|
|
if let cgimg = context.createCGImage(outputImage, from: outputImage.extent) { |
|
|
|
|
return UIImage(cgImage: cgimg) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return UIImage(systemName: "xmark.circle") ?? UIImage() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ViewBuilder |
|
|
|
|
func actionForURL(_ url: URL, removeSource: Bool = false) -> some View { |
|
|
|
|
Menu { |
|
|
|
|
Button { |
|
|
|
|
UIApplication.shared.open(url) |
|
|
|
|
} label: { |
|
|
|
|
Label("Voir", systemImage: "safari") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Button { |
|
|
|
|
urlToShow = url.absoluteString |
|
|
|
|
} label: { |
|
|
|
|
Label("QRCode", systemImage: "qrcode") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ShareLink(item: url) { |
|
|
|
|
Label("Partager le lien", systemImage: "link") |
|
|
|
|
} |
|
|
|
|
} label: { |
|
|
|
|
Text("lien") |
|
|
|
|
.underline() |
|
|
|
|
} |
|
|
|
|
.buttonStyle(.borderless) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#Preview { |
|
|
|
|
BroadcastView() |
|
|
|
|
} |
|
|
|
|
|