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
//  CardSlideView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 2/17/22.
6
//
7
 
8
import SwiftUI
9
 
10
struct CardSlideView: View {
11
 
12
 
13
 
14 efrain 14
 
1 efrain 15
 
14 efrain 16
 
17
    private let userUuid : String
18
    private let positionInitial : Int
1 efrain 19
    private var viewModel = SlideCardViewModel()
20
 
21
    @EnvironmentObject private var appNavigation : AppNavigation
14 efrain 22
 
1 efrain 23
 
24
    init(slideUuid : String, position : Int)
25
    {
14 efrain 26
        let appDao = AppDao.sharedInstance
11 efrain 27
        let appData = appDao.selectOne()
1 efrain 28
 
14 efrain 29
        positionInitial = position
30
        userUuid = appData.userUuid
31
 
32
        viewModel.fetch(slideUuid: slideUuid, userUuid: userUuid)
33
 
34
 
1 efrain 35
        if self.viewModel.slide.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
36
            self.viewModel.slide.name = String(Array(self.viewModel.slide.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
37
        }
38
 
39
 
40
    }
41
 
42
 
43
 
44
    var body: some View {
45
 
46
        Button(action: {
14 efrain 47
            let appDao = AppDao.sharedInstance
11 efrain 48
            var appData = appDao.selectOne()
1 efrain 49
            appData.topicUuidActive = self.viewModel.slide.topicUuid
50
            appData.capsuleUuidActive = self.viewModel.slide.capsuleUuid
51
            appData.slideUuidActive = self.viewModel.slide.uuid
14 efrain 52
            appData.slidePositionInitial = self.positionInitial
11 efrain 53
 
54
            print("update query : 9")
55
            appDao.update(model: appData)
1 efrain 56
 
57
            appNavigation.subpageActive = .gallery
58
 
59
        }) {
60
 
61
 
62
            ZStack {
63
                if self.viewModel.slide.completed == 1 {
64
                    Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage())
65
                        /*
66
                        .alignmentGuide(.top, computeValue: { dimension in
67
                                           10
68
                    })*/
69
                    .offset(x: (Constants.CARD_WIDTH - 40) / 2, y: (-1 * ((Constants.CARD_HEIGHT - 50) / 2)))
70
                    .zIndex(10000)
71
                    .scaleEffect(0.8)
72
                }
73
 
74
                VStack {
75
                    Text( self.viewModel.slide.name)
76
                    .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_CARD_VIEW_TITLE))
8 efrain 77
                    .foregroundColor(Color("color_textview_foreground"))
1 efrain 78
                    .padding(.horizontal, 5)
79
                    .padding(.top, 5)
80
                    .multilineTextAlignment(/*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/)
81
 
82
                    Spacer()
83
 
84
                    HStack {
85
 
86
                        if viewModel.slide.background.isEmpty && viewModel.slide.file.isEmpty {
87
                            Image(uiImage: UIImage(named: "logo") ?? UIImage())
88
                            .resizable()
89
                            .aspectRatio(contentMode: .fit)
90
                        } else {
91
                            CustomAsyncImage(
92
                                url: URL(
93
                                    string:
94
                                        self.viewModel.slide.type == Constants.SLIDE_TYPE_IMAGE ?  self.viewModel.slide.file :  self.viewModel.slide.background)!,
95
                                placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
96
                                image: {
97
                                    Image(uiImage: $0).resizable()
98
                                }
99
                            )
100
                        }
101
                    }.padding(.horizontal, 5)
102
                    //.zIndex(500)
103
 
104
                    Spacer()
105
                    Group() {
106
                        HStack {
107
                            Spacer()
108
                        }
109
                    }
110
                    .background(Color("color_window_background"))
111
 
112
                }
113
                .background(Color("color_card_view_background"))
114
                .cornerRadius(16)
115
                .overlay(
116
                    RoundedRectangle(cornerRadius: 16)
117
                        .stroke(Color("color_card_view_border"), lineWidth: 1)
118
                )
119
                .padding(.horizontal, 5)
120
            }
14 efrain 121
            .onAppear {
122
                self.viewModel.fetchProgress(slideUuid: self.viewModel.slide.uuid, userUuid: self.userUuid)
123
            }
124
            /*
1 efrain 125
            .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_COMPLETED_SLIDE))
126
            { data in
11 efrain 127
                let appData = appDao.selectOne()
1 efrain 128
                if data.userInfo != nil {
129
                    if let notificationSlideUuid = data.userInfo?["slideUuid"]! as? String {
130
                        if !notificationSlideUuid.isEmpty && notificationSlideUuid == self.viewModel.slide.uuid {
131
                            self.viewModel.fetchProgress(slideUuid: notificationSlideUuid, userUuid: appData.userUuid)
132
                        }
133
                    }
134
                }
14 efrain 135
            }*/
1 efrain 136
 
137
        } .padding(.top, 5)
138
    }
139
 
140
}
141
 
142
struct CardSlideView_Previews: PreviewProvider {
143
    static var previews: some View {
144
 
145
 
146
        CardSlideView(slideUuid: "S123", position : 0)
147
    }
148
}