Merge branch 'main' of https://stax.alwaysdata.net/gitea/staxriver/PadelClub
commit
58eccc5692
@ -0,0 +1,173 @@ |
|||||||
|
// |
||||||
|
// EditSharingView.swift |
||||||
|
// Padel Tournament |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 03/02/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
import TipKit |
||||||
|
import CoreTransferable |
||||||
|
|
||||||
|
struct EditSharingView: View { |
||||||
|
@Environment(Tournament.self) var tournament: Tournament |
||||||
|
var match: Match |
||||||
|
@State private var displayRank: Bool = false |
||||||
|
@State private var displayTeamTitle: Bool = false |
||||||
|
@State private var showCamera: Bool = false |
||||||
|
@State private var newImage: UIImage? |
||||||
|
@State private var copied: Bool = false |
||||||
|
|
||||||
|
var shareMessage: String { |
||||||
|
shareMessage(displayRank: displayRank, displayTeamName: displayTeamTitle) |
||||||
|
} |
||||||
|
|
||||||
|
func shareMessage(displayRank: Bool, displayTeamName: Bool) -> String { |
||||||
|
var messageData: [String] = [] |
||||||
|
|
||||||
|
var locAndTime: String = "" |
||||||
|
if let courtName = match.courtName() { |
||||||
|
locAndTime.append("\(courtName)") |
||||||
|
} |
||||||
|
|
||||||
|
if let startDate = match.startDate { |
||||||
|
locAndTime = locAndTime + " à " + startDate.formattedAsHourMinute() |
||||||
|
} |
||||||
|
|
||||||
|
if locAndTime.isEmpty == false { |
||||||
|
messageData.append(locAndTime) |
||||||
|
} |
||||||
|
|
||||||
|
messageData.append(tournament.tournamentTitle()) |
||||||
|
|
||||||
|
let message = [match.isLoserBracket ? "Classement" : nil, match.roundTitle(), match.isLoserBracket ? nil : ((match.index > 0 || match.isGroupStage()) ? match.matchTitle(.short) : nil)].compactMap({ $0 }).joined(separator: " ") |
||||||
|
|
||||||
|
messageData.append(message) |
||||||
|
|
||||||
|
guard let labelOne = match.team(.one)?.teamLabelRanked(displayRank: displayRank, displayTeamName: displayTeamName), let labelTwo = match.team(.two)?.teamLabelRanked(displayRank: displayRank, displayTeamName: displayTeamName) else { |
||||||
|
return messageData.joined(separator: "\n") |
||||||
|
} |
||||||
|
|
||||||
|
let players = "\(labelOne)\ncontre\n\(labelTwo)" |
||||||
|
messageData.append(players) |
||||||
|
|
||||||
|
return messageData.joined(separator: "\n") |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var body: some View { |
||||||
|
List { |
||||||
|
|
||||||
|
if let newImage { |
||||||
|
Section { |
||||||
|
let tip = SharePictureTip() |
||||||
|
TipView(tip) |
||||||
|
.tipStyle(tint: .green) |
||||||
|
} |
||||||
|
|
||||||
|
Section { |
||||||
|
ZStack { |
||||||
|
Color.black |
||||||
|
.ignoresSafeArea() |
||||||
|
Image(uiImage: newImage) |
||||||
|
.resizable() |
||||||
|
.scaledToFit() |
||||||
|
.frame(height: 200, alignment: .center) |
||||||
|
.frame(maxWidth: .infinity, alignment: .center) |
||||||
|
} |
||||||
|
.listRowInsets(EdgeInsets()) |
||||||
|
} footer: { |
||||||
|
HStack { |
||||||
|
Spacer() |
||||||
|
Button("effacer", role: .destructive) { |
||||||
|
self.newImage = nil |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
Button { |
||||||
|
showCamera = true |
||||||
|
} label: { |
||||||
|
Label("Prendre une photo", systemImage: "camera") |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
Section { |
||||||
|
Toggle(isOn: $displayRank) { |
||||||
|
Text("Afficher leurs rangs dans ce tournoi") |
||||||
|
} |
||||||
|
|
||||||
|
Toggle(isOn: $displayTeamTitle) { |
||||||
|
Text("Afficher plutôt le nom de l'équipe") |
||||||
|
} |
||||||
|
} header: { |
||||||
|
Text("Options") |
||||||
|
} |
||||||
|
|
||||||
|
Section { |
||||||
|
Text(shareMessage) |
||||||
|
} header: { |
||||||
|
Text("Message type généré") |
||||||
|
} footer: { |
||||||
|
HStack { |
||||||
|
Spacer() |
||||||
|
Button { |
||||||
|
UIPasteboard.general.string = shareMessage |
||||||
|
copied = true |
||||||
|
} label: { |
||||||
|
Label(copied ? "copié" : "copier", systemImage: "doc.on.doc") |
||||||
|
} |
||||||
|
|
||||||
|
if shareMessage == UIPasteboard.general.string || copied == true { |
||||||
|
Image(systemName: "checkmark") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.toolbar { |
||||||
|
ToolbarItem(placement: .topBarTrailing) { |
||||||
|
if let newImage { |
||||||
|
let photo = Photo(image: Image(uiImage:newImage), caption: shareMessage) |
||||||
|
ShareLink( |
||||||
|
item: photo, |
||||||
|
preview: SharePreview( |
||||||
|
photo.caption, |
||||||
|
image: photo.image)) { |
||||||
|
Text("Partager") |
||||||
|
} |
||||||
|
.onAppear { |
||||||
|
UIPasteboard.general.string = shareMessage |
||||||
|
copied = true |
||||||
|
} |
||||||
|
} else { |
||||||
|
ShareLink("Partager", item: shareMessage) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.navigationTitle("Préparation") |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
.fullScreenCover(isPresented: $showCamera) { |
||||||
|
ImagePickerView(image: $newImage) |
||||||
|
.background(Color.black.edgesIgnoringSafeArea(.all)) |
||||||
|
} |
||||||
|
.onChange(of: displayRank) { |
||||||
|
copied = false |
||||||
|
} |
||||||
|
.onChange(of: displayTeamTitle) { |
||||||
|
copied = false |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct Photo: Transferable { |
||||||
|
static var transferRepresentation: some TransferRepresentation { |
||||||
|
ProxyRepresentation(exporting: \.image) |
||||||
|
ProxyRepresentation(exporting: \.caption) |
||||||
|
} |
||||||
|
|
||||||
|
public var image: Image |
||||||
|
public var caption: String |
||||||
|
} |
||||||
@ -0,0 +1,59 @@ |
|||||||
|
// |
||||||
|
// ImagePicker.swift |
||||||
|
// Poker Analytics 6 |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 22/09/2021. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
#if targetEnvironment(simulator) |
||||||
|
struct ImagePickerView: View { |
||||||
|
@Binding var image: UIImage? |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
EmptyView() |
||||||
|
.onAppear { |
||||||
|
image = UIImage(systemName: "star.fill") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
#else |
||||||
|
|
||||||
|
struct ImagePickerView: UIViewControllerRepresentable { |
||||||
|
|
||||||
|
@Environment(\.presentationMode) var presentationMode |
||||||
|
@Binding var image: UIImage? |
||||||
|
|
||||||
|
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { |
||||||
|
let parent: ImagePickerView |
||||||
|
|
||||||
|
init(_ parent: ImagePickerView) { |
||||||
|
self.parent = parent |
||||||
|
} |
||||||
|
|
||||||
|
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { |
||||||
|
if let uiImage = info[.originalImage] as? UIImage { |
||||||
|
parent.image = uiImage |
||||||
|
} |
||||||
|
parent.presentationMode.wrappedValue.dismiss() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func makeCoordinator() -> Coordinator { |
||||||
|
Coordinator(self) |
||||||
|
} |
||||||
|
|
||||||
|
func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePickerView>) -> UIImagePickerController { |
||||||
|
let picker = UIImagePickerController() |
||||||
|
picker.sourceType = .camera |
||||||
|
picker.allowsEditing = true |
||||||
|
picker.showsCameraControls = true |
||||||
|
picker.delegate = context.coordinator |
||||||
|
return picker |
||||||
|
} |
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext<ImagePickerView>) { } |
||||||
|
} |
||||||
|
|
||||||
|
#endif |
||||||
Loading…
Reference in new issue