Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

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