Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 1 | Rev 9 | 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
    private let appData = AppData.sharedInstance
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
    {
24
        self.viewModel.fetch(slideUuid: slideUuid, userUuid: appData.userUuid)
25
        self.position = position
26
 
27
        if self.viewModel.slide.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
28
            self.viewModel.slide.name = String(Array(self.viewModel.slide.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
29
        }
30
 
31
 
32
    }
33
 
34
 
35
 
36
    var body: some View {
37
 
38
        Button(action: {
39
            appData.topicUuidActive = self.viewModel.slide.topicUuid
40
            appData.capsuleUuidActive = self.viewModel.slide.capsuleUuid
41
            appData.slideUuidActive = self.viewModel.slide.uuid
42
            appData.slidePositionInitial = self.position
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))
8 efrain 65
                    .foregroundColor(Color("color_textview_foreground"))
1 efrain 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
            .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_COMPLETED_SLIDE))
110
            { data in
111
                if data.userInfo != nil {
112
                    if let notificationSlideUuid = data.userInfo?["slideUuid"]! as? String {
113
                        if !notificationSlideUuid.isEmpty && notificationSlideUuid == self.viewModel.slide.uuid {
114
                            self.viewModel.fetchProgress(slideUuid: notificationSlideUuid, userUuid: appData.userUuid)
115
                        }
116
                    }
117
                }
118
            }
119
 
120
        } .padding(.top, 5)
121
    }
122
 
123
}
124
 
125
struct CardSlideView_Previews: PreviewProvider {
126
    static var previews: some View {
127
 
128
 
129
        CardSlideView(slideUuid: "S123", position : 0)
130
    }
131
}