1 |
efrain |
1 |
//
|
|
|
2 |
// CardSlideView.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 2/17/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import SwiftUI
|
|
|
9 |
|
|
|
10 |
struct CardSlideView: View {
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
private let colorCardViewBackground = UIColor(hex: Config.COLOR_WINDOW_BACKGROUND)
|
|
|
16 |
private let colorWindowBackground = UIColor(hex: Config.COLOR_WINDOW_BACKGROUND)
|
|
|
17 |
private let colorCardViewBorder = UIColor(hex: Config.COLOR_CARD_VIEW_BORDER)
|
|
|
18 |
private let colorBackgroundTopicFooter = UIColor(hex: Config.COLOR_BACKGROUND_TOPIC_FOOTER)
|
|
|
19 |
private let colorForegroundTopicProgressBar = UIColor(hex: Config.COLOR_FOREGROUND_TOPIC_PROGRESS_BAR)
|
|
|
20 |
|
|
|
21 |
private let colorTitle = UIColor(hex: Config.COLOR_TEXT_VIEW_TITLE);
|
|
|
22 |
|
|
|
23 |
private var position : Int
|
|
|
24 |
private var viewModel = SlideCardViewModel()
|
|
|
25 |
|
|
|
26 |
@State private var goToGallery : Bool = false
|
|
|
27 |
|
|
|
28 |
init(slideUuid : String, position : Int)
|
|
|
29 |
{
|
|
|
30 |
|
|
|
31 |
print("CardSlideView slideUuid : \(slideUuid)")
|
|
|
32 |
|
|
|
33 |
let preference = Preference.sharedInstance
|
|
|
34 |
self.viewModel.fetch(slideUuid: slideUuid, userUuid: preference.userUuid)
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
self.position = position
|
|
|
38 |
|
|
|
39 |
if self.viewModel.slide.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
|
|
|
40 |
self.viewModel.slide.name = String(Array(self.viewModel.slide.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
var body: some View {
|
|
|
49 |
GeometryReader { geometry in
|
|
|
50 |
//let cardProportional = 1.1 * (geometry.size.height / (geometry.size.width - 20))
|
|
|
51 |
//let cardWidht = (geometry.size.width - 20) / 2
|
|
|
52 |
//let cardHeigh = cardWidht * cardProportional
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
let checkMarkX = (geometry.size.width - 40) / 2
|
|
|
56 |
let checkMarkY = -1 * ((geometry.size.height - 50) / 2)
|
|
|
57 |
|
|
|
58 |
Button(action: {
|
|
|
59 |
let preference = Preference.sharedInstance
|
|
|
60 |
preference.topicUuidActive = self.viewModel.slide.topicUuid
|
|
|
61 |
preference.capsuleUuidActive = self.viewModel.slide.capsuleUuid
|
|
|
62 |
preference.slideUuidActive = self.viewModel.slide.uuid
|
|
|
63 |
preference.save()
|
|
|
64 |
|
|
|
65 |
self.goToGallery = true
|
|
|
66 |
}) {
|
|
|
67 |
NavigationLink("", destination: GridGalleryView(capsuleUuid: self.viewModel.slide.capsuleUuid, position: position), isActive: self.$goToGallery).frame( height: 0)
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
ZStack {
|
|
|
71 |
if self.viewModel.slide.completed == 1 {
|
|
|
72 |
Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage()).alignmentGuide(.top, computeValue: { dimension in
|
|
|
73 |
10
|
|
|
74 |
}).offset(x: checkMarkX, y: checkMarkY)
|
|
|
75 |
.zIndex(10000)
|
|
|
76 |
.scaleEffect(0.8)
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
VStack {
|
|
|
80 |
Text( self.viewModel.slide.name)
|
|
|
81 |
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
|
|
|
82 |
.font(.system(size: 11.0))
|
|
|
83 |
.foregroundColor(Color(colorTitle ?? .red))
|
|
|
84 |
.padding(.horizontal, 5)
|
|
|
85 |
.padding(.top, 5)
|
|
|
86 |
|
|
|
87 |
Spacer()
|
|
|
88 |
HStack {
|
|
|
89 |
|
|
|
90 |
if viewModel.slide.background.isEmpty && viewModel.slide.file.isEmpty {
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
Image(uiImage: UIImage(named: "logo") ?? UIImage())
|
|
|
94 |
.resizable()
|
|
|
95 |
.aspectRatio(contentMode: .fit)
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
} else {
|
|
|
99 |
|
|
|
100 |
CustomAsyncImage(
|
|
|
101 |
url: URL(string:
|
|
|
102 |
self.viewModel.slide.type == Constants.SLIDE_TYPE_IMAGE ? self.viewModel.slide.file : self.viewModel.slide.background)!,
|
|
|
103 |
placeholder: { Text("Cargando...").font(.footnote).foregroundColor(.black)},
|
|
|
104 |
image: {
|
|
|
105 |
Image(uiImage: $0).resizable()
|
|
|
106 |
}
|
|
|
107 |
)
|
|
|
108 |
}
|
|
|
109 |
}.padding(.horizontal, 5)
|
|
|
110 |
.zIndex(500)
|
|
|
111 |
|
|
|
112 |
Spacer()
|
|
|
113 |
|
|
|
114 |
Group() {
|
|
|
115 |
HStack {
|
|
|
116 |
Spacer()
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
.background(Color(colorBackgroundTopicFooter ?? .red))
|
|
|
120 |
|
|
|
121 |
}.background(Color(colorCardViewBackground ?? .red))
|
|
|
122 |
.cornerRadius(16)
|
|
|
123 |
.overlay(
|
|
|
124 |
RoundedRectangle(cornerRadius: 16)
|
|
|
125 |
.stroke(Color(colorCardViewBorder ?? .red), lineWidth: 1)
|
|
|
126 |
)
|
|
|
127 |
.padding(.horizontal, 5)
|
|
|
128 |
} .onAppear {
|
|
|
129 |
print("CardSlideView")
|
|
|
130 |
} .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_COMPLETED_SLIDE))
|
|
|
131 |
{ data in
|
|
|
132 |
if data.userInfo != nil {
|
|
|
133 |
if let notificationSlideUuid = data.userInfo?["slideUuid"]! as? String {
|
|
|
134 |
if !notificationSlideUuid.isEmpty && notificationSlideUuid == self.viewModel.slide.uuid {
|
|
|
135 |
|
|
|
136 |
let preference = Preference.sharedInstance
|
|
|
137 |
|
|
|
138 |
self.viewModel.fetch(slideUuid: notificationSlideUuid, userUuid: preference.userUuid)
|
|
|
139 |
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
.padding(.top, 5)
|
|
|
145 |
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
struct CardSlideView_Previews: PreviewProvider {
|
|
|
154 |
static var previews: some View {
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
CardSlideView(slideUuid: "S123", position : 0)
|
|
|
158 |
}
|
|
|
159 |
}
|