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 |
private let userUuid : String
|
|
|
13 |
private let positionInitial : Int
|
|
|
14 |
private var viewModel = SlideCardViewModel()
|
21 |
efrain |
15 |
private var appData = Environment(\.appData).wrappedValue
|
1 |
efrain |
16 |
|
|
|
17 |
@EnvironmentObject private var appNavigation : AppNavigation
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
init(slideUuid : String, position : Int)
|
|
|
21 |
{
|
|
|
22 |
positionInitial = position
|
|
|
23 |
userUuid = appData.userUuid
|
|
|
24 |
|
|
|
25 |
viewModel.fetch(slideUuid: slideUuid, userUuid: userUuid)
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
if self.viewModel.slide.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
|
|
|
29 |
self.viewModel.slide.name = String(Array(self.viewModel.slide.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
var body: some View {
|
|
|
38 |
|
|
|
39 |
Button(action: {
|
|
|
40 |
appData.topicUuidActive = self.viewModel.slide.topicUuid
|
|
|
41 |
appData.capsuleUuidActive = self.viewModel.slide.capsuleUuid
|
|
|
42 |
appData.slideUuidActive = self.viewModel.slide.uuid
|
|
|
43 |
appData.save()
|
|
|
44 |
|
|
|
45 |
appNavigation.subpageActive = .gallery
|
|
|
46 |
|
|
|
47 |
}) {
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
ZStack {
|
|
|
51 |
if self.viewModel.slide.completed == 1 {
|
|
|
52 |
Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage())
|
|
|
53 |
/*
|
|
|
54 |
.alignmentGuide(.top, computeValue: { dimension in
|
|
|
55 |
10
|
|
|
56 |
})*/
|
|
|
57 |
.offset(x: (Constants.CARD_WIDTH - 40) / 2, y: (-1 * ((Constants.CARD_HEIGHT - 50) / 2)))
|
|
|
58 |
.zIndex(10000)
|
|
|
59 |
.scaleEffect(0.8)
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
VStack {
|
|
|
63 |
Text( self.viewModel.slide.name)
|
|
|
64 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_CARD_VIEW_TITLE))
|
|
|
65 |
.foregroundColor(Color("color_textview_foreground"))
|
|
|
66 |
.padding(.horizontal, 5)
|
|
|
67 |
.padding(.top, 5)
|
|
|
68 |
.multilineTextAlignment(/*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/)
|
|
|
69 |
|
|
|
70 |
Spacer()
|
|
|
71 |
|
|
|
72 |
HStack {
|
|
|
73 |
|
19 |
efrain |
74 |
if viewModel.slide.background.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && viewModel.slide.file.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
1 |
efrain |
75 |
Image(uiImage: UIImage(named: "logo") ?? UIImage())
|
|
|
76 |
.resizable()
|
|
|
77 |
.aspectRatio(contentMode: .fit)
|
|
|
78 |
} else {
|
|
|
79 |
CustomAsyncImage(
|
|
|
80 |
url: URL(
|
|
|
81 |
string:
|
19 |
efrain |
82 |
self.viewModel.slide.type == Constants.SLIDE_TYPE_IMAGE ?
|
|
|
83 |
self.viewModel.slide.file.trimmingCharacters(in: .whitespacesAndNewlines) :
|
|
|
84 |
self.viewModel.slide.background.trimmingCharacters(in: .whitespacesAndNewlines))!,
|
1 |
efrain |
85 |
placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
|
|
|
86 |
image: {
|
|
|
87 |
Image(uiImage: $0).resizable()
|
|
|
88 |
}
|
|
|
89 |
)
|
|
|
90 |
}
|
|
|
91 |
}.padding(.horizontal, 5)
|
|
|
92 |
//.zIndex(500)
|
|
|
93 |
|
|
|
94 |
Spacer()
|
|
|
95 |
Group() {
|
|
|
96 |
HStack {
|
|
|
97 |
Spacer()
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
.background(Color("color_window_background"))
|
|
|
101 |
|
|
|
102 |
}
|
|
|
103 |
.background(Color("color_card_view_background"))
|
|
|
104 |
.cornerRadius(16)
|
|
|
105 |
.overlay(
|
|
|
106 |
RoundedRectangle(cornerRadius: 16)
|
|
|
107 |
.stroke(Color("color_card_view_border"), lineWidth: 1)
|
|
|
108 |
)
|
|
|
109 |
.padding(.horizontal, 5)
|
|
|
110 |
}
|
|
|
111 |
.onAppear {
|
|
|
112 |
self.viewModel.fetchProgress(slideUuid: self.viewModel.slide.uuid, userUuid: self.userUuid)
|
|
|
113 |
}.onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_COMPLETED_SLIDE))
|
|
|
114 |
{ data in
|
|
|
115 |
if data.userInfo != nil {
|
|
|
116 |
if let notificationSlideUuid = data.userInfo?["slideUuid"]! as? String {
|
|
|
117 |
if !notificationSlideUuid.isEmpty && notificationSlideUuid == self.viewModel.slide.uuid {
|
|
|
118 |
self.viewModel.fetchProgress(slideUuid: notificationSlideUuid, userUuid: appData.userUuid)
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
} .padding(.top, 5)
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
struct CardSlideView_Previews: PreviewProvider {
|
|
|
131 |
static var previews: some View {
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
CardSlideView(slideUuid: "S123", position : 0)
|
|
|
135 |
}
|
|
|
136 |
}
|