Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 1 | Rev 19 | Ir a la última revisión | | Comparar con el anterior | 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)
17 efrain 77
                    .cornerRadius(5)
78
                    .padding(.horizontal, 5)
79
                    .padding(5)
1 efrain 80
 
81
 
82
 
83
                VStack(spacing: 0)
84
                {
85
                    HStack {
86
                        Text(self.capsuleName)
87
                            .font(Font.custom(Config.FONT_NAME_BOLD, size: 14))
88
                            .foregroundColor(Color("color_capsule_list_item_title_foreground"))
89
 
90
                        Spacer()
91
 
17 efrain 92
                        /*
1 efrain 93
                        Button(action: {
94
                            appData.topicUuidActive = self.viewModel.capsule.topicUuid
95
                            appData.capsuleUuidActive = self.viewModel.capsule.uuid
96
                            appData.slideUuidActive = ""
97
                            appData.save()
98
 
99
                            appNavigation.subPageSource = .mycapsules
100
 
101
                            withAnimation {
102
                                appNavigation.subpageActive = .slides
103
                            }
104
 
105
 
106
                        }, label: {
107
                            Image(systemName: "arrowtriangle.right.fill")
108
                                .resizable()
109
                                .aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/)
110
                                .frame(width: 16, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
111
                        }).padding(.trailing, 10)
112
                        .foregroundColor(Color("color_capsule_list_item_title_foreground"))
17 efrain 113
                         */
114
                    }.padding(.top, 10)
115
 
1 efrain 116
                    HStack {
117
                        Text(self.capsuleDescription)
17 efrain 118
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: 14))
1 efrain 119
                            .foregroundColor(Color("color_capsule_list_item_description_foreground"))
120
 
121
 
122
                        Spacer()
17 efrain 123
                    }.padding(.top, 5)
1 efrain 124
 
17 efrain 125
                    Spacer()
1 efrain 126
 
17 efrain 127
 
1 efrain 128
                    HStack {
17 efrain 129
                        //Spacer()
1 efrain 130
                        Text("\(self.viewModel.capsule.viewSlides)/\(self.viewModel.capsule.totalSlides)  \(Config.LANG_COMMON_SLIDES)")
131
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: 12))
132
                            .foregroundColor(Color("color_capsule_list_item_description_foreground"))
133
 
17 efrain 134
                        Spacer();
1 efrain 135
 
136
 
137
                    }.padding(.top, 3)
17 efrain 138
                        .padding(.trailing, 5)
139
 
140
                    HStack {
141
                        //Spacer()
142
 
143
                        FiveStarView(rating: self.viewModel.capsule.totalRating, color: Color("color_capsule_list_item_star_foreground"), backgroundColor: Color("color_capsule_list_item_star_background"))
144
                            .frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
145
 
146
                        Spacer()
147
 
148
                    }
149
                        .padding(.top, 3)
150
                        .padding(.bottom, 5)
151
                        .padding(.leading, 5)
152
                        .padding(.trailing, 10)
1 efrain 153
 
154
 
17 efrain 155
                    /*
1 efrain 156
                    Button(action: {
157
                        appData.topicUuidActive = self.viewModel.capsule.topicUuid
158
                        appData.capsuleUuidActive = self.viewModel.capsule.uuid
159
                        appData.slideUuidActive = ""
160
                        appData.save()
161
 
162
                        appNavigation.subPageSource = .mycapsules
163
                        appNavigation.subpageActive = .commentsandrating
164
 
165
                    }, label: {
166
 
167
                    HStack {
168
                        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@*/)
169
                            .padding(.leading, 8)
170
 
171
                        Spacer()
172
 
173
                        Text("\(self.viewModel.capsule.totalComments)")
174
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
175
                            .foregroundColor(Color("color_capsule_list_item_description_foreground"))
176
 
177
                        Image(systemName: "message")
178
                            .resizable()
179
                            .aspectRatio(contentMode: .fill)
180
                            .frame(width: 16, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
181
                            .padding(.trailing, 16)
182
                            .foregroundColor(Color("color_capsule_list_item_description_foreground"))
183
                    }
17 efrain 184
                    }).padding(.top, 3)*/
1 efrain 185
 
17 efrain 186
                    //Spacer()
1 efrain 187
                }
17 efrain 188
 
1 efrain 189
            }
190
 
191
        }
192
 
193
 
194
        Divider()
195
        } .background(Color("color_capsule_list_item_background"))
196
        .padding(.leading, 5)
197
        .padding(.trailing, 5)
198
 
199
    }
200
}
201
 
202
struct MyCapsuleListItemView_Previews: PreviewProvider {
203
 
204
 
205
 
206
 
207
    static var previews: some View {
208
        MyCapsuleListItemView(capsuleUuid : "C123")
209
    }
210
}