Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 11 | Rev 17 | 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
//  CardTopicView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 1/26/22.
6
//
7
 
8
import SwiftUI
9
 
10
struct CardTopicView: View
11
{
12
    @EnvironmentObject private var appNavigation : AppNavigation
13
    @ObservedObject private var viewModel = TopicCardViewModel()
14
 
15
 
14 efrain 16
 
1 efrain 17
    private var topicName : String = ""
18
    private var preview : Bool = false
19
 
20
 
14 efrain 21
    private let userUuid : String
22
 
1 efrain 23
 
14 efrain 24
    init(topicUuid : String)
1 efrain 25
    {
14 efrain 26
        let appDao = AppDao.sharedInstance
11 efrain 27
        let appData = appDao.selectOne()
14 efrain 28
        userUuid = appData.userUuid
1 efrain 29
 
14 efrain 30
        self.viewModel.fetch(topicUuid: topicUuid, userUuid: userUuid)
1 efrain 31
        if viewModel.topic.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
32
            topicName = String(Array(viewModel.topic.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
33
        } else {
34
            topicName = viewModel.topic.name
35
        }
36
    }
37
 
38
    var body: some View {
39
 
40
        Button(action: {
14 efrain 41
            let appDao = AppDao.sharedInstance
11 efrain 42
            var appData = appDao.selectOne()
14 efrain 43
 
1 efrain 44
            appData.topicUuidActive = self.viewModel.topic.uuid
45
            appData.capsuleUuidActive = ""
46
            appData.slideUuidActive = ""
47
 
11 efrain 48
            print("update query : 4")
14 efrain 49
 
11 efrain 50
            appDao.update(model: appData)
51
 
1 efrain 52
 
11 efrain 53
            appNavigation.subPageSource = .topics
1 efrain 54
            appNavigation.subpageActive = .capsules
55
 
56
 
57
        }) {
58
 
59
            VStack(spacing: 0) {
60
 
61
                Text(self.topicName)
62
                .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_CARD_VIEW_TITLE))
8 efrain 63
                .foregroundColor(Color("color_textview_foreground"))
1 efrain 64
                .padding(.horizontal, 5)
65
                .padding(.top, 5)
66
                .multilineTextAlignment(/*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/)
67
 
68
                Spacer()
69
 
70
 
71
                CardTopicImageGroup(requestImage: preview ? "": self.viewModel.topic.image )
72
                .padding(.horizontal, 5)
73
 
74
                Spacer()
75
 
76
                Group() {
77
                    HStack {
78
                        ProgressBar(
79
                            value: self.viewModel.topic.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.topic.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)
14 efrain 104
        }.onAppear {
105
            self.viewModel.fetchProgress(topicUuid: self.viewModel.topic.uuid, userUuid: self.userUuid)
106
 
107
        }
108
        /*
109
        .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_TOPIC))
1 efrain 110
        { data in
11 efrain 111
            let appData =  appDao.selectOne()
1 efrain 112
            if data.userInfo != nil {
113
                if let topicUuid = data.userInfo?["topicUuid"]! as? String {
114
                    if !topicUuid.isEmpty && topicUuid == self.viewModel.topic.uuid {
115
                        self.viewModel.fetchProgress(topicUuid: topicUuid, userUuid: appData.userUuid)
116
 
117
                    }
118
                }
119
            }
14 efrain 120
        }*/
121
        .padding(.top, 5)
1 efrain 122
    }
123
}
124
 
125
 
126
 
127
struct CardTopicView_Previews: PreviewProvider {
128
    static var previews: some View {
129
 
14 efrain 130
        CardTopicView(topicUuid: "T123")
1 efrain 131
    }
132
}
133
 
134
struct CardTopicImageGroup : View {
135
 
136
    var requestImage : String
137
 
138
    var body: some View {
139
        HStack {
140
            if requestImage.isEmpty {
141
 
142
 
143
                Image(uiImage: UIImage(named: "logo") ?? UIImage())
144
                    .resizable()
145
                    .aspectRatio(contentMode: .fit)
146
 
147
 
148
            } else {
149
                CustomAsyncImage(
150
                    url: URL(string: requestImage)!,
151
                    placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
152
                    image: {
153
                        Image(uiImage: $0).resizable()
154
                    }
155
                )
156
            }
157
        }
158
    }
159
}
160