Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

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