Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 1 | 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
//  CapsuleInProgressView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 7/27/22.
6
//
7
 
8
import SwiftUI
9
import HTMLEntities
10
 
11
struct MyCapsuleInProgressView: View {
12
 
13
    @EnvironmentObject var appNavigation : AppNavigation
14
    private var appData = AppData.sharedInstance
15
 
16
    @ObservedObject  private var viewModel = MyCapsulesInProgressViewModel()
17
    private var capsuleTitle : String = ""
18
 
19
    init(capsuleUuid: String)
20
    {
21
        viewModel.fetch()
22
 
23
        if viewModel.capsule.uuid.isEmpty {
24
            self.capsuleTitle = Config.LANG_MY_CAPSULES_INPROGRESS_NOT_AVAILABLE
25
        } else {
26
 
27
            if  viewModel.capsule.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
28
                self.capsuleTitle =  String(Array(viewModel.capsule.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
29
            }  else {
30
                self.capsuleTitle = viewModel.capsule.name
31
            }
32
 
33
 
34
        }
35
 
36
 
37
 
38
    }
39
 
40
    var body: some View {
41
        Group {
42
            HStack {
43
                VStack(spacing: 0) {
44
                    HStack {
45
 
46
 
47
 
48
                        Text(Config.LANG_MY_CAPSULES_INPROGRESS_TITLE)
49
                            .font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_MY_CAPSULES_INPROGRESS_TITLE))
50
                            .foregroundColor(Color("color_capsule_inprogress_foreground_title"))
51
 
52
                        Spacer()
53
                    }
54
                    .padding(.top, 16)
55
                    .padding(.leading, 16)
56
 
57
                    HStack {
58
                        Text(self.capsuleTitle)
59
                            .font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_MY_CAPSULES_INPROGRESS_CAPSULE_NAME))
60
                            .foregroundColor(Color("color_capsule_inprogress_foreground_capsule_name"))
61
 
62
                            .padding(.leading, 4)
63
                            .padding(.trailing, 4)
64
                        Spacer()
65
                    }
66
                    .padding(.top, 10)
67
                    .padding(.leading, 16)
68
 
69
                    HStack {
70
                        ProgressBar(
71
                            value: self.viewModel.capsule.progress,
72
                            maxValue: 100,
73
                            backgroundColor: Color("color_capsule_inprogress_progress_bar_background"),
74
                            foregroundColor: Color("color_capsule_inprogress_progress_bar_foreground")
75
 
76
                        )
77
                        .frame(height: 6)
78
                        .padding(10)
79
 
80
                        Text( String(format: "%.1f", self.viewModel.capsule.progress) + "%")
81
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_MY_CAPSULES_INPROGRESS_PROGRESS_LABEL ))
82
                            .foregroundColor(Color("color_capsule_inprogress_progress_label"))
83
                            .padding(5)
84
                    }
85
                    .padding(.leading, 10)
86
                    .padding(.trailing, 10)
87
 
88
                    Spacer()
89
 
90
                    if !self.viewModel.capsule.uuid.isEmpty {
91
 
92
                        HStack {
93
                            Button(action: {
94
                                self.appData.topicUuidActive = viewModel.capsule.topicUuid
95
                                self.appData.capsuleUuidActive = viewModel.capsule.uuid
96
                                self.appData.slideUuidActive = ""
97
                                self.appData.save()
98
 
99
                                withAnimation {
100
                                    appNavigation.subPageSource = .mycapsules
101
                                    appNavigation.subpageActive = .slides
102
                                }
103
 
104
 
105
                            }, label: {
106
                                Text(Config.LANG_MY_CAPSULES_INPROGRESS_BUTTON_CONTINUE)
107
                                    .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_MY_CAPSULES_INPROGRESS_BUTTON))
108
                                    .foregroundColor(Color("color_capsule_inprogress_button_foreground"))
109
                                    .padding(.vertical, 5)
110
                                    .padding(.horizontal, 10)
111
 
112
                            })
113
                            .background(Color("color_capsule_inprogress_button_background"))
114
                            .cornerRadius(3)
115
                            .overlay(
116
                                RoundedRectangle(cornerRadius: 3)
117
                                    .stroke(Color("color_capsule_inprogress_button_border"), lineWidth:1)
118
                            )
119
 
120
 
121
 
122
                            Spacer()
123
 
124
 
125
                        }
126
                        .padding(.leading, 16)
127
                        .padding(.bottom, 10)
128
                    }
129
 
130
 
131
                }
132
                Group {
19 efrain 133
                    if self.viewModel.capsule.image.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
1 efrain 134
 
135
 
136
                        Image(uiImage: UIImage(named: "logo") ?? UIImage())
137
                            .resizable()
138
                            .resizable()
139
                            .aspectRatio(contentMode: .fit)
140
 
141
 
142
 
143
                    } else {
144
                        CustomAsyncImage(
19 efrain 145
                            url: URL(string: self.viewModel.capsule.image.trimmingCharacters(in: .whitespacesAndNewlines))!,
1 efrain 146
                            placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
147
                            image: {
148
                                Image(uiImage: $0).resizable()
149
 
150
 
151
                            }
152
                        )
153
                    }
154
                } . frame(width: 93, height: 140, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
155
                    .background(Color("color_window_background"))
156
                    .padding(.top, 16)
157
                    .padding(.bottom, 16)
158
                    .padding(.trailing, 16)
159
 
160
            }
161
        }
162
        .frame(width: UIScreen.main.bounds.width - 32, height: 151)
163
        .background(Color("color_capsule_inprogress_background"))
164
        .cornerRadius(8)
165
        .overlay(
166
            RoundedRectangle(cornerRadius: 8)
167
                .stroke(Color("color_capsule_comment_rating_image_border"), lineWidth:1)
168
        )
169
        .shadow(color: Color("color_capsule_inprogress_shadow"), radius:4, x: 5, y: 5)
170
 
171
 
172
    }
173
}
174
 
175
struct MyCapsuleInProgressView_Previews: PreviewProvider {
176
    static var previews: some View {
177
        MyCapsuleInProgressView(capsuleUuid: "C123")
178
    }
179
}