Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 1 | Rev 11 | 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
    private let appData : AppData = AppData.sharedInstance
15
 
16
    private var viewModel : MyCapsulesListingItemView = MyCapsulesListingItemView()
17
    private let capsuleName : String
18
    private let capsuleDescription : String
8 efrain 19
 
1 efrain 20
 
21
    init (capsuleUuid : String) {
22
 
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
 
91
                            appData.topicUuidActive = self.viewModel.capsule.topicUuid
92
                            appData.capsuleUuidActive = self.viewModel.capsule.uuid
93
                            appData.slideUuidActive = ""
94
                            appData.subPageSource = AppData.SUB_PAGE_SOURCE_MY_CAPSULES
95
 
96
                            withAnimation {
8 efrain 97
                                appNavigation.subpageActive = .slides
1 efrain 98
                            }
99
 
100
 
101
                        }, label: {
102
                            Image(systemName: "arrowtriangle.right.fill")
103
                                .resizable()
104
                                .aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/)
105
                                .frame(width: 16, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
106
                        }).padding(.trailing, 10)
107
                        .foregroundColor(Color("color_capsule_list_item_title_foreground"))
108
                    }
109
                    HStack {
110
                        Text(self.capsuleDescription)
111
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
112
                            .foregroundColor(Color("color_capsule_list_item_description_foreground"))
113
 
114
 
115
                        Spacer()
116
                    }.padding(.top, 3)
117
 
118
 
119
                    HStack {
8 efrain 120
                        Text("\(self.viewModel.capsule.viewSlides)/\(self.viewModel.capsule.totalSlides)  \(Config.LANG_COMMON_SLIDES)")
1 efrain 121
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: 12))
122
                            .foregroundColor(Color("color_capsule_list_item_description_foreground"))
123
 
124
                        Spacer()
125
 
126
 
127
                    }.padding(.top, 3)
128
 
129
 
130
                    Button(action: {
8 efrain 131
 
132
 
133
                        appData.topicUuidActive = self.viewModel.capsule.topicUuid
134
                        appData.capsuleUuidActive = self.viewModel.capsule.uuid
135
                        appData.slideUuidActive = ""
136
                        appData.subPageSource = AppData.SUB_PAGE_SOURCE_MY_CAPSULES
137
                        appData.save()
138
 
1 efrain 139
                        appNavigation.subpageActive = .commentsandrating
140
 
141
                    }, label: {
142
 
143
                    HStack {
144
                        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@*/)
145
                            .padding(.leading, 8)
146
 
147
                        Spacer()
148
 
149
                        Text("\(self.viewModel.capsule.totalComments)")
150
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
151
                            .foregroundColor(Color("color_capsule_list_item_description_foreground"))
152
 
153
                        Image(systemName: "message")
154
                            .resizable()
155
                            .aspectRatio(contentMode: .fill)
156
                            .frame(width: 16, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
157
                            .padding(.trailing, 16)
158
                            .foregroundColor(Color("color_capsule_list_item_description_foreground"))
159
                    }
160
                    }).padding(.top, 3)
161
 
162
 
163
                }
164
 
165
 
166
            }
167
 
168
        }
169
 
170
 
171
        Divider()
172
        } .background(Color("color_capsule_list_item_background"))
173
        .padding(.leading, 5)
174
        .padding(.trailing, 5)
175
 
176
    }
177
}
178
 
179
struct MyCapsuleListItemView_Previews: PreviewProvider {
180
 
181
 
182
 
183
 
184
    static var previews: some View {
185
        MyCapsuleListItemView(capsuleUuid : "C123")
186
    }
187
}