Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 8 | 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
//  CardCapsuleView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 2/17/22.
6
//
7
 
8
import SwiftUI
9
 
10
struct CardCapsuleView: View {
11
 
8 efrain 12
 
13
 
9 efrain 14
    private let appDao = AppDao.sharedInstance
1 efrain 15
    private var capsuleTitle : String = ""
16
 
17
    @EnvironmentObject private var appNavigation : AppNavigation
18
    @ObservedObject private var viewModel = CapsuleCardViewModel()
19
 
20
    @State private var goToSlides : Bool = false
21
 
22
 
23
    init(capsuleUuid : String)
24
    {
25
        viewModel.fetch(capsuleUuid: capsuleUuid, userUuid: appData.userUuid)
26
 
27
        if viewModel.capsule.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
28
            capsuleTitle =  String(Array(viewModel.capsule.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
29
        } else {
30
            capsuleTitle = viewModel.capsule.name
31
        }
32
    }
33
 
34
    var body: some View {
35
 
36
        Button(action: {
37
 
38
            appData.topicUuidActive = self.viewModel.capsule.topicUuid
39
            appData.capsuleUuidActive = self.viewModel.capsule.uuid
40
            appData.slideUuidActive = ""
41
            appData.save()
42
 
43
            appNavigation.subpageActive = .slides
44
 
45
        }) {
46
            VStack {
47
                Text(self.capsuleTitle)
48
                .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_CARD_VIEW_TITLE))
8 efrain 49
                .foregroundColor(Color("color_textview_foreground"))
1 efrain 50
                .padding(.horizontal, 5)
51
                .padding(.top, 5)
52
                .multilineTextAlignment(/*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/)
53
 
54
                HStack {
55
                    if self.viewModel.capsule.image.isEmpty {
56
                        Image(uiImage: UIImage(named: "logo") ?? UIImage())
57
                            .resizable()
58
                            .aspectRatio(contentMode: .fit)
59
                    } else {
60
                        CustomAsyncImage(
61
                            url: URL(string: self.viewModel.capsule.image)!,
62
                            placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
63
                            image: {
64
                                Image(uiImage: $0).resizable()
65
                            }
66
                        )
67
                    }
68
                }.padding(.horizontal, 5)
69
 
70
 
71
                Spacer()
72
 
73
                Group() {
74
                    HStack {
75
                        ProgressBar(
76
                            value: self.viewModel.capsule.progress,
77
                            maxValue: 100,
78
                            backgroundColor: Color("color_card_view_progress_background"),
79
                            foregroundColor: Color("color_card_view_progress_foreground")
80
 
81
                        )
82
                        .frame(height: 6)
83
                        .padding(10)
84
 
85
                        Text( String(format: "%.1f", self.viewModel.capsule.progress) + "%")
86
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_CARD_VIEW_FOOTER ))
8 efrain 87
                            .foregroundColor(Color("color_textview_foreground"))
1 efrain 88
                            .padding(5)
89
                    }
90
                }
91
                .background(Color("color_card_view_background_footer"))
92
 
93
            }
94
            .background(Color("color_card_view_background"))
95
            .cornerRadius(16)
96
            .overlay(
97
                RoundedRectangle(cornerRadius: 16)
98
                    .stroke(Color("color_card_view_border"), lineWidth:1)
99
            )
100
            .padding(.horizontal, 5)
101
        }
102
        /*.onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_CAPSULE))
103
        { data in
104
            if data.userInfo != nil {
105
                if let capsuleUuid = data.userInfo?["capsuleUuid"]! as? String {
106
                    if !capsuleUuid.isEmpty && capsuleUuid == self.viewModel.capsule.uuid {
107
 
108
                        self.viewModel.fetchProgress(capsuleUuid: capsuleUuid, userUuid: appData.userUuid)
109
 
110
                    }
111
                }
112
            }
113
        }*/
114
        .padding(.top, 5)
115
    }
116
 
117
 
118
 
119
 
120
 
121
}
122
 
123
struct CardCapsuleView_Previews: PreviewProvider {
124
    static var previews: some View {
125
       CardCapsuleView(capsuleUuid: "C123")
126
    }
127
}
128
 
129