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