| 1 |
efrain |
1 |
//
|
|
|
2 |
// MyCapsuleListingView.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 7/27/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import Foundation
|
|
|
9 |
import SwiftUI
|
|
|
10 |
import HTMLEntities
|
|
|
11 |
|
|
|
12 |
struct MyCapsuleListItemView: View {
|
|
|
13 |
@EnvironmentObject var appNavigation : AppNavigation
|
|
|
14 |
private let appData : AppData = AppData.sharedInstance
|
|
|
15 |
|
|
|
16 |
private var viewModel : MyCapsulesListingItemView = MyCapsulesListingItemView()
|
|
|
17 |
private let capsuleName : String
|
|
|
18 |
private let capsuleDescription : String
|
|
|
19 |
|
|
|
20 |
init (capsuleUuid : String) {
|
|
|
21 |
|
|
|
22 |
self.viewModel.fetch(capsuleUuid: capsuleUuid, userUuid: appData.userUuid)
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
if self.viewModel.capsule.name.count > Constants.MYCAPSULE_TITLE_MAX_LENGTH {
|
|
|
26 |
self.capsuleName = String(Array(self.viewModel.capsule.name)[0...Constants.MYCAPSULE_TITLE_MAX_LENGTH]) + "..."
|
|
|
27 |
} else {
|
|
|
28 |
self.capsuleName = self.viewModel.capsule.name
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
let textHtml = self.viewModel.capsule.description.htmlUnescape()
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
let regex = "<.*?>"
|
|
|
36 |
let repl = ""
|
|
|
37 |
let s = textHtml.replacingOccurrences(of: regex, with: repl, options: [.regularExpression])
|
|
|
38 |
if s.count > Constants.MYCAPSULE_DESCRIPTION_MAX_LENGTH {
|
|
|
39 |
self.capsuleDescription = String(Array(s)[0...Constants.MYCAPSULE_DESCRIPTION_MAX_LENGTH]) + "..."
|
|
|
40 |
} else {
|
|
|
41 |
self.capsuleDescription = s
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
var body: some View {
|
|
|
49 |
VStack(spacing: 0 ) {
|
|
|
50 |
Group {
|
|
|
51 |
HStack {
|
|
|
52 |
Group {
|
|
|
53 |
|
|
|
54 |
if self.viewModel.capsule.image.isEmpty {
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
Image(uiImage: UIImage(named: "logo") ?? UIImage())
|
|
|
58 |
.resizable()
|
|
|
59 |
.resizable()
|
|
|
60 |
.aspectRatio(contentMode: .fit)
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
} else {
|
|
|
65 |
CustomAsyncImage(
|
|
|
66 |
url: URL(string: self.viewModel.capsule.image)!,
|
|
|
67 |
placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
|
|
|
68 |
image: {
|
|
|
69 |
Image(uiImage: $0).resizable()
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
}
|
|
|
73 |
)
|
|
|
74 |
}
|
|
|
75 |
} .frame(width: 64, height:97, alignment: .center)
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
VStack(spacing: 0)
|
|
|
80 |
{
|
|
|
81 |
HStack {
|
|
|
82 |
Text(self.capsuleName)
|
|
|
83 |
.font(Font.custom(Config.FONT_NAME_BOLD, size: 14))
|
|
|
84 |
.foregroundColor(Color("color_capsule_list_item_title_foreground"))
|
|
|
85 |
|
|
|
86 |
Spacer()
|
|
|
87 |
|
|
|
88 |
Button(action: {
|
|
|
89 |
|
|
|
90 |
appData.topicUuidActive = self.viewModel.capsule.topicUuid
|
|
|
91 |
appData.capsuleUuidActive = self.viewModel.capsule.uuid
|
|
|
92 |
appData.slideUuidActive = ""
|
|
|
93 |
appData.subPageSource = AppData.SUB_PAGE_SOURCE_MY_CAPSULES
|
|
|
94 |
|
|
|
95 |
withAnimation {
|
|
|
96 |
appNavigation.subpageActive = .capsules
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
}, label: {
|
|
|
101 |
Image(systemName: "arrowtriangle.right.fill")
|
|
|
102 |
.resizable()
|
|
|
103 |
.aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/)
|
|
|
104 |
.frame(width: 16, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
|
|
105 |
}).padding(.trailing, 10)
|
|
|
106 |
.foregroundColor(Color("color_capsule_list_item_title_foreground"))
|
|
|
107 |
}
|
|
|
108 |
HStack {
|
|
|
109 |
Text(self.capsuleDescription)
|
|
|
110 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
|
|
|
111 |
.foregroundColor(Color("color_capsule_list_item_description_foreground"))
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
Spacer()
|
|
|
115 |
}.padding(.top, 3)
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
HStack {
|
|
|
119 |
Text("\(self.viewModel.capsule.viewSlides)/\(self.viewModel.capsule.totalSlides) Diapositivas")
|
|
|
120 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 12))
|
|
|
121 |
.foregroundColor(Color("color_capsule_list_item_description_foreground"))
|
|
|
122 |
|
|
|
123 |
Spacer()
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
}.padding(.top, 3)
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
Button(action: {
|
|
|
130 |
appNavigation.subpageActive = .commentsandrating
|
|
|
131 |
|
|
|
132 |
}, label: {
|
|
|
133 |
|
|
|
134 |
HStack {
|
|
|
135 |
FiveStarView(rating: self.viewModel.capsule.totalRating, color: Color("color_capsule_list_item_star_foreground"), backgroundColor: Color("color_capsule_list_item_star_background")) .frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
|
|
136 |
.padding(.leading, 8)
|
|
|
137 |
|
|
|
138 |
Spacer()
|
|
|
139 |
|
|
|
140 |
Text("\(self.viewModel.capsule.totalComments)")
|
|
|
141 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
|
|
|
142 |
.foregroundColor(Color("color_capsule_list_item_description_foreground"))
|
|
|
143 |
|
|
|
144 |
Image(systemName: "message")
|
|
|
145 |
.resizable()
|
|
|
146 |
.aspectRatio(contentMode: .fill)
|
|
|
147 |
.frame(width: 16, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
|
|
148 |
.padding(.trailing, 16)
|
|
|
149 |
.foregroundColor(Color("color_capsule_list_item_description_foreground"))
|
|
|
150 |
}
|
|
|
151 |
}).padding(.top, 3)
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
Divider()
|
|
|
163 |
} .background(Color("color_capsule_list_item_background"))
|
|
|
164 |
.padding(.leading, 5)
|
|
|
165 |
.padding(.trailing, 5)
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
struct MyCapsuleListItemView_Previews: PreviewProvider {
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
static var previews: some View {
|
|
|
176 |
MyCapsuleListItemView(capsuleUuid : "C123")
|
|
|
177 |
}
|
|
|
178 |
}
|