You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
6.6 KiB
201 lines
6.6 KiB
//
|
|
// BroadcastView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 01/05/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreImage.CIFilterBuiltins
|
|
import LeStorage
|
|
import TipKit
|
|
|
|
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
|
|
|
|
let tournamentPublishingTip = TournamentPublishingTip()
|
|
let tournamentTVBroadcastTip = TournamentTVBroadcastTip()
|
|
|
|
var body: some View {
|
|
@Bindable var tournament = tournament
|
|
List {
|
|
Section {
|
|
TipView(tournamentPublishingTip) { action in
|
|
UIApplication.shared.open(URLs.padelClub.url)
|
|
}
|
|
.tipStyle(tint: nil)
|
|
}
|
|
Section {
|
|
TipView(tournamentTVBroadcastTip)
|
|
.tipStyle(tint: nil)
|
|
}
|
|
|
|
if tournament.publishManually == false {
|
|
Section {
|
|
Text("En mode automatique, Padel Club détermine le meilleur moment pour publier les informations du tournoi.\n\n• La liste des équipes sera visible au maximum 2 jours après la clôture des inscriptions. À partir des p500, la liste d'attente à la clôture sera également publiée.\n\n• Les convocations ne seront visibles qu'à partir du premier jour du tournoi.\n\n• Les poules ne seront visibles qu'au premier jour des poules.\n\n• Le tableau ne sera visible qu'au premier jour du tableau.")
|
|
} header: {
|
|
Text("Mode Automatique")
|
|
} footer: {
|
|
FooterButtonView("désactiver le mode automatique") {
|
|
tournament.publishManually.toggle()
|
|
}
|
|
}
|
|
}
|
|
|
|
if tournament.publishManually == true {
|
|
Section {
|
|
Text("En mode manuel, vous devez indiquer à Padel Club le moment où vous souhaitez publier les informations du tournoi")
|
|
|
|
Toggle(isOn: $tournament.publishTeams) {
|
|
Text("Publier la liste des équipes")
|
|
Text("Les horaires de convocations ne seront pas publiés")
|
|
}
|
|
Toggle(isOn: $tournament.publishWaitingList) {
|
|
Text("Inclure les équipes en liste d'attente")
|
|
}
|
|
Toggle(isOn: $tournament.publishSummons) {
|
|
Text("Publier les convocations")
|
|
}
|
|
Toggle(isOn: $tournament.publishGroupStages) {
|
|
Text("Publier les poules")
|
|
}
|
|
Toggle(isOn: $tournament.publishBrackets) {
|
|
Text("Publier le tableau")
|
|
}
|
|
} header: {
|
|
Text("Mode Manuel")
|
|
} footer: {
|
|
FooterButtonView("activer le mode automatique") {
|
|
tournament.publishManually.toggle()
|
|
}
|
|
}
|
|
}
|
|
|
|
Section {
|
|
Toggle(isOn: $tournament.isPrivate) {
|
|
Text("Tournoi privé")
|
|
}
|
|
} 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)
|
|
}
|
|
|
|
}
|
|
.headerProminence(.increased)
|
|
.navigationTitle("Publication")
|
|
.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: {
|
|
HStack {
|
|
Spacer()
|
|
Text("lien")
|
|
.underline()
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.buttonStyle(.borderless)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#Preview {
|
|
BroadcastView()
|
|
}
|
|
|