Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 17 | Ir a la última revisión | | Ultima modificación | Ver Log |

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